diff --git a/entity_generation/smurf/src/smurf.cpp b/entity_generation/smurf/src/smurf.cpp index 339dd3bde..8c2f6db42 100644 --- a/entity_generation/smurf/src/smurf.cpp +++ b/entity_generation/smurf/src/smurf.cpp @@ -949,18 +949,15 @@ namespace mars { if (!loadGraphic(graphicList[i])) return 0; - setPose(); - - control->nodes->printNodeMasses(true); - - return 1; - } - - void SMURF::setPose() { + // set model pose ConfigMap map; map["rootNode"] = model->root_link_->name; entity->appendConfig(map); entity->setInitialPose(); + + control->nodes->printNodeMasses(true); + + return 1; } unsigned int SMURF::loadNode(ConfigMap config) { diff --git a/entity_generation/smurf/src/smurf.h b/entity_generation/smurf/src/smurf.h index c73be7f65..efdd0b5e1 100644 --- a/entity_generation/smurf/src/smurf.h +++ b/entity_generation/smurf/src/smurf.h @@ -139,7 +139,6 @@ namespace mars { void poseToVectorAndQuaternion(const urdf::Pose &pose, utils::Vector *v, utils::Quaternion *q); bool isEqualPos(const urdf::Pose &p1, const urdf::Pose p2); bool isNullPos(const urdf::Pose &p); - void setPose(); // load functions unsigned int loadMaterial(configmaps::ConfigMap config); diff --git a/sim/src/core/EntityManager.cpp b/sim/src/core/EntityManager.cpp index b68157da4..12aed8aad 100644 --- a/sim/src/core/EntityManager.cpp +++ b/sim/src/core/EntityManager.cpp @@ -231,7 +231,7 @@ namespace mars { void EntityManager::resetPose() { std::map::iterator iter = entities.begin(); for (; iter != entities.end(); ++iter) { - iter->second->setInitialPose(); + iter->second->setInitialPose(true); } } diff --git a/sim/src/core/SimEntity.cpp b/sim/src/core/SimEntity.cpp index 942b67bea..46e5bfa45 100644 --- a/sim/src/core/SimEntity.cpp +++ b/sim/src/core/SimEntity.cpp @@ -19,6 +19,7 @@ */ #include "SimEntity.h" +#include "SimJoint.h" #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include // ostream_iterator @@ -172,7 +174,7 @@ namespace mars { } } - void SimEntity::setInitialPose() { + void SimEntity::setInitialPose(bool reset) { bool worldAnchor = false; if(!control) return; if(config.find("rootNode") != config.end()) { @@ -215,7 +217,31 @@ namespace mars { control->nodes->editNode(&myNode, EDIT_NODE_ROT | EDIT_NODE_MOVE_ALL); } if(worldAnchor) { - control->sim->connectNodes(id, 0); + if (reset) { + fprintf(stderr, "Resetting initial entity pose.\n"); + std::map::iterator it; + JointId anchorJointId = 0; + for (it=jointIds.begin(); it!=jointIds.end(); ++it) { + if (it->second == "anchor_"+name) { + anchorJointId = it->first; + break; + } + } + SimJoint* anchorjoint = control->joints->getSimJoint(anchorJointId); + if (anchorjoint != NULL) { + anchorjoint->reattachJoint(); + } + else fprintf(stderr, "Could not reset anchor of entity %s.\n", name.c_str()); + } + else { + JointData anchorjoint; + anchorjoint.nodeIndex1 = id; + anchorjoint.nodeIndex2 = 0; + anchorjoint.type = JOINT_TYPE_FIXED; + anchorjoint.name = "anchor_"+name; + JointId anchorJointId = control->joints->addJoint(&anchorjoint); + addJoint(anchorJointId, anchorjoint.name); + } } // set Joints configmaps::ConfigVector::iterator it; diff --git a/sim/src/core/SimEntity.h b/sim/src/core/SimEntity.h index dcf4181c0..b6d914a29 100644 --- a/sim/src/core/SimEntity.h +++ b/sim/src/core/SimEntity.h @@ -115,7 +115,7 @@ namespace mars { std::string getJoint(unsigned long id); - void setInitialPose(); + void setInitialPose(bool reset=false); //debug functions void printNodes();