src/multibody/model.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2020 CNRS INRIA
3 // Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 
6 #ifndef __pinocchio_multibody_model_hpp__
7 #define __pinocchio_multibody_model_hpp__
8 
9 #include "pinocchio/spatial/fwd.hpp"
10 #include "pinocchio/spatial/se3.hpp"
11 #include "pinocchio/spatial/force.hpp"
12 #include "pinocchio/spatial/motion.hpp"
13 #include "pinocchio/spatial/inertia.hpp"
14 
15 #include "pinocchio/multibody/fwd.hpp"
16 #include "pinocchio/multibody/frame.hpp"
17 #include "pinocchio/multibody/joint/joint-generic.hpp"
18 
19 #include "pinocchio/container/aligned-vector.hpp"
20 
21 #include "pinocchio/serialization/serializable.hpp"
22 
23 #include <iostream>
24 #include <map>
25 #include <iterator>
26 
27 namespace pinocchio
28 {
29 
30  template<typename _Scalar, int _Options, template<typename,int> class JointCollectionTpl>
31  struct ModelTpl
32  : serialization::Serializable< ModelTpl<_Scalar,_Options,JointCollectionTpl> >
33  {
34  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
35 
36  typedef _Scalar Scalar;
37  enum { Options = _Options };
38 
39  typedef JointCollectionTpl<Scalar,Options> JointCollection;
41 
47 
52  typedef std::vector<Index> IndexVector;
53 
56 
57  typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointModel) JointModelVector;
58  typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointData) JointDataVector;
59 
60  typedef PINOCCHIO_ALIGNED_STD_VECTOR(Frame) FrameVector;
61 
62  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,Options> VectorXs;
63  typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
64 
66  typedef VectorXs ConfigVectorType;
67 
69  typedef std::map<std::string, ConfigVectorType> ConfigVectorMap;
70 
73  typedef VectorXs TangentVectorType;
74 
76  int nq;
77 
79  int nv;
80 
82  int njoints;
83 
85  int nbodies;
86 
88  int nframes;
89 
91  PINOCCHIO_ALIGNED_STD_VECTOR(Inertia) inertias;
92 
94  PINOCCHIO_ALIGNED_STD_VECTOR(SE3) jointPlacements;
95 
97  JointModelVector joints;
98 
100  std::vector<int> idx_qs;
101 
103  std::vector<int> nqs;
104 
106  std::vector<int> idx_vs;
107 
109  std::vector<int> nvs;
110 
112  std::vector<JointIndex> parents;
113 
115  std::vector<std::string> names;
116 
118  ConfigVectorMap referenceConfigurations;
119 
121  TangentVectorType rotorInertia;
122 
124  TangentVectorType rotorGearRatio;
125 
127  TangentVectorType friction;
128 
130  TangentVectorType damping;
131 
133  TangentVectorType effortLimit;
134 
136  TangentVectorType velocityLimit;
137 
139  ConfigVectorType lowerPositionLimit;
140 
142  ConfigVectorType upperPositionLimit;
143 
145  FrameVector frames;
146 
150  std::vector<IndexVector> supports;
151 
155  std::vector<IndexVector> subtrees;
156 
158  Motion gravity;
159 
161  static const Vector3 gravity981;
162 
164  std::string name;
165 
168  : nq(0)
169  , nv(0)
170  , njoints(1)
171  , nbodies(1)
172  , nframes(0)
173  , inertias(1, Inertia::Zero())
174  , jointPlacements(1, SE3::Identity())
175  , joints(1)
176  , idx_qs(1,0)
177  , nqs(1,0)
178  , idx_vs(1,0)
179  , nvs(1,0)
180  , parents(1, 0)
181  , names(1)
182  , supports(1,IndexVector(1,0))
183  , subtrees(1)
184  , gravity(gravity981,Vector3::Zero())
185  {
186  names[0] = "universe"; // Should be "universe joint (trivial)"
187  // FIXME Should the universe joint be a FIXED_JOINT even if it is
188  // in the list of joints ? See comment in definition of
189  // Model::addJointFrame and Model::addBodyFrame
190  addFrame(Frame("universe", 0, 0, SE3::Identity(), FIXED_JOINT));
191  }
192  ~ModelTpl() {} // std::cout << "Destroy model" << std::endl; }
193 
195  template<typename NewScalar>
197  {
199  ReturnType res;
200  res.nq = nq; res.nv = nv;
201  res.njoints = njoints;
202  res.nbodies = nbodies;
203  res.nframes = nframes;
204  res.parents = parents;
205  res.names = names;
206  res.subtrees = subtrees;
207  res.gravity = gravity.template cast<NewScalar>();
208  res.name = name;
209 
210  res.idx_qs = idx_qs;
211  res.nqs = nqs;
212  res.idx_vs = idx_vs;
213  res.nvs = nvs;
214 
215  // Eigen Vectors
216  res.rotorInertia = rotorInertia.template cast<NewScalar>();
217  res.rotorGearRatio = rotorGearRatio.template cast<NewScalar>();
218  res.friction = friction.template cast<NewScalar>();
219  res.damping = damping.template cast<NewScalar>();
220  res.effortLimit = effortLimit.template cast<NewScalar>();
221  res.velocityLimit = velocityLimit.template cast<NewScalar>();
222  res.lowerPositionLimit = lowerPositionLimit.template cast<NewScalar>();
223  res.upperPositionLimit = upperPositionLimit.template cast<NewScalar>();
224 
225  typename ConfigVectorMap::const_iterator it;
226  for (it = referenceConfigurations.begin();
227  it != referenceConfigurations.end(); it++ )
228  {
229  res.referenceConfigurations.insert(std::make_pair(it->first, it->second.template cast<NewScalar>()));
230  }
231 
232  // reserve vectors
233  res.inertias.resize(inertias.size());
234  res.jointPlacements.resize(jointPlacements.size());
235  res.joints.resize(joints.size());
236  res.frames.resize(frames.size());
237 
239  for(size_t k = 0; k < joints.size(); ++k)
240  {
241  res.inertias[k] = inertias[k].template cast<NewScalar>();
242  res.jointPlacements[k] = jointPlacements[k].template cast<NewScalar>();
243  res.joints[k] = joints[k].template cast<NewScalar>();
244  }
245 
246  for(size_t k = 0; k < frames.size(); ++k)
247  {
248  res.frames[k] = frames[k].template cast<NewScalar>();
249  }
250 
251  return res;
252  }
253 
259  bool operator==(const ModelTpl & other) const
260  {
261  bool res =
262  other.nq == nq
263  && other.nv == nv
264  && other.njoints == njoints
265  && other.nbodies == nbodies
266  && other.nframes == nframes
267  && other.parents == parents
268  && other.names == names
269  && other.subtrees == subtrees
270  && other.gravity == gravity
271  && other.name == name;
272 
273  res &=
274  other.idx_qs == idx_qs
275  && other.nqs == nqs
276  && other.idx_vs == idx_vs
277  && other.nvs == nvs;
278 
279  if(other.referenceConfigurations.size() != referenceConfigurations.size())
280  return false;
281 
282  typename ConfigVectorMap::const_iterator it = referenceConfigurations.begin();
283  typename ConfigVectorMap::const_iterator it_other = other.referenceConfigurations.begin();
284  for(long k = 0; k < (long)referenceConfigurations.size(); ++k)
285  {
286  std::advance(it,k); std::advance(it_other,k);
287 
288  if(it->second.size() != it_other->second.size())
289  return false;
290  if(it->second != it_other->second)
291  return false;
292  }
293 
294  if(other.rotorInertia.size() != rotorInertia.size())
295  return false;
296  res &= other.rotorInertia == rotorInertia;
297  if(!res) return res;
298 
299  if(other.friction.size() != friction.size())
300  return false;
301  res &= other.friction == friction;
302  if(!res) return res;
303 
304  if(other.damping.size() != damping.size())
305  return false;
306  res &= other.damping == damping;
307  if(!res) return res;
308 
309  if(other.rotorGearRatio.size() != rotorGearRatio.size())
310  return false;
311  res &= other.rotorGearRatio == rotorGearRatio;
312  if(!res) return res;
313 
314  if(other.effortLimit.size() != effortLimit.size())
315  return false;
316  res &= other.effortLimit == effortLimit;
317  if(!res) return res;
318 
319  if(other.velocityLimit.size() != velocityLimit.size())
320  return false;
321  res &= other.velocityLimit == velocityLimit;
322  if(!res) return res;
323 
324  if(other.lowerPositionLimit.size() != lowerPositionLimit.size())
325  return false;
326  res &= other.lowerPositionLimit == lowerPositionLimit;
327  if(!res) return res;
328 
329  if(other.upperPositionLimit.size() != upperPositionLimit.size())
330  return false;
331  res &= other.upperPositionLimit == upperPositionLimit;
332  if(!res) return res;
333 
334  for(size_t k = 1; k < inertias.size(); ++k)
335  {
336  res &= other.inertias[k] == inertias[k];
337  if(!res) return res;
338  }
339 
340  for(size_t k = 1; k < other.jointPlacements.size(); ++k)
341  {
342  res &= other.jointPlacements[k] == jointPlacements[k];
343  if(!res) return res;
344  }
345 
346  res &=
347  other.joints == joints
348  && other.frames == frames;
349 
350  return res;
351  }
352 
356  bool operator!=(const ModelTpl & other) const
357  { return !(*this == other); }
358 
376  JointIndex addJoint(const JointIndex parent,
377  const JointModel & joint_model,
378  const SE3 & joint_placement,
379  const std::string & joint_name);
380 
389  JointIndex addJoint(const JointIndex parent,
390  const JointModel & joint_model,
391  const SE3 & joint_placement,
392  const std::string & joint_name,
393  const VectorXs & max_effort,
394  const VectorXs & max_velocity,
395  const VectorXs & min_config,
396  const VectorXs & max_config);
397 
404  JointIndex addJoint(const JointIndex parent,
405  const JointModel & joint_model,
406  const SE3 & joint_placement,
407  const std::string & joint_name,
408  const VectorXs & max_effort,
409  const VectorXs & max_velocity,
410  const VectorXs & min_config,
411  const VectorXs & max_config,
412  const VectorXs & friction,
413  const VectorXs & damping);
414 
424  FrameIndex addJointFrame(const JointIndex & joint_index,
425  int previous_frame_index = -1);
426 
436  void appendBodyToJoint(const JointIndex joint_index, const Inertia & Y,
437  const SE3 & body_placement = SE3::Identity());
438 
450  FrameIndex addBodyFrame(const std::string & body_name,
451  const JointIndex & parentJoint,
452  const SE3 & body_placement = SE3::Identity(),
453  int previousFrame = -1);
454 
466  FrameIndex getBodyId(const std::string & name) const;
467 
475  bool existBodyName(const std::string & name) const;
476 
477 
488  JointIndex getJointId(const std::string & name) const;
489 
497  bool existJointName(const std::string & name) const;
498 
512  FrameIndex getFrameId(const std::string & name,
513  const FrameType & type = (FrameType) (JOINT | FIXED_JOINT | BODY | OP_FRAME | SENSOR )) const;
514 
523  bool existFrame(const std::string & name,
524  const FrameType& type = (FrameType) (JOINT | FIXED_JOINT | BODY | OP_FRAME | SENSOR )) const;
525 
535  FrameIndex addFrame(const Frame & frame,
536  const bool append_inertia = true);
537 
548  template<typename D>
549  inline bool check(const AlgorithmCheckerBase<D> & checker = AlgorithmCheckerBase<D>()) const
550  { return checker.checkModel(*this); }
551 
553  inline bool check() const;
554 
562  inline bool check(const Data & data) const;
563 
564  protected:
565 
571  void addJointIndexToParentSubtrees(const JointIndex joint_id);
572  };
573 
574 } // namespace pinocchio
575 
576 /* --- Details -------------------------------------------------------------- */
577 /* --- Details -------------------------------------------------------------- */
578 /* --- Details -------------------------------------------------------------- */
579 #include "pinocchio/multibody/model.hxx"
580 
581 #endif // ifndef __pinocchio_multibody_model_hpp__
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
parent
Definition: lambdas.py:16
FrameIndex addJointFrame(const JointIndex &joint_index, int previous_frame_index=-1)
Add a joint to the frame tree.
DataTpl< Scalar, Options, JointCollectionTpl > Data
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
int njoints
Number of joints.
bool check(const AlgorithmCheckerBase< D > &checker=AlgorithmCheckerBase< D >()) const
Check the validity of the attributes of Model with respect to the specification of some algorithms...
std::vector< std::string > names
Name of joint i
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
FrameVector frames
Vector of operational frames registered on the model.
bool existBodyName(const std::string &name) const
Check if a body given by its name exists.
std::vector< int > nvs
Dimension of the joint i tangent subspace.
TangentVectorType rotorInertia
Vector of rotor inertia parameters.
typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointModel) JointModelVector
data
VectorXs TangentVectorType
Dense vectorized version of a joint tangent vector (e.g. velocity, acceleration, etc). It also handles the notion of co-tangent vector (e.g. torque, etc).
pinocchio::GeomIndex GeomIndex
JointCollectionTpl< Scalar, Options > JointCollection
std::vector< IndexVector > subtrees
Vector of joint subtrees. subtree[j] corresponds to the subtree supported by the joint j...
bool operator!=(const ModelTpl &other) const
ConfigVectorMap referenceConfigurations
Map of reference configurations, indexed by user given names.
int nframes
Number of operational frames.
FrameType
Enum on the possible types of frame.
bool existJointName(const std::string &name) const
Check if a joint given by its name exists.
void addJointIndexToParentSubtrees(const JointIndex joint_id)
Add the joint_id to its parent subtrees.
std::string name
Model name;.
TangentVectorType rotorGearRatio
Vector of rotor gear ratio parameters.
pinocchio::FrameIndex FrameIndex
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name)
Add a joint to the kinematic tree with infinite bounds.
std::vector< int > nqs
Dimension of the joint i configuration subspace.
TangentVectorType friction
Vector of joint friction parameters.
std::vector< int > idx_qs
Starting index of the joint i in the configuration space.
std::vector< Index > IndexVector
int nbodies
Number of bodies.
pinocchio::JointIndex JointIndex
FrameIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.
FrameIndex getFrameId(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Returns the index of a frame given by its name.
bool existFrame(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Checks if a frame given by its name exists.
Motion gravity
Spatial gravity of the model.
std::map< std::string, ConfigVectorType > ConfigVectorMap
Map between a string (key) and a configuration vector.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
bool check() const
Run check(fusion::list) with DEFAULT_CHECKERS as argument.
JointModelTpl< Scalar, Options, JointCollectionTpl > JointModel
FrameIndex addFrame(const Frame &frame, const bool append_inertia=true)
Adds a frame to the kinematic tree. The inertia stored within the frame will be happened to the inert...
CRTP class describing the API of the checkers.
Definition: check.hpp:22
ForceTpl< Scalar, Options > Force
Main pinocchio namespace.
Definition: timings.cpp:30
bool operator==(const ModelTpl &other) const
Equality comparison operator.
std::vector< int > idx_vs
Starting index of the joint i in the tangent configuration space.
TangentVectorType effortLimit
Vector of maximal joint torques.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1, Options > VectorXs
TangentVectorType damping
Vector of joint damping parameters.
res
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
JointDataTpl< Scalar, Options, JointCollectionTpl > JointData
int nv
Dimension of the velocity vector space.
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
TangentVectorType velocityLimit
Vector of maximal joint velocities.
FrameTpl< Scalar, Options > Frame
std::size_t Index
VectorXs ConfigVectorType
Dense vectorized version of a joint configuration vector.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
static const Vector3 gravity981
Default 3D gravity vector (=(0,0,-9.81)).
std::vector< IndexVector > supports
Vector of joint supports. supports[j] corresponds to the collection of all joints located on the path...
void appendBodyToJoint(const JointIndex joint_index, const Inertia &Y, const SE3 &body_placement=SE3::Identity())
Append a body to a given joint of the kinematic tree.
int nq
Dimension of the configuration vector representation.
InertiaTpl< Scalar, Options > Inertia
SE3Tpl< Scalar, Options > SE3
ModelTpl< NewScalar, Options, JointCollectionTpl > cast() const
MotionTpl< Scalar, Options > Motion
FrameIndex addBodyFrame(const std::string &body_name, const JointIndex &parentJoint, const SE3 &body_placement=SE3::Identity(), int previousFrame=-1)
Add a body to the frame tree.


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04