27#ifndef RBDL_USE_CASADI_MATH
32 }
else if (joint_dof ==
SpatialVector (0., 1., 0., 0., 0., 0.)) {
34 }
else if (joint_dof ==
SpatialVector (0., 0., 1., 0., 0., 0.)) {
36 }
else if (joint_dof ==
SpatialVector (0., 0., 0., 1., 0., 0.)) {
38 }
else if (joint_dof ==
SpatialVector (0., 0., 0., 0., 1., 0.)) {
40 }
else if (joint_dof ==
SpatialVector (0., 0., 0., 0., 0., 1.)) {
44 ostringstream dof_stream(ostringstream::out);
45 dof_stream <<
"custom_axis (" << joint_dof.transpose() <<
")";
46 return dof_stream.str();
53 if (model.mBodies[body_id].mIsVirtual) {
55 if (model.mu[body_id].size() != 1) {
62 return model.GetBodyName(body_id);
65#ifndef RBDL_USE_CASADI_MATH
67 stringstream result (
"");
69 unsigned int q_index = 0;
70 for (
unsigned int i = 1; i < model.mBodies.size(); i++) {
71 if (model.mJoints[i].mDoFCount == 1) {
72 result << setfill(
' ') << setw(3) << q_index <<
": " <<
get_body_name(model,
76 for (
unsigned int j = 0; j < model.mJoints[i].mDoFCount; j++) {
77 result << setfill(
' ') << setw(3) << q_index <<
": " <<
get_body_name(model,
78 i) <<
"_" <<
get_dof_name (model.mJoints[i].mJointAxes[j]) << endl;
88#ifndef RBDL_USE_CASADI_MATH
90 unsigned int body_index = 0,
int indent = 0)
92 stringstream result (
"");
94 for (
int j = 0; j < indent; j++) {
100 if (body_index > 0) {
104 while (model.mBodies[body_index].mIsVirtual) {
105 if (model.mu[body_index].size() == 0) {
108 }
else if (model.mu[body_index].size() > 1) {
109 std::ostringstream errormsg;
111 "Error: Cannot determine multi-dof joint as massless body with id " <<
112 body_index <<
" (name: " << model.GetBodyName(body_index) <<
113 ") has more than one child:" << endl;
114 for (
unsigned int ci = 0; ci < model.mu[body_index].size(); ci++) {
115 errormsg <<
" id: " << model.mu[body_index][ci] <<
" name: " <<
116 model.GetBodyName(model.mu[body_index][ci]) << endl;
123 body_index = model.mu[body_index][0];
126 if (body_index > 0) {
131 unsigned int child_index = 0;
132 for (child_index = 0; child_index < model.mu[body_index].size();
139 for (
unsigned int fbody_index = 0; fbody_index < model.mFixedBodies.size();
141 if (model.mFixedBodies[fbody_index].mMovableParent == body_index) {
142 for (
int j = 0; j < indent + 1; j++) {
146 result << model.GetBodyName(model.fixed_body_discriminator + fbody_index) <<
156#ifndef RBDL_USE_CASADI_MATH
159 stringstream result (
"");
169 stringstream result (
"");
174 for (
unsigned int body_id = 0; body_id < model.mBodies.size(); body_id++) {
175 std::string body_name = model.GetBodyName (body_id);
177 if (body_name.size() == 0) {
184 result << body_name <<
": " << position.transpose() << endl;
201 bool update_kinematics)
205 assert( (com_acceleration == NULL && change_of_angular_momentum == NULL)
206 || (qddot != NULL) );
208 if (update_kinematics) {
212 for (
size_t i = 1; i < model.mBodies.size(); i++) {
213 model.Ic[i] = model.I[i];
214 model.hc[i] = model.Ic[i].toMatrix() * model.v[i];
215 model.hdotc[i] = model.Ic[i] * model.a[i] +
crossf(model.v[i],
216 model.Ic[i] * model.v[i]);
219 if (qddot && (com_acceleration || change_of_angular_momentum)) {
220 for (
size_t i = 1; i < model.mBodies.size(); i++) {
221 model.hdotc[i] = model.Ic[i] * model.a[i] +
crossf(model.v[i],
222 model.Ic[i] * model.v[i]);
230 for (
size_t i = model.mBodies.size() - 1; i > 0; i--) {
231 unsigned int lambda = model.lambda[i];
234 model.Ic[lambda] = model.Ic[lambda] + model.X_lambda[i].applyTranspose (
236 model.hc[lambda] = model.hc[lambda] + model.X_lambda[i].applyTranspose (
239 Itot = Itot + model.X_lambda[i].applyTranspose (model.Ic[i]);
240 htot = htot + model.X_lambda[i].applyTranspose (model.hc[i]);
244 if (qddot && (com_acceleration || change_of_angular_momentum)) {
245 for (
size_t i = model.mBodies.size() - 1; i > 0; i--) {
246 unsigned int lambda = model.lambda[i];
249 model.hdotc[lambda] = model.hdotc[lambda] + model.X_lambda[i].applyTranspose (
252 hdot_tot = hdot_tot + model.X_lambda[i].applyTranspose (model.hdotc[i]);
259 LOG <<
"mass = " << mass <<
" com = " << com.transpose() <<
" htot = " <<
260 htot.transpose() << std::endl;
263 *com_velocity =
Vector3d (htot[3] / mass, htot[4] / mass, htot[5] / mass);
266 if (angular_momentum) {
268 angular_momentum->
set (htot[0], htot[1], htot[2]);
271 if (com_acceleration) {
272 *com_acceleration =
Vector3d (hdot_tot[3] / mass, hdot_tot[4] / mass,
276 if (change_of_angular_momentum) {
278 change_of_angular_momentum->
set (hdot_tot[0], hdot_tot[1], hdot_tot[2]);
290 bool update_kinematics
300 if (update_kinematics) {
305 for (
size_t i = 1; i < model.mBodies.size(); i++) {
306 model.Ic[i] = model.I[i];
307 model.hdotc[i] = model.Ic[i] * model.a[i] +
crossf(model.v[i],
308 model.Ic[i] * model.v[i]);
317 for (
size_t i = model.mBodies.size() - 1; i > 0; i--) {
318 unsigned int lambda = model.lambda[i];
321 model.Ic[lambda] = model.Ic[lambda] + model.X_lambda[i].applyTranspose (
323 model.hc[lambda] = model.hc[lambda] + model.X_lambda[i].applyTranspose (
325 model.hdotc[lambda] = model.hdotc[lambda] + model.X_lambda[i].applyTranspose (
328 I_tot = I_tot + model.X_lambda[i].applyTranspose (model.Ic[i]);
329 h_tot = h_tot + model.X_lambda[i].applyTranspose (model.hc[i]);
330 hdot_tot = hdot_tot + model.X_lambda[i].applyTranspose (model.hdotc[i]);
343 hdot_tot = hdot_tot - mass *
SpatialVector (0., 0., 0., model.gravity[0],
344 model.gravity[1], model.gravity[2]);
353 Vector3d n_0 = hdot_tot.block<3,1>(0,0);
354 Vector3d f = hdot_tot.block<3,1>(3,0);
355 *zmp = normal.cross(n_0) / normal.dot(f);
366 bool update_kinematics)
383 Vector3d g = -
Vector3d (model.gravity[0], model.gravity[1], model.gravity[2]);
384 LOG <<
"pot_energy: " <<
" mass = " << mass <<
" com = " << com.transpose() <<
387 return mass * com.dot(g);
394 bool update_kinematics)
396 if (update_kinematics) {
402 for (
size_t i = 1; i < model.mBodies.size(); i++) {
403 result += 0.5 * model.v[i].transpose() * (model.I[i] * model.v[i]);
static MX_Xd_dynamic Zero(unsigned int nrows, unsigned int ncols=1)
Base class for all RBDL exceptions.
void set(const double &v0, const double &v1, const double &v2)
RBDL_DLLAPI Vector3d CalcBodyToBaseCoordinates(Model &model, const VectorNd &Q, unsigned int body_id, const Vector3d &point_body_coordinates, bool update_kinematics)
Returns the base coordinates of a point given in body coordinates.
RBDL_DLLAPI void UpdateKinematicsCustom(Model &model, const VectorNd *Q, const VectorNd *QDot, const VectorNd *QDDot)
Selectively updates model internal states of body positions, velocities and/or accelerations.
SpatialMatrix crossf(const SpatialVector &v)
SpatialVector_t SpatialVector
SpatialTransform Xtrans(const Vector3d &r)
RBDL_DLLAPI std::string GetModelHierarchy(const Model &model)
Creates a human readable overview of the model.
RBDL_DLLAPI Scalar CalcKineticEnergy(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, bool update_kinematics)
Computes the kinetic energy of the full model.
RBDL_DLLAPI std::string GetModelDOFOverview(const Model &model)
Creates a human readable overview of the Degrees of Freedom.
RBDL_DLLAPI void CalcCenterOfMass(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, const Math::VectorNd *qddot, Scalar &mass, Math::Vector3d &com, Math::Vector3d *com_velocity, Math::Vector3d *com_acceleration, Math::Vector3d *angular_momentum, Math::Vector3d *change_of_angular_momentum, bool update_kinematics)
Computes the Center of Mass (COM) and optionally its linear velocity.
RBDL_DLLAPI void CalcZeroMomentPoint(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, const Math::VectorNd &qddot, Vector3d *zmp, const Math::Vector3d &normal, const Math::Vector3d &point, bool update_kinematics)
Computes the Zero-Moment-Point (ZMP) on a given contact surface.
RBDL_DLLAPI Scalar CalcPotentialEnergy(Model &model, const Math::VectorNd &q, bool update_kinematics)
Computes the potential energy of the full model.
RBDL_DLLAPI std::string GetNamedBodyOriginsOverview(Model &model)
Creates a human readable overview of the locations of all bodies that have names.
std::string print_hierarchy(const RigidBodyDynamics::Model &model, unsigned int body_index=0, int indent=0)
string get_body_name(const RigidBodyDynamics::Model &model, unsigned int body_id)
string get_dof_name(const SpatialVector &joint_dof)
Compact representation for Spatial Inertia.
Vector3d h
Coordinates of the center of mass.
Compact representation of spatial transformations.
SpatialTransform inverse() const
SpatialVector applyAdjoint(const SpatialVector &f_sp)