Biorbd
Joints.cpp
1 #define BIORBD_API_EXPORTS
2 #include "RigidBody/Joints.h"
3 
4 #include <rbdl/rbdl_utils.h>
5 #include <rbdl/Kinematics.h>
6 #include <rbdl/Dynamics.h>
7 #include "Utils/String.h"
8 #include "Utils/Quaternion.h"
9 #include "Utils/Matrix.h"
10 #include "Utils/Error.h"
11 #include "Utils/RotoTrans.h"
12 #include "Utils/Rotation.h"
13 #include "Utils/SpatialVector.h"
14 #include "RigidBody/GeneralizedCoordinates.h"
15 #include "RigidBody/GeneralizedVelocity.h"
16 #include "RigidBody/GeneralizedAcceleration.h"
17 #include "RigidBody/GeneralizedTorque.h"
18 #include "RigidBody/Segment.h"
19 #include "RigidBody/Markers.h"
20 #include "RigidBody/NodeSegment.h"
21 #include "RigidBody/MeshFace.h"
22 #include "RigidBody/Mesh.h"
23 #include "RigidBody/SegmentCharacteristics.h"
24 #include "RigidBody/Contacts.h"
25 
27  RigidBodyDynamics::Model(),
28  m_segments(std::make_shared<std::vector<biorbd::rigidbody::Segment>>()),
29  m_nbRoot(std::make_shared<unsigned int>(0)),
30  m_nbDof(std::make_shared<unsigned int>(0)),
31  m_nbQ(std::make_shared<unsigned int>(0)),
32  m_nbQdot(std::make_shared<unsigned int>(0)),
33  m_nbQddot(std::make_shared<unsigned int>(0)),
34  m_nRotAQuat(std::make_shared<unsigned int>(0)),
35  m_isKinematicsComputed(std::make_shared<bool>(false)),
36  m_totalMass(std::make_shared<double>(0))
37 {
38  this->gravity = biorbd::utils::Vector3d (0, 0, -9.81); // Redéfinition de la gravité pour qu'elle soit en z
39 }
40 
42  RigidBodyDynamics::Model(other),
43  m_segments(other.m_segments),
44  m_nbRoot(other.m_nbRoot),
45  m_nbDof(other.m_nbDof),
46  m_nbQ(other.m_nbQ),
47  m_nbQdot(other.m_nbQdot),
48  m_nbQddot(other.m_nbQddot),
49  m_nRotAQuat(other.m_nRotAQuat),
50  m_isKinematicsComputed(other.m_isKinematicsComputed),
51  m_totalMass(other.m_totalMass)
52 {
53 
54 }
55 
57 {
58 
59 }
60 
62 {
64  copy.DeepCopy(*this);
65  return copy;
66 }
67 
69 {
70  static_cast<RigidBodyDynamics::Model&>(*this) = other;
71  m_segments->resize(other.m_segments->size());
72  for (unsigned int i=0; i<other.m_segments->size(); ++i)
73  (*m_segments)[i] = (*other.m_segments)[i].DeepCopy();
74  *m_nbRoot = *other.m_nbRoot;
75  *m_nbDof = *other.m_nbDof;
76  *m_nbQ = *other.m_nbQ;
77  *m_nbQdot = *other.m_nbQdot;
78  *m_nbQddot = *other.m_nbQddot;
79  *m_nRotAQuat = *other.m_nRotAQuat;
80  *m_isKinematicsComputed = *other.m_isKinematicsComputed;
81  *m_totalMass = *other.m_totalMass;
82 }
83 
85  return nbQ();
86 }
87 unsigned int biorbd::rigidbody::Joints::nbDof() const {
88  return *m_nbDof;
89 }
90 
91 std::vector<biorbd::utils::String> biorbd::rigidbody::Joints::nameDof() const
92 {
93  std::vector<biorbd::utils::String> names;
94  for (unsigned int i = 0; i < nbSegment(); ++i) {
95  for (unsigned int j = 0; j < segment(i).nbDof(); ++j) {
96  names.push_back(segment(i).name() + "_" + segment(i).nameDof(j));
97  }
98  }
99  // Append Quaternion Q
100  for (unsigned int i = 0; i < nbSegment(); ++i) {
101  if (segment(i).isRotationAQuaternion()) {
102  names.push_back(segment(i).name() + "_" + segment(i).nameDof(3));
103  }
104  }
105  return names;
106 }
107 
108 unsigned int biorbd::rigidbody::Joints::nbQ() const {
109  return *m_nbQ;
110 }
111 unsigned int biorbd::rigidbody::Joints::nbQdot() const {
112  return *m_nbQdot;
113 }
115  return *m_nbQddot;
116 }
117 unsigned int biorbd::rigidbody::Joints::nbRoot() const {
118  return *m_nbRoot;
119 }
120 
122  return *m_totalMass;
123 }
124 
126  const biorbd::utils::String &segmentName,
127  const biorbd::utils::String &parentName,
128  const biorbd::utils::String &translationSequence,
129  const biorbd::utils::String &rotationSequence,
130  const std::vector<biorbd::utils::Range>& QRanges,
131  const std::vector<biorbd::utils::Range>& QDotRanges,
132  const std::vector<biorbd::utils::Range>& QDDotRanges,
133  const biorbd::rigidbody::SegmentCharacteristics& characteristics,
134  const RigidBodyDynamics::Math::SpatialTransform& centreOfRotation,
135  int forcePlates)
136 {
138  *this, segmentName, parentName, translationSequence,
139  rotationSequence, QRanges, QDotRanges, QDDotRanges, characteristics,
140  centreOfRotation, forcePlates);
141  if (this->GetBodyId(parentName.c_str()) == std::numeric_limits<unsigned int>::max())
142  *m_nbRoot += tp.nbDof(); // If the segment name is "Root", add the number of DoF of root
143  *m_nbDof += tp.nbDof();
144  *m_nbQ += tp.nbQ();
145  *m_nbQdot += tp.nbQdot();
146  *m_nbQddot += tp.nbQddot();
147 
148  if (tp.isRotationAQuaternion())
149  ++*m_nRotAQuat;
150 
151  *m_totalMass += characteristics.mMass; // Add the segment mass to the total body mass
152  m_segments->push_back(tp);
153  return 0;
154 }
156  const biorbd::utils::String &segmentName,
157  const biorbd::utils::String &parentName,
158  const biorbd::utils::String &seqR,
159  const std::vector<biorbd::utils::Range>& QRanges,
160  const std::vector<biorbd::utils::Range>& QDotRanges,
161  const std::vector<biorbd::utils::Range>& QDDotRanges,
162  const biorbd::rigidbody::SegmentCharacteristics& characteristics,
163  const RigidBodyDynamics::Math::SpatialTransform& cor,
164  int forcePlates)
165 {
167  *this, segmentName, parentName, seqR, QRanges, QDotRanges, QDDotRanges,
168  characteristics, cor, forcePlates);
169  if (this->GetBodyId(parentName.c_str()) == std::numeric_limits<unsigned int>::max())
170  *m_nbRoot += tp.nbDof(); // If the name of the segment is "Root", add the number of DoF of root
171  *m_nbDof += tp.nbDof();
172 
173  *m_totalMass += characteristics.mMass; // Add the segment mass to the total body mass
174  m_segments->push_back(tp);
175  return 0;
176 }
177 
179 {
180  return gravity;
181 }
182 
184  const biorbd::utils::Vector3d &newGravity)
185 {
186  gravity = newGravity;
187 }
188 
190  biorbd::utils::Error::check(idx < m_segments->size(), "Asked for a wrong segment (out of range)");
191  return (*m_segments)[idx];
192 }
193 
195 {
196  return segment(static_cast<unsigned int>(GetBodyBiorbdId(name.c_str())));
197 }
198 
200 {
201  return static_cast<unsigned int>(m_segments->size());
202 }
203 
204 std::vector<RigidBodyDynamics::Math::SpatialVector> biorbd::rigidbody::Joints::dispatchedForce(
205  std::vector<std::vector<biorbd::utils::SpatialVector>> &spatialVector,
206  unsigned int frame) const
207 {
208  // Iterator on the force table
209  std::vector<biorbd::utils::SpatialVector> sv2; // Gather in the same table the values at the same instant of different platforms
210  for (auto vec : spatialVector)
211  sv2.push_back(vec[frame]);
212 
213  // Call the equivalent function that only manages on instant
214  return dispatchedForce(sv2);
215 }
216 
217 std::vector<RigidBodyDynamics::Math::SpatialVector> biorbd::rigidbody::Joints::dispatchedForce(
218  std::vector<biorbd::utils::SpatialVector> &sv) const{ // a spatialVector per platform
219  // Output table
220  std::vector<RigidBodyDynamics::Math::SpatialVector> sv_out;
221 
222  // Null Spatial vector nul to fill the final table
223  biorbd::utils::SpatialVector sv_zero(0.,0.,0.,0.,0.,0.);
224  sv_out.push_back(sv_zero); // The first one is associated with the universe
225 
226  // Dispatch the forces
227  for (auto segment : *m_segments){
228  unsigned int nbDof = segment.nbDof();
229  if (nbDof != 0){ // Do not add anything if the nbDoF is zero
230  // For each segment
231  for (unsigned int i=0; i<nbDof-1; ++i) // Put a sv_zero on each DoF except the last one
232  sv_out.push_back(sv_zero);
233  if (segment.platformIdx() >= 0){ // If the solid is in contact with the platform (!= -1)
234  sv_out.push_back(sv[static_cast<unsigned int>(segment.platformIdx())]); // Put the force of the corresponding platform
235  }
236  else
237  sv_out.push_back(sv_zero); // Otherwise, put zero
238  }
239  }
240 
241  // Return the STL vector of SpatialVector
242  return sv_out;
243 }
244 
246  for (int i=0; i<static_cast<int>(m_segments->size()); ++i)
247  if (!(*m_segments)[static_cast<unsigned int>(i)].name().compare(segmentName))
248  return i;
249  return -1;
250 }
251 
252 std::vector<biorbd::utils::RotoTrans> biorbd::rigidbody::Joints::allGlobalJCS(
254 {
255  UpdateKinematicsCustom (&Q, nullptr, nullptr);
256  return allGlobalJCS();
257 }
258 
259 std::vector<biorbd::utils::RotoTrans> biorbd::rigidbody::Joints::allGlobalJCS() const
260 {
261  std::vector<biorbd::utils::RotoTrans> out;
262  for (unsigned int i=0; i<m_segments->size(); ++i)
263  out.push_back(globalJCS(i));
264  return out;
265 }
266 
269  const biorbd::utils::String &name)
270 {
271  UpdateKinematicsCustom (&Q, nullptr, nullptr);
272  return globalJCS(name);
273 }
274 
277  unsigned int idx)
278 {
279  // update the Kinematics if necessary
280  UpdateKinematicsCustom (&Q, nullptr, nullptr);
281  return globalJCS(idx);
282 }
283 
285 {
286  return globalJCS(static_cast<unsigned int>(GetBodyBiorbdId(name)));
287 }
288 
290  unsigned int idx) const
291 {
292  return CalcBodyWorldTransformation((*m_segments)[idx].id());
293 }
294 
295 std::vector<biorbd::utils::RotoTrans> biorbd::rigidbody::Joints::localJCS() const{
296  std::vector<biorbd::utils::RotoTrans> out;
297 
298  for (unsigned int i=0; i<m_segments->size(); ++i)
299  out.push_back(localJCS(i));
300 
301  return out;
302 }
304  return localJCS(static_cast<unsigned int>(GetBodyBiorbdId(name.c_str())));
305 }
307  return (*m_segments)[idx].localJCS();
308 }
309 
310 
311 std::vector<biorbd::rigidbody::NodeSegment> biorbd::rigidbody::Joints::projectPoint(
313  const std::vector<biorbd::rigidbody::NodeSegment>& v,
314  bool updateKin)
315 {
316  if (updateKin) {
317  UpdateKinematicsCustom(&Q, nullptr, nullptr);
318  }
319 
320  // Assuming that this is also a marker type (via BiorbdModel)
321  const biorbd::rigidbody::Markers& marks = dynamic_cast<biorbd::rigidbody::Markers&>(*this);
322 
323  // Sécurité
324  biorbd::utils::Error::check(marks.nbMarkers() == v.size(), "Number of marker must be equal to number of Vector3d");
325 
326  std::vector<biorbd::rigidbody::NodeSegment> out;
327  for (unsigned int i = 0; i < marks.nbMarkers(); ++i) {
329  if (tp.nbAxesToRemove() != 0) {
330  tp = v[i].applyRT(globalJCS(tp.parent()).transpose());
331  // Prendre la position du nouveau marker avec les infos de celui du modèle
332  out.push_back(projectPoint(Q, tp, false));
333  }
334  else
335  // S'il ne faut rien retirer (renvoyer tout de suite la même position)
336  out.push_back(v[i]);
337  }
338  return out;
339 }
340 
343  const biorbd::utils::Vector3d &v,
344  int segmentIdx,
345  const biorbd::utils::String& axesToRemove,
346  bool updateKin)
347 {
348  if (updateKin) {
349  UpdateKinematicsCustom (&Q);
350  }
351 
352  // Create a marker
353  const biorbd::utils::String& segmentName(segment(static_cast<unsigned int>(segmentIdx)).name());
354  biorbd::rigidbody::NodeSegment node( v.applyRT(globalJCS(static_cast<unsigned int>(segmentIdx)).transpose()), "tp", segmentName,
355  true, true, axesToRemove, static_cast<int>(GetBodyId(segmentName.c_str())));
356 
357  // Project and then reset in global
358  return projectPoint(Q, node, false);
359 }
360 
364  bool updateKin)
365 {
366  // Assuming that this is also a Marker type (via BiorbdModel)
367  return dynamic_cast<biorbd::rigidbody::Markers &>(*this).marker(Q, n, true, updateKin);
368 }
369 
373  bool updateKin)
374 {
375  if (updateKin) {
376  UpdateKinematicsCustom (&Q);
377  }
378 
379  // Assuming that this is also a Marker type (via BiorbdModel)
380  biorbd::rigidbody::Markers &marks = dynamic_cast<biorbd::rigidbody::Markers &>(*this);
381 
382  // If the point has not been projected, there is no effect
383  if (node.nbAxesToRemove() != 0){
384  // Jacobian of the marker
385  node.applyRT(globalJCS(node.parent()).transpose());
386  biorbd::utils::Matrix G_tp(marks.markersJacobian(Q, node.parent(), biorbd::utils::Vector3d(0,0,0), false));
387  biorbd::utils::Matrix JCor(biorbd::utils::Matrix::Zero(9,nbQ()));
388  CalcMatRotJacobian(Q, GetBodyId(node.parent().c_str()), RigidBodyDynamics::Math::Matrix3d::Identity(), JCor, false);
389  for (unsigned int n=0; n<3; ++n)
390  if (node.isAxisKept(n))
391  G_tp += JCor.block(n*3,0,3,nbQ()) * node(n);
392 
393  return G_tp;
394  }
395  else {
396  // Return the value
397  return biorbd::utils::Matrix::Zero(3,nbQ());
398  }
399 }
400 
403  const utils::Vector3d &v,
404  int segmentIdx,
405  const biorbd::utils::String& axesToRemove,
406  bool updateKin)
407 {
408  // Find the point
409  const biorbd::rigidbody::NodeSegment& p(projectPoint(Q, v, segmentIdx, axesToRemove, updateKin));
410 
411  // Return the value
412  return projectPointJacobian(Q, p, updateKin);
413 }
414 
415 std::vector<biorbd::utils::Matrix> biorbd::rigidbody::Joints::projectPointJacobian(
417  const std::vector<biorbd::rigidbody::NodeSegment> &v,
418  bool updateKin)
419 {
420  // Gather the points
421  const std::vector<biorbd::rigidbody::NodeSegment>& tp(projectPoint(Q, v, updateKin));
422 
423  // Calculate the Jacobian if the point is not projected
424  std::vector<biorbd::utils::Matrix> G;
425 
426  for (unsigned int i=0; i<tp.size(); ++i){
427  // Actual marker
428  G.push_back(projectPointJacobian(Q, biorbd::rigidbody::NodeSegment(v[i]), false));
429  }
430  return G;
431 }
432 
433 RigidBodyDynamics::Math::SpatialTransform biorbd::rigidbody::Joints::CalcBodyWorldTransformation (
435  const unsigned int segmentIdx,
436  bool updateKin)
437 {
438  // update the Kinematics if necessary
439  if (updateKin) {
440  UpdateKinematicsCustom (&Q);
441  }
442  return CalcBodyWorldTransformation(segmentIdx);
443 }
444 
445 RigidBodyDynamics::Math::SpatialTransform biorbd::rigidbody::Joints::CalcBodyWorldTransformation(
446  const unsigned int segmentIdx) const
447 {
448  if (segmentIdx >= this->fixed_body_discriminator) {
449  unsigned int fbody_id = segmentIdx - this->fixed_body_discriminator;
450  unsigned int parent_id = this->mFixedBodies[fbody_id].mMovableParent;
451  biorbd::utils::RotoTrans parentRT(
452  this->X_base[parent_id].E.transpose(),
453  this->X_base[parent_id].r);
455  this->mFixedBodies[fbody_id].mParentTransform.E.transpose(),
456  this->mFixedBodies[fbody_id].mParentTransform.r);
457  const biorbd::utils::RotoTrans& transfo_tp = parentRT * bodyRT;
458  return RigidBodyDynamics::Math::SpatialTransform (transfo_tp.rot(), transfo_tp.trans());
459  }
460 
461  return RigidBodyDynamics::Math::SpatialTransform (this->X_base[segmentIdx].E.transpose(), this->X_base[segmentIdx].r);
462 }
463 
466  bool updateKin)
467 {
468  // Return the position of the center of mass from the generalized coordinates
469 
470  // Ensure that the model is in the right configuration
471  if (updateKin) {
472  UpdateKinematicsCustom(&Q);
473  }
474 
475  // For each segment, find the CoM (CoM = sum(segment_mass * pos_com_seg) / total mass)
476  const std::vector<biorbd::rigidbody::NodeSegment>& com_segment(CoMbySegment(Q,true));
477  biorbd::utils::Vector3d com(0, 0, 0);
478  for (unsigned int i=0; i<com_segment.size(); ++i)
479  com += (*m_segments)[i].characteristics().mMass * com_segment[i];
480 
481  // Divide by total mass
482  com = com/this->mass();
483 
484  // Return the CoM
485  return com;
486 }
487 
491  bool updateKin)
492 {
493  return CalcAngularMomentum(Q, Qdot, updateKin);
494 }
495 
498  bool updateKin)
499 {
500  RigidBodyDynamics::Math::MatrixNd massMatrix(nbQ(), nbQ());
501  massMatrix.setZero();
502  RigidBodyDynamics::CompositeRigidBodyAlgorithm(*this, Q, massMatrix, updateKin);
503  return massMatrix;
504 }
505 
509 {
510  // Ensure the model is in the right configuration
511  UpdateKinematicsCustom(&Q, &Qdot);
512 
513  // For each segment, find the CoM
514  biorbd::utils::Vector3d com_dot(0,0,0);
515 
516  // CoMdot = sum(mass_seg * Jacobian * qdot)/mass totale
517  biorbd::utils::Matrix Jac(biorbd::utils::Matrix(3,this->dof_count));
518  for (auto segment : *m_segments){
519  Jac.setZero();
520  RigidBodyDynamics::CalcPointJacobian(
521  *this, Q, GetBodyId(segment.name().c_str()),
522  segment.characteristics().mCenterOfMass, Jac, false);
523  com_dot += ((Jac*Qdot) * segment.characteristics().mMass);
524  }
525  // Divide by total mass
526  com_dot = com_dot/mass();
527 
528  // Return the velocity of CoM
529  return com_dot;
530 }
535 {
536  biorbd::utils::Scalar mass;
537  RigidBodyDynamics::Math::Vector3d com, com_ddot;
538  RigidBodyDynamics::Utils::CalcCenterOfMass(
539  *this, Q, Qdot, &Qddot, mass, com, nullptr, &com_ddot,
540  nullptr, nullptr, true);
541 
542 
543  // Return the acceleration of CoM
544  return com_ddot;
545 }
546 
549 {
550  // Return the position of the center of mass from the generalized coordinates
551 
552  // Ensure that the model is in the right configuration
553  UpdateKinematicsCustom(&Q, nullptr, nullptr);
554 
555  // Total jacobian
556  biorbd::utils::Matrix JacTotal(biorbd::utils::Matrix::Zero(3,this->dof_count));
557 
558  // CoMdot = sum(mass_seg * Jacobian * qdot)/mass total
559  biorbd::utils::Matrix Jac(biorbd::utils::Matrix::Zero(3,this->dof_count));
560  for (auto segment : *m_segments){
561  Jac.setZero();
562  RigidBodyDynamics::CalcPointJacobian(
563  *this, Q, GetBodyId(segment.name().c_str()),
564  segment.characteristics().mCenterOfMass, Jac, false);
565  JacTotal += segment.characteristics().mMass*Jac;
566  }
567 
568  // Divide by total mass
569  JacTotal /= this->mass();
570 
571  // Return the Jacobian of CoM
572  return JacTotal;
573 }
574 
575 
576 std::vector<biorbd::rigidbody::NodeSegment> biorbd::rigidbody::Joints::CoMbySegment(
578  bool updateKin) {
579  if (updateKin) {
580  UpdateKinematicsCustom (&Q);
581  }
582 
583  std::vector<biorbd::rigidbody::NodeSegment> out;
584  for (unsigned int i=0; i<m_segments->size(); ++i){
585  out.push_back(CoMbySegment(Q,i,false));
586  }
587  return out;
588 }
589 
592  bool updateKin)
593 {
594  std::vector<biorbd::rigidbody::NodeSegment> allCoM(CoMbySegment(Q, updateKin));
595  biorbd::utils::Matrix CoMs(3, allCoM.size());
596  for (unsigned int i=0; i<allCoM.size(); ++i){
597  CoMs.block(0, i, 3, 1) = allCoM[i];
598  }
599  return CoMs;
600 }
601 
602 
605  const unsigned int idx,
606  bool updateKin)
607 {
608  biorbd::utils::Error::check(idx < m_segments->size(), "Choosen segment doesn't exist");
609  if (updateKin) {
610  UpdateKinematicsCustom (&Q);
611  }
612  return RigidBodyDynamics::CalcBodyToBaseCoordinates(
613  *this, Q, (*m_segments)[idx].id(),
614  (*m_segments)[idx].characteristics().mCenterOfMass, false);
615 }
616 
617 
618 std::vector<biorbd::utils::Vector3d> biorbd::rigidbody::Joints::CoMdotBySegment(
621  bool updateKin)
622 {
623  if (updateKin) {
624  UpdateKinematicsCustom (&Q);
625  }
626 
627  std::vector<biorbd::utils::Vector3d> out;
628  for (unsigned int i=0; i<m_segments->size(); ++i){
629  out.push_back(CoMdotBySegment(Q,Qdot,i,false));
630  }
631  return out;
632 }
633 
634 
638  const unsigned int idx,
639  bool updateKin)
640 { // Position of the center of mass of segment i
641  biorbd::utils::Error::check(idx < m_segments->size(), "Choosen segment doesn't exist");
642  return CalcPointVelocity(
643  *this, Q, Qdot, (*m_segments)[idx].id(),
644  (*m_segments)[idx].characteristics().mCenterOfMass,updateKin);
645 }
646 
647 
648 std::vector<biorbd::utils::Vector3d> biorbd::rigidbody::Joints::CoMddotBySegment(
652  bool updateKin)
653 {
654  if (updateKin) {
655  UpdateKinematicsCustom (&Q);
656  }
657 
658  std::vector<biorbd::utils::Vector3d> out;
659  for (unsigned int i=0; i<m_segments->size(); ++i){
660  out.push_back(CoMddotBySegment(Q,Qdot,Qddot,i,false));
661  }
662  return out;
663 }
664 
665 
670  const unsigned int idx,
671  bool updateKin)
672 {
673  biorbd::utils::Error::check(idx < m_segments->size(), "Choosen segment doesn't exist");
674  if (updateKin) {
675  UpdateKinematicsCustom (&Q);
676  }
677  return RigidBodyDynamics::CalcPointAcceleration(
678  *this, Q, Qdot, Qddot, (*m_segments)[idx].id(),
679  (*m_segments)[idx].characteristics().mCenterOfMass,false);
680 }
681 
682 std::vector<std::vector<biorbd::utils::Vector3d>> biorbd::rigidbody::Joints::meshPoints(
684  bool updateKin)
685 {
686  if (updateKin) {
687  UpdateKinematicsCustom (&Q);
688  }
689  std::vector<std::vector<biorbd::utils::Vector3d>> v;
690 
691  // Find the position of the segments
692  const std::vector<biorbd::utils::RotoTrans>& RT(allGlobalJCS());
693 
694  // For all the segments
695  for (unsigned int i=0; i<nbSegment(); ++i)
696  v.push_back(meshPoints(RT,i));
697 
698  return v;
699 }
700 std::vector<biorbd::utils::Vector3d> biorbd::rigidbody::Joints::meshPoints(
702  unsigned int i,
703  bool updateKin)
704 {
705  if (updateKin) {
706  UpdateKinematicsCustom (&Q);
707  }
708 
709  // Find the position of the segments
710  const std::vector<biorbd::utils::RotoTrans>& RT(allGlobalJCS());
711 
712  return meshPoints(RT,i);
713 }
714 
715 std::vector<biorbd::utils::Matrix>
718  bool updateKin)
719 {
720  if (updateKin) {
721  UpdateKinematicsCustom (&Q);
722  }
723  const std::vector<biorbd::utils::RotoTrans>& RT(allGlobalJCS());
724 
725  std::vector<biorbd::utils::Matrix> all_points;
726  for (unsigned int i=0; i<m_segments->size(); ++i) {
727  biorbd::utils::Matrix mat(3, mesh(i).nbVertex());
728  for (unsigned int j=0; j<mesh(i).nbVertex(); ++j){
729  biorbd::utils::Vector3d tp (mesh(i).point(j));
730  tp.applyRT(RT[i]);
731  mat.block(0, j, 3, 1) = tp;
732  }
733  all_points.push_back(mat);
734  }
735  return all_points;
736 }
737 std::vector<biorbd::utils::Vector3d> biorbd::rigidbody::Joints::meshPoints(
738  const std::vector<biorbd::utils::RotoTrans> &RT,
739  unsigned int i) const{
740 
741  // Gather the position of the meshings
742  std::vector<biorbd::utils::Vector3d> v;
743  for (unsigned int j=0; j<mesh(i).nbVertex(); ++j){
744  biorbd::utils::Vector3d tp (mesh(i).point(j));
745  tp.applyRT(RT[i]);
746  v.push_back(tp);
747  }
748 
749  return v;
750 }
751 
752 std::vector<std::vector<biorbd::rigidbody::MeshFace>> biorbd::rigidbody::Joints::meshFaces() const{
753  // Gather the position of the meshings for all the segments
754  std::vector<std::vector<biorbd::rigidbody::MeshFace>> v_all;
755  for (unsigned int j=0; j<nbSegment(); ++j)
756  v_all.push_back(meshFaces(j));
757  return v_all;
758 }
759 const std::vector<biorbd::rigidbody::MeshFace> &biorbd::rigidbody::Joints::meshFaces(unsigned int idx) const{
760  // Find the position of the meshings for a segment i
761  return mesh(idx).faces();
762 }
763 
764 std::vector<biorbd::rigidbody::Mesh> biorbd::rigidbody::Joints::mesh() const
765 {
766  std::vector<biorbd::rigidbody::Mesh> segmentOut;
767  for (unsigned int i=0; i<nbSegment(); ++i)
768  segmentOut.push_back(mesh(i));
769  return segmentOut;
770 }
771 
773 {
774  return segment(idx).characteristics().mesh();
775 }
776 
780  bool updateKin)
781 {
782  RigidBodyDynamics::Math::Vector3d com, angular_momentum;
783  biorbd::utils::Scalar mass;
784 
785  // Calculate the angular momentum with the function of the
786  // position of the center of mass
787  if (updateKin) {
788  UpdateKinematicsCustom (&Q, &Qdot);
789  }
790  RigidBodyDynamics::Utils::CalcCenterOfMass(
791  *this, Q, Qdot, nullptr, mass, com, nullptr, nullptr,
792  &angular_momentum, nullptr, false);
793  return angular_momentum;
794 }
799  bool updateKin)
800 {
801  // Definition of the variables
802  RigidBodyDynamics::Math::Vector3d com, angular_momentum;
803  biorbd::utils::Scalar mass;
804 
805  // Calculate the angular momentum with the function of the
806  // position of the center of mass
807  if (updateKin) {
808  UpdateKinematicsCustom (&Q);
809  }
810  RigidBodyDynamics::Utils::CalcCenterOfMass(
811  *this, Q, Qdot, &Qddot, mass, com, nullptr, nullptr,
812  &angular_momentum, nullptr, false);
813 
814  return angular_momentum;
815 }
816 
817 std::vector<biorbd::utils::Vector3d> biorbd::rigidbody::Joints::CalcSegmentsAngularMomentum (
820  bool updateKin) {
821  if (updateKin) {
822  UpdateKinematicsCustom (&Q, &Qdot);
823  }
824 
825  biorbd::utils::Scalar mass;
826  RigidBodyDynamics::Math::Vector3d com;
827  RigidBodyDynamics::Utils::CalcCenterOfMass (
828  *this, Q, Qdot, nullptr, mass, com, nullptr,
829  nullptr, nullptr, nullptr, false);
830  RigidBodyDynamics::Math::SpatialTransform X_to_COM (RigidBodyDynamics::Math::Xtrans(com));
831 
832  std::vector<biorbd::utils::Vector3d> h_segment;
833  for (unsigned int i = 1; i < this->mBodies.size(); i++) {
834  this->Ic[i] = this->I[i];
835  this->hc[i] = this->Ic[i].toMatrix() * this->v[i];
836 
837  RigidBodyDynamics::Math::SpatialVector h = this->X_lambda[i].applyTranspose (this->hc[i]);
838  if (this->lambda[i] != 0) {
839  unsigned int j(i);
840  do {
841  j = this->lambda[j];
842  h = this->X_lambda[j].applyTranspose (h);
843  } while (this->lambda[j]!=0);
844  }
845  h = X_to_COM.applyAdjoint (h);
846  h_segment.push_back(biorbd::utils::Vector3d(h[0],h[1],h[2]));
847  }
848 
849 
850  return h_segment;
851 }
852 
853 std::vector<biorbd::utils::Vector3d> biorbd::rigidbody::Joints::CalcSegmentsAngularMomentum (
857  bool updateKin) {
858  if (updateKin) {
859  UpdateKinematicsCustom (&Q, &Qdot, &Qddot);
860  }
861 
862  biorbd::utils::Scalar mass;
863  RigidBodyDynamics::Math::Vector3d com;
864  RigidBodyDynamics::Utils::CalcCenterOfMass (*this, Q, Qdot, &Qddot, mass, com, nullptr, nullptr, nullptr, nullptr, false);
865  RigidBodyDynamics::Math::SpatialTransform X_to_COM (RigidBodyDynamics::Math::Xtrans(com));
866 
867  std::vector<biorbd::utils::Vector3d> h_segment;
868  for (unsigned int i = 1; i < this->mBodies.size(); i++) {
869  this->Ic[i] = this->I[i];
870  this->hc[i] = this->Ic[i].toMatrix() * this->v[i];
871 
872  RigidBodyDynamics::Math::SpatialVector h = this->X_lambda[i].applyTranspose (this->hc[i]);
873  if (this->lambda[i] != 0) {
874  unsigned int j(i);
875  do {
876  j = this->lambda[j];
877  h = this->X_lambda[j].applyTranspose (h);
878  } while (this->lambda[j]!=0);
879  }
880  h = X_to_COM.applyAdjoint (h);
881  h_segment.push_back(biorbd::utils::Vector3d(h[0],h[1],h[2]));
882  }
883 
884 
885  return h_segment;
886 }
887 
889  return *m_nRotAQuat;
890 }
891 
895  const double k_stab)
896 {
897  biorbd::rigidbody::GeneralizedVelocity QDotOut(Q.size());
898  // Verify if there are quaternions, if not the derivate is directly QDot
899  if (!m_nRotAQuat){
900  QDotOut = QDot;
901  return QDotOut;
902  }
903  unsigned int cmpQuat(0);
904  unsigned int cmpDof(0);
905  for (unsigned int i=0; i<nbSegment(); ++i){
906  const biorbd::rigidbody::Segment& segment_i = segment(i);
907  if (segment_i.isRotationAQuaternion()){
908  // Extraire le quaternion
910  Q(Q.size()-*m_nRotAQuat+cmpQuat),
911  Q.block(cmpDof+segment_i.nbDofTrans(), 0, 3, 1),
912  k_stab);
913 
914  // QDot for translation is actual QDot
915  QDotOut.block(cmpDof, 0, segment_i.nbDofTrans(), 1)
916  = QDot.block(cmpDof, 0, segment_i.nbDofTrans(), 1);
917 
918  // Get the 4d derivative for the quaternion part
919  quat_tp.derivate(QDot.block(cmpDof+segment_i.nbDofTrans(), 0, 3, 1));
920  QDotOut.block(cmpDof+segment_i.nbDofTrans(), 0, 3, 1) = quat_tp.block(1,0,3,1);
921  QDotOut(Q.size()-*m_nRotAQuat+cmpQuat) = quat_tp(0);// Placer dans le vecteur de sortie
922 
923  // Increment the number of done quaternions
924  ++cmpQuat;
925  }
926  else{
927  // If it's a normal, do what it usually does
928  QDotOut.block(cmpDof, 0, segment_i.nbDof(), 1) = QDot.block(cmpDof, 0, segment_i.nbDof(), 1);
929  }
930  cmpDof += segment_i.nbDof();
931  }
932  return QDotOut;
933 }
934 
939  std::vector<biorbd::utils::SpatialVector>* f_ext) {
940  biorbd::rigidbody::GeneralizedTorque Tau(nbGeneralizedTorque());
941  std::vector<RigidBodyDynamics::Math::SpatialVector>* f_ext_rbdl = nullptr;
942  if (f_ext){
943  f_ext_rbdl = new std::vector<RigidBodyDynamics::Math::SpatialVector>();
944  for (unsigned int i=0; i<f_ext->size(); ++i){
945  f_ext_rbdl->push_back( (*f_ext)[i] );
946  }
947  }
948  RigidBodyDynamics::InverseDynamics(*this, Q, QDot, QDDot, Tau, f_ext_rbdl);
949  delete f_ext_rbdl;
950  return Tau;
951 }
952 
957  std::vector<biorbd::utils::SpatialVector>* f_ext)
958 {
960  if (f_ext){
961  std::vector<RigidBodyDynamics::Math::SpatialVector> f_ext_rbdl(dispatchedForce(*f_ext));
962  RigidBodyDynamics::ForwardDynamics(*this, Q, QDot, Tau, QDDot, &f_ext_rbdl);
963  }
964  else {
965  RigidBodyDynamics::ForwardDynamics(*this, Q, QDot, Tau, QDDot);
966  }
967  return QDDot;
968 }
969 
976  std::vector<biorbd::utils::SpatialVector> *f_ext)
977 {
979  CS = dynamic_cast<biorbd::rigidbody::Contacts*>(this)->getConstraints();
980  if (f_ext){
981  std::vector<RigidBodyDynamics::Math::SpatialVector> f_ext_rbdl(dispatchedForce(*f_ext));
982  RigidBodyDynamics::ForwardDynamicsConstraintsDirect(*this, Q, QDot, Tau, CS, QDDot, &f_ext_rbdl);
983  }
984  else {
985  RigidBodyDynamics::ForwardDynamicsConstraintsDirect(*this, Q, QDot, Tau, CS, QDDot);
986  }
987  return QDDot;
988 }
989 
994  std::vector<biorbd::utils::SpatialVector> *f_ext)
995 {
996  biorbd::rigidbody::Contacts CS = dynamic_cast<biorbd::rigidbody::Contacts*>(this)->getConstraints();
997  this->ForwardDynamicsConstraintsDirect(Q, QDot, Tau, CS, f_ext);
998  return CS.getForce();
999 }
1000 
1005  std::vector<biorbd::utils::SpatialVector> *f_ext)
1006 {
1008  biorbd::rigidbody::Contacts CS = dynamic_cast<biorbd::rigidbody::Contacts*>(this)->getConstraints();
1009  CS = dynamic_cast<biorbd::rigidbody::Contacts*>(this)->getConstraints();
1010  if (f_ext){
1011  std::vector<RigidBodyDynamics::Math::SpatialVector> f_ext_rbdl(dispatchedForce(*f_ext));
1012  RigidBodyDynamics::ForwardDynamicsConstraintsDirect(*this, Q, QDot, Tau, CS, QDDot, &f_ext_rbdl);
1013  }
1014  else {
1015  RigidBodyDynamics::ForwardDynamicsConstraintsDirect(*this, Q, QDot, Tau, CS, QDDot);
1016  }
1017  return QDDot;
1018 }
1019 
1023  )
1024 {
1025  biorbd::rigidbody::Contacts CS = dynamic_cast<biorbd::rigidbody::Contacts*>(this)->getConstraints();
1026  if (CS.nbContacts() == 0){
1027  return QDotPre;
1028  } else {
1029  CS = dynamic_cast<biorbd::rigidbody::Contacts*>(this)->getConstraints();
1030 
1032  RigidBodyDynamics::ComputeConstraintImpulsesDirect(*this, Q, QDotPre, CS, QDotPost);
1033  return QDotPost;
1034  }
1035 }
1036 
1038  const biorbd::utils::String& segmentName,
1039  const biorbd::utils::String& dofName)
1040 {
1041  unsigned int idx = 0;
1042 
1043  unsigned int iB = 0;
1044  bool found = false;
1045  while (1){
1046  biorbd::utils::Error::check(iB!=m_segments->size(), "Segment not found");
1047 
1048  if (segmentName.compare( (*m_segments)[iB].name() ) )
1049  idx += (*m_segments)[iB].nbDof();
1050  else{
1051  idx += (*m_segments)[iB].getDofIdx(dofName);
1052  found = true;
1053  break;
1054  }
1055 
1056  ++iB;
1057  }
1058 
1059  biorbd::utils::Error::check(found, "Dof not found");
1060  return idx;
1061 }
1062 
1067 {
1068  checkGeneralizedDimensions(Q, Qdot, Qddot);
1069  RigidBodyDynamics::UpdateKinematicsCustom(*this, Q, Qdot, Qddot);
1070 }
1071 
1074  unsigned int segmentIdx,
1075  const RigidBodyDynamics::Math::Matrix3d &rotation,
1076  RigidBodyDynamics::Math::MatrixNd &G,
1077  bool updateKin)
1078 {
1079 #ifdef RBDL_ENABLE_LOGGING
1080  LOG << "-------- " << __func__ << " --------" << std::endl;
1081 #endif
1082 
1083  // update the Kinematics if necessary
1084  if (updateKin) {
1085  UpdateKinematicsCustom (&Q, nullptr, nullptr);
1086  }
1087 
1088  assert (G.rows() == 9 && G.cols() == this->qdot_size );
1089 
1090  std::vector<biorbd::utils::Vector3d> axes;
1091  axes.push_back(biorbd::utils::Vector3d(1,0,0));
1092  axes.push_back(biorbd::utils::Vector3d(0,1,0));
1093  axes.push_back(biorbd::utils::Vector3d(0,0,1));
1094  for (unsigned int iAxes=0; iAxes<3; ++iAxes){
1095  RigidBodyDynamics::Math::Matrix3d bodyMatRot (
1096  RigidBodyDynamics::CalcBodyWorldOrientation (*this, Q, segmentIdx, false).transpose());
1097  RigidBodyDynamics::Math::SpatialTransform point_trans(
1098  RigidBodyDynamics::Math::SpatialTransform (
1099  RigidBodyDynamics::Math::Matrix3d::Identity(), bodyMatRot * rotation * *(axes.begin()+iAxes)));
1100 
1101 
1102  unsigned int reference_body_id = segmentIdx;
1103 
1104  if (this->IsFixedBodyId(segmentIdx)) {
1105  unsigned int fbody_id = segmentIdx - this->fixed_body_discriminator;
1106  reference_body_id = this->mFixedBodies[fbody_id].mMovableParent;
1107  }
1108 
1109  unsigned int j = reference_body_id;
1110 
1111  // e[j] is set to 1 if joint j contributes to the jacobian that we are
1112  // computing. For all other joints the column will be zero.
1113  while (j != 0) {
1114  unsigned int q_index = this->mJoints[j].q_index;
1115  // If it's not a DoF in translation (3 4 5 in this->S)
1116 #ifdef BIORBD_USE_CASADI_MATH
1117  if (this->S[j].is_zero() && this->S[j](4).is_zero() && this->S[j](5).is_zero())
1118 #else
1119  if (this->S[j](3)!=1.0 && this->S[j](4)!=1.0 && this->S[j](5)!=1.0)
1120 #endif
1121  {
1122  RigidBodyDynamics::Math::SpatialTransform X_base = this->X_base[j];
1123  X_base.r = biorbd::utils::Vector3d(0,0,0); // Remove all concept of translation (only keep the rotation matrix)
1124 
1125  if (this->mJoints[j].mDoFCount == 3) {
1126  G.block(iAxes*3, q_index, 3, 3) = ((point_trans * X_base.inverse()).toMatrix() * this->multdof3_S[j]).block(3,0,3,3);
1127  } else {
1128  G.block(iAxes*3,q_index, 3, 1) = point_trans.apply(X_base.inverse().apply(this->S[j])).block(3,0,3,1);
1129  }
1130  }
1131  j = this->lambda[j]; // Pass to parent segment
1132  }
1133  }
1134 }
1135 
1141 {
1142 #ifndef SKIP_ASSERT
1143  if (Q){
1145  Q->size() == nbQ(),
1146  "Wrong size for the Generalized Coordiates");
1147  }
1148  if (Qdot){
1150  Qdot->size() == nbQdot(),
1151  "Wrong size for the Generalized Velocities");
1152  }
1153  if (Qddot){
1155  Qddot->size() == nbQddot(),
1156  "Wrong size for the Generalized Accelerations");
1157  }
1158 
1159  if (torque){
1161  torque->size() == nbGeneralizedTorque(),
1162  "Wrong size for the Generalized Torques");
1163  }
1164 #endif
1165 }
biorbd::rigidbody::Contacts::getForce
biorbd::utils::Vector getForce() const
Return the force acting on the contraint.
Definition: Contacts.cpp:157
biorbd::rigidbody::NodeSegment::isAxisKept
bool isAxisKept(unsigned int) const
Check if axis is kept.
Definition: NodeSegment.cpp:131
biorbd::utils::Quaternion
Definition: Quaternion.h:28
biorbd::rigidbody::Joints::checkGeneralizedDimensions
void checkGeneralizedDimensions(const biorbd::rigidbody::GeneralizedCoordinates *Q=nullptr, const biorbd::rigidbody::GeneralizedVelocity *Qdot=nullptr, const biorbd::rigidbody::GeneralizedAcceleration *Qddot=nullptr, const biorbd::rigidbody::GeneralizedTorque *torque=nullptr)
Check for the Generalized coordinates, velocities, acceleration and torque dimensions.
Definition: Joints.cpp:1136
biorbd::rigidbody::Joints::getDofIndex
unsigned int getDofIndex(const biorbd::utils::String &SegmentName, const biorbd::utils::String &dofName)
Return the index of a DoF in a segment.
Definition: Joints.cpp:1037
biorbd::rigidbody::Joints::CoMbySegment
std::vector< biorbd::rigidbody::NodeSegment > CoMbySegment(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool updateKin=true)
Return the position of the center of mass of each segment.
Definition: Joints.cpp:576
biorbd::rigidbody::Joints::dispatchedForce
std::vector< RigidBodyDynamics::Math::SpatialVector > dispatchedForce(std::vector< std::vector< biorbd::utils::SpatialVector >> &spatialVector, unsigned int frame) const
Dispatch the forces from the force plate in a vector.
Definition: Joints.cpp:204
biorbd::utils::SpatialVector
Wrapper of the Eigen::Matrix<double, 6, 1> or Casadi::MX(6, 1)
Definition: SpatialVector.h:19
biorbd::rigidbody::Joints::CalcAngularMomentum
biorbd::utils::Vector3d CalcAngularMomentum(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot, bool updateKin)
Calculate the angular momentum of the center of mass.
Definition: Joints.cpp:777
biorbd::rigidbody::Joints::CalcBodyWorldTransformation
RigidBodyDynamics::Math::SpatialTransform CalcBodyWorldTransformation(const biorbd::rigidbody::GeneralizedCoordinates &Q, const unsigned int segmentIdx, bool updateKin=true)
Calculate the joint coordinate system (JCS) in global reference frame of a specified segment.
Definition: Joints.cpp:433
biorbd::rigidbody::Joints::m_nbQdot
std::shared_ptr< unsigned int > m_nbQdot
The total number of Qdot.
Definition: Joints.h:823
biorbd::utils::Vector
Wrapper of the Eigen VectorXd.
Definition: Vector.h:20
biorbd::utils::Quaternion::derivate
void derivate(const biorbd::utils::Vector &w)
Return the time derivative of the quaterion.
Definition: Quaternion.cpp:317
biorbd::rigidbody::Segment::isRotationAQuaternion
bool isRotationAQuaternion() const
Return if the rotation DoF of this segment is a quaternion.
Definition: Segment.cpp:181
biorbd::utils::Vector3d
Wrapper around Eigen Vector3d and attach it to a parent.
Definition: Vector3d.h:24
biorbd::rigidbody::Joints::CoMJacobian
biorbd::utils::Matrix CoMJacobian(const biorbd::rigidbody::GeneralizedCoordinates &Q)
Return the jacobian matrix of the center of mass.
Definition: Joints.cpp:547
biorbd::rigidbody::Joints::nbRoot
unsigned int nbRoot() const
Return the dof on the root.
Definition: Joints.cpp:117
biorbd::rigidbody::Joints::AddSegment
unsigned int AddSegment(const biorbd::utils::String &segmentName, const biorbd::utils::String &parentName, const biorbd::utils::String &translationSequence, const biorbd::utils::String &rotationSequence, const std::vector< biorbd::utils::Range > &QRanges, const std::vector< biorbd::utils::Range > &QDotRanges, const std::vector< biorbd::utils::Range > &QDDotRanges, const biorbd::rigidbody::SegmentCharacteristics &characteristics, const RigidBodyDynamics::Math::SpatialTransform &centreOfRotation, int forcePlates=-1)
Add a segment to the model.
Definition: Joints.cpp:125
biorbd::rigidbody::Joints::meshFaces
std::vector< std::vector< MeshFace > > meshFaces() const
Return the mesh faces for all the segments.
Definition: Joints.cpp:752
biorbd::rigidbody::Joints::CoM
biorbd::utils::Vector3d CoM(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool updateKin=true)
Return the position of the center of mass.
Definition: Joints.cpp:464
biorbd::rigidbody::Joints::Joints
Joints()
Construct a joint model.
Definition: Joints.cpp:26
biorbd::rigidbody::Segment::nbQdot
unsigned int nbQdot() const
Return the number of generalized velocities.
Definition: Segment.cpp:215
biorbd::rigidbody::SegmentCharacteristics
Characteristics of a segment, namely the mass, the center of mass, the inertia, the length and its me...
Definition: SegmentCharacteristics.h:27
biorbd::utils::Vector3d::applyRT
biorbd::utils::Vector3d applyRT(const RotoTrans &rt) const
Apply a RotoTrans to the 3D vector.
Definition: Vector3d.cpp:95
biorbd::rigidbody::GeneralizedCoordinates
Class GeneralizedCoordinates.
Definition: GeneralizedCoordinates.h:15
biorbd::rigidbody::Joints::nbDof
unsigned int nbDof() const
Return the number of degrees of freedom (DoF)
Definition: Joints.cpp:87
biorbd::rigidbody::Segment::nbDofTrans
unsigned int nbDofTrans() const
Return the number of translation DoF of the segment.
Definition: Segment.cpp:206
biorbd::rigidbody::Joints::ContactForcesFromForwardDynamicsConstraintsDirect
biorbd::utils::Vector ContactForcesFromForwardDynamicsConstraintsDirect(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &QDot, const biorbd::rigidbody::GeneralizedTorque &Tau, std::vector< biorbd::utils::SpatialVector > *f_ext=nullptr)
Interface for contacts of the forward dynamics with contact of RBDL.
Definition: Joints.cpp:990
biorbd::rigidbody::Joints::m_totalMass
std::shared_ptr< double > m_totalMass
Mass of all the bodies combined.
Definition: Joints.h:827
biorbd::rigidbody::Joints::nameDof
std::vector< biorbd::utils::String > nameDof() const
Return the names of the degree of freedom (DoF)
Definition: Joints.cpp:91
biorbd::rigidbody::Joints::m_nbDof
std::shared_ptr< unsigned int > m_nbDof
The total number of degrees of freedom
Definition: Joints.h:821
biorbd::rigidbody::Joints::computeQdot
biorbd::rigidbody::GeneralizedVelocity computeQdot(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedCoordinates &QDot, const double k_stab=1)
Return the derivate of Q in function of Qdot (if not Quaternion, Qdot is directly returned)
Definition: Joints.cpp:892
biorbd::rigidbody::Segment::nbDof
unsigned int nbDof() const
Return the number of DoF of the segment.
Definition: Segment.cpp:203
biorbd::rigidbody::Joints::allGlobalJCS
std::vector< biorbd::utils::RotoTrans > allGlobalJCS() const
Return the joint coordinate system (JCS) in global reference frame at a given Q.
Definition: Joints.cpp:259
biorbd::rigidbody::Joints::mass
double mass() const
Return the total mass of the model.
Definition: Joints.cpp:121
biorbd::rigidbody::Joints::m_nbQddot
std::shared_ptr< unsigned int > m_nbQddot
The total number of Qddot.
Definition: Joints.h:824
biorbd::rigidbody::Joints::globalJCS
biorbd::utils::RotoTrans globalJCS(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::utils::String &name)
Return the joint coordinate system (JCS) for the segment in global reference frame at a given Q.
Definition: Joints.cpp:267
biorbd::rigidbody::Markers::markersJacobian
std::vector< biorbd::utils::Matrix > markersJacobian(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool removeAxis=true, bool updateKin=true)
Return the jacobian of the markers.
Definition: Markers.cpp:308
biorbd::rigidbody::Markers
Holder for the marker set.
Definition: Markers.h:23
biorbd::rigidbody::Joints::nbGeneralizedTorque
unsigned int nbGeneralizedTorque() const
Return the number of generalized torque.
Definition: Joints.cpp:84
biorbd::rigidbody::Joints::GetBodyBiorbdId
int GetBodyBiorbdId(const biorbd::utils::String &segmentName) const
Return the biorbd body identification.
Definition: Joints.cpp:245
biorbd::rigidbody::Joints::mesh
std::vector< biorbd::rigidbody::Mesh > mesh() const
Return the segment mesh.
Definition: Joints.cpp:764
biorbd::rigidbody::Mesh
A class that holds the geometry of a segment.
Definition: Mesh.h:21
biorbd::rigidbody::Segment::nbQ
unsigned int nbQ() const
Return the number of generalized coordinates.
Definition: Segment.cpp:212
biorbd::rigidbody::Joints::nbQ
unsigned int nbQ() const
Return the number of generalized coordinates (Q)
Definition: Joints.cpp:108
biorbd::rigidbody::Markers::nbMarkers
unsigned int nbMarkers() const
Return the number of markers.
Definition: Markers.cpp:286
biorbd::rigidbody::Joints::nbQuat
unsigned int nbQuat() const
Return the number of segments that are described using quaternions.
Definition: Joints.cpp:888
biorbd::rigidbody::NodeSegment::nbAxesToRemove
int nbAxesToRemove() const
Return the number of axes to remove.
Definition: NodeSegment.cpp:136
biorbd::utils::RotoTrans::trans
biorbd::utils::Vector3d trans() const
Return the translation vector.
Definition: RotoTrans.cpp:92
biorbd::rigidbody::Joints::CoMddot
biorbd::utils::Vector3d CoMddot(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot, const biorbd::rigidbody::GeneralizedAcceleration &Qddot)
Return the acceleration of the center of mass.
Definition: Joints.cpp:531
biorbd::rigidbody::Joints::CoMdot
biorbd::utils::Vector3d CoMdot(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot)
Return the velocity of the center of mass.
Definition: Joints.cpp:506
biorbd::Model
The actual musculoskeletal model that holds everything in biorbd.
Definition: BiorbdModel.h:78
biorbd::rigidbody::Contacts::nbContacts
unsigned int nbContacts() const
Return the number of contacts.
Definition: Contacts.cpp:114
biorbd::rigidbody::Joints
This is the core of the musculoskeletal model in biorbd.
Definition: Joints.h:40
biorbd::rigidbody::Joints::m_nbRoot
std::shared_ptr< unsigned int > m_nbRoot
The number of DoF on the root segment.
Definition: Joints.h:820
biorbd::utils::RotoTrans
Homogenous matrix to describe translations and rotations simultaneously.
Definition: RotoTrans.h:34
biorbd::rigidbody::Joints::localJCS
std::vector< biorbd::utils::RotoTrans > localJCS() const
Return all the joint coordinate system (JCS) in its parent reference frame.
Definition: Joints.cpp:295
biorbd::rigidbody::Joints::segment
const biorbd::rigidbody::Segment & segment(unsigned int idx) const
Get a segment of index idx.
Definition: Joints.cpp:189
biorbd::rigidbody::Joints::CoMbySegmentInMatrix
biorbd::utils::Matrix CoMbySegmentInMatrix(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool updateKin=true)
Return the position of the center of mass of each segment in a matrix.
Definition: Joints.cpp:590
biorbd::rigidbody::Joints::CoMddotBySegment
std::vector< biorbd::utils::Vector3d > CoMddotBySegment(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot, const biorbd::rigidbody::GeneralizedAcceleration &Qddot, bool updateKin=true)
Return the acceleration of the center of mass of each segment.
Definition: Joints.cpp:648
biorbd::rigidbody::Joints::projectPoint
biorbd::rigidbody::NodeSegment projectPoint(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::utils::Vector3d &v, int segmentIdx, const biorbd::utils::String &axesToRemove, bool updateKin=true)
Project a point on specific axis of a segment.
Definition: Joints.cpp:341
biorbd::rigidbody::Joints::InverseDynamics
biorbd::rigidbody::GeneralizedTorque InverseDynamics(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &QDot, const biorbd::rigidbody::GeneralizedAcceleration &QDDot, std::vector< biorbd::utils::SpatialVector > *f_ext=nullptr)
Interface for the inverse dynamics of RBDL.
Definition: Joints.cpp:935
biorbd::rigidbody::Joints::nbSegment
unsigned int nbSegment() const
Return the actual number of segment.
Definition: Joints.cpp:199
biorbd::utils::Matrix
A wrapper for the Eigen::MatrixXd.
Definition: Matrix.h:21
biorbd::rigidbody::GeneralizedAcceleration
Class GeneralizedAcceleration.
Definition: GeneralizedAcceleration.h:15
biorbd::rigidbody::Joints::CalcMatRotJacobian
void CalcMatRotJacobian(const biorbd::rigidbody::GeneralizedCoordinates &Q, unsigned int segmentIdx, const RigidBodyDynamics::Math::Matrix3d &rotation, RigidBodyDynamics::Math::MatrixNd &G, bool updateKin)
Calculate the jacobian matrix of a rotation matrix.
Definition: Joints.cpp:1072
biorbd::rigidbody::Segment
Description of a segment.
Definition: Segment.h:24
biorbd::rigidbody::Joints::nbQddot
unsigned int nbQddot() const
Return the number of generalized acceleration (Qddot)
Definition: Joints.cpp:114
biorbd::rigidbody::Joints::m_nbQ
std::shared_ptr< unsigned int > m_nbQ
The total number of Q.
Definition: Joints.h:822
biorbd::rigidbody::Joints::~Joints
virtual ~Joints()
Properly destroy class.
Definition: Joints.cpp:56
biorbd::rigidbody::GeneralizedTorque
Class GeneralizedTorque.
Definition: GeneralizedTorque.h:15
biorbd::rigidbody::Joints::meshPoints
std::vector< std::vector< biorbd::utils::Vector3d > > meshPoints(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool updateKin=true)
Return the vertices of the mesh for all segments in global reference frame.
Definition: Joints.cpp:682
biorbd::rigidbody::Joints::meshPointsInMatrix
std::vector< biorbd::utils::Matrix > meshPointsInMatrix(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool updateKin=true)
Return all the vertices of the mesh points in a matrix.
Definition: Joints.cpp:716
biorbd::rigidbody::Joints::massMatrix
biorbd::utils::Matrix massMatrix(const biorbd::rigidbody::GeneralizedCoordinates &Q, bool updateKin=true)
Get the mass matrix at a given position Q.
Definition: Joints.cpp:496
biorbd::rigidbody::Markers::marker
const biorbd::rigidbody::NodeSegment & marker(unsigned int idx) const
Return the marker of index idx.
Definition: Markers.cpp:60
biorbd::rigidbody::Joints::DeepCopy
biorbd::rigidbody::Joints DeepCopy() const
Deep copy of the joints.
Definition: Joints.cpp:61
biorbd::rigidbody::Joints::angularMomentum
biorbd::utils::Vector3d angularMomentum(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot, bool updateKin=true)
Calculate the angular momentum of the center of mass.
Definition: Joints.cpp:488
biorbd::utils::String
Wrapper around the std::string class with augmented functionality.
Definition: String.h:17
biorbd::rigidbody::Joints::CalcSegmentsAngularMomentum
std::vector< biorbd::utils::Vector3d > CalcSegmentsAngularMomentum(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot, bool updateKin)
Calculate the segment center of mass angular momentum.
Definition: Joints.cpp:817
biorbd::rigidbody::Segment::nbQddot
unsigned int nbQddot() const
Return the number of generalized accelerations.
Definition: Segment.cpp:218
biorbd::rigidbody::Joints::getGravity
biorbd::utils::Vector3d getGravity() const
Get the current gravity.
Definition: Joints.cpp:178
biorbd::rigidbody::Contacts
Class Contacts.
Definition: Contacts.h:30
biorbd::rigidbody::Joints::ForwardDynamicsConstraintsDirect
biorbd::rigidbody::GeneralizedAcceleration ForwardDynamicsConstraintsDirect(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &QDot, const biorbd::rigidbody::GeneralizedTorque &Tau, biorbd::rigidbody::Contacts &CS, std::vector< biorbd::utils::SpatialVector > *f_ext=nullptr)
Interface for the forward dynamics with contact of RBDL.
Definition: Joints.cpp:971
biorbd::rigidbody::Joints::m_isKinematicsComputed
std::shared_ptr< bool > m_isKinematicsComputed
If the kinematics are computed.
Definition: Joints.h:826
biorbd::rigidbody::NodeSegment
A point attached to a segment, generally speaking a skin marker.
Definition: NodeSegment.h:19
biorbd::rigidbody::Joints::UpdateKinematicsCustom
void UpdateKinematicsCustom(const biorbd::rigidbody::GeneralizedCoordinates *Q=nullptr, const biorbd::rigidbody::GeneralizedVelocity *Qdot=nullptr, const biorbd::rigidbody::GeneralizedAcceleration *Qddot=nullptr)
Update the kinematic variables such as body velocities and accelerations in the model to reflect the ...
Definition: Joints.cpp:1063
biorbd::rigidbody::Joints::ComputeConstraintImpulsesDirect
biorbd::rigidbody::GeneralizedVelocity ComputeConstraintImpulsesDirect(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &QDotPre)
Compute the QDot post from an impact.
Definition: Joints.cpp:1020
biorbd::rigidbody::Joints::CoMdotBySegment
std::vector< biorbd::utils::Vector3d > CoMdotBySegment(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &Qdot, bool updateKin=true)
Return the velocity of the center of mass of each segment.
Definition: Joints.cpp:618
biorbd::utils::Node::parent
const biorbd::utils::String & parent() const
Return the parent name of the node.
Definition: Node.cpp:64
biorbd::rigidbody::GeneralizedVelocity
Class GeneralizedVelocity.
Definition: GeneralizedVelocity.h:15
biorbd::rigidbody::Joints::projectPointJacobian
biorbd::utils::Matrix projectPointJacobian(const biorbd::rigidbody::GeneralizedCoordinates &Q, biorbd::rigidbody::NodeSegment p, bool updateKin)
Return the jacobian matrix of the projected markers for a marker from the model.
Definition: Joints.cpp:370
biorbd::rigidbody::Joints::m_nRotAQuat
std::shared_ptr< unsigned int > m_nRotAQuat
The number of segments per quaternion.
Definition: Joints.h:825
biorbd::utils::Error::check
static void check(bool cond, const biorbd::utils::String &message)
Assert that raises the error message if false.
Definition: Error.cpp:10
biorbd::rigidbody::Joints::m_segments
std::shared_ptr< std::vector< biorbd::rigidbody::Segment > > m_segments
All the articulations.
Definition: Joints.h:818
biorbd::utils::RotoTrans::rot
biorbd::utils::Rotation rot() const
Return the rotation matrix.
Definition: RotoTrans.cpp:97
biorbd::rigidbody::Joints::nbQdot
unsigned int nbQdot() const
Return the number of generalized velocities (Qdot)
Definition: Joints.cpp:111
biorbd::rigidbody::Joints::setGravity
void setGravity(const biorbd::utils::Vector3d &newGravity)
Set the gravity.
Definition: Joints.cpp:183
biorbd::rigidbody::Joints::ForwardDynamics
biorbd::rigidbody::GeneralizedAcceleration ForwardDynamics(const biorbd::rigidbody::GeneralizedCoordinates &Q, const biorbd::rigidbody::GeneralizedVelocity &QDot, const biorbd::rigidbody::GeneralizedTorque &Tau, std::vector< biorbd::utils::SpatialVector > *f_ext=nullptr)
Interface for the forward dynamics of RBDL.
Definition: Joints.cpp:953