joint-model-base.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2019 CNRS INRIA
3 // Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 
6 #ifndef __pinocchio_multibody_joint_model_base_hpp__
7 #define __pinocchio_multibody_joint_model_base_hpp__
8 
9 #include "pinocchio/multibody/joint/joint-base.hpp"
10 #include "pinocchio/multibody/joint/joint-common-operations.hpp"
11 
12 #include "pinocchio/math/matrix-block.hpp"
13 
14 #include <limits>
15 
16 #define PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,TYPENAME) \
17  typedef Eigen::DenseIndex Index; \
18  typedef TYPENAME traits<Joint>::Scalar Scalar; \
19  typedef TYPENAME traits<Joint>::JointDataDerived JointDataDerived; \
20  typedef TYPENAME traits<Joint>::JointModelDerived JointModelDerived; \
21  typedef TYPENAME traits<Joint>::Constraint_t Constraint_t; \
22  typedef TYPENAME traits<Joint>::Transformation_t Transformation_t; \
23  typedef TYPENAME traits<Joint>::Motion_t Motion_t; \
24  typedef TYPENAME traits<Joint>::Bias_t Bias_t; \
25  typedef TYPENAME traits<Joint>::U_t U_t; \
26  typedef TYPENAME traits<Joint>::D_t D_t; \
27  typedef TYPENAME traits<Joint>::UD_t UD_t; \
28  enum { \
29  Options = traits<Joint>::Options, \
30  NQ = traits<Joint>::NQ, \
31  NV = traits<Joint>::NV \
32  }; \
33  typedef TYPENAME traits<Joint>::ConfigVector_t ConfigVector_t; \
34  typedef TYPENAME traits<Joint>::TangentVector_t TangentVector_t
35 
36 #ifdef __clang__
37 
38  #define PINOCCHIO_JOINT_TYPEDEF(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,PINOCCHIO_EMPTY_ARG)
39  #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,typename)
40 
41 #elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 2)
42 
43  #define PINOCCHIO_JOINT_TYPEDEF(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,PINOCCHIO_EMPTY_ARG)
44  #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,typename)
45 
46 #else
47 
48  #define PINOCCHIO_JOINT_TYPEDEF(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,typename)
49  #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint,typename)
50 
51 #endif
52 
53 #define PINOCCHIO_JOINT_USE_INDEXES(Joint) \
54  typedef JointModelBase<Joint> Base; \
55  using Base::idx_q; \
56  using Base::idx_v
57 
58 #define PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelTpl) \
59 template<typename Scalar, int Options, typename NewScalar> \
60 struct CastType< NewScalar, JointModelTpl<Scalar,Options> > \
61 { typedef JointModelTpl<NewScalar,Options> type; }
62 
63 namespace pinocchio
64 {
65 
66  template<typename Derived>
68  {
69  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
70 
73 
74  JointModelDerived & derived() { return *static_cast<Derived*>(this); }
75  const JointModelDerived & derived() const { return *static_cast<const Derived*>(this); }
76 
77  JointDataDerived createData() const { return derived().createData(); }
78 
79  template<typename ConfigVectorType>
80  void calc(JointDataDerived & data,
81  const Eigen::MatrixBase<ConfigVectorType> & qs) const
82  {
83  derived().calc(data,qs.derived());
84  }
85 
86  template<typename ConfigVectorType, typename TangentVectorType>
87  void calc(JointDataDerived & data,
88  const Eigen::MatrixBase<ConfigVectorType> & qs,
89  const Eigen::MatrixBase<TangentVectorType> & vs) const
90  {
91  derived().calc(data,qs.derived(),vs.derived());
92  }
93 
94  template<typename Matrix6Type>
95  void calc_aba(JointDataDerived & data,
96  const Eigen::MatrixBase<Matrix6Type> & I,
97  const bool update_I = false) const
98  {
99  derived().calc_aba(data, PINOCCHIO_EIGEN_CONST_CAST(Matrix6Type,I), update_I);
100  }
101 
102  int nv() const { return derived().nv_impl(); }
103  int nq() const { return derived().nq_impl(); }
104 
105  // Default _impl methods are reimplemented by dynamic-size joints.
106  int nv_impl() const { return NV; }
107  int nq_impl() const { return NQ; }
108 
109  int idx_q() const { return derived().idx_q_impl(); }
110  int idx_v() const { return derived().idx_v_impl(); }
111  JointIndex id() const { return derived().id_impl(); }
112 
113  int idx_q_impl() const { return i_q; }
114  int idx_v_impl() const { return i_v; }
115  JointIndex id_impl() const { return i_id; }
116 
117  void setIndexes(JointIndex id, int q, int v)
118  { derived().setIndexes_impl(id, q, v); }
119 
120  void setIndexes_impl(JointIndex id,int q,int v)
121  { i_id = id, i_q = q; i_v = v; }
122 
123  void disp(std::ostream & os) const
124  {
125  using namespace std;
126  os
127  << shortname() << endl
128  << " index: " << id() << endl
129  << " index q: " << idx_q() << endl
130  << " index v: " << idx_v() << endl
131  << " nq: " << nq() << endl
132  << " nv: " << nv() << endl
133  ;
134  }
135 
136  friend std::ostream & operator << (std::ostream & os, const JointModelBase<Derived> & joint)
137  {
138  joint.disp(os);
139  return os;
140  }
141 
142  std::string shortname() const { return derived().shortname(); }
143  static std::string classname() { return Derived::classname(); }
144 
145  template<typename NewScalar>
147  { return derived().template cast<NewScalar>(); }
148 
149  template <class OtherDerived>
150  bool operator==(const JointModelBase<OtherDerived> & other) const
151  { return derived().isEqual(other.derived()); }
152 
153  template <class OtherDerived>
154  bool operator!=(const JointModelBase<OtherDerived> & other) const
155  { return !(derived() == other.derived()); }
156 
157  template <class OtherDerived>
159  { return false; }
160 
161  bool isEqual(const JointModelBase<Derived> & other) const
162  {
163  return derived().hasSameIndexes(other.derived());
164  }
165 
166  template <class OtherDerived>
168  {
169  return other.id() == id()
170  && other.idx_q() == idx_q()
171  && other.idx_v() == idx_v();
172  }
173 
174  /* Acces to dedicated segment in robot config space. */
175  // Const access
176  template<typename D>
177  typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
178  jointConfigSelector(const Eigen::MatrixBase<D> & a) const
179  { return derived().jointConfigSelector_impl(a); }
180 
181  template<typename D>
182  typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
183  jointConfigSelector_impl(const Eigen::MatrixBase<D> & a) const
184  { return SizeDepType<NQ>::segment(a.derived(),idx_q(),nq()); }
185 
186  // Non-const access
187  template<typename D>
188  typename SizeDepType<NQ>::template SegmentReturn<D>::Type
189  jointConfigSelector(Eigen::MatrixBase<D> & a) const
190  { return derived().jointConfigSelector_impl(a); }
191 
192  template<typename D>
193  typename SizeDepType<NQ>::template SegmentReturn<D>::Type
194  jointConfigSelector_impl(Eigen::MatrixBase<D> & a) const
195  { return SizeDepType<NQ>::segment(a,idx_q(),nq()); }
196 
197  /* Acces to dedicated segment in robot config velocity space. */
198  // Const access
199  template<typename D>
200  typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
201  jointVelocitySelector(const Eigen::MatrixBase<D> & a) const
202  { return derived().jointVelocitySelector_impl(a.derived()); }
203 
204  template<typename D>
205  typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
206  jointVelocitySelector_impl(const Eigen::MatrixBase<D> & a) const
207  { return SizeDepType<NV>::segment(a.derived(),idx_v(),nv()); }
208 
209  // Non-const access
210  template<typename D>
211  typename SizeDepType<NV>::template SegmentReturn<D>::Type
212  jointVelocitySelector(Eigen::MatrixBase<D> & a) const
213  { return derived().jointVelocitySelector_impl(a.derived()); }
214 
215  template<typename D>
216  typename SizeDepType<NV>::template SegmentReturn<D>::Type
217  jointVelocitySelector_impl(Eigen::MatrixBase<D> & a) const
218  { return SizeDepType<NV>::segment(a.derived(),idx_v(),nv()); }
219 
220  /* Acces to dedicated columns in a ForceSet or MotionSet matrix.*/
221  // Const access
222  template<typename D>
223  typename SizeDepType<NV>::template ColsReturn<D>::ConstType
224  jointCols(const Eigen::MatrixBase<D>& A) const
225  { return derived().jointCols_impl(A.derived()); }
226 
227  template<typename D>
228  typename SizeDepType<NV>::template ColsReturn<D>::ConstType
229  jointCols_impl(const Eigen::MatrixBase<D>& A) const
230  { return SizeDepType<NV>::middleCols(A.derived(),idx_v(),nv()); }
231 
232  // Non-const access
233  template<typename D>
234  typename SizeDepType<NV>::template ColsReturn<D>::Type
235  jointCols(Eigen::MatrixBase<D>& A) const
236  { return derived().jointCols_impl(A.derived()); }
237 
238  template<typename D>
239  typename SizeDepType<NV>::template ColsReturn<D>::Type
240  jointCols_impl(Eigen::MatrixBase<D> & A) const
241  { return SizeDepType<NV>::middleCols(A.derived(),idx_v(),nv()); }
242 
243  /* Acces to dedicated rows in a matrix.*/
244  // Const access
245  template<typename D>
246  typename SizeDepType<NV>::template RowsReturn<D>::ConstType
247  jointRows(const Eigen::MatrixBase<D> & A) const
248  { return derived().jointRows_impl(A.derived()); }
249 
250  template<typename D>
251  typename SizeDepType<NV>::template RowsReturn<D>::ConstType
252  jointRows_impl(const Eigen::MatrixBase<D> & A) const
253  { return SizeDepType<NV>::middleRows(A.derived(),idx_v(),nv()); }
254 
255  // Non-const access
256  template<typename D>
257  typename SizeDepType<NV>::template RowsReturn<D>::Type
258  jointRows(Eigen::MatrixBase<D> & A) const
259  { return derived().jointRows_impl(A.derived()); }
260 
261  template<typename D>
262  typename SizeDepType<NV>::template RowsReturn<D>::Type
263  jointRows_impl(Eigen::MatrixBase<D> & A) const
264  { return SizeDepType<NV>::middleRows(A.derived(),idx_v(),nv()); }
265 
267  // Const access
268  template<typename D>
269  typename SizeDepType<NV>::template BlockReturn<D>::ConstType
270  jointBlock(const Eigen::MatrixBase<D> & Mat) const
271  { return derived().jointBlock_impl(Mat.derived()); }
272 
273  template<typename D>
274  typename SizeDepType<NV>::template BlockReturn<D>::ConstType
275  jointBlock_impl(const Eigen::MatrixBase<D> & Mat) const
276  { return SizeDepType<NV>::block(Mat.derived(),idx_v(),idx_v(),nv(),nv()); }
277 
278  // Non-const access
279  template<typename D>
280  typename SizeDepType<NV>::template BlockReturn<D>::Type
281  jointBlock(Eigen::MatrixBase<D> & Mat) const
282  { return derived().jointBlock_impl(Mat.derived()); }
283 
284  template<typename D>
285  typename SizeDepType<NV>::template BlockReturn<D>::Type
286  jointBlock_impl(Eigen::MatrixBase<D> & Mat) const
287  { return SizeDepType<NV>::block(Mat.derived(),idx_v(),idx_v(),nv(),nv()); }
288 
289  protected:
290 
294  inline JointModelBase()
295  : i_id(std::numeric_limits<JointIndex>::max()), i_q(-1), i_v(-1) {}
296 
301  inline JointModelBase(const JointModelBase & clone)
302  { *this = clone; }
303 
308  inline JointModelBase & operator=(const JointModelBase & clone)
309  {
310  i_id = clone.i_id;
311  i_q = clone.i_q;
312  i_v = clone.i_v;
313  return *this;
314  }
315 
316  // data
317  JointIndex i_id; // ID of the joint in the multibody list.
318  int i_q; // Index of the joint configuration in the joint configuration vector.
319  int i_v; // Index of the joint velocity in the joint velocity vector.
320 
321  }; // struct JointModelBase
322 
323 } // namespace pinocchio
324 
325 #endif // ifndef __pinocchio_multibody_joint_model_base_hpp__
326 
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
SizeDepType< NV >::template ColsReturn< D >::Type jointCols_impl(Eigen::MatrixBase< D > &A) const
bool operator==(const JointModelBase< OtherDerived > &other) const
void calc(JointDataDerived &data, const Eigen::MatrixBase< ConfigVectorType > &qs) const
int NQ
Definition: dpendulum.py:8
void setIndexes(JointIndex id, int q, int v)
JointIndex id_impl() const
SizeDepType< NV >::template RowsReturn< D >::Type jointRows(Eigen::MatrixBase< D > &A) const
SizeDepType< NQ >::template SegmentReturn< D >::ConstType jointConfigSelector_impl(const Eigen::MatrixBase< D > &a) const
SizeDepType< NV >::template ColsReturn< D >::ConstType jointCols_impl(const Eigen::MatrixBase< D > &A) const
SizeDepType< NV >::template RowsReturn< D >::ConstType jointRows(const Eigen::MatrixBase< D > &A) const
JointModelBase & operator=(const JointModelBase &clone)
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
SizeDepType< NV >::template BlockReturn< D >::ConstType jointBlock_impl(const Eigen::MatrixBase< D > &Mat) const
SizeDepType< NV >::template SegmentReturn< D >::Type jointVelocitySelector_impl(Eigen::MatrixBase< D > &a) const
const JointModelDerived & derived() const
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
#define PINOCCHIO_EIGEN_CONST_CAST(TYPE, OBJ)
Macro for an automatic const_cast.
void setIndexes_impl(JointIndex id, int q, int v)
SizeDepType< NV >::template ColsReturn< D >::Type jointCols(Eigen::MatrixBase< D > &A) const
void disp(std::ostream &os) const
SizeDepType< NQ >::template SegmentReturn< D >::ConstType jointConfigSelector(const Eigen::MatrixBase< D > &a) const
static BlockReturn< D >::ConstType block(const Eigen::MatrixBase< D > &mat, typename Eigen::DenseBase< D >::Index row_id, typename Eigen::DenseBase< D >::Index col_id, typename Eigen::DenseBase< D >::Index row_size_block=NV, typename Eigen::DenseBase< D >::Index col_size_block=NV)
bool isEqual(const JointModelBase< Derived > &other) const
JointDataDerived createData() const
SizeDepType< NQ >::template SegmentReturn< D >::Type jointConfigSelector(Eigen::MatrixBase< D > &a) const
SizeDepType< NV >::template BlockReturn< D >::ConstType jointBlock(const Eigen::MatrixBase< D > &Mat) const
Returns a block of dimension nv()xnv() located at position idx_v(),idx_v() in the matrix Mat...
bool operator!=(const JointModelBase< OtherDerived > &other) const
SizeDepType< NV >::template SegmentReturn< D >::ConstType jointVelocitySelector_impl(const Eigen::MatrixBase< D > &a) const
SizeDepType< NV >::template SegmentReturn< D >::Type jointVelocitySelector(Eigen::MatrixBase< D > &a) const
bool isEqual(const JointModelBase< OtherDerived > &) const
JointModelDerived & derived()
SizeDepType< NV >::template RowsReturn< D >::ConstType jointRows_impl(const Eigen::MatrixBase< D > &A) const
CastType< NewScalar, Derived >::type cast() const
static ColsReturn< D >::ConstType middleCols(const Eigen::MatrixBase< D > &mat, typename Eigen::DenseBase< D >::Index start, typename Eigen::DenseBase< D >::Index size=NV)
static std::string classname()
Main pinocchio namespace.
Definition: timings.cpp:30
SizeDepType< NV >::template ColsReturn< D >::ConstType jointCols(const Eigen::MatrixBase< D > &A) const
SizeDepType< NV >::template RowsReturn< D >::Type jointRows_impl(Eigen::MatrixBase< D > &A) const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef traits< Derived >::JointDerived JointDerived
PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived)
JointModelBase(const JointModelBase &clone)
Common traits structure to fully define base classes for CRTP.
Definition: src/fwd.hpp:44
SizeDepType< NV >::template BlockReturn< D >::Type jointBlock_impl(Eigen::MatrixBase< D > &Mat) const
SizeDepType< NV >::template SegmentReturn< D >::ConstType jointVelocitySelector(const Eigen::MatrixBase< D > &a) const
static RowsReturn< D >::ConstType middleRows(const Eigen::MatrixBase< D > &mat, typename Eigen::DenseBase< D >::Index start, typename Eigen::DenseBase< D >::Index size=NV)
NV
Definition: dcrba.py:444
static SegmentReturn< D >::ConstType segment(const Eigen::MatrixBase< D > &mat, typename Eigen::DenseBase< D >::Index start, typename Eigen::DenseBase< D >::Index size=NV)
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type...
Definition: src/fwd.hpp:55
void calc_aba(JointDataDerived &data, const Eigen::MatrixBase< Matrix6Type > &I, const bool update_I=false) const
SizeDepType< NV >::template BlockReturn< D >::Type jointBlock(Eigen::MatrixBase< D > &Mat) const
bool hasSameIndexes(const JointModelBase< OtherDerived > &other) const
std::string shortname() const
void calc(JointDataDerived &data, const Eigen::MatrixBase< ConfigVectorType > &qs, const Eigen::MatrixBase< TangentVectorType > &vs) const
SizeDepType< NQ >::template SegmentReturn< D >::Type jointConfigSelector_impl(Eigen::MatrixBase< D > &a) const


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:03