Biorbd
Joints.h
1 #ifndef BIORBD_RIGIDBODY_JOINTS_H
2 #define BIORBD_RIGIDBODY_JOINTS_H
3 
4 #include <memory>
5 #include <rbdl/Model.h>
6 #include <rbdl/Constraints.h>
7 #include "biorbdConfig.h"
8 
9 namespace biorbd {
10 namespace utils {
11 class String;
12 class RotoTrans;
13 class Matrix;
14 class Vector;
15 class Vector3d;
16 class Range;
17 class SpatialVector;
18 }
19 
20 namespace rigidbody {
21 class GeneralizedCoordinates;
22 class GeneralizedVelocity;
23 class GeneralizedAcceleration;
24 class GeneralizedTorque;
25 class NodeSegment;
26 class MeshFace;
27 class Segment;
28 class SegmentCharacteristics;
29 class Mesh;
30 class Contacts;
31 
35 #ifdef SWIG
36 class BIORBD_API Joints
37 #else
38 class BIORBD_API Joints : public RigidBodyDynamics::Model
39 #endif
40 {
41 public:
42 
46  Joints();
47 
52  Joints(
53  const biorbd::rigidbody::Joints& other);
54 
58  virtual ~Joints();
59 
64  biorbd::rigidbody::Joints DeepCopy() const;
65 
70  void DeepCopy(
71  const biorbd::rigidbody::Joints& other);
72 
86  unsigned int AddSegment(
87  const biorbd::utils::String &segmentName,
88  const biorbd::utils::String &parentName,
89  const biorbd::utils::String &translationSequence,
90  const biorbd::utils::String &rotationSequence,
91  const std::vector<biorbd::utils::Range>& QRanges,
92  const std::vector<biorbd::utils::Range>& QDotRanges,
93  const std::vector<biorbd::utils::Range>& QDDotRanges,
94  const biorbd::rigidbody::SegmentCharacteristics& characteristics,
95  const RigidBodyDynamics::Math::SpatialTransform& centreOfRotation,
96  int forcePlates=-1);
97 
110  unsigned int AddSegment(
111  const biorbd::utils::String &segmentName,
112  const biorbd::utils::String &parentName,
113  const biorbd::utils::String &translationSequence,
114  const std::vector<biorbd::utils::Range>& QRanges,
115  const std::vector<biorbd::utils::Range>& QDotRanges,
116  const std::vector<biorbd::utils::Range>& QDDotRanges,
117  const biorbd::rigidbody::SegmentCharacteristics& characteristics,
118  const RigidBodyDynamics::Math::SpatialTransform& centreOfRotation,
119  int forcePlates=-1);
120 
121 
122  // -- GENERAL MODELLING -- //
127  biorbd::utils::Vector3d getGravity() const;
128 
133  void setGravity(
134  const biorbd::utils::Vector3d& newGravity);
135 
136  // -- INFORMATION ON THE MODEL -- //
142  int GetBodyBiorbdId(
143  const biorbd::utils::String &segmentName) const;
144 
149  unsigned int nbGeneralizedTorque() const;
150 
155  unsigned int nbSegment() const;
156 
161  unsigned int nbDof() const;
162 
169  unsigned int getDofIndex(
170  const biorbd::utils::String& SegmentName,
171  const biorbd::utils::String& dofName);
172 
177  std::vector<biorbd::utils::String> nameDof() const;
178 
183  unsigned int nbQ() const;
184 
189  unsigned int nbQdot() const;
190 
195  unsigned int nbQddot() const;
196 
201  unsigned int nbRoot() const;
202 
207  unsigned int nbQuat() const;
208 
214  const biorbd::rigidbody::Segment& segment(
215  unsigned int idx) const;
216 
222  const biorbd::rigidbody::Segment& segment(
223  const biorbd::utils::String& name) const;
224  // ------------------------------ //
225 
226 
227  // -- FORCE PLATE DISPATCHER -- //
234  std::vector<RigidBodyDynamics::Math::SpatialVector> dispatchedForce(
235  std::vector<std::vector<biorbd::utils::SpatialVector>> &spatialVector,
236  unsigned int frame) const;
237 
243  std::vector<RigidBodyDynamics::Math::SpatialVector> dispatchedForce(
244  std::vector<biorbd::utils::SpatialVector> &sv) const;
245  // ---------------------------- //
246 
247 
254  void UpdateKinematicsCustom(
256  const biorbd::rigidbody::GeneralizedVelocity *Qdot = nullptr,
257  const biorbd::rigidbody::GeneralizedAcceleration *Qddot = nullptr);
258 
259 
260  // -- POSITION INTERFACE OF THE MODEL -- //
261 
267  std::vector<biorbd::utils::RotoTrans> allGlobalJCS(
269 
276  std::vector<biorbd::utils::RotoTrans> allGlobalJCS() const;
277 
284  biorbd::utils::RotoTrans globalJCS(
286  const biorbd::utils::String &name);
287 
294  biorbd::utils::RotoTrans globalJCS(
296  unsigned int idx);
297 
305  biorbd::utils::RotoTrans globalJCS(
306  const biorbd::utils::String &name) const;
307 
315  biorbd::utils::RotoTrans globalJCS(
316  unsigned int idx) const;
317 
322  std::vector<biorbd::utils::RotoTrans> localJCS() const;
323 
329  biorbd::utils::RotoTrans localJCS(
330  const biorbd::utils::String &name) const;
331 
337  biorbd::utils::RotoTrans localJCS(
338  const unsigned int idx) const;
339 
349  biorbd::rigidbody::NodeSegment projectPoint(
351  const biorbd::utils::Vector3d &v,
352  int segmentIdx,
353  const biorbd::utils::String& axesToRemove,
354  bool updateKin=true);
355 
367  std::vector<biorbd::rigidbody::NodeSegment> projectPoint(
369  const std::vector<biorbd::rigidbody::NodeSegment> &v,
370  bool updateKin=true);
371 
379  biorbd::rigidbody::NodeSegment projectPoint(
382  bool updateKin);
383 
391  biorbd::utils::Matrix projectPointJacobian(
394  bool updateKin);
395 
405  biorbd::utils::Matrix projectPointJacobian(
407  const biorbd::utils::Vector3d &v,
408  int segmentIdx,
409  const biorbd::utils::String& axesToRemove,
410  bool updateKin);
411 
423  std::vector<biorbd::utils::Matrix> projectPointJacobian(
425  const std::vector<biorbd::rigidbody::NodeSegment> &v,
426  bool updateKin);
427  // ------------------------------------- //
428 
429 
430  // -- MASS RELATED STUFF -- //
435  double mass() const;
436 
445  bool updateKin=true);
446 
453  std::vector<biorbd::rigidbody::NodeSegment> CoMbySegment(
455  bool updateKin=true);
456 
463  biorbd::utils::Matrix CoMbySegmentInMatrix(
465  bool updateKin=true);
466 
474  biorbd::utils::Vector3d CoMbySegment(
476  const unsigned int idx,
477  bool updateKin=true);
478 
488 
496  biorbd::utils::Vector3d CoMddot(
500 
508  std::vector<biorbd::utils::Vector3d> CoMdotBySegment(
511  bool updateKin=true);
512 
521  biorbd::utils::Vector3d CoMdotBySegment(
524  const unsigned int idx,
525  bool updateKin=true);
526 
535  std::vector<biorbd::utils::Vector3d> CoMddotBySegment(
539  bool updateKin=true);
540 
550  biorbd::utils::Vector3d CoMddotBySegment(
554  const unsigned int idx,
555  bool updateKin=true);
556 
562  biorbd::utils::Matrix CoMJacobian(
564  // ------------------------ //
565 
566 
567  // -- MESH OF THE MODEL -- //
574  std::vector<std::vector<biorbd::utils::Vector3d>> meshPoints(
576  bool updateKin = true);
577 
585  std::vector<biorbd::utils::Vector3d> meshPoints(
587  unsigned int idx,
588  bool updateKin = true);
589 
596  std::vector<biorbd::utils::Matrix> meshPointsInMatrix(
598  bool updateKin = true
599  );
600 
605  std::vector<std::vector<MeshFace> > meshFaces() const;
606 
612  const std::vector<biorbd::rigidbody::MeshFace> &meshFaces(
613  unsigned int idx) const;
614 
619  std::vector<biorbd::rigidbody::Mesh> mesh() const;
620 
626  const biorbd::rigidbody::Mesh& mesh(
627  unsigned int idx) const;
628  // ----------------------- //
629 
630 
631  // -- ANGULAR MOMENTUM FUNCTIONS -- //
639  biorbd::utils::Vector3d angularMomentum(
642  bool updateKin = true); // Wrapper pour le moment angulaire
643 
650  biorbd::utils::Matrix massMatrix(
652  bool updateKin = true);
653 
661  biorbd::utils::Vector3d CalcAngularMomentum (
664  bool updateKin);
665 
674  biorbd::utils::Vector3d CalcAngularMomentum (
678  bool updateKin);
679 
687  std::vector<biorbd::utils::Vector3d> CalcSegmentsAngularMomentum (
690  bool updateKin);
691 
700  std::vector<biorbd::utils::Vector3d> CalcSegmentsAngularMomentum (
704  bool updateKin);
705  // -------------------------------- //
706 
715  void CalcMatRotJacobian (
717  unsigned int segmentIdx,
718  const RigidBodyDynamics::Math::Matrix3d &rotation,
719  RigidBodyDynamics::Math::MatrixNd &G,
720  bool updateKin);
721 
732  const double k_stab = 1);
733 
734  // ---- DYNAMIC INTERFACE ---- //
743  biorbd::rigidbody::GeneralizedTorque InverseDynamics(
747  std::vector<biorbd::utils::SpatialVector>* f_ext = nullptr);
748 
761  std::vector<biorbd::utils::SpatialVector>* f_ext = nullptr);
762 
772  biorbd::rigidbody::GeneralizedAcceleration ForwardDynamicsConstraintsDirect(
777  std::vector<biorbd::utils::SpatialVector>* f_ext = nullptr);
778 
787  biorbd::utils::Vector ContactForcesFromForwardDynamicsConstraintsDirect(
791  std::vector<biorbd::utils::SpatialVector>* f_ext = nullptr);
792 
801  biorbd::rigidbody::GeneralizedAcceleration ForwardDynamicsConstraintsDirect(
805  std::vector<biorbd::utils::SpatialVector>* f_ext = nullptr);
806 
813  biorbd::rigidbody::GeneralizedVelocity ComputeConstraintImpulsesDirect(
816 
817 protected:
818  std::shared_ptr<std::vector<biorbd::rigidbody::Segment>> m_segments;
819 
820  std::shared_ptr<unsigned int> m_nbRoot;
821  std::shared_ptr<unsigned int> m_nbDof;
822  std::shared_ptr<unsigned int> m_nbQ;
823  std::shared_ptr<unsigned int> m_nbQdot;
824  std::shared_ptr<unsigned int> m_nbQddot;
825  std::shared_ptr<unsigned int> m_nRotAQuat;
826  std::shared_ptr<bool> m_isKinematicsComputed;
827  std::shared_ptr<double> m_totalMass;
828 
836  RigidBodyDynamics::Math::SpatialTransform CalcBodyWorldTransformation(
838  const unsigned int segmentIdx,
839  bool updateKin = true);
840 
848  RigidBodyDynamics::Math::SpatialTransform CalcBodyWorldTransformation(
849  const unsigned int segmentIdx) const;
850 
857  std::vector<biorbd::utils::Vector3d> meshPoints(
858  const std::vector<biorbd::utils::RotoTrans> &RT,
859  unsigned int idx) const;
860 
861 public:
869  void checkGeneralizedDimensions(
871  const biorbd::rigidbody::GeneralizedVelocity *Qdot = nullptr,
872  const biorbd::rigidbody::GeneralizedAcceleration *Qddot = nullptr,
873  const biorbd::rigidbody::GeneralizedTorque *torque = nullptr);
874 };
875 
876 }}
877 
878 #endif // BIORBD_RIGIDBODY_JOINTS_H
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::Vector3d
Wrapper around Eigen Vector3d and attach it to a parent.
Definition: Vector3d.h:24
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::rigidbody::GeneralizedCoordinates
Class GeneralizedCoordinates.
Definition: GeneralizedCoordinates.h:15
biorbd::rigidbody::Joints::m_totalMass
std::shared_ptr< double > m_totalMass
Mass of all the bodies combined.
Definition: Joints.h:827
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::m_nbQddot
std::shared_ptr< unsigned int > m_nbQddot
The total number of Qddot.
Definition: Joints.h:824
biorbd::rigidbody::Mesh
A class that holds the geometry of a segment.
Definition: Mesh.h:21
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::utils::Matrix
A wrapper for the Eigen::MatrixXd.
Definition: Matrix.h:21
biorbd::rigidbody::GeneralizedAcceleration
Class GeneralizedAcceleration.
Definition: GeneralizedAcceleration.h:15
biorbd::rigidbody::Segment
Description of a segment.
Definition: Segment.h:24
biorbd::rigidbody::Joints::m_nbQ
std::shared_ptr< unsigned int > m_nbQ
The total number of Q.
Definition: Joints.h:822
biorbd::rigidbody::GeneralizedTorque
Class GeneralizedTorque.
Definition: GeneralizedTorque.h:15
biorbd::utils::String
Wrapper around the std::string class with augmented functionality.
Definition: String.h:17
biorbd::rigidbody::Contacts
Class Contacts.
Definition: Contacts.h:30
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::GeneralizedVelocity
Class GeneralizedVelocity.
Definition: GeneralizedVelocity.h:15
biorbd::rigidbody::Joints::m_nRotAQuat
std::shared_ptr< unsigned int > m_nRotAQuat
The number of segments per quaternion.
Definition: Joints.h:825
biorbd::rigidbody::Joints::m_segments
std::shared_ptr< std::vector< biorbd::rigidbody::Segment > > m_segments
All the articulations.
Definition: Joints.h:818