pinocchio  2.4.4
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
joint-revolute-unbounded.hpp
1 //
2 // Copyright (c) 2016-2019 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_joint_revolute_unbounded_hpp__
6 #define __pinocchio_joint_revolute_unbounded_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 #include "pinocchio/math/sincos.hpp"
10 #include "pinocchio/spatial/inertia.hpp"
11 #include "pinocchio/multibody/joint/joint-base.hpp"
12 #include "pinocchio/multibody/joint/joint-revolute.hpp"
13 
14 namespace pinocchio
15 {
16 
17  template<typename Scalar, int Options, int axis> struct JointRevoluteUnboundedTpl;
18 
19  template<typename _Scalar, int _Options, int axis>
20  struct traits< JointRevoluteUnboundedTpl<_Scalar,_Options,axis> >
21  {
22  enum {
23  NQ = 2,
24  NV = 1
25  };
26  typedef _Scalar Scalar;
27  enum { Options = _Options };
34 
35  // [ABA]
36  typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
37  typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
38  typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
39 
40  PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
41 
42  typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
43  typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
44  };
45 
46  template<typename Scalar, int Options, int axis>
47  struct traits< JointDataRevoluteUnboundedTpl<Scalar,Options,axis> >
49 
50  template<typename Scalar, int Options, int axis>
51  struct traits< JointModelRevoluteUnboundedTpl<Scalar,Options,axis> >
53 
54  template<typename _Scalar, int _Options, int axis>
55  struct JointDataRevoluteUnboundedTpl : public JointDataBase< JointDataRevoluteUnboundedTpl<_Scalar,_Options,axis> >
56  {
57  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59  PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
60  PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
61 
62  Constraint_t S;
63  Transformation_t M;
64  Motion_t v;
65  Bias_t c;
66 
67  // [ABA] specific data
68  U_t U;
69  D_t Dinv;
70  UD_t UDinv;
71 
73  : M((Scalar)0,(Scalar)1)
74  , v((Scalar)0)
75  , U(U_t::Zero())
76  , Dinv(D_t::Zero())
77  , UDinv(UD_t::Zero())
78  {}
79 
80  static std::string classname()
81  {
82  return std::string("JointDataRUB") + axisLabel<axis>();
83  }
84  std::string shortname() const { return classname(); }
85 
86  }; // struct JointDataRevoluteUnbounded
87 
88  template<typename NewScalar, typename Scalar, int Options, int axis>
89  struct CastType< NewScalar, JointModelRevoluteUnboundedTpl<Scalar,Options,axis> >
90  {
92  };
93 
94  template<typename _Scalar, int _Options, int axis>
96  : public JointModelBase< JointModelRevoluteUnboundedTpl<_Scalar,_Options,axis> >
97  {
98  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
100  PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
101  typedef JointRevoluteTpl<Scalar,_Options,axis> JointDerivedBase;
102 
104  using Base::id;
105  using Base::idx_q;
106  using Base::idx_v;
107  using Base::setIndexes;
108 
109  JointDataDerived createData() const { return JointDataDerived(); }
110 
111  template<typename ConfigVector>
112  void calc(JointDataDerived & data,
113  const typename Eigen::MatrixBase<ConfigVector> & qs) const
114  {
115  typedef typename ConfigVector::Scalar OtherScalar;
116  typename ConfigVector::template ConstFixedSegmentReturnType<NQ>::Type
117  & q = qs.template segment<NQ> (idx_q());
118 
119  const OtherScalar & ca = q(0);
120  const OtherScalar & sa = q(1);
121 
122  data.M.setValues(sa,ca);
123  }
124 
125  template<typename ConfigVector, typename TangentVector>
126  void calc(JointDataDerived & data,
127  const typename Eigen::MatrixBase<ConfigVector> & qs,
128  const typename Eigen::MatrixBase<TangentVector> & vs) const
129  {
130  calc(data,qs.derived());
131 
132  data.v.angularRate() = static_cast<Scalar>(vs[idx_v()]);
133  }
134 
135  template<typename Matrix6Like>
136  void calc_aba(JointDataDerived & data, const Eigen::MatrixBase<Matrix6Like> & I, const bool update_I) const
137  {
138  data.U = I.col(Inertia::ANGULAR + axis);
139  data.Dinv[0] = (Scalar)(1)/I(Inertia::ANGULAR + axis,Inertia::ANGULAR + axis);
140  data.UDinv.noalias() = data.U * data.Dinv[0];
141 
142  if (update_I)
143  PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
144  }
145 
146  static std::string classname()
147  {
148  return std::string("JointModelRUB") + axisLabel<axis>();
149  }
150  std::string shortname() const { return classname(); }
151 
153  template<typename NewScalar>
155  {
157  ReturnType res;
158  res.setIndexes(id(),idx_q(),idx_v());
159  return res;
160  }
161 
162  }; // struct JointModelRevoluteUnboundedTpl
163 
165  {
166  template<typename ConfigVectorIn, typename Scalar, typename ConfigVectorOut>
167  static void run(const Eigen::MatrixBase<ConfigVectorIn> & q,
168  const Scalar & scaling,
169  const Scalar & offset,
170  const Eigen::MatrixBase<ConfigVectorOut> & dest)
171  {
172  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(ConfigVectorIn,2);
173  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(ConfigVectorOut,2);
174 
175  const typename ConfigVectorIn::Scalar & ca = q(0);
176  const typename ConfigVectorIn::Scalar & sa = q(1);
177 
178  const typename ConfigVectorIn::Scalar & theta = math::atan2(sa,ca);
179  const typename ConfigVectorIn::Scalar & theta_transform = scaling * theta + offset;
180 
181  ConfigVectorOut & dest_ = PINOCCHIO_EIGEN_CONST_CAST(ConfigVectorOut,dest);
182  SINCOS(theta_transform,&dest_.coeffRef(1),&dest_.coeffRef(0));
183  }
184  };
185 
186  template<typename Scalar, int Options, int axis>
188  {
190  };
191 
195 
199 
203 
204 } //namespace pinocchio
205 
206 #include <boost/type_traits.hpp>
207 
208 namespace boost
209 {
210  template<typename Scalar, int Options, int axis>
211  struct has_nothrow_constructor< ::pinocchio::JointModelRevoluteUnboundedTpl<Scalar,Options,axis> >
212  : public integral_constant<bool,true> {};
213 
214  template<typename Scalar, int Options, int axis>
215  struct has_nothrow_copy< ::pinocchio::JointModelRevoluteUnboundedTpl<Scalar,Options,axis> >
216  : public integral_constant<bool,true> {};
217 
218  template<typename Scalar, int Options, int axis>
219  struct has_nothrow_constructor< ::pinocchio::JointDataRevoluteUnboundedTpl<Scalar,Options,axis> >
220  : public integral_constant<bool,true> {};
221 
222  template<typename Scalar, int Options, int axis>
223  struct has_nothrow_copy< ::pinocchio::JointDataRevoluteUnboundedTpl<Scalar,Options,axis> >
224  : public integral_constant<bool,true> {};
225 }
226 
227 #endif // ifndef __pinocchio_joint_revolute_unbounded_hpp__
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
Definition: casadi.hpp:13
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...
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
Assign the correct configuration vector space affine transformation according to the joint type...
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
JointModelRevoluteUnboundedTpl< NewScalar, Options, axis > cast() const
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:26
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:35
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type...
Definition: fwd.hpp:46
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...