Model.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 <assert.h>
12 #include <iostream>
13 #include <limits>
14 #include <thread>
15 
17 #include "rdl_dynamics/Model.h"
18 
19 using namespace RobotDynamics;
20 using namespace RobotDynamics::Math;
21 
22 Model::Model(unsigned int* n_threads) : work(new boost::asio::io_service::work(io_service))
23 {
26  comFrame.reset(new FixedReferenceFrame("robot_com", worldFrame, Math::SpatialTransform(), 0));
27 
28  Body root_body;
29  Joint root_joint;
30 
31  mass = 0.;
32 
33  // structural information
34  lambda.push_back(0);
35  lambda_q.push_back(0);
36  mu.push_back(std::vector<unsigned int>());
37  dof_count = 0;
38  q_size = 0;
39  qdot_size = 0;
41 
42  std::vector<unsigned int> id_chain;
43  id_chain.push_back(0);
44  lambda_chain.push_back(id_chain);
45 
46  gravity = SpatialVector(0., 0., 0., 0., -9.81, 0.);
47 
48  // state information
51 
52  v.push_back(rootBodySpatialVelocity);
53  a.push_back(rootBodySpatialAcceleration);
54 
55  // Joints
56  mJoints.push_back(root_joint);
57  S.push_back(MotionVector(SpatialVectorZero));
59  X_T.push_back(SpatialTransform());
60 
61  X_J.push_back(SpatialTransform());
63  c_J.push_back(SpatialVectorZero);
64 
65  // Spherical joints
66  multdof3_S.push_back(Matrix63::Zero());
67  multdof3_S_o.push_back(Matrix63::Zero());
68  multdof3_U.push_back(Matrix63::Zero());
69  multdof3_Dinv.push_back(Matrix3d::Zero());
70  multdof3_u.push_back(Vector3d::Zero());
71  multdof3_w_index.push_back(0);
72 
73  // Dynamic variables
74  c.push_back(SpatialVectorZero);
75  IA.push_back(SpatialMatrixIdentity);
76  pA.push_back(RobotDynamics::Math::SpatialForce(worldFrame, 0., 0., 0., 0., 0., 0.));
77  U.push_back(SpatialVectorZero);
78 
79  u = VectorNd::Zero(1);
80  d = VectorNd::Zero(1);
81 
82  f.push_back(RobotDynamics::Math::SpatialForce(worldFrame, 0., 0., 0., 0., 0., 0.));
83  f_b.push_back(RobotDynamics::Math::SpatialForce(worldFrame, 0., 0., 0., 0., 0., 0.));
84  hc.push_back(RobotDynamics::Math::Momentum());
85 
86  // Bodies
87  X_lambda.push_back(SpatialTransform());
88 
89  bodyFrames.push_back(worldFrame); // 0th body is world
90  bodyCenteredFrames.push_back(worldFrame); // 0th body centered frame is world
91  I.push_back(SpatialInertia(worldFrame));
92  Ib_c.push_back(SpatialInertia(worldFrame));
93  Ic.push_back(RigidBodyInertia());
94 
95  mBodies.push_back(root_body);
96  mBodyNameMap["ROOT"] = 0;
97 
98  fixed_body_discriminator = std::numeric_limits<unsigned int>::max() / 2;
99 
100  unsigned int num_threads = n_threads == nullptr ? std::thread::hardware_concurrency() : *n_threads;
101  for(unsigned int i = 0; i < num_threads; ++i)
102  {
103  threads.push_back(thread_pool.create_thread(boost::bind(&boost::asio::io_service::run, &io_service)));
104  }
105 }
106 
107 unsigned int addBodyFixedJoint(Model& model, const unsigned int parent_id, const SpatialTransform& joint_frame, const Joint& joint, const Body& body,
108  std::string body_name)
109 {
110  FixedBody fbody = FixedBody::CreateFromBody(body);
111  model.mass += fbody.mMass;
112  fbody.mMovableParent = parent_id;
113  fbody.mParentTransform = joint_frame;
114 
115  if (model.IsFixedBodyId(parent_id))
116  {
117  FixedBody fixed_parent = model.mFixedBodies.at(parent_id - model.fixed_body_discriminator);
118 
119  fbody.mMovableParent = fixed_parent.mMovableParent;
120  fbody.mParentTransform = joint_frame * fixed_parent.mParentTransform;
121  }
122 
123  // merge the two bodies
124  Body parent_body = model.mBodies.at(fbody.mMovableParent);
125  parent_body.join(fbody.mParentTransform, body);
126  model.mBodies.at(fbody.mMovableParent) = parent_body;
127 
128  model.I.at(fbody.mMovableParent).set(createFromMassComInertiaC(parent_body.mMass, parent_body.mCenterOfMass, parent_body.mInertia));
129  model.Ib_c.at(fbody.mMovableParent).set(createFromMassComInertiaC(parent_body.mMass, Vector3dZero, parent_body.mInertia));
130 
131  // Since the bodies have been combined and there is a new COM, need to update the body's COM frame xform to parent.
132  model.bodyCenteredFrames.at(fbody.mMovableParent)->setTransformFromParent(Xtrans(parent_body.mCenterOfMass));
133 
134  model.mFixedBodies.push_back(fbody);
135 
136  if (model.mFixedBodies.size() > std::numeric_limits<unsigned int>::max() - model.fixed_body_discriminator)
137  {
138  std::string msg = "Error: cannot add more than " + std::to_string(std::numeric_limits<unsigned int>::max() - model.mFixedBodies.size()) +
139  " fixed bodies. You need to modify Model::fixed_body_discriminator for this.";
140  throw RdlException(msg);
141  }
142 
143  ReferenceFramePtr fixedBodyFrame;
144  fixedBodyFrame.reset(new FixedReferenceFrame(body_name, model.bodyFrames.at(fbody.mMovableParent), fbody.mParentTransform, fbody.mMovableParent));
145  model.fixedBodyFrames.push_back(fixedBodyFrame);
146 
147  if (body_name.size() != 0)
148  {
149  if (model.mBodyNameMap.find(body_name) != model.mBodyNameMap.end())
150  {
151  std::string msg = "Error: Fixed body with name '" + body_name + "' already exists!";
152  throw RdlException(msg);
153  }
154  model.mBodyNameMap[body_name] = model.mFixedBodies.size() + model.fixed_body_discriminator - 1;
155  model.referenceFrameMap[body_name] = fixedBodyFrame;
156  }
157 
158  return model.mFixedBodies.size() + model.fixed_body_discriminator - 1;
159 }
160 
161 unsigned int addBodyMultiDofJoint(Model& model, const unsigned int parent_id, const SpatialTransform& joint_frame, const Joint& joint, const Body& body,
162  std::string body_name)
163 {
164  // Here we emulate multi DoF joints by simply adding nullbodies. This
165  // allows us to use fixed size elements for S,v,a, etc. which is very
166  // fast in Eigen.
167  unsigned int joint_count = 0;
168  if (joint.mJointType == JointType1DoF)
169  {
170  joint_count = 1;
171  }
172  else if (joint.mJointType == JointType2DoF)
173  {
174  joint_count = 2;
175  }
176  else if (joint.mJointType == JointType3DoF)
177  {
178  joint_count = 3;
179  }
180  else if (joint.mJointType == JointType4DoF)
181  {
182  joint_count = 4;
183  }
184  else if (joint.mJointType == JointType5DoF)
185  {
186  joint_count = 5;
187  }
188  else if (joint.mJointType == JointType6DoF)
189  {
190  joint_count = 6;
191  }
192  else if (joint.mJointType == JointTypeFloatingBase)
193  // no action required
194  {
195  }
196  else
197  {
198  std::cerr << "Error: Invalid joint type: " << joint.mJointType << std::endl;
199 
200  assert(0 && !"Invalid joint type!");
201  }
202 
203  Body null_body(0., Vector3d(0., 0., 0.), Vector3d(0., 0., 0.));
204  null_body.mIsVirtual = true;
205 
206  unsigned int null_parent = parent_id;
207  SpatialTransform joint_frame_transform;
208 
209  if (joint.mJointType == JointTypeFloatingBase)
210  {
211  null_parent = model.addBody(parent_id, joint_frame, Joint(JointTypeTranslationXYZ), null_body);
212 
213  return model.addBody(null_parent, SpatialTransform(), Joint(JointTypeSpherical), body, body_name);
214  }
215 
216  Joint single_dof_joint;
217  unsigned int j;
218 
219  // Here we add multiple virtual bodies that have no mass or inertia for
220  // which each is attached to the model with a single degree of freedom
221  // joint.
222  for (j = 0; j < joint_count; j++)
223  {
224  single_dof_joint = Joint(joint.mJointAxes[j]);
225  if (single_dof_joint.mJointType == JointType1DoF)
226  {
227  Vector3d rotation(joint.mJointAxes[j][0], joint.mJointAxes[j][1], joint.mJointAxes[j][2]);
228  Vector3d translation(joint.mJointAxes[j][3], joint.mJointAxes[j][4], joint.mJointAxes[j][5]);
229 
230  if (rotation == Vector3d(0., 0., 0.))
231  {
232  single_dof_joint = Joint(JointTypePrismatic, translation);
233  }
234  else if (translation == Vector3d(0., 0., 0.))
235  {
236  single_dof_joint = Joint(JointTypeRevolute, rotation);
237  }
238  else
239  {
240  std::cerr << "Invalid joint axis: " << joint.mJointAxes[0].transpose() << ". Helical joints not (yet) supported." << std::endl;
241  abort();
242  }
243  }
244 
245  // the first joint has to be transformed by joint_frame, all the
246  // others must have a null transformation
247  if (j == 0)
248  {
249  joint_frame_transform = joint_frame;
250  }
251  else
252  {
253  joint_frame_transform = SpatialTransform();
254  }
255 
256  if (j == joint_count - 1)
257  {
258  // if we are at the last we must add the real body
259  break;
260  }
261  else
262  {
263  // otherwise we just add an intermediate body
264  null_parent = model.addBody(null_parent, joint_frame_transform, single_dof_joint, null_body);
265  }
266  }
267 
268  return model.addBody(null_parent, joint_frame_transform, single_dof_joint, body, body_name);
269 }
270 
271 unsigned int Model::addBody(const unsigned int parent_id, const SpatialTransform& joint_frame, const Joint& joint, const Body& body, std::string body_name)
272 {
273  assert(lambda.size() > 0);
274  assert(joint.mJointType != JointTypeUndefined);
275 
276  if (joint.mJointType == JointTypeFixed)
277  {
278  previously_added_body_id = addBodyFixedJoint(*this, parent_id, joint_frame, joint, body, body_name);
279 
281  }
282  else if ((joint.mJointType == JointTypeSpherical) || (joint.mJointType == JointTypeEulerZYX) || (joint.mJointType == JointTypeEulerXYZ) ||
284  {
285  // no action required
286  }
287  else if (joint.mJointType != JointTypePrismatic && joint.mJointType != JointTypeRevolute && joint.mJointType != JointTypeRevoluteX &&
289  {
290  previously_added_body_id = addBodyMultiDofJoint(*this, parent_id, joint_frame, joint, body, body_name);
292  }
293 
294  // If we add the body to a fixed body we have to make sure that we
295  // actually add it to its movable parent.
296  unsigned int movable_parent_id = parent_id;
297  SpatialTransform movable_parent_transform;
298 
299  if (IsFixedBodyId(parent_id))
300  {
301  unsigned int fbody_id = parent_id - fixed_body_discriminator;
302  movable_parent_id = mFixedBodies.at(fbody_id).mMovableParent;
303  movable_parent_transform = mFixedBodies.at(fbody_id).mParentTransform;
304  }
305 
306  // structural information
307  lambda.push_back(movable_parent_id);
308  unsigned int lambda_q_last = mJoints.back().q_index;
309 
310  if (mJoints[mJoints.size() - 1].mDoFCount > 0 && mJoints[mJoints.size() - 1].mJointType != JointTypeCustom)
311  {
312  lambda_q_last = lambda_q_last + mJoints.back().mDoFCount;
313  }
314  else if (mJoints[mJoints.size() - 1].mJointType == JointTypeCustom)
315  {
316  lambda_q_last = lambda_q_last + mCustomJoints.back()->mDoFCount;
317  }
318 
319  for (unsigned int i = 0; i < joint.mDoFCount; i++)
320  {
321  lambda_q.push_back(lambda_q_last + i);
322  }
323  mu.push_back(std::vector<unsigned int>());
324  mu.at(movable_parent_id).push_back(mBodies.size());
325 
326  num_branch_ends = 0;
327  for(unsigned int i = 0; i < mu.size(); ++i)
328  {
329  if(mu[i].size() == 0)
330  {
331  num_branch_ends++;
332  }
333  }
334 
335  // Bodies
336  X_lambda.push_back(joint_frame);
337 
338  ReferenceFramePtr bodyFrame;
339  ReferenceFramePtr parentBodyFrame;
340  if (!movable_parent_id)
341  {
342  parentBodyFrame = ReferenceFrame::getWorldFrame();
343  // movable_parent_id = 0 so this is the root body, and it's parent frame is world frame
344  bodyFrame.reset(new ReferenceFrame(body_name, parentBodyFrame, X_lambda.back(), true, mBodies.size()));
345  }
346  else
347  {
348  parentBodyFrame = bodyFrames.at(movable_parent_id);
349  bodyFrame.reset(new ReferenceFrame(body_name, parentBodyFrame, joint_frame * movable_parent_transform, true, mBodies.size()));
350  }
351 
352  bodyFrames.push_back(bodyFrame);
353  referenceFrameMap[body_name] = bodyFrame;
354 
355  mBodies.push_back(body);
356  nbodies0_vec.conservativeResize(mBodies.size());
357  nbodies0_vec.setZero();
358 
359  if (!body_name.empty())
360  {
361  if (mBodyNameMap.find(body_name) != mBodyNameMap.end())
362  {
363  std::string msg = "Error: Body with name '" + body_name + "' already exists!";
364  throw RdlException(msg);
365  }
366  mBodyNameMap[body_name] = mBodies.size() - 1;
367  }
368 
369  // state information
370  // Body spatial velocity. Expressed in body frame
371  v.push_back(SpatialMotion(bodyFrame, ReferenceFrame::getWorldFrame(), bodyFrame, SpatialVectorZero));
372  a.push_back(SpatialAcceleration(bodyFrame, ReferenceFrame::getWorldFrame(), bodyFrame, SpatialVectorZero));
373 
374  // Joints
375  unsigned int prev_joint_index = mJoints.size() - 1;
376  mJoints.push_back(joint);
377 
378  mJoints.back().q_index = mJoints.at(prev_joint_index).q_index + mJoints.at(prev_joint_index).mDoFCount;
379 
380  S.push_back(MotionVector(joint.mJointAxes[0]));
381  S_o.push_back(MotionVector(SpatialVectorZero));
382  // Joint state variables
383  X_J.push_back(SpatialTransform());
384  c_J.push_back(SpatialVector(0., 0., 0., 0., 0., 0.));
385 
386  v_J.push_back(SpatialMotion(bodyFrame, parentBodyFrame, bodyFrame, joint.mJointAxes[0]));
387 
388  // workspace for joints with 3 dof
389  multdof3_S.push_back(Matrix63::Zero(6, 3));
390  multdof3_S_o.push_back(Matrix63::Zero(6, 3));
391  multdof3_U.push_back(Matrix63::Zero());
392  multdof3_Dinv.push_back(Matrix3d::Zero());
393  multdof3_u.push_back(Vector3d::Zero());
394  multdof3_w_index.push_back(0);
395 
396  dof_count = dof_count + joint.mDoFCount;
397 
398  ndof0_mat.conservativeResize(dof_count, dof_count);
399  ndof0_mat.setZero();
400 
401  ndof0_vec.conservativeResize(dof_count);
402  ndof0_vec.setZero();
403 
404  // update the w components of the Quaternions. They are stored at the end
405  // of the q vector
406  int multdof3_joint_counter = 0;
407  for (unsigned int i = 1; i < mJoints.size(); i++)
408  {
409  if (mJoints.at(i).mJointType == JointTypeSpherical)
410  {
411  multdof3_w_index.at(i) = dof_count + multdof3_joint_counter;
412  multdof3_joint_counter++;
413  }
414  }
415 
416  q_size = dof_count + multdof3_joint_counter;
417  q0_vec.conservativeResize(q_size);
418  q0_vec.setZero();
419 
420  qdot_size = qdot_size + joint.mDoFCount;
421 
422  three_x_qd0.conservativeResize(3, qdot_size);
423  three_x_qd0.setZero();
424 
425  // we have to invert the transformation as it is later always used from the
426  // child bodies perspective.
427  X_T.push_back(joint_frame * movable_parent_transform);
428 
429  // Dynamic variables
430  c.push_back(SpatialVector(0., 0., 0., 0., 0., 0.));
431  IA.push_back(SpatialMatrix::Zero(6, 6));
432  pA.push_back(RobotDynamics::Math::SpatialForce(bodyFrame, 0., 0., 0., 0., 0., 0.));
433  U.push_back(SpatialVector(0., 0., 0., 0., 0., 0.));
434 
435  d = VectorNd::Zero(mBodies.size());
436  u = VectorNd::Zero(mBodies.size());
437 
438  f.push_back(RobotDynamics::Math::SpatialForce(bodyFrame, 0., 0., 0., 0., 0., 0.));
439  f_b.push_back(RobotDynamics::Math::SpatialForce(bodyFrame, 0., 0., 0., 0., 0., 0.));
440 
441  ReferenceFramePtr centerOfMassFrame;
442  centerOfMassFrame.reset(new FixedReferenceFrame(body_name + "_com", bodyFrames.back(), Xtrans(body.mCenterOfMass), bodyFrame->getMovableBodyId()));
443 
444  bodyCenteredFrames.push_back(centerOfMassFrame);
445 
446  if (!validateRigidBodyInertia(body))
447  {
448  std::cerr << "\033[1;31m Body " << body_name << " failed inertia validation\033[0m" << std::endl;
449  }
450 
451  SpatialInertia bodyInertia(bodyFrames.back(), createFromMassComInertiaC(body.mMass, body.mCenterOfMass, body.mInertia));
452  SpatialInertia bodyCenteredInertia(centerOfMassFrame, createFromMassComInertiaC(body.mMass, Vector3dZero, body.mInertia));
453 
454  I.push_back(bodyInertia);
455  Ib_c.push_back(bodyCenteredInertia);
456  Ic.push_back(bodyInertia);
457 
458  hc.push_back(RobotDynamics::Math::Momentum());
459 
460  if (mBodies.size() == fixed_body_discriminator)
461  {
462  std::cerr << "Error: cannot add more than " << fixed_body_discriminator
463  << " movable bodies. You need to modify "
464  "Model::fixed_body_discriminator for this."
465  << std::endl;
466  assert(0);
467  abort();
468  }
469 
470  previously_added_body_id = mBodies.size() - 1;
471 
472  mJointUpdateOrder.clear();
473 
474  // update the joint order computation
475  std::vector<std::pair<JointType, unsigned int>> joint_types;
476  for (unsigned int i = 0; i < mJoints.size(); i++)
477  {
478  joint_types.push_back(std::pair<JointType, unsigned int>(mJoints[i].mJointType, i));
479  mJointUpdateOrder.push_back(mJoints[i].mJointType);
480  }
481 
482  mJointUpdateOrder.clear();
483  JointType current_joint_type = JointTypeUndefined;
484  while (joint_types.size() != 0)
485  {
486  current_joint_type = joint_types[0].first;
487 
488  std::vector<std::pair<JointType, unsigned int>>::iterator type_iter = joint_types.begin();
489 
490  while (type_iter != joint_types.end())
491  {
492  if (type_iter->first == current_joint_type)
493  {
494  mJointUpdateOrder.push_back(type_iter->second);
495  type_iter = joint_types.erase(type_iter);
496  }
497  else
498  {
499  ++type_iter;
500  }
501  }
502  }
503 
504  std::vector<unsigned int> parent_chain(lambda_chain.at(movable_parent_id).size() + 1);
505  for (unsigned int idx = 0; idx < lambda_chain.at(movable_parent_id).size(); idx++)
506  {
507  parent_chain[idx] = lambda_chain.at(movable_parent_id).at(idx);
508  }
509 
510  parent_chain.back() = previously_added_body_id; // add this joint
511  lambda_chain.push_back(parent_chain);
512 
513  mass += body.mMass;
515 }
516 
517 unsigned int Model::appendBody(const Math::SpatialTransform& joint_frame, const Joint& joint, const Body& body, std::string body_name)
518 {
519  return Model::addBody(previously_added_body_id, joint_frame, joint, body, body_name);
520 }
521 
522 unsigned int Model::addBodyCustomJoint(const unsigned int parent_id, const Math::SpatialTransform& joint_frame, CustomJoint* custom_joint, const Body& body,
523  std::string body_name)
524 {
525  custom_joint->ndof0_vec = VectorNd::Zero(custom_joint->mDoFCount);
526  Joint proxy_joint(JointTypeCustom, custom_joint->mDoFCount);
527  proxy_joint.custom_joint_index = mCustomJoints.size();
528 
529  // proxy_joint.mDoFCount = custom_joint->mDoFCount; //MM added. Otherwise
530  // model.q_size = 0, which is not good.
531 
532  mCustomJoints.push_back(custom_joint);
533 
534  unsigned int body_id = addBody(parent_id, joint_frame, proxy_joint, body, body_name);
535 
536  return body_id;
537 }
538 
539 void Model::crawlChainKinematics(unsigned int b_id, std::atomic<unsigned int>* branch_ends, const Math::VectorNd *Q, const Math::VectorNd *QDot, const Math::VectorNd *QDDot)
540 {
541  if(b_id > 0)
542  {
543  if(Q && !QDot && !QDDot)
544  {
545  jcalc(*this, b_id, (*Q), q0_vec);
546  }
547  else if(Q && QDot && !QDDot)
548  {
549  jcalc(*this, b_id, *Q, *QDot);
550 
551  ReferenceFramePtr bodyFrame = bodyFrames[b_id];
552  unsigned int lambda_id = lambda[b_id];
553 
554  if(lambda_id != 0)
555  {
556  v[b_id].set(v[lambda_id].transform_copy(bodyFrame->getTransformFromParent()) + v_J[b_id]);
557  c[b_id] = c_J[b_id] + v[b_id] % v_J[b_id];
558  }
559  else
560  {
561  v[b_id].set(v_J[b_id]);
562  c[b_id] = c_J[b_id] + v[b_id] % v_J[b_id];
563  }
564  }
565  else if(Q && QDot && QDDot)
566  {
567  jcalc(*this, b_id, *Q, *QDot);
568 
569  ReferenceFramePtr bodyFrame = bodyFrames[b_id];
570  unsigned int lambda_id = lambda[b_id];
571 
572  if(lambda_id != 0)
573  {
574  v[b_id].set(v[lambda_id].transform_copy(bodyFrame->getTransformFromParent()) + v_J[b_id]);
575  c[b_id] = c_J[b_id] + v[b_id] % v_J[b_id];
576  }
577  else
578  {
579  v[b_id].set(v_J[b_id]);
580  c[b_id] = c_J[b_id] + v[b_id] % v_J[b_id];
581  }
582 
583  unsigned int q_index = mJoints[b_id].q_index;
584 
585  if(lambda_id != 0)
586  {
587  a[b_id].set(a[lambda_id].transform_copy(bodyFrame->getTransformFromParent()) + c[b_id]);
588  }
589  else
590  {
591  a[b_id].set(c[b_id]);
592  }
593 
594  if(mJoints[b_id].mJointType != JointTypeCustom)
595  {
596  if(mJoints[b_id].mDoFCount == 1)
597  {
598  a[b_id].set(a[b_id] + S[b_id] * (*QDDot)[q_index]);
599  }
600  else if(mJoints[b_id].mDoFCount == 3)
601  {
602  Vector3d omegadot_temp((*QDDot)[q_index], (*QDDot)[q_index + 1], (*QDDot)[q_index + 2]);
603  a[b_id].set(a[b_id] + multdof3_S[b_id] * omegadot_temp);
604  }
605  }
606  else
607  {
608  unsigned int custom_index = mJoints[b_id].custom_joint_index;
609  const CustomJoint *custom_joint = mCustomJoints[custom_index];
610  unsigned int joint_dof_count = custom_joint->mDoFCount;
611 
612  a[b_id].set(a[b_id] + (mCustomJoints[custom_index]->S * (QDDot->block(q_index, 0, joint_dof_count, 1))));
613  }
614  }
615  }
616 
617  if(mu[b_id].size() > 1)
618  {
619  unsigned int mu_size = mu[b_id].size();
620  for(unsigned int i = 0; i < mu_size - 1; ++i)
621  {
622  // spawn threads here
623  io_service.post(boost::bind(&Model::crawlChainKinematics, this, mu[b_id][i], branch_ends, Q, QDot, QDDot));
624  }
625 
626  // we have a current thread that can process this one, so no need to spawn yet another thread
627  crawlChainKinematics(mu[b_id][mu_size - 1], branch_ends, Q, QDot, QDDot);
628 
629  return;
630  }
631  else if(mu[b_id].size() == 1)
632  {
633  crawlChainKinematics(mu[b_id][0], branch_ends, Q, QDot, QDDot);
634  return;
635  }
636 
637  (*branch_ends)++;
638 }
std::vector< unsigned int > lambda_q
Definition: Model.h:159
unsigned int mDoFCount
Definition: Joint.h:688
Math::MotionVectorV S_o
Definition: Model.h:212
std::vector< Math::SpatialMatrix > IA
The spatial inertia of the bodies.
Definition: Model.h:251
std::vector< unsigned int > mJointUpdateOrder
Definition: Model.h:221
bool IsFixedBodyId(unsigned int body_id) const
Checks whether the body is rigidly attached to another body.
Definition: Model.h:483
Emulated 3 DoF joint.
Definition: Joint.h:209
std::vector< Joint > mJoints
All joints.
Definition: Model.h:209
3 DoF joint that uses Euler ZYX convention (faster than emulated
Definition: Joint.h:197
SpatialVector SpatialVectorZero
Describes all properties of a single body.
Definition: Body.h:30
Math::VectorNd u
Temporary variable u (RBDA p. 130)
Definition: Model.h:263
std::vector< Math::SpatialVector > c_J
Definition: Model.h:217
User defined joints of varying size.
Definition: Joint.h:213
std::vector< unsigned int > multdof3_w_index
Definition: Model.h:240
VectorNd QDDot
boost::thread_group thread_pool
Definition: Model.h:336
Math::VectorNd ndof0_vec
Definition: Joint.h:696
std::vector< Math::Matrix63 > multdof3_U
Definition: Model.h:237
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
Definition: Joint.h:662
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
unsigned int num_branch_ends
Definition: Model.h:328
VectorNd QDot
Math::VectorNd ndof0_vec
Definition: Model.h:284
Keeps the information of a body and how it is attached to another body.
Definition: Body.h:173
Math::SpatialInertiaV Ib_c
Definition: Model.h:273
VectorNd Q
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
Fixed joint which causes the inertial properties to be merged with.
Definition: Joint.h:205
void join(const Math::SpatialTransform &transform, const Body &other_body)
Joins inertial parameters of two bodies to create a composite body.
Definition: Body.h:98
void jcalc(Model &model, unsigned int joint_id, const Math::VectorNd &q, const Math::VectorNd &qdot)
Computes all variables for a joint model and updates the body frame as well as the body&#39;s center of m...
Definition: Joint.cc:23
std::vector< boost::thread * > threads
Definition: Model.h:335
static ReferenceFramePtr getWorldFrame()
Get a pointer to the world frame.
double mMass
The mass of the body.
Definition: Body.h:156
Math::MotionVector gravity
the cartesian vector of the gravity
Definition: Model.h:196
Math::Matrix3d mInertia
Inertia matrix at the center of mass.
Definition: Body.h:162
unsigned int appendBody(const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Adds a Body to the model such that the previously added Body is the Parent.
Definition: Model.cc:517
std::vector< std::vector< unsigned int > > mu
Definition: Model.h:162
std::vector< ReferenceFramePtr > bodyFrames
Definition: Model.h:145
unsigned int addBodyCustomJoint(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, CustomJoint *custom_joint, const Body &body, std::string body_name="")
Definition: Model.cc:522
Math::VectorNd nbodies0_vec
Definition: Model.h:285
ReferenceFramePtr worldFrame
Definition: Model.h:141
std::map< std::string, unsigned int > mBodyNameMap
Human readable names for the bodies.
Definition: Model.h:324
unsigned int addBody(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Connects a given body to the model.
Definition: Model.cc:271
double mMass
The mass of the body.
Definition: Body.h:176
std::vector< Math::SpatialTransform > X_lambda
Transformation from the parent body to the current body .
Definition: Model.h:295
Math::SpatialMotionV v
Definition: Model.h:202
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
boost::asio::io_service io_service
Definition: Model.h:333
unsigned int q_size
The size of the -vector. For models without spherical joints the value is the same as Model::dof_coun...
Definition: Model.h:178
std::vector< Math::Momentum > hc
Definition: Model.h:275
Compact representation of spatial transformations.
Math::MatrixNd ndof0_mat
Definition: Model.h:281
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...
Math::SpatialForceV pA
The spatial bias force.
Definition: Model.h:254
Emulated 4 DoF joint.
Definition: Joint.h:210
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
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
unsigned int custom_joint_index
Definition: Joint.h:635
Emulated 6 DoF joint.
Definition: Joint.h:212
Describes a joint relative to the predecessor body.
Definition: Joint.h:228
3 DoF joint that uses Euler XYZ convention (faster than emulated
Definition: Joint.h:199
Emulated 5 DoF joint.
Definition: Joint.h:211
ReferenceFrame object used to tell what frame objects are expressed in. Every ReferenceFrame has a po...
Math::VectorNd q0_vec
Definition: Model.h:283
Math::VectorNd d
Temporary variable D_i (RBDA p. 130)
Definition: Model.h:260
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.h:25
void crawlChainKinematics(unsigned int b_id, std::atomic< unsigned int > *branch_ends, const Math::VectorNd *Q, const Math::VectorNd *QDot, const Math::VectorNd *QDDot)
Definition: Model.cc:539
A Math::SpatialInertia is a RigidBodyInertia explicitly expressed in a RobotDynamics::ReferenceFrame...
unsigned int addBodyMultiDofJoint(Model &model, const unsigned int parent_id, const SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name)
Definition: Model.cc:161
Math::SpatialAccelerationV a
The spatial velocity of the bodies.
Definition: Model.h:200
std::vector< CustomJoint * > mCustomJoints
Definition: Model.h:242
JointType
General types of joints.
Definition: Joint.h:187
std::map< std::string, ReferenceFramePtr > referenceFrameMap
Definition: Model.h:327
std::vector< Math::Matrix3d > multdof3_Dinv
Definition: Model.h:238
std::vector< ReferenceFramePtr > bodyCenteredFrames
Definition: Model.h:152
unsigned int mDoFCount
Number of degrees of freedom of the joint. Note: CustomJoints.
Definition: Joint.h:633
Math::SpatialVector * mJointAxes
The spatial axes of the joint.
Definition: Joint.h:625
Model(unsigned int *n_threads=nullptr)
Constructor.
Definition: Model.cc:22
Contains all information about the rigid body model.
Definition: Model.h:121
A 6-DoF joint for floating-base (or freeflyer) systems.
Definition: Joint.h:204
Math types such as vectors and matrices and utility functions.
Definition: ForceVector.hpp:21
std::vector< Math::SpatialVector > U
Temporary variable U_i (RBDA p. 130)
Definition: Model.h:257
Math::SpatialInertiaV I
Definition: Model.h:269
std::vector< Math::SpatialVector > c
The velocity dependent spatial acceleration.
Definition: Model.h:248
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
Definition: Model.h:312
SpatialMatrix SpatialMatrixIdentity
Math::Vector3d mCenterOfMass
The position of the center of mass in body coordinates.
Definition: Body.h:159
Emulated 2 DoF joint.
Definition: Joint.h:208
Math::RigidBodyInertiaV Ic
Definition: Model.h:270
SpatialAcceleration. For clarity, the ReferenceFrames are stated as follows. A spatial acceleration i...
A SpatialForce is a spatial vector with the angular part being three moments and the linear part bein...
bool validateRigidBodyInertia(const Body &body)
Definition: Model.h:677
A custom exception.
Math::MatrixNd three_x_qd0
Definition: Model.h:282
Math::SpatialMotionV v_J
Definition: Model.h:219
std::vector< std::vector< unsigned int > > lambda_chain
Definition: Model.h:157
std::vector< Math::Matrix63 > multdof3_S
Motion subspace for joints with 3 degrees of freedom.
Definition: Model.h:235
std::vector< ReferenceFramePtr > fixedBodyFrames
Definition: Model.h:154
3 DoF joint using Quaternions for joint positional variables and
Definition: Joint.h:195
unsigned int mMovableParent
Id of the movable body that this fixed body is attached to.
Definition: Body.h:185
std::vector< Math::SpatialTransform > X_J
Definition: Model.h:215
unsigned int addBodyFixedJoint(Model &model, const unsigned int parent_id, const SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name)
Definition: Model.cc:107
std::vector< Math::Vector3d > multdof3_u
Definition: Model.h:239
Math::SpatialTransform mParentTransform
Transforms spatial quantities expressed for the parent to the.
Definition: Body.h:189
JointType mJointType
Type of joint.
Definition: Joint.h:628
Math::SpatialForceV f
Internal forces on the body (used only InverseDynamics())
Definition: Model.h:266
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
std::vector< Math::SpatialTransform > X_T
Transformations from the parent body to the frame of the joint.
Definition: Model.h:225
unsigned int previously_added_body_id
Id of the previously added body, required for Model::appendBody()
Definition: Model.h:193
unsigned int qdot_size
The size of the.
Definition: Model.h:187
Math::SpatialForceV f_b
Definition: Model.h:267
Math::MotionVectorV S
Definition: Model.h:211
static FixedBody CreateFromBody(const Body &body)
Definition: Body.h:192
static RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d &com, const Matrix3d &inertia_C)
3 DoF joint that uses Euler YXZ convention (faster than emulated
Definition: Joint.h:201


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