38 #include <Rcs_typedef.h> 39 #include <Rcs_macros.h> 40 #include <Rcs_VecNd.h> 41 #include <Rcs_basicMath.h> 43 #ifdef GRAPHICS_AVAILABLE 45 #include <RcsViewer.h> 47 #include <GraphNode.h> 48 #include <PhysicsNode.h> 49 #include <KeyCatcher.h> 66 unsigned int numPosCtrlJoints = 0;
68 if (JNT->jacobiIndex != -1) {
69 if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_POSITION) {
134 std::unique_lock<std::mutex> lock(
graphLock);
139 MatNd_setZero(SENSOR->rawData);
154 #ifdef GRAPHICS_AVAILABLE 157 viewer->removeInternal(
"PhysicsNode");
167 #ifdef GRAPHICS_AVAILABLE 171 Rcs::PhysicsNode* pNode =
new Rcs::PhysicsNode(
physicsSim,
true);
173 pNode->physicsNd->togglePhysicsModel();
174 pNode->physicsNd->toggleGraphicsModel();
205 std::cout <<
"--------------------------------------------------" << std::endl;
206 std::cout <<
"Simulation Step " <<
currentStep << std::endl;
207 std::cout <<
"--------------------------------------------------" << std::endl;
212 if (!
actionSpace()->checkDimension(action, &iaMsg)) {
213 throw std::invalid_argument(
"Invalid action - " + iaMsg);
220 std::unique_lock<std::mutex> lock(
graphLock);
228 std::ostringstream jvMsg;
229 unsigned int numJV = 0;
232 if (JNT->constrained) {
236 double qi = MatNd_get2(
q_ctrl, JNT->jointIndex, 0);
237 if ((qi < JNT->q_min) || (qi > JNT->q_max)) {
239 jvMsg <<
" " << JNT->name <<
": " << qi <<
" [" << JNT->q_min <<
", " << JNT->q_max <<
"[" 244 std::ostringstream os;
245 os <<
"Detected " << numJV <<
" joint limit violations: " << std::endl << jvMsg.str();
250 if (disturbance !=
nullptr &&
disturber !=
nullptr) {
252 if (disturbance->m != 3 || disturbance->n != 1) {
253 throw std::invalid_argument(
"Invalid disturbance");
298 MatNd_destroy(noise);
318 physicsSim->applyLinearVelocity(BODY, BODY->x_dot);
319 physicsSim->applyAngularVelocity(BODY, BODY->omega);
351 #ifdef GRAPHICS_AVAILABLE 360 else if (mode ==
"human") {
364 viewer =
new Rcs::Viewer(
true,
false);
365 auto kc =
new Rcs::KeyCatcher();
370 if (amIK !=
nullptr) {
372 Rcs::GraphNode* gDesNode =
new Rcs::GraphNode(amIK->getController()->getGraph(),
true,
false);
373 gDesNode->setGhostMode(
true);
377 Rcs::PhysicsNode* pNode =
new Rcs::PhysicsNode(
physicsSim,
true);
379 pNode->physicsNd->togglePhysicsModel();
380 pNode->physicsNd->toggleGraphicsModel();
383 Rcs::GraphNode* gNode =
new Rcs::GraphNode(
config->
graph,
true,
false);
384 gNode->toggleReferenceFrames();
388 hud =
new Rcs::HUD();
390 std::string hudColor;
392 hud->setColor(hudColor.c_str());
394 hud->resize(1024, 100);
396 viewer->setWindowSize(0, 0, 1024, 768);
397 viewer->setUpdateFrequency(50.0);
400 viewer->setBackgroundColor(
"PEWTER");
412 hud->setText(hudText);
416 static bool warned =
false;
420 RMSGS(
"RcsPySim compiled in headless mode, therefore rendering is not available!");
427 #ifdef GRAPHICS_AVAILABLE 432 RPAUSE_MSG(
"Please move the graphics window so the window position is initialized properly." 433 "Press ENTER to continue.");
435 viewer->toggleVideoRecording();
438 static bool warned =
false;
441 RMSGS(
"RcsPySim compiled in headless mode, therefore rendering not available!");
472 if (tnb ==
nullptr) {
478 throw std::invalid_argument(
"Transition noise dimension must match internal state dimension");
virtual bool getProperty(std::string &out, const char *property)=0
void setTransitionNoiseBuffer(const MatNd *tnb)
virtual bool getPropertyBool(const char *property, bool def=false)=0
MatNd * createValueMatrix() const
unsigned int getInternalStateDim()
virtual void render(std::string mode="human", bool close=false)
virtual MatNd * reset(PropertySource *domainParam=PropertySource::empty(), const MatNd *initState=NULL)
const BoxSpace * actionSpace()
PhysicsBase * createSimulator(PropertySource *values)
virtual void initViewer(Rcs::Viewer *viewer)
const BoxSpace * observationSpace()
unsigned int currentStep
Counters.
Viewer * viewer
Visualization.
const BoxSpace * getSpace() const
virtual ForceDisturber * createForceDisturber()
bool checkJointLimits
Flag to enable joint limit checking.
double dt
The time step [s].
MatNd * currentObservation
Observation and action at last step.
RcsSimEnv(PropertySource *propertySource)
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)=0
void toggleVideoRecording()
MatNd * computeObservation(const MatNd *currentAction, double dt) const
virtual void applyInitialState(const MatNd *initialState)=0
PhysicsParameterManager * physicsManager
Physics simulator factory.
virtual InitStateSetter * createInitStateSetter()
ForceDisturber * disturber
Disturbance force simulator.
PhysicsBase * physicsSim
Physics simulator.
MatNd * q_ctrl
Temporary matrices.
static ExperimentConfig * create(PropertySource *properties)
ObservationModel * observationModel
Observation model (pluggable) used to create the observation which will be returned from step() ...
PropertySource * properties
Property source (owned)
virtual void getHUDText(std::vector< std::string > &linesOut, double currentTime, const MatNd *currentObservation, const MatNd *currentAction, PhysicsBase *simulator, PhysicsParameterManager *physicsManager, ForceDisturber *forceDisturber)
MatNd * transitionNoiseBuffer
Transition noise values (every column is one set of noise values for every state variable) ...
const AM * unwrap() const
bool transitionNoiseIncludeVelocity
InitStateSetter * initStateSetter
Initial state setter.
ExperimentConfig * config
Experiment configuration.
void apply(Rcs::PhysicsBase *sim, double force[3])
ActionModel * actionModel
Action model (pluggable)
virtual MatNd * step(const MatNd *action, const MatNd *disturbance=NULL)
std::mutex graphLock
Guards for parallel access to graph (can happen from gui)
RcsGraph * graph
Graph description.
const BoxSpace * initStateSpace()
PhysicsParameterManager * createPhysicsParameterManager()