54 ostringstream dof_stream(ostringstream::out);
55 dof_stream <<
"custom (" << joint_dof.transpose() <<
")";
56 return dof_stream.str();
61 if (model.
mBodies[body_id].mIsVirtual)
64 if (model.
mu[body_id].size() != 1)
77 stringstream result(
"");
79 unsigned int q_index = 0;
80 for (
unsigned int i = 1; i < model.
mBodies.size(); i++)
82 if (model.
mJoints[i].mDoFCount == 1)
84 result << setfill(
' ') << setw(3) << q_index <<
": " <<
getBodyName(model, i) <<
"_" <<
getDofName(model.
S[i]) << endl;
89 for (
unsigned int j = 0; j < model.
mJoints[i].mDoFCount; j++)
91 result << setfill(
' ') << setw(3) << q_index <<
": " <<
getBodyName(model, i) <<
"_" <<
getDofName(model.
mJoints[i].mJointAxes[j]) << endl;
102 stringstream result(
"");
104 for (
int j = 0; j < indent; j++)
116 while (model.
mBodies[body_index].mIsVirtual)
118 if (model.
mu[body_index].size() == 0)
123 else if (model.
mu[body_index].size() > 1)
126 <<
"Error: Cannot determine multi-dof joint as massless body with id " << body_index <<
" (name: " << model.
GetBodyName(body_index)
127 <<
") has more than one child:" << endl;
128 for (
unsigned int ci = 0; ci < model.
mu[body_index].size(); ci++)
130 cerr <<
" id: " << model.
mu[body_index][ci] <<
" name: " << model.
GetBodyName(model.
mu[body_index][ci]) << endl;
137 body_index = model.
mu[body_index][0];
146 unsigned int child_index = 0;
147 for (child_index = 0; child_index < model.
mu[body_index].size(); child_index++)
149 result <<
printHierarchy(model, model.
mu[body_index][child_index], indent + 1);
153 for (
unsigned int fbody_index = 0; fbody_index < model.
mFixedBodies.size(); fbody_index++)
155 if (model.
mFixedBodies[fbody_index].mMovableParent == body_index)
157 for (
int j = 0; j < indent + 1; j++)
171 stringstream result(
"");
180 stringstream result(
"");
185 for (
unsigned int body_id = 0; body_id < model.
mBodies.size(); body_id++)
187 std::string body_name = model.
GetBodyName(body_id);
189 if (body_name.size() == 0)
196 result << body_name <<
": " << position.transpose() << endl;
204 if (update_kinematics)
209 for (
size_t i = 1; i < model.
mBodies.size(); i++)
211 model.
Ic[i] = model.
I[i];
216 for (
size_t i = model.
mBodies.size() - 1; i > 0; i--)
218 unsigned int lambda = model.
lambda[i];
222 model.
Ic[lambda] = model.
Ic[lambda] + model.
Ic[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
226 Itot = Itot + model.
Ic[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
230 com = Itot.
h / Itot.
m;
243 Vector3d comPosition, comVelocity, angularMomentum;
245 calcCenterOfMass(model, q, qdot, mass, comPosition, &comVelocity, &angularMomentum, update_kinematics);
256 if (angular_momentum)
263 Vector3d* angular_momentum,
bool update_kinematics)
265 if (update_kinematics)
270 for (
size_t i = 1; i < model.
mBodies.size(); i++)
272 model.
Ic[i] = model.
I[i];
273 model.
hc[i] = model.
Ic[i] * model.
v[i];
279 for (
size_t i = model.
mBodies.size() - 1; i > 0; i--)
281 unsigned int lambda = model.
lambda[i];
285 model.
Ic[lambda] = model.
Ic[lambda] + model.
Ic[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
286 model.
hc[lambda] = model.
hc[lambda] + model.
hc[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
290 Itot = Itot + model.
Ic[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
291 htot = htot + model.
hc[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
300 *com_velocity =
Vector3d(htot[3] / mass, htot[4] / mass, htot[5] / mass);
303 if (angular_momentum)
307 angular_momentum->
set(htot[0], htot[1], htot[2]);
313 if (update_kinematics)
325 Vector3d p_com(0., 0., 0.), v_com(0., 0., 0.);
327 for (
unsigned int i = 1; i < model.
mBodies.size(); i++)
329 double bodyMass = model.
mBodies[i].mMass;
336 (model.
bodyFrames[i]->getTransformToRoot().E * (model.
v[i].getLinearPart() - model.
mBodies[i].mCenterOfMass.cross(model.
v[i].getAngularPart())));
389 for (
size_t i = 1; i < model.
mBodies.size(); i++)
391 model.
hc[i] = model.
I[i] * model.
v[i];
396 for (
size_t i = model.
mBodies.size() - 1; i > 0; i--)
398 unsigned int lambda = model.
lambda[i];
402 model.
hc[lambda] = model.
hc[lambda] + model.
hc[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
406 htot = htot + model.
hc[i].transform_copy(model.
bodyFrames[i]->getTransformToParent());
422 if (update_kinematics)
432 if (update_kinematics)
442 if (update_kinematics)
448 for (
unsigned int i = 1; i < model.
mBodies.size(); i++)
450 if (!model.
mBodies[i].mIsVirtual)
466 assert(jCom.cols() == model.
qdot_size && jCom.rows() == 3);
468 if (update_kinematics)
474 for (
unsigned int i = 1; i < model.
mBodies.size(); i++)
480 if (model.
mJoints[i].mDoFCount == 1)
482 jCom.col(model.
mJoints[i].q_index) = (K * model.
S[i].transform_copy(model.
bodyFrames[i]->getTransformToRoot())).block(3, 0, 3, 1);
484 else if (model.
mJoints[i].mDoFCount == 3)
486 jCom.block(0, model.
mJoints[i].q_index, 3, 3) = (K * (model.
bodyFrames[i]->getTransformToRoot().toMatrix() * model.
multdof3_S[i])).block(3, 0, 3, 3);
491 jCom.block(0, model.
mJoints[i].q_index, 3, model.
mJoints[i].mDoFCount) =
493 .block(3, 0, 3, model.
mJoints[i].mDoFCount);
502 if (updateKinematics)
507 std::vector<unsigned int> childBodyIds = model.
mu[bodyId];
511 for (
unsigned int j = 0; j < childBodyIds.size(); j++)
516 return comScaledByMass;
521 std::vector<unsigned int> childBodyIds = model.
mu[bodyId];
523 double subtreeMass = model.
mBodies[bodyId].mMass;
525 for (
unsigned int j = 0; j < childBodyIds.size(); j++)
541 return mass * com.dot(g);
546 if (update_kinematics)
553 for (
size_t i = 1; i < model.
mBodies.size(); i++)
555 result += (0.5 * model.
v[i].dot(model.
I[i] * model.
v[i]));
562 assert(A.cols() == model.
qdot_size && A.rows() == 6);
564 if (update_kinematics)
575 for (
unsigned int i = 1; i < model.
mBodies.size(); i++)
583 if (model.
mJoints[j].mDoFCount == 1)
585 A.col(model.
mJoints[j].q_index) += (model.
I[i] * model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame)))
586 .transform_copy(bodyFrame->getTransformToRoot())
587 .transform_copy(X_com);
589 else if (model.
mJoints[j].mDoFCount == 3)
591 for (
int k = 0; k < 3; k++)
593 A.col(model.
mJoints[j].q_index + k) +=
594 X_com.
toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
601 unsigned int k = model.
mJoints[j].custom_joint_index;
604 X_com.
toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
605 (model.
I[i].toMatrix() * model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame).toMatrix() * model.
mCustomJoints[k]->S);
615 assert(Adot.cols() == model.
qdot_size && Adot.rows() == 6);
617 if (update_kinematics)
626 MotionVector com_twist(0., 0., 0., com_velocity.x(), com_velocity.y(), com_velocity.z());
632 for (
unsigned int i = 1; i < model.
mBodies.size(); i++)
643 if (model.
mJoints[j].mDoFCount == 1)
645 Adot.col(model.
mJoints[j].q_index) +=
646 v_tmp.
crossf() * (model.
I[i] * model.
S[j].transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame)))
647 .transform_copy(bodyFrame->getTransformToRoot())
648 .transform_copy(X_com) +
650 .transform_copy(bodyFrame->getTransformToRoot())
651 .transform_copy(X_com);
653 else if (model.
mJoints[j].mDoFCount == 3)
655 for (
int k = 0; k < 3; k++)
657 Adot.col(model.
mJoints[j].q_index + k) +=
658 v_tmp.crossf() * X_com.
toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
659 (model.
I[i].toMatrix() *
661 X_com.
toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
663 .transform_copy(model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame)));
669 unsigned int k = model.
mJoints[j].custom_joint_index;
672 v_tmp.crossf() * X_com.
toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
673 (model.
I[i].toMatrix() * model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame).toMatrix() * model.
mCustomJoints[k]->S) +
674 X_com.
toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
675 (model.
I[i].toMatrix() * model.
bodyFrames[j]->getTransformToDesiredFrame(bodyFrame).toMatrix() *
void calcCenterOfMassVelocity(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, Math::Vector3d &com_vel, bool update_kinematics=true)
Computes the Center of Mass (COM) velocity in world frame.
void calcCenterOfMassJacobian(Model &model, const Math::VectorNd &q, Math::MatrixNd &jCom, bool update_kinematics=true)
Computes the matrix such that .
File containing the FramePoint<T> object definition.
std::vector< Joint > mJoints
All joints.
A FramePoint is a 3D point that is expressed in a ReferenceFrame. To change the ReferenceFrame a Fram...
SpatialTransform XrotQuat(double x, double y, double z, double w)
SpatialMatrix crossf()
Get the spatial force cross matrix.
User defined joints of varying size.
Matrix3d Matrix3dIdentity
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
std::vector< unsigned int > lambda
Math::Vector3d calcSubtreeCenterOfMassScaledByMass(Model &model, const unsigned int bodyId, const Math::VectorNd &q, bool updateKinematics=true)
Calculates the center of mass of a subtree starting with the body with ID bodyId and scales it by the...
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
std::string getNamedBodyOriginsOverview(Model &model)
Creates a human readable overview of the locations of all bodies that have names. ...
RobotDynamics::Math::FramePoint updateCenterOfMassFrame(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the center of mass and updates the center of mass reference frame of the model...
A ForceVector is a SpatialVector containing 3 moments and 3 linear forces.
std::string getModelHierarchy(const Model &model)
Creates a human readable overview of the model.
static Matrix3d toTildeForm(const Point3d &p)
Math::MotionVector gravity
the cartesian vector of the gravity
std::string getModelDOFOverview(const Model &model)
Creates a human readable overview of the Degrees of Freedom.
void transform(const SpatialTransform &X)
Performs the following in place transform .
std::vector< std::vector< unsigned int > > mu
std::string getBodyName(const RobotDynamics::Model &model, unsigned int body_id)
get body name, returns empty string if bodyid is virtual and has multiple child bodies ...
std::vector< ReferenceFramePtr > bodyFrames
ReferenceFramePtr worldFrame
EIGEN_STRONG_INLINE void setIncludingFrame(const Math::Vector3d &v, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame this object is expressed in as well as the (x,y,z) coordinates of the poi...
std::string printHierarchy(const RobotDynamics::Model &model, unsigned int body_index=0, int indent=0)
EIGEN_STRONG_INLINE Math::Vector3d vec() const
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
std::vector< Math::Momentum > hc
Momentum is mass/inertia multiplied by velocity.
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
double calcSubtreeMass(Model &model, const unsigned int bodyId)
Calculates the total mass of the subtree beginning with body bodyId and traversing outwards from ther...
double calcPotentialEnergy(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the potential energy of the full model.
std::vector< Math::Matrix63 > multdof3_S_o
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
Math::SpatialForce calcGravityWrenchOnCenterOfMass(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the gravitational wrench experienced on the robots center of mass.
void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
Set the x, y, and z components and the ReferenceFrame these components are expressed in...
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
void calcCentroidalMomentumMatrixDot(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, Math::MatrixNd &Adot, bool update_kinematics=true)
Calculates the time derivative of the centroidal momentum matrix, i.e. the matrix computed by RobotDy...
Quaternion that are used for singularity free joints.
void updateKinematics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
std::vector< CustomJoint * > mCustomJoints
void calcCentroidalMomentumMatrix(Model &model, const Math::VectorNd &q, Math::MatrixNd &A, bool update_kinematics=true)
Calculates the centroidal momentum matrix, for a model. The centroidal momentum matrix is a matrix ...
std::vector< ReferenceFramePtr > bodyCenteredFrames
std::string getDofName(const Math::SpatialVector &joint_dof)
get string abbreviation for dof name from spatial vector.
Contains all information about the rigid body model.
void updateKinematicsCustom(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations.
void calcCenterOfMass(Model &model, const Math::VectorNd &q, Math::Vector3d &com, bool update_kinematics=true)
Computes the Center of Mass (COM) position.
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
void set(const Eigen::Vector3d &v)
Math::RigidBodyInertiaV Ic
SpatialTransform XeulerZYX(double yaw, double pitch, double roll)
Get transform with zero translation and intrinsic euler z/y/x rotation.
A SpatialForce is a spatial vector with the angular part being three moments and the linear part bein...
std::vector< Math::Matrix63 > multdof3_S
Motion subspace for joints with 3 degrees of freedom.
std::string GetBodyName(unsigned int body_id) const
Returns the name of a body for a given body id.
MotionVector transform_copy(const SpatialTransform &X) const
Copies, transforms, and returns a MotionVector. Performs .
double calcKineticEnergy(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, bool update_kinematics=true)
Computes the kinetic energy of the full model.
unsigned int dof_count
number of degrees of freedoms of the model
Namespace for all structures of the RobotDynamics library.
ReferenceFramePtr comFrame
unsigned int qdot_size
The size of the.