pinocchio  2.7.1
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,4,4,Options> Matrix4;
23  typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
24  typedef Matrix6 ActionMatrixType;
25  typedef Matrix4 HomogeneousMatrixType;
26  typedef typename Vector6ArgType::template FixedSegmentReturnType<3>::Type LinearType;
27  typedef typename Vector6ArgType::template FixedSegmentReturnType<3>::Type AngularType;
28  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
29  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
31  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) DataRefType;
32  typedef DataRefType ToVectorReturnType;
33  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) ConstDataRefType;
34  typedef ConstDataRefType ToVectorConstReturnType;
36 
37  }; // traits ForceRef
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  template<typename Vector6ArgType>
52  class ForceRef : public ForceDense< ForceRef<Vector6ArgType> >
53  {
54  public:
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56  typedef ForceDense<ForceRef> Base;
57  typedef typename traits<ForceRef>::DataRefType DataRefType;
58  FORCE_TYPEDEF_TPL(ForceRef);
59 
60  using Base::operator=;
61  using Base::operator==;
62  using Base::operator!=;
63 
65  ForceRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) f_like)
66  : m_ref(f_like)
67  {
68  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
69  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
70  assert(f_like.size() == 6);
71  }
72 
74  ForceRef(const ForceRef & other)
75  : m_ref(other.m_ref)
76  {}
77 
78  ToVectorConstReturnType toVector_impl() const { return m_ref; }
79  ToVectorReturnType toVector_impl() { return m_ref; }
80 
81  // Getters
82  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
83  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
84  AngularType angular_impl() { return m_ref.template segment<3> (ANGULAR); }
85  LinearType linear_impl() { return m_ref.template segment<3> (LINEAR); }
86 
87  template<typename V3>
88  void angular_impl(const Eigen::MatrixBase<V3> & w)
89  {
90  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
91  angular_impl()=w;
92  }
93 
94  template<typename V3>
95  void linear_impl(const Eigen::MatrixBase<V3> & v)
96  {
97  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
98  linear_impl()=v;
99  }
100 
101  ForceRef & ref() { return *this; }
102 
103  protected:
104  DataRefType m_ref;
105 
106  }; // class ForceRef<Vector6Like>
107 
108  template<typename Vector6ArgType>
109  struct traits< ForceRef<const Vector6ArgType> >
110  {
111  typedef typename Vector6ArgType::Scalar Scalar;
112  typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(Vector6ArgType) Vector6;
113  enum {
114  LINEAR = 0,
115  ANGULAR = 3,
116  Options = Vector6::Options
117  };
118  typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
119  typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
120  typedef Matrix6 ActionMatrixType;
121  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
122  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
123  typedef ConstLinearType LinearType;
124  typedef ConstAngularType AngularType;
126  typedef ForcePlain PlainReturnType;
127  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) ConstDataRefType;
128  typedef ConstDataRefType ToVectorConstReturnType;
129  typedef ConstDataRefType DataRefType;
130  typedef DataRefType ToVectorReturnType;
132 
133  }; // traits ForceRef<const Vector6ArgType>
134 
135  template<typename Vector6ArgType>
136  class ForceRef<const Vector6ArgType>
137  : public ForceDense< ForceRef<const Vector6ArgType> >
138  {
139  public:
140  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
141  typedef ForceDense<ForceRef> Base;
142  typedef typename traits<ForceRef>::DataRefType DataRefType;
143  FORCE_TYPEDEF_TPL(ForceRef);
144 
145  ForceRef(typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) f_like)
146  : m_ref(f_like)
147  {
148  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
149  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
150  assert(f_like.size() == 6);
151  }
152 
153  ToVectorConstReturnType toVector_impl() const { return m_ref; }
154 
155  // Getters
156  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
157  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
158 
159  const ForceRef & ref() const { return *this; }
160 
161  protected:
162  DataRefType m_ref;
163 
164  }; // class ForceRef<Vector6Like>
165 
166 } // namespace pinocchio
167 
168 #endif // ifndef __pinocchio_force_ref_hpp__
pinocchio::MotionAlgebraAction
Return type of the ation of a Motion onto an object of type D.
Definition: motion.hpp:46
pinocchio::SE3GroupAction
Definition: se3.hpp:39
pinocchio::ForceRef::ForceRef
ForceRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) f_like)
Default constructor from a 6 dimensional vector.
Definition: force-ref.hpp:65
pinocchio::ForceTpl< Scalar, Options >
pinocchio::ForceRef::ForceRef
ForceRef(const ForceRef &other)
Copy constructor from another ForceRef.
Definition: force-ref.hpp:74
pinocchio::ForceRef
Definition: force-ref.hpp:52
pinocchio::ForceDense
Definition: force-dense.hpp:24
pinocchio::ForceRef< const Vector6ArgType >
Definition: force-ref.hpp:136
pinocchio::traits
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:44
pinocchio
Main pinocchio namespace.
Definition: treeview.dox:11