pinocchio  3.9.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
model.hpp
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 <map>
24#include <iterator>
25
26namespace pinocchio
27{
28 template<
29 typename NewScalar,
30 typename Scalar,
31 int Options,
32 template<typename, int> class JointCollectionTpl>
33 struct CastType<NewScalar, ModelTpl<Scalar, Options, JointCollectionTpl>>
34 {
36 };
37
38 template<typename _Scalar, int _Options, template<typename, int> class JointCollectionTpl>
39 struct traits<ModelTpl<_Scalar, _Options, JointCollectionTpl>>
40 {
41 typedef _Scalar Scalar;
42 };
43
44 template<typename _Scalar, int _Options, template<typename, int> class JointCollectionTpl>
45 struct ModelTpl
46 : serialization::Serializable<ModelTpl<_Scalar, _Options, JointCollectionTpl>>
47 , NumericalBase<ModelTpl<_Scalar, _Options, JointCollectionTpl>>
48 {
49 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50
51 typedef _Scalar Scalar;
52 enum
53 {
54 Options = _Options
55 };
56
57 typedef JointCollectionTpl<Scalar, Options> JointCollection;
59
60 typedef SE3Tpl<Scalar, Options> SE3;
61 typedef MotionTpl<Scalar, Options> Motion;
62 typedef ForceTpl<Scalar, Options> Force;
63 typedef InertiaTpl<Scalar, Options> Inertia;
64 typedef FrameTpl<Scalar, Options> Frame;
65
66 typedef pinocchio::Index Index;
67 typedef pinocchio::JointIndex JointIndex;
68 typedef pinocchio::GeomIndex GeomIndex;
69 typedef pinocchio::FrameIndex FrameIndex;
70 typedef std::vector<Index> IndexVector;
71
74
75 typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointModel) JointModelVector;
76 typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointData) JointDataVector;
77
78 typedef PINOCCHIO_ALIGNED_STD_VECTOR(Frame) FrameVector;
79
80 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs;
81 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
82
83 typedef PINOCCHIO_ALIGNED_STD_VECTOR(Inertia) InertiaVector;
84 typedef PINOCCHIO_ALIGNED_STD_VECTOR(SE3) SE3Vector;
85
87 typedef VectorXs ConfigVectorType;
88
90 typedef std::map<std::string, ConfigVectorType> ConfigVectorMap;
91
95 typedef VectorXs TangentVectorType;
96
98 int nq;
99
101 int nv;
102
105
108
111
114
116 InertiaVector inertias;
117
119 SE3Vector jointPlacements;
120
122 JointModelVector joints;
123
125 std::vector<int> idx_qs;
126
128 std::vector<int> nqs;
129
131 std::vector<int> idx_vs;
132
134 std::vector<int> nvs;
135
137 std::vector<int> idx_vExtendeds;
138
140 std::vector<int> nvExtendeds;
141
144 std::vector<JointIndex> parents;
145
148 std::vector<IndexVector> children;
149
151 std::vector<JointIndex> mimicking_joints;
152
156 std::vector<JointIndex> mimicked_joints;
157
159 std::vector<std::string> names;
160
163
166 VectorXs armature;
167
170
173
176
179
182
185
188
191
193 FrameVector frames;
194
200 std::vector<IndexVector> supports;
201
206 std::vector<IndexVector> mimic_joint_supports;
207
211 std::vector<IndexVector> subtrees;
212
214 Motion gravity;
215
217 static const Vector3 gravity981;
218
220 std::string name;
221
224 : nq(0)
225 , nv(0)
226 , nvExtended(0)
227 , njoints(1)
228 , nbodies(1)
229 , nframes(0)
230 , inertias(1, Inertia::Zero())
231 , jointPlacements(1, SE3::Identity())
232 , joints(1)
233 , idx_qs(1, 0)
234 , nqs(1, 0)
235 , idx_vs(1, 0)
236 , nvs(1, 0)
237 , idx_vExtendeds(1, 0)
238 , nvExtendeds(1, 0)
239 , parents(1, 0)
240 , children(1)
241 , names(1)
242 , supports(1, IndexVector(1, 0))
243 , mimic_joint_supports(1, IndexVector(1, 0))
244 , subtrees(1)
245 , gravity(gravity981, Vector3::Zero())
246 {
247 names[0] = "universe"; // Should be "universe joint (trivial)"
248 // FIXME Should the universe joint be a FIXED_JOINT even if it is
249 // in the list of joints ? See comment in definition of
250 // Model::addJointFrame and Model::addBodyFrame
251 addFrame(Frame("universe", 0, 0, SE3::Identity(), FIXED_JOINT));
252 }
253
259 template<typename S2, int O2>
260 explicit ModelTpl(const ModelTpl<S2, O2> & other)
261 {
262 *this = other.template cast<Scalar>();
263 }
264
266 template<typename NewScalar>
268
274 bool operator==(const ModelTpl & other) const;
275
279 bool operator!=(const ModelTpl & other) const
280 {
281 return !(*this == other);
282 }
283
303 JointIndex addJoint(
304 const JointIndex parent,
305 const JointModel & joint_model,
306 const SE3 & joint_placement,
307 const std::string & joint_name);
308
318 JointIndex addJoint(
319 const JointIndex parent,
320 const JointModel & joint_model,
321 const SE3 & joint_placement,
322 const std::string & joint_name,
323 const VectorXs & max_effort,
324 const VectorXs & max_velocity,
325 const VectorXs & min_config,
326 const VectorXs & max_config);
327
335 JointIndex addJoint(
336 const JointIndex parent,
337 const JointModel & joint_model,
338 const SE3 & joint_placement,
339 const std::string & joint_name,
340 const VectorXs & max_effort,
341 const VectorXs & max_velocity,
342 const VectorXs & min_config,
343 const VectorXs & max_config,
344 const VectorXs & friction,
345 const VectorXs & damping);
346
356 FrameIndex addJointFrame(const JointIndex & joint_index, int previous_frame_index = -1);
357
369 const JointIndex joint_index,
370 const Inertia & Y,
371 const SE3 & body_placement = SE3::Identity());
372
385 FrameIndex addBodyFrame(
386 const std::string & body_name,
387 const JointIndex & parentJoint,
388 const SE3 & body_placement = SE3::Identity(),
389 int parentFrame = -1);
390
402 FrameIndex getBodyId(const std::string & name) const;
403
411 bool existBodyName(const std::string & name) const;
412
423 JointIndex getJointId(const std::string & name) const;
424
432 bool existJointName(const std::string & name) const;
433
447 FrameIndex getFrameId(
448 const std::string & name,
449 const FrameType & type = (FrameType)(JOINT | FIXED_JOINT | BODY | OP_FRAME | SENSOR)) const;
450
460 const std::string & name,
461 const FrameType & type = (FrameType)(JOINT | FIXED_JOINT | BODY | OP_FRAME | SENSOR)) const;
462
475 FrameIndex addFrame(const Frame & frame, const bool append_inertia = true);
476
487 template<typename D>
489 {
490 return checker.checkModel(*this);
491 }
492
498 std::vector<bool> hasConfigurationLimit();
499
505 std::vector<bool> hasConfigurationLimitInTangent();
506
508 bool check() const;
509
517 bool check(const Data & data) const;
518
519 protected:
525 void addJointIndexToParentSubtrees(const JointIndex joint_id);
526 };
527
528} // namespace pinocchio
529
530/* --- Details -------------------------------------------------------------- */
531/* --- Details -------------------------------------------------------------- */
532/* --- Details -------------------------------------------------------------- */
533#include "pinocchio/multibody/model.hxx"
534
535#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
536 #include "pinocchio/multibody/model.txx"
537#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
538
539#endif // ifndef __pinocchio_multibody_model_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
FrameType
Enum on the possible types of frames.
Definition frame.hpp:32
@ BODY
body frame: attached to the collision, inertial or visual properties of a link
Definition frame.hpp:36
@ SENSOR
sensor frame: defined in a sensor element
Definition frame.hpp:38
@ OP_FRAME
operational frame: user-defined frames that are defined at runtime
Definition frame.hpp:33
@ JOINT
joint frame: attached to the child body of a joint (a.k.a. child frame)
Definition frame.hpp:34
@ FIXED_JOINT
fixed joint frame: joint frame but for a fixed joint
Definition frame.hpp:35
CRTP class describing the API of the checkers.
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type....
Definition fwd.hpp:99
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
Definition frame.hpp:56
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name, const VectorXs &max_effort, const VectorXs &max_velocity, const VectorXs &min_config, const VectorXs &max_config, const VectorXs &friction, const VectorXs &damping)
CastType< NewScalar, ModelTpl >::type cast() const
FrameIndex addJointFrame(const JointIndex &joint_index, int previous_frame_index=-1)
Add a joint to the frame tree.
FrameIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.
bool operator==(const ModelTpl &other) const
Equality comparison operator.
ModelTpl()
Default constructor. Builds an empty model with no joints.
Definition model.hpp:223
bool operator!=(const ModelTpl &other) const
Definition model.hpp:279
FrameIndex addBodyFrame(const std::string &body_name, const JointIndex &parentJoint, const SE3 &body_placement=SE3::Identity(), int parentFrame=-1)
Add a body to the frame tree.
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.
bool check() const
Run check(fusion::list) with DEFAULT_CHECKERS as argument.
ModelTpl(const ModelTpl< S2, O2 > &other)
Copy constructor by casting.
Definition model.hpp:260
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
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.
bool check(const Data &data) const
Run checkData on data and current model.
void addJointIndexToParentSubtrees(const JointIndex joint_id)
Add the joint_id to its parent subtrees.
bool existBodyName(const std::string &name) const
Check if a body given by its name exists.
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 check(const AlgorithmCheckerBase< D > &checker=AlgorithmCheckerBase< D >()) const
Check the validity of the attributes of Model with respect to the specification of some algorithms.
Definition model.hpp:488
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name, const VectorXs &max_effort, const VectorXs &max_velocity, const VectorXs &min_config, const VectorXs &max_config)
std::map< std::string, ConfigVectorType > ConfigVectorMap
Definition model.hpp:90
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.
std::vector< bool > hasConfigurationLimit()
Check if joints have configuration limits.
bool existJointName(const std::string &name) const
Check if a joint given by its name exists.
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...
std::vector< bool > hasConfigurationLimitInTangent()
Check if joints have configuration limits.