diff --git a/dart/dynamics/BodyNode.cpp b/dart/dynamics/BodyNode.cpp index d154077374b80..477ea0ea3e239 100644 --- a/dart/dynamics/BodyNode.cpp +++ b/dart/dynamics/BodyNode.cpp @@ -470,7 +470,7 @@ const Eigen::Vector3d& BodyNode::getLocalCOM() const { } Eigen::Vector3d BodyNode::getWorldCOM() const { - return mW.linear() * mCenterOfMass; + return mW * mCenterOfMass; } Eigen::Matrix6d BodyNode::getInertia() const { diff --git a/dart/dynamics/BodyNode.h b/dart/dynamics/BodyNode.h index a6e626fb8f31e..31b22229a5540 100644 --- a/dart/dynamics/BodyNode.h +++ b/dart/dynamics/BodyNode.h @@ -155,7 +155,7 @@ class BodyNode { /// mass in the body frame. const Eigen::Vector3d& getLocalCOM() const; - /// \brief Get a point vector from the origin of body frame to the center of + /// \brief Get a point vector from the origin world frame to the center of /// mass in the world frame. Eigen::Vector3d getWorldCOM() const; diff --git a/dart/dynamics/Skeleton.cpp b/dart/dynamics/Skeleton.cpp index 857565969d730..54c8d00cade9f 100644 --- a/dart/dynamics/Skeleton.cpp +++ b/dart/dynamics/Skeleton.cpp @@ -636,17 +636,15 @@ void Skeleton::setConstraintForceVector(const Eigen::VectorXd& _Fc) { } Eigen::Vector3d Skeleton::getWorldCOM() { - Eigen::Vector3d com(0, 0, 0); + Eigen::Vector3d com(0.0, 0.0, 0.0); - assert(mTotalMass != 0); const int nNodes = getNumBodyNodes(); - for (int i = 0; i < nNodes; i++) { BodyNode* bodyNode = getBodyNode(i); - com += bodyNode->getMass() * - (bodyNode->getWorldTransform() * bodyNode->getLocalCOM()); + com += bodyNode->getMass() * bodyNode->getWorldCOM(); } + assert(mTotalMass != 0.0); return com / mTotalMass; }