6 #ifndef __pinocchio_joint_revolute_hpp__ 7 #define __pinocchio_joint_revolute_hpp__ 9 #include "pinocchio/math/sincos.hpp" 10 #include "pinocchio/spatial/inertia.hpp" 11 #include "pinocchio/multibody/constraint.hpp" 12 #include "pinocchio/multibody/joint/joint-base.hpp" 13 #include "pinocchio/spatial/spatial-axis.hpp" 14 #include "pinocchio/utils/axis-label.hpp" 23 template<
typename Scalar,
int Options,
int axis>
29 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
30 struct MotionAlgebraAction<
MotionRevoluteTpl<Scalar,Options,axis>, MotionDerived>
36 template<
typename _Scalar,
int _Options,
int axis>
39 typedef _Scalar Scalar;
40 enum { Options = _Options };
41 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
42 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
43 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
44 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
45 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
46 typedef Vector3 AngularType;
47 typedef Vector3 LinearType;
48 typedef const Vector3 ConstAngularType;
49 typedef const Vector3 ConstLinearType;
50 typedef Matrix6 ActionMatrixType;
60 template<
typename _Scalar,
int _Options,
int _axis>
69 typedef _Scalar Scalar;
71 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
72 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
73 typedef Matrix3 AngularType;
74 typedef Matrix3 AngularRef;
75 typedef Matrix3 ConstAngularRef;
76 typedef typename Vector3::ConstantReturnType LinearType;
77 typedef typename Vector3::ConstantReturnType LinearRef;
78 typedef const typename Vector3::ConstantReturnType ConstLinearRef;
85 template<
typename Scalar,
int Options,
int axis>
86 struct SE3GroupAction< TransformRevoluteTpl<Scalar,Options,axis> >
90 template<
typename _Scalar,
int _Options,
int axis>
93 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
99 : m_sin(sin), m_cos(cos)
102 PlainType plain()
const 104 PlainType res(PlainType::Identity());
105 _setRotation (res.rotation());
109 operator PlainType()
const {
return plain(); }
111 template<
typename S2,
int O2>
121 res.rotation().col(0) = m.rotation().col(0);
122 res.rotation().col(1).noalias() = m_cos * m.rotation().col(1) + m_sin * m.rotation().col(2);
123 res.rotation().col(2).noalias() = res.rotation().col(0).cross(res.rotation().col(1));
128 res.rotation().col(1) = m.rotation().col(1);
129 res.rotation().col(2).noalias() = m_cos * m.rotation().col(2) + m_sin * m.rotation().col(0);
130 res.rotation().col(0).noalias() = res.rotation().col(1).cross(res.rotation().col(2));
135 res.rotation().col(2) = m.rotation().col(2);
136 res.rotation().col(0).noalias() = m_cos * m.rotation().col(0) + m_sin * m.rotation().col(1);
137 res.rotation().col(1).noalias() = res.rotation().col(2).cross(res.rotation().col(0));
142 assert(
false &&
"must nerver happened");
146 res.translation() = m.translation();
150 const Scalar & sin()
const {
return m_sin; }
151 const Scalar & cos()
const {
return m_cos; }
153 template<
typename OtherScalar>
154 void setValues(
const OtherScalar & sin,
const OtherScalar & cos)
155 { m_sin = sin; m_cos = cos; }
157 LinearType translation()
const {
return LinearType::PlainObject::Zero(3); };
158 AngularType rotation()
const {
159 AngularType m(AngularType::Identity(3));
167 inline void _setRotation (
typename PlainType::AngularRef& rot)
const 173 rot.coeffRef(1,1) = m_cos; rot.coeffRef(1,2) = -m_sin;
174 rot.coeffRef(2,1) = m_sin; rot.coeffRef(2,2) = m_cos;
179 rot.coeffRef(0,0) = m_cos; rot.coeffRef(0,2) = m_sin;
180 rot.coeffRef(2,0) = -m_sin; rot.coeffRef(2,2) = m_cos;
185 rot.coeffRef(0,0) = m_cos; rot.coeffRef(0,1) = -m_sin;
186 rot.coeffRef(1,0) = m_sin; rot.coeffRef(1,1) = m_cos;
191 assert(
false &&
"must nerver happened");
198 template<
typename _Scalar,
int _Options,
int axis>
201 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
205 typedef typename Axis::CartesianAxis3 CartesianAxis3;
209 template<
typename OtherScalar>
214 template<
typename MotionDerived>
217 m.linear().setZero();
218 for(Eigen::DenseIndex k = 0; k < 3; ++k)
219 m.angular()[k] = k == axis ? w : (Scalar)0;
222 template<
typename MotionDerived>
226 v.angular()[axis] += (OtherScalar)w;
229 template<
typename S2,
int O2,
typename D2>
232 v.angular().noalias() = m.rotation().col(axis) * w;
233 v.linear().noalias() = m.translation().cross(v.angular());
236 template<
typename S2,
int O2>
240 se3Action_impl(m,res);
244 template<
typename S2,
int O2,
typename D2>
250 CartesianAxis3::alphaCross(w,m.translation(),v3_tmp);
251 v.linear().noalias() = m.rotation().transpose() * v3_tmp;
254 v.angular().noalias() = m.rotation().transpose().col(axis) * w;
257 template<
typename S2,
int O2>
258 MotionPlain se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m)
const 261 se3ActionInverse_impl(m,res);
265 template<
typename M1,
typename M2>
270 CartesianAxis3::alphaCross(-w,v.linear(),mout.linear());
273 CartesianAxis3::alphaCross(-w,v.angular(),mout.angular());
276 template<
typename M1>
288 template<
typename S1,
int O1,
int axis,
typename MotionDerived>
289 typename MotionDerived::MotionPlain
293 typename MotionDerived::MotionPlain res(m2);
298 template<
typename MotionDerived,
typename S2,
int O2,
int axis>
300 typename MotionDerived::MotionPlain
303 return m2.motionAction(m1);
310 template<
typename Scalar,
int Options,
int axis>
312 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
314 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
316 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
319 template<
typename _Scalar,
int _Options,
int axis>
322 typedef _Scalar Scalar;
323 enum { Options = _Options };
324 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
325 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
326 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
327 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
328 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
329 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
330 typedef Matrix3 Angular_t;
331 typedef Vector3 Linear_t;
332 typedef const Matrix3 ConstAngular_t;
333 typedef const Vector3 ConstLinear_t;
334 typedef Matrix6 ActionMatrix_t;
335 typedef Eigen::Quaternion<Scalar,0> Quaternion_t;
345 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
346 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
347 typedef DenseBase MatrixReturnType;
348 typedef const DenseBase ConstMatrixReturnType;
351 template<
typename _Scalar,
int _Options,
int axis>
355 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
358 enum { NV = 1, Options = _Options };
365 template<
typename Vector1Like>
366 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const 367 {
return JointMotion(v[0]); }
369 template<
typename S1,
int O1>
370 Eigen::Matrix<Scalar,6,1,Options>
373 Eigen::Matrix<Scalar,6,1,Options> res;
374 res.template head<3>() = m.translation().cross(m.rotation().col(axis));
375 res.template tail<3>() = m.rotation().col(axis);
379 int nv_impl()
const {
return NV; }
386 template<
typename Derived>
389 {
return f.
angular().template segment<1>(axis); }
393 typename Eigen::MatrixBase<D>::ConstRowXpr
397 return F.row(ANGULAR + axis);
409 DenseBase matrix_impl()
const 417 template<
typename MotionDerived>
427 template<
typename _Scalar,
int _Options,
int _axis>
430 typedef _Scalar Scalar;
440 template<
typename S1,
int O1,
typename S2,
int O2>
441 inline Eigen::Matrix<S2,6,1,O2>
451 const typename Inertia::Symmetric3 & I = Y.inertia();
453 Eigen::Matrix<S2,6,1,O2> res;
454 res << (S2)0,-m*z,m*y,
461 template<
typename S1,
int O1,
typename S2,
int O2>
462 inline Eigen::Matrix<S2,6,1,O2>
472 const typename Inertia::Symmetric3 & I = Y.inertia();
473 Eigen::Matrix<S2,6,1,O2> res;
474 res << m*z,(S2)0,-m*x,
481 template<
typename S1,
int O1,
typename S2,
int O2>
482 inline Eigen::Matrix<S2,6,1,O2>
492 const typename Inertia::Symmetric3 & I = Y.inertia();
493 Eigen::Matrix<S2,6,1,O2> res; res << -m*y,m*x,(S2)0,
501 template<
typename M6Like,
typename S2,
int O2,
int axis>
502 inline const typename M6Like::ConstColXpr
505 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
506 return Y.col(Inertia::ANGULAR + axis);
509 template<
typename _Scalar,
int _Options,
int axis>
516 typedef _Scalar Scalar;
517 enum { Options = _Options };
524 typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
527 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
528 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
529 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
531 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
533 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
534 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
537 template<
typename Scalar,
int Options,
int axis>
541 template<
typename Scalar,
int Options,
int axis>
545 template<
typename _Scalar,
int _Options,
int axis>
548 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
550 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE;
551 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
566 static std::string classname() {
return std::string(
"JointDataRevolute"); }
567 std::string
shortname()
const {
return classname(); }
571 template<
typename NewScalar,
typename Scalar,
int Options,
int axis>
577 template<
typename _Scalar,
int _Options,
int axis>
580 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
582 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE;
588 using Base::setIndexes;
590 JointDataDerived
createData()
const {
return JointDataDerived(); }
592 template<
typename ConfigVector>
594 void calc(JointDataDerived & data,
595 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 597 typedef typename ConfigVector::Scalar OtherScalar;
599 const OtherScalar & q = qs[
idx_q()];
600 OtherScalar ca,sa;
SINCOS(q,&sa,&ca);
601 data.M.setValues(sa,ca);
604 template<
typename ConfigVector,
typename TangentVector>
606 void calc(JointDataDerived & data,
607 const typename Eigen::MatrixBase<ConfigVector> & qs,
608 const typename Eigen::MatrixBase<TangentVector> & vs)
const 610 calc(data,qs.derived());
612 data.v.w = (Scalar)vs[
idx_v()];
615 template<
typename Matrix6Like>
616 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const 618 data.U = I.col(Inertia::ANGULAR + axis);
619 data.Dinv[0] = Scalar(1)/I(Inertia::ANGULAR + axis,Inertia::ANGULAR + axis);
620 data.UDinv.noalias() = data.U * data.Dinv[0];
623 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
629 return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
632 static std::string classname()
634 return std::string(
"JointModelR") + axisLabel<axis>();
636 std::string
shortname()
const {
return classname(); }
639 template<
typename NewScalar>
664 #include <boost/type_traits.hpp> 668 template<
typename Scalar,
int Options,
int axis>
670 :
public integral_constant<bool,true> {};
672 template<
typename Scalar,
int Options,
int axis>
674 :
public integral_constant<bool,true> {};
676 template<
typename Scalar,
int Options,
int axis>
678 :
public integral_constant<bool,true> {};
680 template<
typename Scalar,
int Options,
int axis>
682 :
public integral_constant<bool,true> {};
685 #endif // ifndef __pinocchio_joint_revolute_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...
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.
ModelTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType finiteDifferenceIncrement(const ModelTpl< Scalar, Options, JointCollectionTpl > &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...
JointModelRevoluteTpl< NewScalar, Options, axis > cast() const
void SINCOS(const Scalar &a, Scalar *sa, Scalar *ca)
Computes sin/cos values of a given input scalar.
Eigen::MatrixBase< D >::ConstRowXpr operator*(const Eigen::MatrixBase< D > &F) const
[CRBA] MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
ConstAngularType angular() const
Return the angular part of the force vector.
Main pinocchio namespace.
Common traits structure to fully define base classes for CRTP.
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type...
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...