pinocchio  2.7.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
motion-tpl.hpp
1 //
2 // Copyright (c) 2015-2018 CNRS
3 // Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 
6 #ifndef __pinocchio_motion_tpl_hpp__
7 #define __pinocchio_motion_tpl_hpp__
8 
9 namespace pinocchio
10 {
11  template<typename _Scalar, int _Options>
12  struct traits< MotionTpl<_Scalar, _Options> >
13  {
14  typedef _Scalar Scalar;
15  typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
16  typedef Eigen::Matrix<Scalar,6,1,_Options> Vector6;
17  typedef Eigen::Matrix<Scalar,4,4,_Options> Matrix4;
18  typedef Eigen::Matrix<Scalar,6,6,_Options> Matrix6;
19  typedef Matrix6 ActionMatrixType;
20  typedef Matrix4 HomogeneousMatrixType;
21  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
22  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
23  typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
24  typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
25  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
26  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
28  typedef const MotionPlain & PlainReturnType;
29  enum {
30  LINEAR = 0,
31  ANGULAR = 3,
32  Options = _Options
33  };
34 
36  }; // traits MotionTpl
37 
38  template<typename _Scalar, int _Options>
39  class MotionTpl : public MotionDense< MotionTpl< _Scalar, _Options > >
40  {
41  public:
42  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43  typedef MotionDense<MotionTpl> Base;
44  MOTION_TYPEDEF_TPL(MotionTpl);
45  enum { Options = _Options };
46 
47  using Base::operator=;
48  using Base::linear;
49  using Base::angular;
50 
51  using Base::__plus__;
52  using Base::__opposite__;
53  using Base::__minus__;
54  using Base::__pequ__;
55  using Base::__mequ__;
56  using Base::__mult__;
57 
58  // Constructors
59  MotionTpl() : m_data() {}
60 
61  template<typename V1,typename V2>
62  MotionTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w)
63  {
64  assert(v.size() == 3);
65  assert(w.size() == 3);
66  linear() = v; angular() = w;
67  }
68 
69  template<typename V6>
70  explicit MotionTpl(const Eigen::MatrixBase<V6> & v)
71  : m_data(v)
72  {
73  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6);
74  assert(v.size() == 6);
75  }
76 
77  template<int O2>
78  explicit MotionTpl(const MotionTpl<Scalar,O2> & clone)
79  : m_data(clone.toVector())
80  {}
81 
82  // Same explanation as converting constructor from MotionBase
83  template <typename M2,
84  typename std::enable_if<
85  !std::is_convertible<MotionDense<M2>, MotionTpl>::value,
86  bool>::type = true>
87  explicit MotionTpl(const MotionDense<M2> & clone)
88  { linear() = clone.linear(); angular() = clone.angular(); }
89 
90  // MotionBase implement a conversion function to PlainReturnType.
91  // Usually, PlainReturnType is defined as MotionTpl.
92  // In this case, this converting constructor is redundant and
93  // create a warning with -Wconversion
94  template <typename M2,
95  typename std::enable_if<
96  !std::is_convertible<MotionBase<M2>, MotionTpl>::value,
97  bool>::type = true>
98  explicit MotionTpl(const MotionBase<M2> & clone)
99  { *this = clone; }
100 
101  // initializers
102  static MotionTpl Zero() { return MotionTpl(Vector6::Zero()); }
103  static MotionTpl Random() { return MotionTpl(Vector6::Random()); }
104 
105  inline PlainReturnType plain() const { return *this; }
106 
107  ToVectorConstReturnType toVector_impl() const { return m_data; }
108  ToVectorReturnType toVector_impl() { return m_data; }
109 
110  // Getters
111  ConstAngularType angular_impl() const { return m_data.template segment<3> (ANGULAR); }
112  ConstLinearType linear_impl() const { return m_data.template segment<3> (LINEAR); }
113  AngularType angular_impl() { return m_data.template segment<3> (ANGULAR); }
114  LinearType linear_impl() { return m_data.template segment<3> (LINEAR); }
115 
116  template<typename V3>
117  void angular_impl(const Eigen::MatrixBase<V3> & w)
118  {
119  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
120  angular_impl()=w;
121  }
122  template<typename V3>
123  void linear_impl(const Eigen::MatrixBase<V3> & v)
124  {
125  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
126  linear_impl()=v;
127  }
128 
129  // Specific operators for MotionTpl and MotionRef
130  template<int O2>
131  MotionPlain __plus__(const MotionTpl<Scalar,O2> & v) const
132  { return MotionPlain(m_data+v.toVector()); }
133 
134  template<typename Vector6ArgType>
135  MotionPlain __plus__(const MotionRef<Vector6ArgType> & v) const
136  { return MotionPlain(m_data+v.toVector()); }
137 
138  template<int O2>
139  MotionPlain __minus__(const MotionTpl<Scalar,O2> & v) const
140  { return MotionPlain(m_data-v.toVector()); }
141 
142  template<typename Vector6ArgType>
143  MotionPlain __minus__(const MotionRef<Vector6ArgType> & v) const
144  { return MotionPlain(m_data-v.toVector()); }
145 
146  template<int O2>
147  MotionTpl & __pequ__(const MotionTpl<Scalar,O2> & v)
148  { m_data += v.toVector(); return *this; }
149 
150  template<typename Vector6ArgType>
151  MotionTpl & __pequ__(const MotionRef<Vector6ArgType> & v)
152  { m_data += v.toVector(); return *this; }
153 
154  template<int O2>
155  MotionTpl & __mequ__(const MotionTpl<Scalar,O2> & v)
156  { m_data -= v.toVector(); return *this; }
157 
158  template<typename Vector6ArgType>
159  MotionTpl & __mequ__(const MotionRef<Vector6ArgType> & v)
160  { m_data -= v.toVector(); return *this; }
161 
162  template<typename OtherScalar>
163  MotionPlain __mult__(const OtherScalar & alpha) const
164  { return MotionPlain(alpha*m_data); }
165 
166  MotionRef<Vector6> ref() { return MotionRef<Vector6>(m_data); }
167 
169  template<typename NewScalar>
171  {
172  typedef MotionTpl<NewScalar,Options> ReturnType;
173  ReturnType res(linear().template cast<NewScalar>(),
174  angular().template cast<NewScalar>());
175  return res;
176  }
177 
178  protected:
179  Vector6 m_data;
180 
181  }; // class MotionTpl
182 
183 } // namespace pinocchio
184 
185 #endif // ifndef __pinocchio_motion_tpl_hpp__
pinocchio::MotionTpl::cast
MotionTpl< NewScalar, Options > cast() const
Definition: motion-tpl.hpp:170
pinocchio::MotionDense
Definition: fwd.hpp:41
pinocchio::traits
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:44
pinocchio::MotionTpl
Definition: fwd.hpp:43
pinocchio::MotionRef
Definition: fwd.hpp:42
pinocchio
Main pinocchio namespace.
Definition: treeview.dox:11