pinocchio  3.3.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
frame.hpp
1 //
2 // Copyright (c) 2016-2021 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_frame_hpp__
6 #define __pinocchio_multibody_frame_hpp__
7 
8 #include "pinocchio/spatial/se3.hpp"
9 #include "pinocchio/spatial/inertia.hpp"
10 #include "pinocchio/multibody/fwd.hpp"
11 #include "pinocchio/multibody/model-item.hpp"
12 
13 #include <string>
14 
15 namespace pinocchio
16 {
31  enum FrameType
32  {
33  OP_FRAME = 0x1 << 0,
34  JOINT = 0x1 << 1,
35  FIXED_JOINT = 0x1 << 2,
36  BODY =
37  0x1 << 3,
38  SENSOR = 0x1 << 4
39  };
40 
41  template<typename _Scalar, int _Options>
42  struct traits<FrameTpl<_Scalar, _Options>>
43  {
44  typedef _Scalar Scalar;
45  enum
46  {
47  Options = _Options
48  };
49  };
50 
54  template<typename _Scalar, int _Options>
55  struct FrameTpl : ModelItem<FrameTpl<_Scalar, _Options>>
56  {
57  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59  typedef typename traits<ModelItemDerived>::Scalar Scalar;
60  enum
61  {
63  };
65 
68  typedef pinocchio::JointIndex JointIndex;
69 
73  PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
74  PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
76  : Base()
79  , type()
80  , inertia(Inertia::Zero())
81  {
82  } // needed by std::vector
83  PINOCCHIO_COMPILER_DIAGNOSTIC_POP
84 
94  PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
95  PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
97  const std::string & name,
98  const JointIndex parentJoint,
99  const SE3 & frame_placement,
100  const FrameType type,
101  const Inertia & inertia = Inertia::Zero())
102  : Base(name, parentJoint, 0, frame_placement)
105  , type(type)
106  , inertia(inertia)
107  {
108  }
109  PINOCCHIO_COMPILER_DIAGNOSTIC_POP
110 
121  PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
122  PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
124  const std::string & name,
125  const JointIndex parent_joint,
126  const FrameIndex parent_frame,
127  const SE3 & frame_placement,
128  const FrameType type,
129  const Inertia & inertia = Inertia::Zero())
130  : Base(name, parent_joint, parent_frame, frame_placement)
133  , type(type)
134  , inertia(inertia)
135  {
136  }
137  PINOCCHIO_COMPILER_DIAGNOSTIC_POP
138 
144  PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
145  PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
146  FrameTpl(const FrameTpl & other)
147  : Base(other.name, other.parentJoint, other.parentFrame, other.placement)
150  , type(other.type)
151  , inertia(other.inertia)
152  {
153  }
154  PINOCCHIO_COMPILER_DIAGNOSTIC_POP
155 
161  PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
162  PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
163  template<typename S2, int O2>
164  explicit FrameTpl(const FrameTpl<S2, O2> & other)
165  : Base(
166  other.name, other.parentJoint, other.parentFrame, other.placement.template cast<Scalar>())
169  , type(other.type)
170  , inertia(other.inertia.template cast<Scalar>())
171  {
172  }
173  PINOCCHIO_COMPILER_DIAGNOSTIC_POP
174 
181 
183  {
184  name = other.name;
185  parentJoint = other.parentJoint;
186  parentFrame = other.parentFrame;
187  placement = other.placement;
188  type = other.type;
189  inertia = other.inertia;
190  return *this;
191  }
192 
200  template<typename S2, int O2>
201  bool operator==(const FrameTpl<S2, O2> & other) const
202  {
203  return name == other.name && parentJoint == other.parentJoint
204  && parentFrame == other.parentFrame && placement == other.placement
205  && type == other.type && inertia == other.inertia;
206  }
207 
211  template<typename S2, int O2>
212  bool operator!=(const FrameTpl<S2, O2> & other) const
213  {
214  return !(*this == other);
215  }
216 
218  template<typename NewScalar>
220  {
221  typedef FrameTpl<NewScalar, Options> ReturnType;
222  ReturnType res(
223  name, parentJoint, parentFrame, placement.template cast<NewScalar>(), type,
224  inertia.template cast<NewScalar>());
225  return res;
226  }
227 
228  // data
231  PINOCCHIO_DEPRECATED JointIndex & parent;
232 
235  PINOCCHIO_DEPRECATED FrameIndex & previousFrame;
236 
237  using Base::name;
238  using Base::parentFrame;
239  using Base::parentJoint;
240  using Base::placement;
241 
244 
249 
250  }; // struct FrameTpl
251 
252  template<typename Scalar, int Options>
253  inline std::ostream & operator<<(std::ostream & os, const FrameTpl<Scalar, Options> & f)
254  {
255  os << "Frame name: " << f.name << " paired to (parent joint/ parent frame)"
256  << "(" << f.parentJoint << "/" << f.parentFrame << ")" << std::endl
257  << "with relative placement wrt parent joint:\n"
258  << f.placement << "containing inertia:\n"
259  << f.inertia << std::endl;
260 
261  return os;
262  }
263 
264 } // namespace pinocchio
265 
266 #endif // ifndef __pinocchio_multibody_frame_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
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
Definition: frame.hpp:56
bool operator!=(const FrameTpl< S2, O2 > &other) const
Definition: frame.hpp:212
FrameIndex parentFrame
Index of the parent frame.
Definition: model-item.hpp:36
PINOCCHIO_DEPRECATED JointIndex & parent
Index of the parent joint.
Definition: frame.hpp:231
JointIndex parentJoint
Index of the parent joint.
Definition: model-item.hpp:28
PINOCCHIO_COMPILER_DIAGNOSTIC_POP PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS FrameTpl(const std::string &name, const JointIndex parent_joint, const FrameIndex parent_frame, const SE3 &frame_placement, const FrameType type, const Inertia &inertia=Inertia::Zero())
Builds a frame defined by its name, its joint parent id, its placement and its type.
Definition: frame.hpp:123
PINOCCHIO_DEPRECATED FrameIndex & previousFrame
Index of the previous frame.
Definition: frame.hpp:235
FrameTpl< NewScalar, Options > cast() const
Definition: frame.hpp:219
bool operator==(const FrameTpl< S2, O2 > &other) const
Equality comparison operator.
Definition: frame.hpp:201
PINOCCHIO_COMPILER_DIAGNOSTIC_POP FrameTpl< Scalar, Options > & operator=(const FrameTpl< Scalar, Options > &other)
Copy assignment operator. It needs to be user-define because references cannot be re-assigned during ...
Definition: frame.hpp:182
std::string name
Name of the kinematic element.
Definition: model-item.hpp:25
FrameType type
Type of the frame.
Definition: frame.hpp:243
PINOCCHIO_COMPILER_DIAGNOSTIC_POP PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS FrameTpl(const std::string &name, const JointIndex parentJoint, const SE3 &frame_placement, const FrameType type, const Inertia &inertia=Inertia::Zero())
Builds a frame defined by its name, its joint parent id, its placement and its type.
Definition: frame.hpp:96
PINOCCHIO_COMPILER_DIAGNOSTIC_POP PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS FrameTpl(const FrameTpl &other)
Copy constructor.
Definition: frame.hpp:146
PINOCCHIO_COMPILER_DIAGNOSTIC_POP PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS FrameTpl(const FrameTpl< S2, O2 > &other)
Copy constructor by casting.
Definition: frame.hpp:164
SE3 placement
Position of kinematic element in parent joint frame.
Definition: model-item.hpp:39
Inertia inertia
Inertia information attached to the frame. This inertia will be appended to the inertia supported by ...
Definition: frame.hpp:248
PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS FrameTpl()
Default constructor of a frame.
Definition: frame.hpp:75
FrameIndex parentFrame
Index of the parent frame.
Definition: model-item.hpp:36
JointIndex parentJoint
Index of the parent joint.
Definition: model-item.hpp:28
std::string name
Name of the kinematic element.
Definition: model-item.hpp:25
SE3 placement
Position of kinematic element in parent joint frame.
Definition: model-item.hpp:39
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:72