pinocchio  3.3.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
joint-generic.hpp
1 //
2 // Copyright (c) 2016-2021 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_joint_generic_hpp__
6 #define __pinocchio_multibody_joint_generic_hpp__
7 
8 #include "pinocchio/multibody/joint/joint-collection.hpp"
9 #include "pinocchio/multibody/joint/joint-composite.hpp"
10 #include "pinocchio/multibody/joint/joint-basic-visitors.hxx"
11 #include "pinocchio/container/aligned-vector.hpp"
12 
13 #include <boost/mpl/contains.hpp>
14 
15 namespace pinocchio
16 {
17 
18  template<
19  typename Scalar,
20  int Options = context::Options,
21  template<typename S, int O> class JointCollectionTpl = JointCollectionDefaultTpl>
22  struct JointTpl;
24 
25  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
26  struct traits<JointTpl<_Scalar, _Options, JointCollectionTpl>>
27  {
28  enum
29  {
30  Options = _Options,
31  NQ = Eigen::Dynamic, // Dynamic because unknown at compile time
32  NV = Eigen::Dynamic
33  };
34 
35  typedef _Scalar Scalar;
36  typedef JointCollectionTpl<Scalar, Options> JointCollection;
39 
44 
45  // [ABA]
46  typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> U_t;
47  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> D_t;
48  typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> UD_t;
49 
55  typedef Motion_t MotionTypeRef;
56  typedef Bias_t BiasTypeConstRef;
57  typedef Bias_t BiasTypeRef;
58  typedef U_t UTypeConstRef;
59  typedef U_t UTypeRef;
60  typedef D_t DTypeConstRef;
61  typedef D_t DTypeRef;
62  typedef UD_t UDTypeConstRef;
63  typedef UD_t UDTypeRef;
64 
65  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> ConfigVector_t;
66  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> TangentVector_t;
67 
68  typedef ConfigVector_t ConfigVectorTypeConstRef;
69  typedef ConfigVector_t ConfigVectorTypeRef;
70  typedef TangentVector_t TangentVectorTypeConstRef;
71  typedef TangentVector_t TangentVectorTypeRef;
72  };
73 
74  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
75  struct traits<JointDataTpl<_Scalar, _Options, JointCollectionTpl>>
76  {
78  typedef typename traits<JointDerived>::Scalar Scalar;
79  };
80 
81  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
82  struct traits<JointModelTpl<_Scalar, _Options, JointCollectionTpl>>
83  {
85  typedef typename traits<JointDerived>::Scalar Scalar;
86  };
87 
88  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
89  struct JointDataTpl
90  : public JointDataBase<JointDataTpl<_Scalar, _Options, JointCollectionTpl>>
91  , JointCollectionTpl<_Scalar, _Options>::JointDataVariant
92  {
93  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
94 
97 
98  PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
99 
100  typedef JointCollectionTpl<_Scalar, _Options> JointCollection;
101  typedef typename JointCollection::JointDataVariant JointDataVariant;
102 
103  using Base::operator==;
104  using Base::operator!=;
105 
106  JointDataVariant & toVariant()
107  {
108  return *static_cast<JointDataVariant *>(this);
109  }
110  const JointDataVariant & toVariant() const
111  {
112  return *static_cast<const JointDataVariant *>(this);
113  }
114 
115  ConfigVector_t joint_q() const
116  {
117  return pinocchio::joint_q(*this);
118  }
119  TangentVector_t joint_v() const
120  {
121  return pinocchio::joint_v(*this);
122  }
123  Constraint_t S() const
124  {
125  return joint_motin_subspace_xd(*this);
126  }
127  Transformation_t M() const
128  {
129  return joint_transform(*this);
130  }
131  Motion_t v() const
132  {
133  return motion(*this);
134  }
135  Bias_t c() const
136  {
137  return bias(*this);
138  }
139 
140  // [ABA CCRBA]
141  U_t U() const
142  {
143  return u_inertia(*this);
144  }
145  D_t Dinv() const
146  {
147  return dinv_inertia(*this);
148  }
149  UD_t UDinv() const
150  {
151  return udinv_inertia(*this);
152  }
153  D_t StU() const
154  {
155  return stu_inertia(*this);
156  }
157 
158  JointDataTpl()
159  : JointDataVariant()
160  {
161  }
162 
163  JointDataTpl(const JointDataVariant & jdata_variant)
164  : JointDataVariant(jdata_variant)
165  {
166  }
167 
168  template<typename JointDataDerived>
170  : JointCollection::JointDataVariant((JointDataVariant)jdata.derived())
171  {
172  BOOST_MPL_ASSERT((boost::mpl::contains<typename JointDataVariant::types, JointDataDerived>));
173  }
174 
175  // Define all the standard accessors
176  ConfigVector_t joint_q_accessor() const
177  {
178  return joint_q();
179  }
180  TangentVector_t joint_v_accessor() const
181  {
182  return joint_v();
183  }
184  Constraint_t S_accessor() const
185  {
186  return S();
187  }
188  Transformation_t M_accessor() const
189  {
190  return M();
191  }
192  Motion_t v_accessor() const
193  {
194  return v();
195  }
196  Bias_t c_accessor() const
197  {
198  return c();
199  }
200  U_t U_accessor() const
201  {
202  return U();
203  }
204  D_t Dinv_accessor() const
205  {
206  return Dinv();
207  }
208  UD_t UDinv_accessor() const
209  {
210  return UDinv();
211  }
212  D_t StU_accessor() const
213  {
214  return StU();
215  }
216 
217  static std::string classname()
218  {
219  return "JointData";
220  }
221  std::string shortname() const
222  {
223  return ::pinocchio::shortname(*this);
224  }
225 
226  template<typename JointDataDerived>
227  bool isEqual(const JointDataBase<JointDataDerived> & other) const
228  {
229  return ::pinocchio::isEqual(*this, other.derived());
230  }
231 
232  bool isEqual(const JointDataTpl & other) const
233  {
234  return Base::isEqual(other) && toVariant() == other.toVariant();
235  }
236 
237  bool operator==(const JointDataTpl & other) const
238  {
239  return isEqual(other);
240  }
241 
242  bool operator!=(const JointDataTpl & other) const
243  {
244  return !(*this == other);
245  }
246  };
247 
248  template<
249  typename NewScalar,
250  typename Scalar,
251  int Options,
252  template<typename S, int O> class JointCollectionTpl>
253  struct CastType<NewScalar, JointModelTpl<Scalar, Options, JointCollectionTpl>>
254  {
256  };
257 
258  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
260  : JointModelBase<JointModelTpl<_Scalar, _Options, JointCollectionTpl>>
261  , JointCollectionTpl<_Scalar, _Options>::JointModelVariant
262  {
263  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
264 
266 
267  PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
268  PINOCCHIO_JOINT_USE_INDEXES(JointModelTpl);
269 
270  typedef JointCollectionTpl<Scalar, Options> JointCollection;
271  typedef typename JointCollection::JointDataVariant JointDataVariant;
272  typedef typename JointCollection::JointModelVariant JointModelVariant;
273 
274  using Base::id;
275  using Base::setIndexes;
276  using Base::operator==;
277  using Base::operator!=;
278 
279  JointModelTpl()
280  : JointModelVariant()
281  {
282  }
283 
284  JointModelTpl(const JointModelVariant & jmodel_variant)
285  : JointCollection::JointModelVariant(jmodel_variant)
286  {
287  }
288 
289  const std::vector<bool> hasConfigurationLimit() const
290  {
291  return ::pinocchio::hasConfigurationLimit(*this);
292  }
293 
294  const std::vector<bool> hasConfigurationLimitInTangent() const
295  {
296  return ::pinocchio::hasConfigurationLimitInTangent(*this);
297  }
298 
299  template<typename JointModelDerived>
301  : JointModelVariant((JointModelVariant)jmodel.derived())
302  {
303  BOOST_MPL_ASSERT(
304  (boost::mpl::contains<typename JointModelVariant::types, JointModelDerived>));
305  }
306 
307  JointModelVariant & toVariant()
308  {
309  return *static_cast<JointModelVariant *>(this);
310  }
311 
312  const JointModelVariant & toVariant() const
313  {
314  return *static_cast<const JointModelVariant *>(this);
315  }
316 
317  JointDataDerived createData() const
318  {
319  return ::pinocchio::createData<Scalar, Options, JointCollectionTpl>(*this);
320  }
321 
322  template<typename JointModelDerived>
323  bool isEqual(const JointModelBase<JointModelDerived> & other) const
324  {
325  return ::pinocchio::isEqual(*this, other.derived());
326  }
327 
328  template<typename JointModelDerived>
329  bool hasSameIndexes(const JointModelBase<JointModelDerived> & other) const
330  {
331  return ::pinocchio::hasSameIndexes(*this, other.derived());
332  }
333 
334  bool isEqual(const JointModelTpl & other) const
335  {
336  return Base::isEqual(other) && toVariant() == other.toVariant();
337  }
338 
339  bool operator==(const JointModelTpl & other) const
340  {
341  return isEqual(other);
342  }
343 
344  bool operator!=(const JointModelTpl & other) const
345  {
346  return !(*this == other);
347  }
348 
349  template<typename ConfigVector>
350  void calc(JointDataDerived & data, const Eigen::MatrixBase<ConfigVector> & q) const
351  {
352  calc_zero_order(*this, data, q.derived());
353  }
354 
355  template<typename TangentVector>
356  void calc(
357  JointDataDerived & data, const Blank blank, const Eigen::MatrixBase<TangentVector> & v) const
358  {
359  calc_first_order(*this, data, blank, v.derived());
360  }
361 
362  template<typename ConfigVector, typename TangentVector>
363  void calc(
364  JointDataDerived & data,
365  const Eigen::MatrixBase<ConfigVector> & q,
366  const Eigen::MatrixBase<TangentVector> & v) const
367  {
368  calc_first_order(*this, data, q.derived(), v.derived());
369  }
370 
371  template<typename VectorLike, typename Matrix6Like>
372  void calc_aba(
373  JointDataDerived & data,
374  const Eigen::MatrixBase<VectorLike> & armature,
375  const Eigen::MatrixBase<Matrix6Like> & I,
376  const bool update_I) const
377  {
378  ::pinocchio::calc_aba(
379  *this, data, armature.derived(), PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I), update_I);
380  }
381 
382  std::string shortname() const
383  {
384  return ::pinocchio::shortname(*this);
385  }
386  static std::string classname()
387  {
388  return "JointModel";
389  }
390 
391  int nq_impl() const
392  {
393  return ::pinocchio::nq(*this);
394  }
395  int nv_impl() const
396  {
397  return ::pinocchio::nv(*this);
398  }
399 
400  int idx_q_impl() const
401  {
402  return ::pinocchio::idx_q(*this);
403  }
404  int idx_v_impl() const
405  {
406  return ::pinocchio::idx_v(*this);
407  }
408 
409  JointIndex id_impl() const
410  {
411  return ::pinocchio::id(*this);
412  }
413 
414  void setIndexes(JointIndex id, int nq, int nv)
415  {
416  ::pinocchio::setIndexes(*this, id, nq, nv);
417  }
418 
420  template<typename NewScalar>
422  {
423  return cast_joint<NewScalar, Scalar, Options, JointCollectionTpl>(*this);
424  }
425  };
426 
427  typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointData) JointDataVector;
428  typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointModel) JointModelVector;
429 
430  template<
431  typename Scalar,
432  int Options,
433  template<typename S, int O> class JointCollectionTpl,
434  typename JointDataDerived>
435  bool operator==(
436  const JointDataBase<JointDataDerived> & joint_data,
437  const JointDataTpl<Scalar, Options, JointCollectionTpl> & joint_data_generic)
438  {
439  return joint_data_generic == joint_data.derived();
440  }
441 
442  template<
443  typename Scalar,
444  int Options,
445  template<typename S, int O> class JointCollectionTpl,
446  typename JointDataDerived>
447  bool operator!=(
448  const JointDataBase<JointDataDerived> & joint_data,
449  const JointDataTpl<Scalar, Options, JointCollectionTpl> & joint_data_generic)
450  {
451  return joint_data_generic != joint_data.derived();
452  }
453 
454  template<
455  typename Scalar,
456  int Options,
457  template<typename S, int O> class JointCollectionTpl,
458  typename JointModelDerived>
459  bool operator==(
460  const JointModelBase<JointModelDerived> & joint_model,
461  const JointModelTpl<Scalar, Options, JointCollectionTpl> & joint_model_generic)
462  {
463  return joint_model_generic == joint_model.derived();
464  }
465 
466  template<
467  typename Scalar,
468  int Options,
469  template<typename S, int O> class JointCollectionTpl,
470  typename JointModelDerived>
471  bool operator!=(
472  const JointModelBase<JointModelDerived> & joint_model,
473  const JointModelTpl<Scalar, Options, JointCollectionTpl> & joint_model_generic)
474  {
475  return joint_model_generic != joint_model.derived();
476  }
477 
478 } // namespace pinocchio
479 
480 #endif // ifndef __pinocchio_multibody_joint_generic_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > u_inertia(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointUInertiaVisitor to get the U matrix of the inertia matrix decomposi...
MotionTpl< Scalar, Options > motion(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointMotionVisitor to get the joint internal motion as a dense motion.
MotionTpl< Scalar, Options > bias(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointBiasVisitor to get the joint bias as a dense motion.
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Options > stu_inertia(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointStUInertiaVisitor to get St*I*S matrix of the inertia matrix decomp...
JointMotionSubspaceTpl< Eigen::Dynamic, Scalar, Options > joint_motin_subspace_xd(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataVariant through JointConstraintVisitor to get the joint constraint as a dense constr...
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Options > dinv_inertia(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointDInvInertiaVisitor to get the D^{-1} matrix of the inertia matrix d...
SE3Tpl< Scalar, Options > joint_transform(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointTransformVisitor to get the joint internal transform (transform bet...
void calc_first_order(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Visit a JointModelTpl and the corresponding JointDataTpl through JointCalcFirstOrderVisitor to comput...
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > udinv_inertia(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointUDInvInertiaVisitor to get U*D^{-1} matrix of the inertia matrix de...
JointDataTpl< Scalar, Options, JointCollectionTpl >::TangentVector_t joint_v(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataVariant through JointConfigVisitor to get the joint velocity vector.
void calc_zero_order(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata, const Eigen::MatrixBase< ConfigVectorType > &q)
Visit a JointModelTpl and the corresponding JointDataTpl through JointCalcZeroOrderVisitor to compute...
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space.
JointDataTpl< Scalar, Options, JointCollectionTpl >::ConfigVector_t joint_q(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataVariant through JointConfigVisitor to get the joint configuration vector.
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space.
Blank type.
Definition: fwd.hpp:77
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type....
Definition: fwd.hpp:99
bool isEqual(const JointDataBase< Derived > &other) const
&#160;
JointModelTpl< NewScalar, Options, JointCollectionTpl > cast() const
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:72