pinocchio  3.3.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
joint-revolute-unbounded.hpp
1 //
2 // Copyright (c) 2016-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_joint_revolute_unbounded_hpp__
6 #define __pinocchio_multibody_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>
19 
20  template<typename _Scalar, int _Options, int axis>
21  struct traits<JointRevoluteUnboundedTpl<_Scalar, _Options, axis>>
22  {
23  enum
24  {
25  NQ = 2,
26  NV = 1
27  };
28  typedef _Scalar Scalar;
29  enum
30  {
31  Options = _Options
32  };
39 
40  // [ABA]
41  typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
42  typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
43  typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
44 
45  typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
46  typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
47 
48  PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
49  };
50 
51  template<typename _Scalar, int _Options, int axis>
52  struct traits<JointDataRevoluteUnboundedTpl<_Scalar, _Options, axis>>
53  {
55  typedef _Scalar Scalar;
56  };
57 
58  template<typename _Scalar, int _Options, int axis>
59  struct traits<JointModelRevoluteUnboundedTpl<_Scalar, _Options, axis>>
60  {
62  typedef _Scalar Scalar;
63  };
64 
65  template<typename _Scalar, int _Options, int axis>
67  : public JointDataBase<JointDataRevoluteUnboundedTpl<_Scalar, _Options, axis>>
68  {
69  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
71  PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
72  PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
73 
74  ConfigVector_t joint_q;
75  TangentVector_t joint_v;
76 
77  Constraint_t S;
78  Transformation_t M;
79  Motion_t v;
80  Bias_t c;
81 
82  // [ABA] specific data
83  U_t U;
84  D_t Dinv;
85  UD_t UDinv;
86  D_t StU;
87 
89  : joint_q(Scalar(1), Scalar(0))
90  , joint_v(TangentVector_t::Zero())
91  , M((Scalar)0, (Scalar)1)
92  , v((Scalar)0)
93  , U(U_t::Zero())
94  , Dinv(D_t::Zero())
95  , UDinv(UD_t::Zero())
96  , StU(D_t::Zero())
97  {
98  }
99 
100  static std::string classname()
101  {
102  return std::string("JointDataRUB") + axisLabel<axis>();
103  }
104  std::string shortname() const
105  {
106  return classname();
107  }
108 
109  }; // struct JointDataRevoluteUnbounded
110 
111  template<typename NewScalar, typename Scalar, int Options, int axis>
112  struct CastType<NewScalar, JointModelRevoluteUnboundedTpl<Scalar, Options, axis>>
113  {
115  };
116 
117  template<typename _Scalar, int _Options, int axis>
119  : public JointModelBase<JointModelRevoluteUnboundedTpl<_Scalar, _Options, axis>>
120  {
121  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
123  PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
125 
127  using Base::id;
128  using Base::idx_q;
129  using Base::idx_v;
130  using Base::setIndexes;
131 
132  typedef Eigen::Matrix<Scalar, 3, 1, _Options> Vector3;
133 
134  JointDataDerived createData() const
135  {
136  return JointDataDerived();
137  }
138 
139  const std::vector<bool> hasConfigurationLimit() const
140  {
141  return {false, false};
142  }
143 
144  const std::vector<bool> hasConfigurationLimitInTangent() const
145  {
146  return {false};
147  }
148 
149  template<typename ConfigVector>
150  void calc(JointDataDerived & data, const typename Eigen::MatrixBase<ConfigVector> & qs) const
151  {
152  data.joint_q = qs.template segment<NQ>(idx_q());
153 
154  const Scalar & ca = data.joint_q[0];
155  const Scalar & sa = data.joint_q[1];
156 
157  data.M.setValues(sa, ca);
158  }
159 
160  template<typename TangentVector>
161  void
162  calc(JointDataDerived & data, const Blank, const typename Eigen::MatrixBase<TangentVector> & vs)
163  const
164  {
165  data.joint_v[0] = vs[idx_v()];
166  data.v.angularRate() = data.joint_v[0];
167  }
168 
169  template<typename ConfigVector, typename TangentVector>
170  void calc(
171  JointDataDerived & data,
172  const typename Eigen::MatrixBase<ConfigVector> & qs,
173  const typename Eigen::MatrixBase<TangentVector> & vs) const
174  {
175  calc(data, qs.derived());
176  data.joint_v[0] = vs[idx_v()];
177  data.v.angularRate() = data.joint_v[0];
178  }
179 
180  template<typename VectorLike, typename Matrix6Like>
181  void calc_aba(
182  JointDataDerived & data,
183  const Eigen::MatrixBase<VectorLike> & armature,
184  const Eigen::MatrixBase<Matrix6Like> & I,
185  const bool update_I) const
186  {
187  data.U = I.col(Inertia::ANGULAR + axis);
188  data.Dinv[0] =
189  (Scalar)(1) / (I(Inertia::ANGULAR + axis, Inertia::ANGULAR + axis) + armature[0]);
190  data.UDinv.noalias() = data.U * data.Dinv[0];
191 
192  if (update_I)
193  PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
194  }
195 
196  static std::string classname()
197  {
198  return std::string("JointModelRUB") + axisLabel<axis>();
199  }
200  std::string shortname() const
201  {
202  return classname();
203  }
204 
205  Vector3 getMotionAxis() const
206  {
207  switch (axis)
208  {
209  case 0:
210  return Vector3::UnitX();
211  case 1:
212  return Vector3::UnitY();
213  case 2:
214  return Vector3::UnitZ();
215  default:
216  assert(false && "must never happen");
217  break;
218  }
219  }
220 
222  template<typename NewScalar>
224  {
226  ReturnType res;
227  res.setIndexes(id(), idx_q(), idx_v());
228  return res;
229  }
230 
231  }; // struct JointModelRevoluteUnboundedTpl
232 
234  {
235  template<typename ConfigVectorIn, typename Scalar, typename ConfigVectorOut>
236  static void run(
237  const Eigen::MatrixBase<ConfigVectorIn> & q,
238  const Scalar & scaling,
239  const Scalar & offset,
240  const Eigen::MatrixBase<ConfigVectorOut> & dest)
241  {
242  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(ConfigVectorIn, 2);
243  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(ConfigVectorOut, 2);
244 
245  const typename ConfigVectorIn::Scalar & ca = q(0);
246  const typename ConfigVectorIn::Scalar & sa = q(1);
247 
248  const typename ConfigVectorIn::Scalar & theta = math::atan2(sa, ca);
249  const typename ConfigVectorIn::Scalar & theta_transform = scaling * theta + offset;
250 
251  ConfigVectorOut & dest_ = PINOCCHIO_EIGEN_CONST_CAST(ConfigVectorOut, dest);
252  SINCOS(theta_transform, &dest_.coeffRef(1), &dest_.coeffRef(0));
253  }
254  };
255 
256  template<typename Scalar, int Options, int axis>
258  {
260  };
261 
265 
269 
273 
274 } // namespace pinocchio
275 
276 #include <boost/type_traits.hpp>
277 
278 namespace boost
279 {
280  template<typename Scalar, int Options, int axis>
281  struct has_nothrow_constructor<::pinocchio::JointModelRevoluteUnboundedTpl<Scalar, Options, axis>>
282  : public integral_constant<bool, true>
283  {
284  };
285 
286  template<typename Scalar, int Options, int axis>
287  struct has_nothrow_copy<::pinocchio::JointModelRevoluteUnboundedTpl<Scalar, Options, axis>>
288  : public integral_constant<bool, true>
289  {
290  };
291 
292  template<typename Scalar, int Options, int axis>
293  struct has_nothrow_constructor<::pinocchio::JointDataRevoluteUnboundedTpl<Scalar, Options, axis>>
294  : public integral_constant<bool, true>
295  {
296  };
297 
298  template<typename Scalar, int Options, int axis>
299  struct has_nothrow_copy<::pinocchio::JointDataRevoluteUnboundedTpl<Scalar, Options, axis>>
300  : public integral_constant<bool, true>
301  {
302  };
303 } // namespace boost
304 
305 #endif // ifndef __pinocchio_multibody_joint_revolute_unbounded_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
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.
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.
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:27
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
Assign the correct configuration vector space affine transformation according to the joint type.
JointModelRevoluteUnboundedTpl< NewScalar, Options, axis > cast() const
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:72