pinocchio  UNKNOWN
joint-revolute-unbounded.hpp
1 //
2 // Copyright (c) 2016-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_joint_revolute_unbounded_hpp__
19 #define __se3_joint_revolute_unbounded_hpp__
20 
21 #include "pinocchio/math/fwd.hpp"
22 #include "pinocchio/math/sincos.hpp"
23 #include "pinocchio/spatial/inertia.hpp"
24 #include "pinocchio/multibody/joint/joint-base.hpp"
25 #include "pinocchio/multibody/joint/joint-revolute.hpp"
26 
27 namespace se3
28 {
29 
30  template<typename Scalar, int Options, int axis> struct JointRevoluteUnboundedTpl;
31 
32  template<typename _Scalar, int _Options, int axis>
33  struct traits< JointRevoluteUnboundedTpl<_Scalar,_Options,axis> >
34  {
35  enum {
36  NQ = 2,
37  NV = 1
38  };
39  typedef _Scalar Scalar;
40  enum { Options = _Options };
44  typedef SE3 Transformation_t;
46  typedef BiasZero Bias_t;
47  typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
48 
49  // [ABA]
50  typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
51  typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
52  typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
53 
54  typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
55  typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
56  };
57 
58  template<typename Scalar, int Options, int axis>
59  struct traits< JointDataRevoluteUnboundedTpl<Scalar,Options,axis> >
61 
62  template<typename Scalar, int Options, int axis>
63  struct traits< JointModelRevoluteUnboundedTpl<Scalar,Options,axis> >
65 
66  template<typename _Scalar, int _Options, int axis>
67  struct JointDataRevoluteUnboundedTpl : public JointDataBase< JointDataRevoluteUnboundedTpl<_Scalar,_Options,axis> >
68  {
70  SE3_JOINT_TYPEDEF_TEMPLATE;
71 
72  Constraint_t S;
73  Transformation_t M;
74  Motion_t v;
75  Bias_t c;
76  F_t F;
77 
78  // [ABA] specific data
79  U_t U;
80  D_t Dinv;
81  UD_t UDinv;
82 
83  JointDataRevoluteUnboundedTpl() : M(1), U(), Dinv(), UDinv()
84  {}
85 
86  }; // struct JointDataRevoluteUnbounded
87 
88  template<typename _Scalar, int _Options, int axis>
89  struct JointModelRevoluteUnboundedTpl : public JointModelBase< JointModelRevoluteUnboundedTpl<_Scalar,_Options,axis> >
90  {
92  SE3_JOINT_TYPEDEF_TEMPLATE;
93  typedef JointRevoluteTpl<Scalar,_Options,axis> JointDerivedBase;
94 
95 
100 
101  JointDataDerived createData() const { return JointDataDerived(); }
102 
103  template<typename ConfigVector>
104  void calc(JointDataDerived & data,
105  const typename Eigen::MatrixBase<ConfigVector> & qs) const
106  {
107  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVector);
108  typedef typename ConfigVector::Scalar OtherScalar;
109  typename ConfigVector::template ConstFixedSegmentReturnType<NQ>::Type
110  & q = qs.template segment<NQ> (idx_q());
111 
112  const OtherScalar & ca = q(0);
113  const OtherScalar & sa = q(1);
114 
115  JointDerivedBase::cartesianRotation(ca,sa,data.M.rotation());
116  }
117 
118  template<typename ConfigVector, typename TangentVector>
119  void calc(JointDataDerived & data,
120  const typename Eigen::MatrixBase<ConfigVector> & qs,
121  const typename Eigen::MatrixBase<TangentVector> & vs) const
122  {
123  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TangentVector_t,TangentVector);
124  calc(data,qs.derived());
125 
126  data.v.w = (Scalar)vs[idx_v()];;
127  }
128 
129  template<typename S2, int O2>
130  void calc_aba(JointDataDerived & data, Eigen::Matrix<S2,6,6,O2> & I, const bool update_I) const
131  {
132  data.U = I.col(Inertia::ANGULAR + axis);
133  data.Dinv[0] = (Scalar)(1)/I(Inertia::ANGULAR + axis,Inertia::ANGULAR + axis);
134  data.UDinv.noalias() = data.U * data.Dinv[0];
135 
136  if (update_I)
137  I -= data.UDinv * data.U.transpose();
138  }
139 
140  Scalar finiteDifferenceIncrement() const
141  {
142  using std::sqrt;
143  return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
144  }
145 
146  static std::string classname()
147  {
148  return std::string("JointModelRUB") + axisLabel<axis>();
149  }
150  std::string shortname() const { return classname(); }
151 
152  }; // struct JointModelRevoluteUnboundedTpl
153 
157 
161 
165 
166 } //namespace se3
167 
168 #endif // ifndef __se3_joint_revolute_unbounded_hpp__
JointDataVariant createData(const JointModelVariant &jmodel)
Visit a JointModelVariant through CreateData visitor to create a JointDataVariant.
void calc_aba(const JointModelVariant &jmodel, JointDataVariant &jdata, Inertia::Matrix6 &I, const bool update_I)
Visit a JointDataVariant and the corresponding JointModelVariant through JointCalcAbaVisitor to...
std::string shortname(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointShortnameVisitor to get the shortname of the derived joint mod...
int idx_q(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxQVisitor to get the index in the full model configuration s...
Eigen::VectorXd finiteDifferenceIncrement(const Model &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...
int idx_v(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxVVisitor to get the index in the full model tangent space c...