pinocchio  2.1.3
joint-generic.hpp
1 //
2 // Copyright (c) 2016,2018 CNRS
3 //
4 
5 #ifndef __pinocchio_joint_generic_hpp__
6 #define __pinocchio_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<typename Scalar, int Options = 0, template<typename S, int O> class JointCollectionTpl = JointCollectionDefaultTpl>
19  struct JointTpl;
20  typedef JointTpl<double> Joint;
21 
22  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
23  struct traits< JointTpl<_Scalar,_Options,JointCollectionTpl> >
24  {
25  enum {
26  Options = _Options,
27  NQ = Eigen::Dynamic, // Dynamic because unknown at compile time
28  NV = Eigen::Dynamic
29  };
30 
31  typedef _Scalar Scalar;
32  typedef JointCollectionTpl<Scalar,Options> JointCollection;
35 
40 
41  typedef Eigen::Matrix<Scalar,6,Eigen::Dynamic,Options> F_t;
42  // [ABA]
43  typedef Eigen::Matrix<Scalar,6,Eigen::Dynamic,Options> U_t;
44  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,Options> D_t;
45  typedef Eigen::Matrix<Scalar,6,Eigen::Dynamic,Options> UD_t;
46 
47  typedef Constraint_t ConstraintTypeConstRef;
48  typedef Transformation_t TansformTypeConstRef;
49  typedef Motion_t MotionTypeConstRef;
50  typedef Bias_t BiasTypeConstRef;
51  typedef U_t UTypeConstRef;
52  typedef U_t UTypeRef;
53  typedef D_t DTypeConstRef;
54  typedef UD_t UDTypeConstRef;
55 
56  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,Options> ConfigVector_t;
57  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,Options> TangentVector_t;
58  };
59 
60  template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
61  struct traits< JointDataTpl<Scalar,Options,JointCollectionTpl> >
63 
64  template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
65  struct traits< JointModelTpl<Scalar,Options,JointCollectionTpl> >
67 
68  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
69  struct JointDataTpl
70  : public JointDataBase< JointDataTpl<_Scalar,_Options,JointCollectionTpl> >
71  , JointCollectionTpl<_Scalar,_Options>::JointDataVariant
72  {
73  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
74 
76  typedef JointDataBase<JointDataTpl> Base;
77 
78  PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE;
79 
80  typedef JointCollectionTpl<_Scalar,_Options> JointCollection;
81  typedef typename JointCollection::JointDataVariant JointDataVariant;
82 
83  JointDataVariant & toVariant() { return *static_cast<JointDataVariant*>(this); }
84  const JointDataVariant & toVariant() const { return *static_cast<const JointDataVariant*>(this); }
85 
86  Constraint_t S() const { return constraint_xd(*this); }
87  Transformation_t M() const { return joint_transform(*this); }
88  Motion_t v() const { return motion(*this); }
89  Bias_t c() const { return bias(*this); }
90 
91  // [ABA CCRBA]
92  U_t U() const { return u_inertia(*this); }
93  D_t Dinv() const { return dinv_inertia(*this); }
94  UD_t UDinv() const { return udinv_inertia(*this); }
95 
96  JointDataTpl() : JointDataVariant() {}
97 
98  JointDataTpl(const JointDataVariant & jdata_variant)
99  : JointDataVariant(jdata_variant)
100  {}
101 
102  template<typename JointDataDerived>
104  : JointCollection::JointDataVariant((JointDataVariant)jdata.derived())
105  {
106  BOOST_MPL_ASSERT((boost::mpl::contains<typename JointDataVariant::types,JointDataDerived>));
107  }
108 
110  Constraint_t S_accessor() const { return S(); }
111  Transformation_t M_accessor() const { return M(); }
112  Motion_t v_accessor() const { return v(); }
113  Bias_t c_accessor() const { return c(); }
114  U_t U_accessor() const { return U(); }
115  D_t Dinv_accessor() const { return Dinv(); }
116  UD_t UDinv_accessor() const { return UDinv(); }
117 
118  static std::string classname() { return "JointData"; }
119  std::string shortname() const { return ::pinocchio::shortname(*this); }
120 
121  };
122 
123  template<typename NewScalar, typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
124  struct CastType< NewScalar, JointModelTpl<Scalar,Options,JointCollectionTpl> >
125  {
127  };
128 
129  template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
130  struct JointModelTpl
131  : JointModelBase< JointModelTpl<_Scalar,_Options,JointCollectionTpl> >
132  , JointCollectionTpl<_Scalar,_Options>::JointModelVariant
133  {
134  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
135 
137 
138  PINOCCHIO_JOINT_TYPEDEF_TEMPLATE;
139  PINOCCHIO_JOINT_USE_INDEXES;
140 
141  typedef JointCollectionTpl<Scalar,Options> JointCollection;
142  typedef typename JointCollection::JointDataVariant JointDataVariant;
143  typedef typename JointCollection::JointModelVariant JointModelVariant;
144 
145  using Base::id;
146  using Base::setIndexes;
147  using Base::operator==;
148  using Base::operator!=;
149 
150  JointModelTpl() : JointModelVariant() {}
151 
152  JointModelTpl(const JointModelVariant & jmodel_variant)
153  : JointCollection::JointModelVariant(jmodel_variant)
154  {}
155 
156  template<typename JointModelDerived>
158  : JointModelVariant((JointModelVariant)jmodel.derived())
159  {
160  BOOST_MPL_ASSERT((boost::mpl::contains<typename JointModelVariant::types,JointModelDerived>));
161  }
162 
163  JointModelVariant & toVariant()
164  { return *static_cast<JointModelVariant*>(this); }
165 
166  const JointModelVariant & toVariant() const
167  { return *static_cast<const JointModelVariant*>(this); }
168 
169  JointDataDerived createData() const
170  { return ::pinocchio::createData<Scalar,Options,JointCollectionTpl>(*this); }
171 
172  using Base::isEqual;
173  bool isEqual(const JointModelTpl & other) const
174  {
175  return Base::isEqual(other)
176  && toVariant() == other.toVariant();
177  }
178 
179  template<typename ConfigVector>
180  void calc(JointDataDerived & data,
181  const Eigen::MatrixBase<ConfigVector> & q) const
182  { calc_zero_order(*this,data,q); }
183 
184  template<typename ConfigVector, typename TangentVector>
185  void calc(JointDataDerived & data,
186  const Eigen::MatrixBase<ConfigVector> & q,
187  const Eigen::MatrixBase<TangentVector> & v) const
188  { calc_first_order(*this,data,q,v); }
189 
190  template<typename Matrix6Like>
191  void calc_aba(JointDataDerived & data, const Eigen::MatrixBase<Matrix6Like> & I, const bool update_I) const
192  { ::pinocchio::calc_aba(*this,data,PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I),update_I); }
193 
194  std::string shortname() const { return ::pinocchio::shortname(*this); }
195  static std::string classname() { return "JointModel"; }
196 
197  int nq_impl() const { return ::pinocchio::nq(*this); }
198  int nv_impl() const { return ::pinocchio::nv(*this); }
199 
200  int idx_q() const { return ::pinocchio::idx_q(*this); }
201  int idx_v() const { return ::pinocchio::idx_v(*this); }
202 
203  JointIndex id() const { return ::pinocchio::id(*this); }
204 
205  void setIndexes(JointIndex id, int nq, int nv)
206  { ::pinocchio::setIndexes(*this,id, nq, nv); }
207 
209  template<typename NewScalar>
211  {
212  return cast_joint<NewScalar,Scalar,Options,JointCollectionTpl>(*this);
213  }
214  };
215 
218 
219 } // namespace pinocchio
220 
221 #endif // ifndef __pinocchio_joint_generic_hpp__
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space...
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...
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
int idx_v(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxVVisitor to get the index in the full model tangent space corre...
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space...
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
SE3Tpl< Scalar, Options > joint_transform(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointTransformVisitor to get the joint internal transform (transform bet...
JointIndex id(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdVisitor to get the index of the joint in the kinematic chain...
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...
JointModelTpl< NewScalar, Options, JointCollectionTpl > cast() const
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
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...
Main pinocchio namespace.
Definition: treeview.dox:24
void setIndexes(JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointIndex id, int q, int v)
Visit a JointModelTpl through JointSetIndexesVisitor to set the indexes of the joint in the kinematic...
MotionTpl< Scalar, Options > bias(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataTpl through JointBiasVisitor to get the joint bias as a dense motion.
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...
Common traits structure to fully define base classes for CRTP.
Definition: spatial/fwd.hpp:29
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type...
Definition: spatial/fwd.hpp:35
Constraint_t S_accessor() const
Define all the standard accessors.
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...
ConstraintTpl< Eigen::Dynamic, Scalar, Options > constraint_xd(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataVariant through JointConstraintVisitor to get the joint constraint as a dense constr...
void calc_aba(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata, const Eigen::MatrixBase< Matrix6Type > &I, const bool update_I)
Visit a JointModelTpl and the corresponding JointDataTpl through JointCalcAbaVisitor to...
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...