Skip to content

Commit

Permalink
Merge pull request #283 from EzraBrooks/fix-cloning-mimic-joints
Browse files Browse the repository at this point in the history
Fix mimic joints pointing to the original robot after a clone
  • Loading branch information
gkjohnson authored Feb 20, 2024
2 parents 8d11bdc + 0f414be commit 2454202
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions javascript/src/URDFClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ class URDFRobot extends URDFLink {

});

// Repair mimic joint references once we've re-accumulated all our joint data
for (const joint in this.joints) {
this.joints[joint].mimicJoints = this.joints[joint].mimicJoints.map((mimicJoint) => this.joints[mimicJoint.name]);
}

this.frames = {
...this.colliders,
...this.visual,
Expand Down
11 changes: 8 additions & 3 deletions javascript/test/URDFRobot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,20 @@ describe('URDFRobot', () => {
</joint>
<link name="LINK3"/>
</robot>
`).clone();
`);

const jointB = res.joints['B'];
const cloned = res.clone();

const jointB = cloned.joints['B'];
expect(jointB.mimicJoint).toEqual('A');
expect(jointB.multiplier).toEqual(23);
expect(jointB.offset).toEqual(-5);

const jointA = res.joints['A'];
const jointA = cloned.joints['A'];
expect(jointA.mimicJoints.length).toEqual(1);
expect(jointA.mimicJoints[0].name).toEqual('B');

// Expect the cloned joint not to be a reference to the joint on the robot that was cloned
expect(jointA.mimicJoints[0]).not.toBe(res.joints['A'].mimicJoints[0]);
});
});

0 comments on commit 2454202

Please sign in to comment.