rdl_utils.cc
Go to the documentation of this file.
1 /*
2  * Original Copyright (c) 2011-2016 Martin Felis <martin.felis@iwr.uni-heidelberg.de>
3  *
4  *
5  * RDL - Robot Dynamics Library
6  * Modifications Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
7  *
8  * Licensed under the zlib license. See LICENSE for more details.
9  */
10 
11 #include <iomanip>
12 
13 #include "rdl_dynamics/rdl_utils.h"
19 
20 namespace RobotDynamics
21 {
22 namespace Utils
23 {
24 using namespace std;
25 using namespace Math;
26 
27 string getDofName(const SpatialVector& joint_dof)
28 {
29  if (joint_dof == SpatialVector(1., 0., 0., 0., 0., 0.))
30  {
31  return "RX";
32  }
33  else if (joint_dof == SpatialVector(0., 1., 0., 0., 0., 0.))
34  {
35  return "RY";
36  }
37  else if (joint_dof == SpatialVector(0., 0., 1., 0., 0., 0.))
38  {
39  return "RZ";
40  }
41  else if (joint_dof == SpatialVector(0., 0., 0., 1., 0., 0.))
42  {
43  return "TX";
44  }
45  else if (joint_dof == SpatialVector(0., 0., 0., 0., 1., 0.))
46  {
47  return "TY";
48  }
49  else if (joint_dof == SpatialVector(0., 0., 0., 0., 0., 1.))
50  {
51  return "TZ";
52  }
53 
54  ostringstream dof_stream(ostringstream::out);
55  dof_stream << "custom (" << joint_dof.transpose() << ")";
56  return dof_stream.str();
57 }
58 
59 string getBodyName(const RobotDynamics::Model& model, unsigned int body_id)
60 {
61  if (model.mBodies[body_id].mIsVirtual)
62  {
63  // if there is not a unique child we do not know what to do...
64  if (model.mu[body_id].size() != 1)
65  {
66  return "";
67  }
68 
69  return getBodyName(model, model.mu[body_id][0]);
70  }
71 
72  return model.GetBodyName(body_id);
73 }
74 
75 std::string getModelDOFOverview(const Model& model)
76 {
77  stringstream result("");
78 
79  unsigned int q_index = 0;
80  for (unsigned int i = 1; i < model.mBodies.size(); i++)
81  {
82  if (model.mJoints[i].mDoFCount == 1)
83  {
84  result << setfill(' ') << setw(3) << q_index << ": " << getBodyName(model, i) << "_" << getDofName(model.S[i]) << endl;
85  q_index++;
86  }
87  else
88  {
89  for (unsigned int j = 0; j < model.mJoints[i].mDoFCount; j++)
90  {
91  result << setfill(' ') << setw(3) << q_index << ": " << getBodyName(model, i) << "_" << getDofName(model.mJoints[i].mJointAxes[j]) << endl;
92  q_index++;
93  }
94  }
95  }
96 
97  return result.str();
98 }
99 
100 std::string printHierarchy(const RobotDynamics::Model& model, unsigned int body_index = 0, int indent = 0)
101 {
102  stringstream result("");
103 
104  for (int j = 0; j < indent; j++)
105  {
106  result << " ";
107  }
108 
109  result << getBodyName(model, body_index);
110 
111  if (body_index > 0)
112  {
113  result << " [ ";
114  }
115 
116  while (model.mBodies[body_index].mIsVirtual)
117  {
118  if (model.mu[body_index].size() == 0)
119  {
120  result << " end";
121  break;
122  }
123  else if (model.mu[body_index].size() > 1)
124  {
125  cerr << endl
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++)
129  {
130  cerr << " id: " << model.mu[body_index][ci] << " name: " << model.GetBodyName(model.mu[body_index][ci]) << endl;
131  }
132  abort();
133  }
134 
135  result << getDofName(model.S[body_index]) << ", ";
136 
137  body_index = model.mu[body_index][0];
138  }
139 
140  if (body_index > 0)
141  {
142  result << getDofName(model.S[body_index]) << " ]";
143  }
144  result << endl;
145 
146  unsigned int child_index = 0;
147  for (child_index = 0; child_index < model.mu[body_index].size(); child_index++)
148  {
149  result << printHierarchy(model, model.mu[body_index][child_index], indent + 1);
150  }
151 
152  // print fixed children
153  for (unsigned int fbody_index = 0; fbody_index < model.mFixedBodies.size(); fbody_index++)
154  {
155  if (model.mFixedBodies[fbody_index].mMovableParent == body_index)
156  {
157  for (int j = 0; j < indent + 1; j++)
158  {
159  result << " ";
160  }
161 
162  result << model.GetBodyName(model.fixed_body_discriminator + fbody_index) << " [fixed]" << endl;
163  }
164  }
165 
166  return result.str();
167 }
168 
169 std::string getModelHierarchy(const Model& model)
170 {
171  stringstream result("");
172 
173  result << printHierarchy(model);
174 
175  return result.str();
176 }
177 
179 {
180  stringstream result("");
181 
182  VectorNd Q(VectorNd::Zero(model.dof_count));
183  updateKinematicsCustom(model, &Q, NULL, NULL);
184 
185  for (unsigned int body_id = 0; body_id < model.mBodies.size(); body_id++)
186  {
187  std::string body_name = model.GetBodyName(body_id);
188 
189  if (body_name.size() == 0)
190  {
191  continue;
192  }
193 
194  Vector3d position = model.bodyFrames[body_id]->getInverseTransformToRoot().r;
195 
196  result << body_name << ": " << position.transpose() << endl;
197  }
198 
199  return result.str();
200 }
201 
202 void calcCenterOfMass(Model& model, const Math::VectorNd& q, Math::Vector3d& com, bool update_kinematics)
203 {
204  if (update_kinematics)
205  {
206  updateKinematicsCustom(model, &q, nullptr, nullptr);
207  }
208 
209  for (size_t i = 1; i < model.mBodies.size(); i++)
210  {
211  model.Ic[i] = model.I[i];
212  }
213 
214  RigidBodyInertia Itot;
215 
216  for (size_t i = model.mBodies.size() - 1; i > 0; i--)
217  {
218  unsigned int lambda = model.lambda[i];
219 
220  if (lambda != 0)
221  {
222  model.Ic[lambda] = model.Ic[lambda] + model.Ic[i].transform_copy(model.bodyFrames[i]->getTransformToParent());
223  }
224  else
225  {
226  Itot = Itot + model.Ic[i].transform_copy(model.bodyFrames[i]->getTransformToParent());
227  }
228  }
229 
230  com = Itot.h / Itot.m;
231 }
232 
233 void calcCenterOfMass(Model& model, const Math::VectorNd& q, FramePoint& com, bool update_kinematics)
234 {
235  Vector3d com_v;
236  calcCenterOfMass(model, q, com_v, update_kinematics);
237  com.setIncludingFrame(com_v, model.worldFrame);
238 }
239 
240 void calcCenterOfMass(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, double& mass, Math::FramePoint& com, Math::FrameVector* com_velocity,
241  Math::FrameVector* angular_momentum, bool update_kinematics)
242 {
243  Vector3d comPosition, comVelocity, angularMomentum;
244 
245  calcCenterOfMass(model, q, qdot, mass, comPosition, &comVelocity, &angularMomentum, update_kinematics);
246 
247  ReferenceFramePtr worldFrame = model.worldFrame;
248 
249  com.setIncludingFrame(comPosition, worldFrame);
250 
251  if (com_velocity)
252  {
253  com_velocity->setIncludingFrame(comVelocity, worldFrame);
254  }
255 
256  if (angular_momentum)
257  {
258  angular_momentum->setIncludingFrame(angularMomentum, worldFrame);
259  }
260 }
261 
262 void calcCenterOfMass(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, double& mass, Math::Vector3d& com, Math::Vector3d* com_velocity,
263  Vector3d* angular_momentum, bool update_kinematics)
264 {
265  if (update_kinematics)
266  {
267  updateKinematicsCustom(model, &q, &qdot, NULL);
268  }
269 
270  for (size_t i = 1; i < model.mBodies.size(); i++)
271  {
272  model.Ic[i] = model.I[i];
273  model.hc[i] = model.Ic[i] * model.v[i];
274  }
275 
276  RigidBodyInertia Itot;
277  Momentum htot;
278 
279  for (size_t i = model.mBodies.size() - 1; i > 0; i--)
280  {
281  unsigned int lambda = model.lambda[i];
282 
283  if (lambda != 0)
284  {
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());
287  }
288  else
289  {
290  Itot = Itot + model.Ic[i].transform_copy(model.bodyFrames[i]->getTransformToParent());
291  htot = htot + model.hc[i].transform_copy(model.bodyFrames[i]->getTransformToParent());
292  }
293  }
294 
295  mass = Itot.m;
296  com = Itot.h / mass;
297 
298  if (com_velocity)
299  {
300  *com_velocity = Vector3d(htot[3] / mass, htot[4] / mass, htot[5] / mass);
301  }
302 
303  if (angular_momentum)
304  {
305  htot.transform(Xtrans(com));
306  // htot = Xtrans(com).applyAdjoint(htot);
307  angular_momentum->set(htot[0], htot[1], htot[2]);
308  }
309 }
310 
311 void calcCenterOfMass(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, Math::FramePoint& com, Math::FrameVector* com_velocity, bool update_kinematics)
312 {
313  if (update_kinematics)
314  {
315  if (com_velocity)
316  {
317  updateKinematicsCustom(model, &q, &qdot, nullptr);
318  }
319  else
320  {
321  updateKinematicsCustom(model, &q, nullptr, nullptr);
322  }
323  }
324 
325  Vector3d p_com(0., 0., 0.), v_com(0., 0., 0.);
326  double mass = 0;
327  for (unsigned int i = 1; i < model.mBodies.size(); i++)
328  {
329  double bodyMass = model.mBodies[i].mMass;
330  mass += bodyMass;
331  p_com += bodyMass * model.bodyCenteredFrames[i]->getInverseTransformToRoot().r;
332 
333  if (com_velocity)
334  {
335  v_com += bodyMass *
336  (model.bodyFrames[i]->getTransformToRoot().E * (model.v[i].getLinearPart() - model.mBodies[i].mCenterOfMass.cross(model.v[i].getAngularPart())));
337  }
338  }
339 
340  com.setIncludingFrame(p_com / mass, model.worldFrame);
341 
342  if (com_velocity)
343  {
344  com_velocity->setIncludingFrame(v_com / mass, model.worldFrame);
345  }
346 }
347 
349 {
351  calcCenterOfMass(model, q, com, update_kinematics);
352  updateCenterOfMassFrame(model, com.vec());
353  return com;
354 }
355 
356 RobotDynamics::Math::FramePoint updateCenterOfMassFrame(Model& model, const Math::VectorNd& q, const Math::Vector3d& euler_ypr, bool update_kinematics)
357 {
359  calcCenterOfMass(model, q, com, update_kinematics);
360  updateCenterOfMassFrame(model, com.vec(), euler_ypr);
361  return com;
362 }
363 
364 RobotDynamics::Math::FramePoint updateCenterOfMassFrame(Model& model, const Math::VectorNd& q, const Math::Quaternion& orientation, bool update_kinematics)
365 {
367  calcCenterOfMass(model, q, com, update_kinematics);
368  updateCenterOfMassFrame(model, com.vec(), orientation);
369  return com;
370 }
371 
372 void updateCenterOfMassFrame(Model& model, const Math::Vector3d& p_com)
373 {
374  model.comFrame->setTransformFromParent(Math::Xtrans(p_com));
375 }
376 
377 void updateCenterOfMassFrame(Model& model, const Math::Vector3d& p_com, const Math::Vector3d& euler_ypr)
378 {
379  model.comFrame->setTransformFromParent(Math::XeulerZYX(euler_ypr) * Math::Xtrans(p_com));
380 }
381 
382 void updateCenterOfMassFrame(Model& model, const Math::Vector3d& p_com, const Math::Quaternion& orientation)
383 {
384  model.comFrame->setTransformFromParent(Math::XrotQuat(orientation) * Math::Xtrans(p_com));
385 }
386 
388 {
389  for (size_t i = 1; i < model.mBodies.size(); i++)
390  {
391  model.hc[i] = model.I[i] * model.v[i];
392  }
393 
394  RigidBodyInertia Itot;
395  Momentum htot;
396  for (size_t i = model.mBodies.size() - 1; i > 0; i--)
397  {
398  unsigned int lambda = model.lambda[i];
399 
400  if (lambda != 0)
401  {
402  model.hc[lambda] = model.hc[lambda] + model.hc[i].transform_copy(model.bodyFrames[i]->getTransformToParent());
403  }
404  else
405  {
406  htot = htot + model.hc[i].transform_copy(model.bodyFrames[i]->getTransformToParent());
407  }
408  }
409 
410  com_vel = Vector3d(htot[3] / model.mass, htot[4] / model.mass, htot[5] / model.mass);
411 }
412 
414 {
416  calcCenterOfMassVelocity(model, v);
417  com_vel.setIncludingFrame(v, model.worldFrame);
418 }
419 
420 void calcCenterOfMassVelocity(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, Math::Vector3d& com_vel, bool update_kinematics)
421 {
422  if (update_kinematics)
423  {
424  updateKinematicsCustom(model, &q, &qdot, NULL);
425  }
426 
427  calcCenterOfMassVelocity(model, com_vel);
428 }
429 
430 void calcCenterOfMassVelocity(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, Math::FrameVector& com_vel, bool update_kinematics)
431 {
432  if (update_kinematics)
433  {
434  updateKinematicsCustom(model, &q, &qdot, NULL);
435  }
436 
437  calcCenterOfMassVelocity(model, com_vel);
438 }
439 
441 {
442  if (update_kinematics)
443  {
444  updateKinematicsCustom(model, &q, nullptr, nullptr);
445  }
446 
448  for (unsigned int i = 1; i < model.mBodies.size(); i++)
449  {
450  if (!model.mBodies[i].mIsVirtual)
451  {
452  RobotDynamics::ReferenceFramePtr body_com_frame = model.bodyCenteredFrames[i];
453  // Gravity wrench on body in world frame
454  Math::ForceVector fg(model.mBodies[i].mMass * model.gravity.transform_copy(model.worldFrame->getTransformToDesiredFrame(body_com_frame)));
455  // transform wrench to com frame
456  fg.transform(body_com_frame->getTransformToDesiredFrame(model.comFrame));
457  f += fg;
458  }
459  }
460 
461  return Math::SpatialForce(model.comFrame, f);
462 }
463 
464 void calcCenterOfMassJacobian(Model& model, const Math::VectorNd& q, Math::MatrixNd& jCom, bool update_kinematics)
465 {
466  assert(jCom.cols() == model.qdot_size && jCom.rows() == 3);
467 
468  if (update_kinematics)
469  {
470  updateKinematicsCustom(model, &q, nullptr, nullptr);
471  }
472 
474  for (unsigned int i = 1; i < model.mBodies.size(); i++)
475  {
476  K.block<3, 3>(3, 0) = -toTildeForm(calcSubtreeCenterOfMassScaledByMass(model, i, q, false));
477  K.block<3, 3>(3, 3) = Math::Matrix3dIdentity * calcSubtreeMass(model, i);
478  if (model.mJoints[i].mJointType != JointTypeCustom)
479  {
480  if (model.mJoints[i].mDoFCount == 1)
481  {
482  jCom.col(model.mJoints[i].q_index) = (K * model.S[i].transform_copy(model.bodyFrames[i]->getTransformToRoot())).block(3, 0, 3, 1);
483  }
484  else if (model.mJoints[i].mDoFCount == 3)
485  {
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);
487  }
488  }
489  else
490  {
491  jCom.block(0, model.mJoints[i].q_index, 3, model.mJoints[i].mDoFCount) =
492  (K * (model.bodyFrames[i]->getTransformToRoot().toMatrix() * model.mCustomJoints[model.mJoints[i].custom_joint_index]->S))
493  .block(3, 0, 3, model.mJoints[i].mDoFCount);
494  }
495  }
496 
497  jCom /= calcSubtreeMass(model, 0);
498 }
499 
500 Math::Vector3d calcSubtreeCenterOfMassScaledByMass(Model& model, const unsigned int bodyId, const VectorNd& q, bool updateKinematics)
501 {
502  if (updateKinematics)
503  {
504  updateKinematicsCustom(model, &q, nullptr, nullptr);
505  }
506 
507  std::vector<unsigned int> childBodyIds = model.mu[bodyId];
508 
509  Math::Vector3d comScaledByMass(model.bodyCenteredFrames[bodyId]->getInverseTransformToRoot().r * model.mBodies[bodyId].mMass);
510 
511  for (unsigned int j = 0; j < childBodyIds.size(); j++)
512  {
513  comScaledByMass += calcSubtreeCenterOfMassScaledByMass(model, childBodyIds[j], q, false);
514  }
515 
516  return comScaledByMass;
517 }
518 
519 double calcSubtreeMass(Model& model, const unsigned int bodyId)
520 {
521  std::vector<unsigned int> childBodyIds = model.mu[bodyId];
522 
523  double subtreeMass = model.mBodies[bodyId].mMass;
524 
525  for (unsigned int j = 0; j < childBodyIds.size(); j++)
526  {
527  subtreeMass += calcSubtreeMass(model, childBodyIds[j]);
528  }
529 
530  return subtreeMass;
531 }
532 
533 double calcPotentialEnergy(Model& model, const Math::VectorNd& q, bool update_kinematics)
534 {
535  double mass;
536  Vector3d com;
537  calcCenterOfMass(model, q, VectorNd::Zero(model.qdot_size), mass, com, NULL, NULL, update_kinematics);
538 
539  Vector3d g = -Vector3d(model.gravity[3], model.gravity[4], model.gravity[5]);
540 
541  return mass * com.dot(g);
542 }
543 
544 double calcKineticEnergy(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, bool update_kinematics)
545 {
546  if (update_kinematics)
547  {
548  updateKinematicsCustom(model, &q, &qdot, NULL);
549  }
550 
551  double result = 0.;
552 
553  for (size_t i = 1; i < model.mBodies.size(); i++)
554  {
555  result += (0.5 * model.v[i].dot(model.I[i] * model.v[i]));
556  }
557  return result;
558 }
559 
560 void calcCentroidalMomentumMatrix(Model& model, const Math::VectorNd& q, Math::MatrixNd& A, bool update_kinematics)
561 {
562  assert(A.cols() == model.qdot_size && A.rows() == 6);
563 
564  if (update_kinematics)
565  {
566  updateKinematicsCustom(model, &q, nullptr, nullptr);
567  }
568 
569  Vector3d com;
570  calcCenterOfMass(model, q, com, false);
571  SpatialTransform X_com = Xtrans(com);
572 
573  // cppcheck-suppress variableScope
574  unsigned int j;
575  for (unsigned int i = 1; i < model.mBodies.size(); i++)
576  {
577  j = i;
578  ReferenceFramePtr bodyFrame = model.bodyFrames[i];
579  while (j != 0)
580  {
581  if (model.mJoints[j].mJointType != JointTypeCustom)
582  {
583  if (model.mJoints[j].mDoFCount == 1)
584  {
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);
588  }
589  else if (model.mJoints[j].mDoFCount == 3)
590  {
591  for (int k = 0; k < 3; k++)
592  {
593  A.col(model.mJoints[j].q_index + k) +=
594  X_com.toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
595  (model.I[i].toMatrix() * MotionVector(model.multdof3_S[j].col(k)).transform_copy(model.bodyFrames[j]->getTransformToDesiredFrame(bodyFrame)));
596  }
597  }
598  }
599  else
600  {
601  unsigned int k = model.mJoints[j].custom_joint_index;
602 
603  A.block(0, model.mJoints[j].q_index, 6, model.mCustomJoints[k]->mDoFCount) +=
604  X_com.toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
605  (model.I[i].toMatrix() * model.bodyFrames[j]->getTransformToDesiredFrame(bodyFrame).toMatrix() * model.mCustomJoints[k]->S);
606  }
607 
608  j = model.lambda[j];
609  }
610  }
611 }
612 
613 void calcCentroidalMomentumMatrixDot(Model& model, const Math::VectorNd& q, const Math::VectorNd& qdot, Math::MatrixNd& Adot, bool update_kinematics)
614 {
615  assert(Adot.cols() == model.qdot_size && Adot.rows() == 6);
616 
617  if (update_kinematics)
618  {
619  updateKinematicsCustom(model, &q, &qdot, nullptr);
620  }
621 
622  FramePoint com;
623  FrameVector com_velocity;
624  calcCenterOfMass(model, q, qdot, com, &com_velocity, false);
625  SpatialTransform X_com = Xtrans(com.vec());
626  MotionVector com_twist(0., 0., 0., com_velocity.x(), com_velocity.y(), com_velocity.z());
627  // cppcheck-suppress variableScope
628  MotionVector v_tmp;
629 
630  // cppcheck-suppress variableScope
631  unsigned int j;
632  for (unsigned int i = 1; i < model.mBodies.size(); i++)
633  {
634  j = i;
635  ReferenceFramePtr bodyFrame = model.bodyFrames[i];
636 
637  v_tmp = -MotionVector(com_twist - model.v[i].transform_copy(bodyFrame->getTransformToRoot())).transform_copy(X_com);
638 
639  while (j != 0)
640  {
641  if (model.mJoints[j].mJointType != JointTypeCustom)
642  {
643  if (model.mJoints[j].mDoFCount == 1)
644  {
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) +
649  (model.I[i] * MotionVector(model.S_o[j] + model.v[j] % model.S[j]).transform_copy(model.bodyFrames[j]->getTransformToDesiredFrame(bodyFrame)))
650  .transform_copy(bodyFrame->getTransformToRoot())
651  .transform_copy(X_com);
652  }
653  else if (model.mJoints[j].mDoFCount == 3)
654  {
655  for (int k = 0; k < 3; k++)
656  {
657  Adot.col(model.mJoints[j].q_index + k) +=
658  v_tmp.crossf() * X_com.toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
659  (model.I[i].toMatrix() *
660  MotionVector(model.multdof3_S[j].col(k)).transform_copy(model.bodyFrames[j]->getTransformToDesiredFrame(bodyFrame))) +
661  X_com.toMatrixAdjoint() * bodyFrame->getTransformToRoot().toMatrixAdjoint() *
662  (model.I[i].toMatrix() * MotionVector(model.multdof3_S_o[j].col(k) + model.v[j].crossm() * model.multdof3_S[j].col(k))
663  .transform_copy(model.bodyFrames[j]->getTransformToDesiredFrame(bodyFrame)));
664  }
665  }
666  }
667  else
668  {
669  unsigned int k = model.mJoints[j].custom_joint_index;
670 
671  Adot.block(0, model.mJoints[j].q_index, 6, model.mCustomJoints[k]->mDoFCount) +=
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() *
676  (model.mCustomJoints[k]->S_o + model.v[j].crossm() * model.mCustomJoints[k]->S));
677  }
678 
679  j = model.lambda[j];
680  }
681  }
682 }
683 } // namespace Utils
684 } // namespace RobotDynamics
Math::MotionVectorV S_o
Definition: Model.h:212
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.
Definition: rdl_utils.cc:420
void calcCenterOfMassJacobian(Model &model, const Math::VectorNd &q, Math::MatrixNd &jCom, bool update_kinematics=true)
Computes the matrix such that .
Definition: rdl_utils.cc:464
File containing the FramePoint<T> object definition.
std::vector< Joint > mJoints
All joints.
Definition: Model.h:209
A FramePoint is a 3D point that is expressed in a ReferenceFrame. To change the ReferenceFrame a Fram...
Definition: FramePoint.hpp:40
SpatialTransform XrotQuat(double x, double y, double z, double w)
SpatialMatrix crossf()
Get the spatial force cross matrix.
User defined joints of varying size.
Definition: Joint.h:213
Matrix3d Matrix3dIdentity
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
Definition: Model.h:298
std::vector< unsigned int > lambda
Definition: Model.h:156
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...
Definition: rdl_utils.cc:500
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
VectorNd Q
std::string getNamedBodyOriginsOverview(Model &model)
Creates a human readable overview of the locations of all bodies that have names. ...
Definition: rdl_utils.cc:178
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...
Definition: rdl_utils.cc:348
A ForceVector is a SpatialVector containing 3 moments and 3 linear forces.
Definition: ForceVector.hpp:27
std::string getModelHierarchy(const Model &model)
Creates a human readable overview of the model.
Definition: rdl_utils.cc:169
static Matrix3d toTildeForm(const Point3d &p)
Definition: Point3.hpp:370
Math::MotionVector gravity
the cartesian vector of the gravity
Definition: Model.h:196
std::string getModelDOFOverview(const Model &model)
Creates a human readable overview of the Degrees of Freedom.
Definition: rdl_utils.cc:75
void transform(const SpatialTransform &X)
Performs the following in place transform .
std::vector< std::vector< unsigned int > > mu
Definition: Model.h:162
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 ...
Definition: rdl_utils.cc:59
std::vector< ReferenceFramePtr > bodyFrames
Definition: Model.h:145
ReferenceFramePtr worldFrame
Definition: Model.h:141
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...
Definition: FramePoint.hpp:138
std::string printHierarchy(const RobotDynamics::Model &model, unsigned int body_index=0, int indent=0)
Definition: rdl_utils.cc:100
EIGEN_STRONG_INLINE Math::Vector3d vec() const
Definition: Point3.hpp:269
Math::SpatialMotionV v
Definition: Model.h:202
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
std::vector< Math::Momentum > hc
Definition: Model.h:275
Compact representation of spatial transformations.
Momentum is mass/inertia multiplied by velocity.
Definition: Momentum.hpp:27
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...
Definition: rdl_utils.cc:519
double calcPotentialEnergy(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the potential energy of the full model.
Definition: rdl_utils.cc:533
std::vector< Math::Matrix63 > multdof3_S_o
Definition: Model.h:236
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
Definition: Model.h:321
Math::SpatialForce calcGravityWrenchOnCenterOfMass(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the gravitational wrench experienced on the robots center of mass.
Definition: rdl_utils.cc:440
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...
Definition: FrameVector.hpp:33
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...
Definition: rdl_utils.cc:613
Quaternion that are used for singularity free joints.
Definition: Quaternion.h:25
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.h:25
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.
Definition: Kinematics.cc:25
SpatialMatrix toMatrixAdjoint() const
Returns Spatial transform that transforms spatial force vectors.
std::vector< CustomJoint * > mCustomJoints
Definition: Model.h:242
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 ...
Definition: rdl_utils.cc:560
std::vector< ReferenceFramePtr > bodyCenteredFrames
Definition: Model.h:152
std::string getDofName(const Math::SpatialVector &joint_dof)
get string abbreviation for dof name from spatial vector.
Definition: rdl_utils.cc:27
Contains all information about the rigid body model.
Definition: Model.h:121
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.
Definition: Kinematics.cc:72
Math::SpatialInertiaV I
Definition: Model.h:269
void calcCenterOfMass(Model &model, const Math::VectorNd &q, Math::Vector3d &com, bool update_kinematics=true)
Computes the Center of Mass (COM) position.
Definition: rdl_utils.cc:202
Eigen::MatrixXd MatrixNd
Definition: rdl_eigenmath.h:26
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
Definition: Model.h:312
void set(const Eigen::Vector3d &v)
Definition: rdl_eigenmath.h:83
Math::RigidBodyInertiaV Ic
Definition: Model.h:270
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.
Definition: Model.h:235
std::string GetBodyName(unsigned int body_id) const
Returns the name of a body for a given body id.
Definition: Model.h:464
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.
Definition: rdl_utils.cc:544
unsigned int dof_count
number of degrees of freedoms of the model
Definition: Model.h:169
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
ReferenceFramePtr comFrame
Definition: Model.h:331
unsigned int qdot_size
The size of the.
Definition: Model.h:187
Math::MotionVectorV S
Definition: Model.h:211


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:27