Skip to content

Commit

Permalink
Merge pull request #818 from dartsim/fix_zero_dof
Browse files Browse the repository at this point in the history
Fix that ZeroDofJoint::getIndexInTree() is called
  • Loading branch information
jslee02 authored Nov 5, 2016
2 parents 7366f42 + 08b8f21 commit c6603fc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Fixed bug of ContactConstraint with kinematic joints: [#809](https://github.com/dartsim/dart/pull/809)

* Misc

* Fixed that ZeroDofJoint::getIndexInTree was called: [#818](https://github.com/dartsim/dart/pull/818)

### DART 6.1.1 (2016-10-14)

* Build
Expand Down
10 changes: 7 additions & 3 deletions dart/dynamics/BodyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2092,9 +2092,13 @@ void BodyNode::aggregateSpatialToGeneralized(Eigen::VectorXd& _generalized,
}

// Project the spatial quantity to generalized coordinates
std::size_t iStart = mParentJoint->getIndexInTree(0);
_generalized.segment(iStart, mParentJoint->getNumDofs())
= mParentJoint->getSpatialToGeneralized(mArbitrarySpatial);
const auto numDofs = mParentJoint->getNumDofs();
if (numDofs > 0u)
{
const std::size_t iStart = mParentJoint->getIndexInTree(0);
_generalized.segment(iStart, numDofs)
= mParentJoint->getSpatialToGeneralized(mArbitrarySpatial);
}
}

//==============================================================================
Expand Down
20 changes: 20 additions & 0 deletions unittests/comprehensive/test_Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,26 @@ TEST(Skeleton, ZeroDofJointInReferential)
EXPECT_FALSE(branch->getIndexOf(zeroDof2) == INVALID_INDEX);
}

TEST(Skeleton, ZeroDofJointConstraintForces)
{
// This is a regression test which makes sure that the BodyNodes of
// ZeroDofJoints will be correctly aggregate constraint forces.
SkeletonPtr skel = Skeleton::create();

BodyNode* bn = skel->createJointAndBodyNodePair<RevoluteJoint>().second;
BodyNode* zeroDof1 = skel->createJointAndBodyNodePair<WeldJoint>(bn).second;
bn = skel->createJointAndBodyNodePair<PrismaticJoint>(zeroDof1).second;
skel->createJointAndBodyNodePair<WeldJoint>(bn);

const auto numSkelDofs = skel->getNumDofs();
for (auto& bodyNode : skel->getBodyNodes())
bodyNode->setConstraintImpulse(Eigen::Vector6d::Random());

// Make sure this does not cause seg-fault
Eigen::VectorXd constraintForces = skel->getConstraintForces();
EXPECT_EQ(constraintForces.size(), static_cast<int>(numSkelDofs));
}

TEST(Skeleton, Referential)
{
std::vector<SkeletonPtr> skeletons = getSkeletons();
Expand Down

0 comments on commit c6603fc

Please sign in to comment.