pinocchio  2.4.4
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
force-ref.hpp
1 //
2 // Copyright (c) 2017-2019 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_force_ref_hpp__
6 #define __pinocchio_force_ref_hpp__
7 
8 namespace pinocchio
9 {
10 
11  template<typename Vector6ArgType>
12  struct traits< ForceRef<Vector6ArgType> >
13  {
14  typedef typename Vector6ArgType::Scalar Scalar;
15  typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(Vector6ArgType) Vector6;
16  enum {
17  LINEAR = 0,
18  ANGULAR = 3,
19  Options = Vector6::Options
20  };
21  typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
22  typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
23  typedef Matrix6 ActionMatrixType;
24  typedef typename Vector6ArgType::template FixedSegmentReturnType<3>::Type LinearType;
25  typedef typename Vector6ArgType::template FixedSegmentReturnType<3>::Type AngularType;
26  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
27  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
29  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) DataRefType;
30  typedef DataRefType ToVectorReturnType;
31  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) ConstDataRefType;
32  typedef ConstDataRefType ToVectorConstReturnType;
34 
35  }; // traits ForceRef
36 
37  template<typename Vector6ArgType>
38  struct SE3GroupAction< ForceRef<Vector6ArgType> >
39  {
40  typedef typename traits< ForceRef<Vector6ArgType> >::ForcePlain ReturnType;
41  };
42 
43  template<typename Vector6ArgType, typename MotionDerived>
44  struct MotionAlgebraAction< ForceRef<Vector6ArgType>, MotionDerived >
45  {
46  typedef typename traits< ForceRef<Vector6ArgType> >::ForcePlain ReturnType;
47  };
48 
49  template<typename Vector6ArgType>
50  class ForceRef : public ForceDense< ForceRef<Vector6ArgType> >
51  {
52  public:
53  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
54  typedef ForceDense<ForceRef> Base;
55  typedef typename traits<ForceRef>::DataRefType DataRefType;
56  FORCE_TYPEDEF_TPL(ForceRef);
57 
58  using Base::operator=;
59  using Base::operator==;
60  using Base::operator!=;
61 
62  ForceRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) f_like)
63  : m_ref(f_like)
64  {
65  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
66  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
67  assert(f_like.size() == 6);
68  }
69 
70  ToVectorConstReturnType toVector_impl() const { return m_ref; }
71  ToVectorReturnType toVector_impl() { return m_ref; }
72 
73  // Getters
74  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
75  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
76  AngularType angular_impl() { return m_ref.template segment<3> (ANGULAR); }
77  LinearType linear_impl() { return m_ref.template segment<3> (LINEAR); }
78 
79  template<typename V3>
80  void angular_impl(const Eigen::MatrixBase<V3> & w)
81  {
82  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
83  angular_impl()=w;
84  }
85 
86  template<typename V3>
87  void linear_impl(const Eigen::MatrixBase<V3> & v)
88  {
89  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
90  linear_impl()=v;
91  }
92 
93  ForceRef & ref() { return *this; }
94 
95  protected:
96  DataRefType m_ref;
97 
98  }; // class ForceRef<Vector6Like>
99 
100  template<typename Vector6ArgType>
101  struct traits< ForceRef<const Vector6ArgType> >
102  {
103  typedef typename Vector6ArgType::Scalar Scalar;
104  typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(Vector6ArgType) Vector6;
105  enum {
106  LINEAR = 0,
107  ANGULAR = 3,
108  Options = Vector6::Options
109  };
110  typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
111  typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
112  typedef Matrix6 ActionMatrixType;
113  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
114  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
115  typedef ConstLinearType LinearType;
116  typedef ConstAngularType AngularType;
118  typedef ForcePlain PlainReturnType;
119  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) ConstDataRefType;
120  typedef ConstDataRefType ToVectorConstReturnType;
121  typedef ConstDataRefType DataRefType;
122  typedef DataRefType ToVectorReturnType;
124 
125  }; // traits ForceRef<const Vector6ArgType>
126 
127  template<typename Vector6ArgType>
128  class ForceRef<const Vector6ArgType>
129  : public ForceDense< ForceRef<const Vector6ArgType> >
130  {
131  public:
132  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
133  typedef ForceDense<ForceRef> Base;
134  typedef typename traits<ForceRef>::DataRefType DataRefType;
135  FORCE_TYPEDEF_TPL(ForceRef);
136 
137  ForceRef(typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) f_like)
138  : m_ref(f_like)
139  {
140  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
141  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
142  assert(f_like.size() == 6);
143  }
144 
145  ToVectorConstReturnType toVector_impl() const { return m_ref; }
146 
147  // Getters
148  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
149  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
150 
151  const ForceRef & ref() const { return *this; }
152 
153  protected:
154  DataRefType m_ref;
155 
156  }; // class ForceRef<Vector6Like>
157 
158 } // namespace pinocchio
159 
160 #endif // ifndef __pinocchio_force_ref_hpp__
Return type of the ation of a Motion onto an object of type D.
Definition: motion.hpp:44
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:35