pinocchio  2.1.3
force-ref.hpp
1 //
2 // Copyright (c) 2017-2018 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  namespace internal
38  {
39  template<typename Vector6ArgType>
40  struct SE3GroupAction< ForceRef<Vector6ArgType> >
41  {
42  typedef typename traits< ForceRef<Vector6ArgType> >::ForcePlain ReturnType;
43  };
44 
45  template<typename Vector6ArgType, typename MotionDerived>
46  struct MotionAlgebraAction< ForceRef<Vector6ArgType>, MotionDerived >
47  {
48  typedef typename traits< ForceRef<Vector6ArgType> >::ForcePlain ReturnType;
49  };
50  }
51 
52  template<typename Vector6ArgType>
53  class ForceRef : public ForceDense< ForceRef<Vector6ArgType> >
54  {
55  public:
56  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
57  typedef ForceDense<ForceRef> Base;
58  typedef typename traits<ForceRef>::DataRefType DataRefType;
59  FORCE_TYPEDEF_TPL(ForceRef);
60 
61  using Base::operator=;
62 
63  ForceRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) f_like)
64  : m_ref(f_like)
65  {
66  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
67  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
68  assert(f_like.size() == 6);
69  }
70 
71  ToVectorConstReturnType toVector_impl() const { return m_ref; }
72  ToVectorReturnType toVector_impl() { return m_ref; }
73 
74  // Getters
75  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
76  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
77  AngularType angular_impl() { return m_ref.template segment<3> (ANGULAR); }
78  LinearType linear_impl() { return m_ref.template segment<3> (LINEAR); }
79 
80  template<typename V3>
81  void angular_impl(const Eigen::MatrixBase<V3> & w)
82  {
83  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
84  angular_impl()=w;
85  }
86 
87  template<typename V3>
88  void linear_impl(const Eigen::MatrixBase<V3> & v)
89  {
90  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
91  linear_impl()=v;
92  }
93 
94  ForceRef & ref() { return *this; }
95 
96  protected:
97  DataRefType m_ref;
98 
99  }; // class ForceRef<Vector6Like>
100 
101  template<typename Vector6ArgType>
102  class ForceRef<const Vector6ArgType>
103  : public ForceDense< ForceRef<const Vector6ArgType> >
104  {
105  public:
106  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
107  typedef ForceDense<ForceRef> Base;
108  typedef typename traits<ForceRef>::DataRefType DataRefType;
109  FORCE_TYPEDEF_TPL(ForceRef);
110 
111  ForceRef(typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) f_like)
112  : m_ref(f_like)
113  {
114  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
115  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
116  assert(f_like.size() == 6);
117  }
118 
119  ToVectorConstReturnType toVector_impl() const { return m_ref; }
120 
121  // Getters
122  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
123  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
124 
125  const ForceRef & ref() const { return *this; }
126 
127  protected:
128  DataRefType m_ref;
129 
130  }; // class ForceRef<Vector6Like>
131 
132 } // namespace pinocchio
133 
134 #endif // ifndef __pinocchio_force_ref_hpp__
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: spatial/fwd.hpp:29