pinocchio  2.4.4
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,6,6,_Options> Matrix6;
18  typedef Matrix6 ActionMatrixType;
19  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
20  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
21  typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
22  typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
23  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
24  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
26  typedef const MotionPlain & PlainReturnType;
27  enum {
28  LINEAR = 0,
29  ANGULAR = 3,
30  Options = _Options
31  };
32 
34  }; // traits MotionTpl
35 
36  template<typename _Scalar, int _Options>
37  class MotionTpl : public MotionDense< MotionTpl< _Scalar, _Options > >
38  {
39  public:
40  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41  typedef MotionDense<MotionTpl> Base;
42  MOTION_TYPEDEF_TPL(MotionTpl);
43  enum { Options = _Options };
44 
45  using Base::operator=;
46  using Base::linear;
47  using Base::angular;
48 
49  using Base::__plus__;
50  using Base::__opposite__;
51  using Base::__minus__;
52  using Base::__pequ__;
53  using Base::__mequ__;
54  using Base::__mult__;
55 
56  // Constructors
57  MotionTpl() : m_data() {}
58 
59  template<typename V1,typename V2>
60  MotionTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w)
61  {
62  assert(v.size() == 3);
63  assert(w.size() == 3);
64  linear() = v; angular() = w;
65  }
66 
67  template<typename V6>
68  explicit MotionTpl(const Eigen::MatrixBase<V6> & v)
69  : m_data(v)
70  {
71  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6);
72  assert(v.size() == 6);
73  }
74 
75  template<int O2>
76  explicit MotionTpl(const MotionTpl<Scalar,O2> & clone)
77  : m_data(clone.toVector())
78  {}
79 
80  template<typename M2>
81  explicit MotionTpl(const MotionDense<M2> & clone)
82  { linear() = clone.linear(); angular() = clone.angular(); }
83 
84  template<typename M2>
85  explicit MotionTpl(const MotionBase<M2> & clone)
86  { *this = clone; }
87 
88  // initializers
89  static MotionTpl Zero() { return MotionTpl(Vector6::Zero()); }
90  static MotionTpl Random() { return MotionTpl(Vector6::Random()); }
91 
92  inline PlainReturnType plain() const { return *this; }
93 
94  ToVectorConstReturnType toVector_impl() const { return m_data; }
95  ToVectorReturnType toVector_impl() { return m_data; }
96 
97  // Getters
98  ConstAngularType angular_impl() const { return m_data.template segment<3> (ANGULAR); }
99  ConstLinearType linear_impl() const { return m_data.template segment<3> (LINEAR); }
100  AngularType angular_impl() { return m_data.template segment<3> (ANGULAR); }
101  LinearType linear_impl() { return m_data.template segment<3> (LINEAR); }
102 
103  template<typename V3>
104  void angular_impl(const Eigen::MatrixBase<V3> & w)
105  {
106  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
107  angular_impl()=w;
108  }
109  template<typename V3>
110  void linear_impl(const Eigen::MatrixBase<V3> & v)
111  {
112  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
113  linear_impl()=v;
114  }
115 
116  // Specific operators for MotionTpl and MotionRef
117  template<int O2>
118  MotionPlain __plus__(const MotionTpl<Scalar,O2> & v) const
119  { return MotionPlain(m_data+v.toVector()); }
120 
121  template<typename Vector6ArgType>
122  MotionPlain __plus__(const MotionRef<Vector6ArgType> & v) const
123  { return MotionPlain(m_data+v.toVector()); }
124 
125  template<int O2>
126  MotionPlain __minus__(const MotionTpl<Scalar,O2> & v) const
127  { return MotionPlain(m_data-v.toVector()); }
128 
129  template<typename Vector6ArgType>
130  MotionPlain __minus__(const MotionRef<Vector6ArgType> & v) const
131  { return MotionPlain(m_data-v.toVector()); }
132 
133  template<int O2>
134  MotionTpl & __pequ__(const MotionTpl<Scalar,O2> & v)
135  { m_data += v.toVector(); return *this; }
136 
137  template<typename Vector6ArgType>
138  MotionTpl & __pequ__(const MotionRef<Vector6ArgType> & v)
139  { m_data += v.toVector(); return *this; }
140 
141  template<int O2>
142  MotionTpl & __mequ__(const MotionTpl<Scalar,O2> & v)
143  { m_data -= v.toVector(); return *this; }
144 
145  template<typename Vector6ArgType>
146  MotionTpl & __mequ__(const MotionRef<Vector6ArgType> & v)
147  { m_data -= v.toVector(); return *this; }
148 
149  template<typename OtherScalar>
150  MotionPlain __mult__(const OtherScalar & alpha) const
151  { return MotionPlain(alpha*m_data); }
152 
153  MotionRef<Vector6> ref() { return MotionRef<Vector6>(m_data); }
154 
156  template<typename NewScalar>
158  {
159  typedef MotionTpl<NewScalar,Options> ReturnType;
160  ReturnType res(linear().template cast<NewScalar>(),
161  angular().template cast<NewScalar>());
162  return res;
163  }
164 
165  protected:
166  Vector6 m_data;
167 
168  }; // class MotionTpl
169 
170 } // namespace pinocchio
171 
172 #endif // ifndef __pinocchio_motion_tpl_hpp__
MotionTpl< NewScalar, Options > cast() const
Definition: motion-tpl.hpp:157
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:35