Biorbd
Segment.h
1 #ifndef BIORBD_RIGIDBODY_SEGMENT_H
2 #define BIORBD_RIGIDBODY_SEGMENT_H
3 
4 #include <vector>
5 #include <rbdl/Model.h>
6 #include <rbdl/Joint.h>
7 #include "biorbdConfig.h"
8 #include "Utils/Node.h"
9 
10 namespace biorbd {
11 namespace utils {
12 class RotoTrans;
13 class Range;
14 }
15 
16 namespace rigidbody {
17 class Joints;
18 class SegmentCharacteristics;
19 
23 class BIORBD_API Segment : public biorbd::utils::Node
24 {
25 public:
29  Segment();
30 
45  Segment(
47  const biorbd::utils::String &name,
48  const biorbd::utils::String &parentName,
49  const biorbd::utils::String &seqT,
50  const biorbd::utils::String &seqR,
51  const std::vector<biorbd::utils::Range>& QRanges,
52  const std::vector<biorbd::utils::Range>& QDotRanges,
53  const std::vector<biorbd::utils::Range>& QDDotRanges,
54  const biorbd::rigidbody::SegmentCharacteristics& characteristics,
55  const RigidBodyDynamics::Math::SpatialTransform& cor,
56  int PF = -1);
57 
71  Segment(
73  const biorbd::utils::String &name,
74  const biorbd::utils::String &parentName,
75  const biorbd::utils::String &seqR,
76  const std::vector<biorbd::utils::Range>& QRanges,
77  const std::vector<biorbd::utils::Range>& QDotRanges,
78  const std::vector<biorbd::utils::Range>& QDDotRanges,
79  const biorbd::rigidbody::SegmentCharacteristics& characteristics,
80  const RigidBodyDynamics::Math::SpatialTransform& cor,
81  int PF = -1);
82 
87  biorbd::rigidbody::Segment DeepCopy() const;
88 
93  void DeepCopy(
94  const biorbd::rigidbody::Segment& other);
95 
99  virtual ~Segment();
100 
105  unsigned int id() const;
106 
111  int platformIdx() const;
112 
117  const biorbd::utils::String& seqT() const;
118 
123  const biorbd::utils::String& seqR() const;
124 
129  const std::vector<biorbd::utils::Range>&
130  QRanges() const;
131 
136  const std::vector<biorbd::utils::Range>&
137  QDotRanges() const;
138 
143  const std::vector<biorbd::utils::Range>&
144  QDDotRanges() const;
145 
150  unsigned int nbDof() const;
151 
156  unsigned int nbDofTrans() const;
157 
162  unsigned int nbDofRot() const;
163 
168  unsigned int nbQ() const;
169 
174  unsigned int nbQdot() const;
175 
180  unsigned int nbQddot() const;
181 
188  unsigned int nbGeneralizedTorque() const;
189 
194  unsigned int getDofIdx(
195  const biorbd::utils::String &dofName) const;
196 
201  const biorbd::utils::String& nameDof(
202  const unsigned int i) const;
203 
208  biorbd::utils::RotoTrans localJCS() const;
209 
214  const biorbd::rigidbody::SegmentCharacteristics& characteristics() const;
215 
220  bool isRotationAQuaternion() const;
221 
222 protected:
226  void setType();
227 
228  std::shared_ptr<int> m_idxPF;
229 
233  void setPF(
234  int idx);
235 
236  std::shared_ptr<RigidBodyDynamics::Math::SpatialTransform> m_cor;
237 
247  void setDofs(
249  const biorbd::utils::String &seqT,
250  const biorbd::utils::String &seqR,
251  const std::vector<biorbd::utils::Range>& QRanges,
252  const std::vector<biorbd::utils::Range>& QDotRanges,
253  const std::vector<biorbd::utils::Range>& QDDotRanges);
254 
260  void setNumberOfDof(
261  unsigned int nbTrans,
262  unsigned int nbRot);
263 
264  std::shared_ptr<biorbd::utils::String> m_seqT;
265  std::shared_ptr<biorbd::utils::String> m_seqR;
266  std::shared_ptr<std::vector<biorbd::utils::Range>> m_QRanges;
267  std::shared_ptr<std::vector<biorbd::utils::Range>> m_QDotRanges;
268  std::shared_ptr<std::vector<biorbd::utils::Range>> m_QDDotRanges;
269  std::shared_ptr<unsigned int> m_nbDof;
270  std::shared_ptr<unsigned int> m_nbQdot;
271  std::shared_ptr<unsigned int> m_nbQddot;
272  std::shared_ptr<unsigned int> m_nbDofTrue;
273  std::shared_ptr<unsigned int> m_nbDofTrueOutside;
274  std::shared_ptr<unsigned int> m_nbDofTrans;
275  std::shared_ptr<unsigned int> m_nbDofRot;
276  std::shared_ptr<unsigned int> m_nbDofQuat;
277 
278  std::shared_ptr<bool> m_isQuaternion;
279 
286  void determineIfRotIsQuaternion(const biorbd::utils::String &seqR);
287 
288  std::shared_ptr<std::vector<RigidBodyDynamics::Joint>> m_dof;
289  std::shared_ptr<std::vector<unsigned int>> m_idxDof;
290 
296  void setSequence(
297  const biorbd::utils::String &seqT,
298  const biorbd::utils::String &seqR);
299 
305  void fillSequence();
306 
312  void str2numSequence(
313  std::vector<unsigned int> &sequenceInteger,
314  const biorbd::utils::String &sequenceText);
315 
321  void str2numSequence(
322  const biorbd::utils::String &seqT,
323  const biorbd::utils::String &seqR);
324 
325  std::shared_ptr<std::vector<unsigned int>> m_sequenceTrans;
326  std::shared_ptr<std::vector<unsigned int>> m_sequenceRot;
327  std::shared_ptr<std::vector<biorbd::utils::String>> m_nameDof;
328 
333  virtual void setJoints(biorbd::rigidbody::Joints& model);
334 
338  virtual void setJointAxis();
339 
340  std::shared_ptr<std::vector<unsigned int>> m_dofPosition;
341 
348  void setDofCharacteristicsOnLastBody();
349 
350  std::shared_ptr<biorbd::rigidbody::SegmentCharacteristics> m_characteristics;
351  std::shared_ptr<std::vector<biorbd::rigidbody::SegmentCharacteristics>> m_dofCharacteristics;
352 
353 
354 };
355 
356 }}
357 
358 #endif // BIORBD_RIGIDBODY_SEGMENT_H
biorbd::rigidbody::Segment::m_idxPF
std::shared_ptr< int > m_idxPF
Platform index which acts on the segment.
Definition: Segment.h:228
biorbd::rigidbody::Segment::m_QDDotRanges
std::shared_ptr< std::vector< biorbd::utils::Range > > m_QDDotRanges
Minimum and maximum acceleration values that each dof should hold. This is only prescriptive and can ...
Definition: Segment.h:268
biorbd::rigidbody::Segment::m_sequenceRot
std::shared_ptr< std::vector< unsigned int > > m_sequenceRot
Euler rotation sequence.
Definition: Segment.h:326
biorbd::rigidbody::Segment::m_seqT
std::shared_ptr< biorbd::utils::String > m_seqT
Translation sequence.
Definition: Segment.h:264
biorbd::rigidbody::Segment::m_dof
std::shared_ptr< std::vector< RigidBodyDynamics::Joint > > m_dof
Actual DoF: t1, t2, t3, r1, r2, r3; where the order depends on seqT and seqR.
Definition: Segment.h:288
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::Node
A node is an abstract element which is assigned to a parent.
Definition: Node.h:16
biorbd::rigidbody::Segment::m_nbDofTrue
std::shared_ptr< unsigned int > m_nbDofTrue
Number of degrees of freedom including the extra DoF when there is a quaternion.
Definition: Segment.h:272
biorbd::rigidbody::Segment::m_idxDof
std::shared_ptr< std::vector< unsigned int > > m_idxDof
Index of the parent segment.
Definition: Segment.h:289
biorbd::rigidbody::Segment::m_nbQdot
std::shared_ptr< unsigned int > m_nbQdot
Number of generalized velocities.
Definition: Segment.h:270
biorbd::rigidbody::Segment::m_nbDofTrans
std::shared_ptr< unsigned int > m_nbDofTrans
Number of degrees of freedom in translation.
Definition: Segment.h:274
biorbd::rigidbody::Segment::m_nbDof
std::shared_ptr< unsigned int > m_nbDof
Number of degrees of freedom.
Definition: Segment.h:269
biorbd::rigidbody::Segment::m_QDotRanges
std::shared_ptr< std::vector< biorbd::utils::Range > > m_QDotRanges
Minimum and maximum velocity values that each dof should hold. This is only prescriptive and can be i...
Definition: Segment.h:267
biorbd::rigidbody::Segment::m_sequenceTrans
std::shared_ptr< std::vector< unsigned int > > m_sequenceTrans
Translation sequence.
Definition: Segment.h:325
biorbd::rigidbody::Joints
This is the core of the musculoskeletal model in biorbd.
Definition: Joints.h:40
biorbd::utils::RotoTrans
Homogenous matrix to describe translations and rotations simultaneously.
Definition: RotoTrans.h:34
biorbd::rigidbody::Segment::m_seqR
std::shared_ptr< biorbd::utils::String > m_seqR
Euler rotation sequence.
Definition: Segment.h:265
biorbd::rigidbody::Segment::m_isQuaternion
std::shared_ptr< bool > m_isQuaternion
If DoF in rotation is a Quaternion.
Definition: Segment.h:278
biorbd::rigidbody::Segment
Description of a segment.
Definition: Segment.h:24
biorbd::rigidbody::Segment::m_nbDofQuat
std::shared_ptr< unsigned int > m_nbDofQuat
Number of degrees of freedom in rotation if expressed in quaternion.
Definition: Segment.h:276
biorbd::rigidbody::Segment::m_dofCharacteristics
std::shared_ptr< std::vector< biorbd::rigidbody::SegmentCharacteristics > > m_dofCharacteristics
Variable containing the inertial data and other from each segment (on a 6DoF segment,...
Definition: Segment.h:351
biorbd::rigidbody::Segment::m_QRanges
std::shared_ptr< std::vector< biorbd::utils::Range > > m_QRanges
Minimum and maximum coordinate values that each dof should hold. This is only prescriptive and can be...
Definition: Segment.h:266
biorbd::rigidbody::Segment::m_characteristics
std::shared_ptr< biorbd::rigidbody::SegmentCharacteristics > m_characteristics
Non-used virtual segment; it allows to "save" the data and to avoid the use of multiple intermediate ...
Definition: Segment.h:350
biorbd::utils::String
Wrapper around the std::string class with augmented functionality.
Definition: String.h:17
biorbd::rigidbody::Segment::m_nameDof
std::shared_ptr< std::vector< biorbd::utils::String > > m_nameDof
To store the DoF names.
Definition: Segment.h:327
biorbd::rigidbody::Segment::m_nbDofTrueOutside
std::shared_ptr< unsigned int > m_nbDofTrueOutside
Number of degree of freedom read from the outside (Same as nDof except if Quaternion)
Definition: Segment.h:273
biorbd::rigidbody::Segment::m_nbQddot
std::shared_ptr< unsigned int > m_nbQddot
Number of generalized accelerations.
Definition: Segment.h:271
biorbd::rigidbody::Segment::m_cor
std::shared_ptr< RigidBodyDynamics::Math::SpatialTransform > m_cor
Attitude of the segment in parent reference frame.
Definition: Segment.h:236
biorbd::rigidbody::Segment::m_nbDofRot
std::shared_ptr< unsigned int > m_nbDofRot
Number of degrees of freedom in rotation.
Definition: Segment.h:275
biorbd::rigidbody::Segment::m_dofPosition
std::shared_ptr< std::vector< unsigned int > > m_dofPosition
Position in the x, y, and z sequence.
Definition: Segment.h:340