pinocchio  UNKNOWN
model.hpp
1 //
2 // Copyright (c) 2015-2018 CNRS
3 // Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 // This file is part of Pinocchio
6 // Pinocchio is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // Pinocchio is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // Pinocchio If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef __se3_model_hpp__
20 #define __se3_model_hpp__
21 
22 #include "pinocchio/spatial/fwd.hpp"
23 #include "pinocchio/spatial/se3.hpp"
24 #include "pinocchio/spatial/force.hpp"
25 #include "pinocchio/spatial/motion.hpp"
26 #include "pinocchio/spatial/inertia.hpp"
27 #include "pinocchio/multibody/fwd.hpp"
28 #include "pinocchio/multibody/frame.hpp"
29 #include "pinocchio/multibody/joint/joint.hpp"
30 #include "pinocchio/deprecated.hh"
31 #include "pinocchio/utils/string-generator.hpp"
32 #include "pinocchio/container/aligned-vector.hpp"
33 
34 #include <iostream>
35 #include <Eigen/Cholesky>
36 
37 namespace se3
38 {
39  struct Model
40  {
41  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42  typedef se3::Index Index;
43  typedef se3::JointIndex JointIndex;
44  typedef se3::GeomIndex GeomIndex;
45  typedef se3::FrameIndex FrameIndex;
46  typedef std::vector<Index> IndexVector;
47 
49  int nq;
50 
52  int nv;
53 
55  int njoints;
56 
58  int nbodies;
59 
61  int nframes;
62 
65 
68 
71 
73  std::vector<JointIndex> parents;
74 
76  std::vector<std::string> names;
77 
79  Eigen::VectorXd neutralConfiguration;
80 
82  Eigen::VectorXd rotorInertia;
83 
85  Eigen::VectorXd rotorGearRatio;
86 
88  Eigen::VectorXd effortLimit;
90  Eigen::VectorXd velocityLimit;
91 
93  Eigen::VectorXd lowerPositionLimit;
95  Eigen::VectorXd upperPositionLimit;
96 
99 
103  std::vector<IndexVector> subtrees;
104 
107 
109  static const Eigen::Vector3d gravity981;
110 
112  std::string name;
113 
116  : nq(0)
117  , nv(0)
118  , njoints(1)
119  , nbodies(1)
120  , nframes(0)
121  , inertias(1)
122  , jointPlacements(1, SE3::Identity())
123  , joints(1)
124  , parents(1, 0)
125  , names(1)
126  , subtrees(1)
127  , gravity( gravity981,Eigen::Vector3d::Zero() )
128  {
129  names[0] = "universe"; // Should be "universe joint (trivial)"
130  // FIXME Should the universe joint be a FIXED_JOINT even if it is
131  // in the list of joints ? See comment in definition of
132  // Model::addJointFrame and Model::addBodyFrame
133  addFrame(Frame("universe", 0, 0, SE3::Identity(), FIXED_JOINT));
134  // Inertia of universe has no sense.
135  inertias[0].mass() = std::numeric_limits<double>::quiet_NaN();
136  inertias[0].lever().fill (std::numeric_limits<double>::quiet_NaN());
137  inertias[0].inertia().fill (std::numeric_limits<double>::quiet_NaN());
138  }
139  ~Model() {} // std::cout << "Destroy model" << std::endl; }
140 
163  template<typename JointModelDerived>
164  JointIndex addJoint(const JointIndex parent, const JointModelBase<JointModelDerived> & joint_model, const SE3 & joint_placement,
165  const std::string & joint_name,
166  const Eigen::VectorXd & max_effort,
167  const Eigen::VectorXd & max_velocity,
168  const Eigen::VectorXd & min_config,
169  const Eigen::VectorXd & max_config
170  );
171 
189  template<typename JointModelDerived>
190  JointIndex addJoint(const JointIndex parent, const JointModelBase<JointModelDerived> & joint_model, const SE3 & joint_placement,
191  const std::string & joint_name
192  );
193 
203  int addJointFrame (const JointIndex& jointIndex,
204  int frameIndex = -1);
205 
215  void appendBodyToJoint(const JointIndex joint_index, const Inertia & Y,
216  const SE3 & body_placement = SE3::Identity());
217 
229  int addBodyFrame (const std::string & body_name,
230  const JointIndex & parentJoint,
231  const SE3 & body_placement = SE3::Identity(),
232  int previousFrame = -1);
233 
245  JointIndex getBodyId(const std::string & name) const;
246 
254  bool existBodyName(const std::string & name) const;
255 
256 
267  JointIndex getJointId(const std::string & name) const;
268 
276  bool existJointName(const std::string & name) const;
277 
285  PINOCCHIO_DEPRECATED const std::string & getJointName(const JointIndex index) const;
286 
300  FrameIndex getFrameId (const std::string & name, const FrameType& type = (FrameType) (JOINT | FIXED_JOINT | BODY | OP_FRAME | SENSOR )) const;
301 
310  bool existFrame (const std::string & name, const FrameType& type = (FrameType) (JOINT | FIXED_JOINT | BODY | OP_FRAME | SENSOR )) const;
311 
312 
321  int addFrame(const Frame & frame);
322 
330  template<typename D>
331  inline bool check(const AlgorithmCheckerBase<D> & checker = AlgorithmCheckerBase<D>()) const
332  { return checker.checkModel(*this); }
333 
335  inline bool check() const;
336 
342  inline bool check(const Data & data) const;
343 
344  protected:
345 
350  void addJointIndexToParentSubtrees(const JointIndex joint_id);
351  };
352 
353 } // namespace se3
354 
355 /* --- Details -------------------------------------------------------------- */
356 /* --- Details -------------------------------------------------------------- */
357 /* --- Details -------------------------------------------------------------- */
358 #include "pinocchio/multibody/model.hxx"
359 
360 #endif // ifndef __se3_model_hpp__
std::string name
Model name;.
Definition: model.hpp:112
PINOCCHIO_DEPRECATED const std::string & getJointName(const JointIndex index) const
Get the name of a joint given by its index.
Definition: model.hxx:194
bool existJointName(const std::string &name) const
Check if a joint given by its name exists.
Definition: model.hxx:189
Eigen::VectorXd lowerPositionLimit
Lower joint configuration limit.
Definition: model.hpp:93
int nq
Dimension of the configuration vector representation.
Definition: model.hpp:49
int nv
Dimension of the velocity vector space.
Definition: model.hpp:52
container::aligned_vector< SE3 > jointPlacements
Placement (SE3) of the input of joint i regarding to the parent joint output li.
Definition: model.hpp:67
Eigen::VectorXd effortLimit
Vector of maximal joint torques.
Definition: model.hpp:88
container::aligned_vector< Frame > frames
Vector of operational frames registered on the model.
Definition: model.hpp:98
int addFrame(const Frame &frame)
Adds a frame to the kinematic tree.
Definition: model.hxx:219
Eigen::VectorXd rotorGearRatio
Vector of rotor gear ratio parameters.
Definition: model.hpp:85
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
Definition: model.hpp:70
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.
Definition: model.hxx:200
std::vector< IndexVector > subtrees
Vector of subtrees. subtree[j] corresponds to the subtree supported by the joint j. The first element of subtree[j] is the index of the joint j itself.
Definition: model.hpp:103
void addJointIndexToParentSubtrees(const JointIndex joint_id)
Add the joint_id to its parent subtrees.
Definition: model.hxx:233
Eigen::VectorXd neutralConfiguration
Vector of joint&#39;s neutral configurations.
Definition: model.hpp:79
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.
Definition: model.hxx:147
Eigen::VectorXd rotorInertia
Vector of rotor inertia parameters.
Definition: model.hpp:82
CRTP class describing the API of the checkers.
Definition: check.hpp:35
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
Definition: model.hpp:73
Eigen::VectorXd upperPositionLimit
Upper joint configuration limit.
Definition: model.hpp:95
static const Eigen::Vector3d gravity981
Default 3D gravity vector (=(0,0,-9.81)).
Definition: model.hpp:109
bool check() const
Run check(fusion::list) with DEFAULT_CHECKERS as argument.
int nbodies
Number of bodies.
Definition: model.hpp:58
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
Definition: frame.hpp:44
Model()
Default constructor. Builds an empty model with no joints.
Definition: model.hpp:115
Motion gravity
Spatial gravity of the model.
Definition: model.hpp:106
bool check(const AlgorithmCheckerBase< D > &checker=AlgorithmCheckerBase< D >()) const
Definition: model.hpp:331
container::aligned_vector< Inertia > inertias
Spatial inertias of the body i expressed in the supporting joint frame i.
Definition: model.hpp:64
bool existBodyName(const std::string &name) const
Check if a body given by its name exists.
Definition: model.hxx:175
Specialization of an std::vector with an aligned allocator. This specialization might be used when th...
int addJointFrame(const JointIndex &jointIndex, int frameIndex=-1)
Add a joint to the frame tree.
Definition: model.hxx:133
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.
Definition: model.hxx:212
FrameType
Enum on the possible types of frame.
Definition: frame.hpp:31
int njoints
Number of joints.
Definition: model.hpp:55
std::vector< std::string > names
Name of joint i
Definition: model.hpp:76
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
Definition: model.hxx:181
Eigen::VectorXd velocityLimit
Vector of maximal joint velocities.
Definition: model.hpp:90
int 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.
Definition: model.hxx:156
JointIndex addJoint(const JointIndex parent, const JointModelBase< JointModelDerived > &joint_model, const SE3 &joint_placement, const std::string &joint_name, const Eigen::VectorXd &max_effort, const Eigen::VectorXd &max_velocity, const Eigen::VectorXd &min_config, const Eigen::VectorXd &max_config)
Add a joint to the kinematic tree with given bounds.
Definition: model.hxx:57
JointIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.
Definition: model.hxx:170
int nframes
Number of operational frames.
Definition: model.hpp:61