Skip to content

Commit

Permalink
Fix reset problem, where joints have been loaded in wrong order
Browse files Browse the repository at this point in the history
  • Loading branch information
hwiedPro committed Mar 1, 2019
1 parent 9016c92 commit b3af26f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions sim/src/core/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ namespace mars {
}

void EntityManager::resetPose() {
std::map<unsigned long, SimEntity*>::iterator iter = entities.begin();
for (; iter != entities.end(); ++iter) {
iter->second->setInitialPose(true);
for (auto iter: entities) {
iter.second->removeAnchor();
}
for (auto iter: entities) {
iter.second->setInitialPose(true);
}
}

Expand Down
17 changes: 17 additions & 0 deletions sim/src/core/JointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ namespace mars {
// set the next free id
jointS->index = next_joint_id;
next_joint_id++;
if (jointS->config.hasKey("desired_id"))
{
unsigned long des_id=jointS->config["desired_id"];
bool found = false;
for (auto j : simJoints)
{
if (j.first == des_id) {
found = true;
}
}
if (!found) {
jointS->index = des_id;
next_joint_id--;
if (des_id>= next_joint_id)
next_joint_id = des_id + 1;
}
}
SimJoint* newJoint = new SimJoint(control, *jointS);
newJoint->setAttachedNodes(node1, node2);
// newJoint->setSJoint(*jointS);
Expand Down
7 changes: 6 additions & 1 deletion sim/src/core/SimEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ namespace mars {
}
}

void SimEntity::removeAnchor() {
if (hasAnchorJoint()) control->joints->removeJoint(anchorJointId);
}

bool SimEntity::hasAnchorJoint() {
return (anchorJointId != 0);
}
Expand Down Expand Up @@ -438,7 +442,8 @@ namespace mars {
anchorjoint.anchorPos = ANCHOR_NODE1;
anchorjoint.type = JOINT_TYPE_FIXED;
anchorjoint.name = "anchor_"+name;
anchorJointId = control->joints->addJoint(&anchorjoint, true);
if (hasAnchorJoint()) anchorjoint.config["desired_id"] = anchorJointId;
anchorJointId = control->joints->addJoint(&anchorjoint, hasAnchorJoint());
addJoint(anchorJointId, anchorjoint.name);
} else {
//if there was a joint before, remove it
Expand Down
2 changes: 2 additions & 0 deletions sim/src/core/SimEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ namespace mars {

const configmaps::ConfigMap getConfig();

void removeAnchor();

bool hasAnchorJoint();

void setInitialPose(bool reset=false/*compatibility*/, configmaps::ConfigMap* pPoseCfg=NULL);
Expand Down

0 comments on commit b3af26f

Please sign in to comment.