19 #ifndef __se3_joint_spherical_ZYX_hpp__ 20 #define __se3_joint_spherical_ZYX_hpp__ 22 #include "pinocchio/macros.hpp" 23 #include "pinocchio/multibody/joint/joint-base.hpp" 24 #include "pinocchio/multibody/constraint.hpp" 25 #include "pinocchio/math/sincos.hpp" 26 #include "pinocchio/spatial/inertia.hpp" 27 #include "pinocchio/spatial/skew.hpp" 34 template<
typename _Scalar,
int _Options>
37 typedef _Scalar Scalar;
38 enum { Options = _Options };
39 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
40 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
41 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
42 typedef typename EIGEN_REF_CONSTTYPE(Vector6) ToVectorConstReturnType;
43 typedef typename EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
44 typedef Matrix6 ActionMatrixType;
45 typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
46 typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
47 typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
48 typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
56 template <
typename _Scalar,
int _Options>
64 {
return MotionPlain(MotionPlain::Vector3::Zero(),c_J); }
66 Vector3 & operator() () {
return c_J; }
67 const Vector3 & operator() ()
const {
return c_J; }
71 {
return other.linear().isZero() && other.angular() == c_J; }
75 { other.angular() += c_J; }
80 template<
typename MotionDerived,
typename S2,
int O2>
81 inline typename MotionDerived::MotionPlain
83 {
return typename MotionDerived::MotionPlain(v.linear(), v.angular() + c()); }
85 template<
typename S1,
int O1,
typename MotionDerived>
86 inline typename MotionDerived::MotionPlain
88 {
return typename MotionDerived::MotionPlain(v.linear(), v.angular() + c()); }
92 template<
typename Scalar,
int Options>
94 :
traits< BiasSphericalZYXTpl<Scalar,Options> >
97 template<
typename _Scalar,
int _Options>
104 template<
typename Vector3Like>
108 Vector3 & operator() () {
return w; }
109 const Vector3 & operator() ()
const {
return w; }
111 operator MotionPlain()
const 112 {
return MotionPlain(MotionPlain::Vector3::Zero(),w); }
114 operator Vector3()
const {
return w; }
116 template<
typename Derived>
125 template <
typename S1,
int O1,
typename S2,
int O2>
131 template <
typename S1,
int O1,
typename MotionDerived>
132 typename MotionDerived::MotionPlain
136 typedef typename MotionDerived::MotionPlain ReturnType;
137 return ReturnType(m2.linear(),m2.angular()+ m1.w);
142 template <
typename _Scalar,
int _Options>
145 typedef _Scalar Scalar;
146 enum { Options = _Options };
147 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
148 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
149 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
150 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
151 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
152 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
153 typedef Matrix3 Angular_t;
154 typedef Vector3 Linear_t;
155 typedef const Matrix3 ConstAngular_t;
156 typedef const Vector3 ConstLinear_t;
157 typedef Matrix6 ActionMatrix_t;
158 typedef Eigen::Quaternion<Scalar,Options> Quaternion_t;
167 typedef Eigen::Matrix<Scalar,3,1,Options> JointMotion;
168 typedef Eigen::Matrix<Scalar,3,1,Options> JointForce;
169 typedef Eigen::Matrix<Scalar,6,3,Options> DenseBase;
170 typedef DenseBase MatrixReturnType;
171 typedef const DenseBase ConstMatrixReturnType;
174 template<
typename _Scalar,
int _Options>
178 enum { NV = 3, Options = _Options };
185 : S_minimal(Matrix3::Constant(NAN))
188 template<
typename Matrix3Like>
190 : S_minimal(subspace)
191 { EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3Like,3,3); }
193 template<
typename S1,
int O1>
195 {
return Motion(Motion::Vector3::Zero(),
199 template<
typename Vector3Like>
200 Motion operator*(
const Eigen::MatrixBase<Vector3Like> & v)
const 202 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3);
203 return Motion(Motion::Vector3::Zero(), S_minimal * v);
207 Matrix3 & operator() () {
return S_minimal; }
208 const Matrix3 & operator() ()
const {
return S_minimal; }
210 int nv_impl()
const {
return NV; }
217 template<
typename Derived>
218 #if EIGEN_VERSION_AT_LEAST(3,2,90) 219 const typename Eigen::Product<
220 Eigen::Transpose<const Matrix3>,
221 Eigen::Block<const typename ForceDense<Derived>::Vector6,3,1>
224 const typename Eigen::ProductReturnType<
225 Eigen::Transpose<const Matrix3>,
227 Eigen::Block<const typename ForceDense<Derived>::Vector6,3,1>
232 return ref.S_minimal.transpose() * phi.
angular();
237 #if EIGEN_VERSION_AT_LEAST(3,2,90) 238 const typename Eigen::Product<
239 typename Eigen::Transpose<const Matrix3>,
240 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type
243 const typename Eigen::ProductReturnType<
244 typename Eigen::Transpose<const Matrix3>,
245 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type
248 operator* (
const Eigen::MatrixBase<D> & F)
const 250 EIGEN_STATIC_ASSERT(D::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
251 return ref.S_minimal.transpose () * F.template middleRows<3>(ANGULAR);
257 DenseBase matrix_impl()
const 260 S.template middleRows<3>(LINEAR).setZero();
261 S.template middleRows<3>(ANGULAR) = S_minimal;
269 template<
typename S1,
int O1>
270 Eigen::Matrix<Scalar,6,3,Options>
279 Eigen::Matrix<Scalar,6,3,Options> result;
280 result.template middleRows<3>(ANGULAR).noalias() = m.rotation () * S_minimal;
281 for(
int k = 0; k < 3; ++k)
282 result.template middleRows<3>(LINEAR).col(k) =
283 m.translation().cross(result.template middleRows<3>(Motion::ANGULAR).col(k));
288 template<
typename MotionDerived>
291 const typename MotionDerived::ConstLinearType v = m.linear();
292 const typename MotionDerived::ConstAngularType w = m.angular();
295 cross(v,S_minimal,res.template middleRows<3>(LINEAR));
296 cross(w,S_minimal,res.template middleRows<3>(ANGULAR));
327 template<
typename MotionDerived,
typename S2,
int O2>
328 inline typename MotionDerived::MotionPlain
333 typedef typename MotionDerived::MotionPlain ReturnType;
334 return ReturnType(m1.linear().cross(m2.w), m1.angular().cross(m2.w));
338 template <
typename S1,
int O1,
typename S2,
int O2>
339 Eigen::Matrix<S1,6,3,O1>
345 Eigen::Matrix<S1,6,3,O1> M;
346 alphaSkew (-Y.mass(),Y.lever(),M.template middleRows<3>(Constraint::LINEAR));
347 M.template middleRows<3>(Constraint::ANGULAR) = (Y.inertia () -
348 typename Symmetric3::AlphaSkewSquare(Y.mass (), Y.lever ())).matrix();
350 return (M * S.S_minimal).eval();
355 template<
typename Matrix6Like,
typename S2,
int O2>
356 #if EIGEN_VERSION_AT_LEAST(3,2,90) 357 const typename Eigen::Product<
358 typename Eigen::internal::remove_const<typename SizeDepType<3>::ColsReturn<Matrix6Like>::ConstType>::type,
362 const typename Eigen::ProductReturnType<
363 typename Eigen::internal::remove_const<typename SizeDepType<3>::ColsReturn<Matrix6Like>::ConstType>::type,
367 operator*(
const Eigen::MatrixBase<Matrix6Like> & Y,
370 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix6Like,6,6);
371 return Y.derived().template middleCols<3>(Inertia::ANGULAR) * S.S_minimal;
376 template<
typename S1,
int O1>
377 struct SE3GroupAction< ConstraintSphericalZYXTpl<S1,O1> >
383 typedef Eigen::Matrix<S1,6,3,O1> ReturnType;
386 template<
typename S1,
int O1,
typename MotionDerived>
387 struct MotionAlgebraAction< ConstraintSphericalZYXTpl<S1,O1>, MotionDerived >
389 typedef Eigen::Matrix<S1,6,3,O1> ReturnType;
395 template<
typename _Scalar,
int _Options>
402 typedef _Scalar Scalar;
403 enum { Options = _Options };
410 typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
413 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
414 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
415 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
417 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
418 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
421 template<
typename Scalar,
int Options>
425 template<
typename Scalar,
int Options>
429 template<
typename _Scalar,
int _Options>
433 SE3_JOINT_TYPEDEF_TEMPLATE;
451 template<
typename _Scalar,
int _Options>
455 SE3_JOINT_TYPEDEF_TEMPLATE;
462 JointDataDerived
createData()
const {
return JointDataDerived(); }
464 template<
typename ConfigVector>
465 void calc(JointDataDerived & data,
466 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 468 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVector);
469 typename ConfigVector::template ConstFixedSegmentReturnType<NQ>::Type & q = qs.template segment<NQ>(
idx_q());
471 typedef typename ConfigVector::Scalar S2;
473 S2 c0,s0; SINCOS(q(0), &s0, &c0);
474 S2 c1,s1; SINCOS(q(1), &s1, &c1);
475 S2 c2,s2; SINCOS(q(2), &s2, &c2);
477 data.M.rotation () << c0 * c1,
478 c0 * s1 * s2 - s0 * c2,
479 c0 * s1 * c2 + s0 * s2,
481 s0 * s1 * s2 + c0 * c2,
482 s0 * s1 * c2 - c0 * s2,
488 << -s1, Scalar(0), Scalar(1),
489 c1 * s2, c2, Scalar(0),
490 c1 * c2, -s2, Scalar(0);
493 template<
typename ConfigVector,
typename TangentVector>
494 void calc(JointDataDerived & data,
495 const typename Eigen::MatrixBase<ConfigVector> & qs,
496 const typename Eigen::MatrixBase<TangentVector> & vs)
const 498 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVector);
499 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TangentVector_t,TangentVector);
500 typename ConfigVector::template ConstFixedSegmentReturnType<NQ>::Type & q = qs.template segment<NQ>(
idx_q());
502 typedef typename ConfigVector::Scalar S2;
504 S2 c0,s0; SINCOS(q(0), &s0, &c0);
505 S2 c1,s1; SINCOS(q(1), &s1, &c1);
506 S2 c2,s2; SINCOS(q(2), &s2, &c2);
508 data.M.rotation () << c0 * c1,
509 c0 * s1 * s2 - s0 * c2,
510 c0 * s1 * c2 + s0 * s2,
512 s0 * s1 * s2 + c0 * c2,
513 s0 * s1 * c2 - c0 * s2,
519 << -s1, Scalar(0), Scalar(1),
520 c1 * s2, c2, Scalar(0),
521 c1 * c2, -s2, Scalar(0);
523 typename TangentVector::template ConstFixedSegmentReturnType<NV>::Type & q_dot = vs.template segment<NV>(
idx_v());
525 data.v().noalias() = data.S.S_minimal * q_dot;
527 data.c()(0) = -c1 * q_dot(0) * q_dot(1);
528 data.c()(1) = -s1 * s2 * q_dot(0) * q_dot(1) + c1 * c2 * q_dot(0) * q_dot(2) - s2 * q_dot(1) * q_dot(2);
529 data.c()(2) = -s1 * c2 * q_dot(0) * q_dot(1) - c1 * s2 * q_dot(0) * q_dot(2) - c2 * q_dot(1) * q_dot(2);
532 template<
typename S2,
int O2>
533 void calc_aba(JointDataDerived & data, Eigen::Matrix<S2,6,6,O2> & I,
const bool update_I)
const 535 typedef Eigen::Matrix<S2,3,3,O2> Matrix3;
537 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) * data.S.S_minimal;
538 Matrix3 tmp(data.S.S_minimal.transpose() * data.U.template middleRows<3>(Motion::ANGULAR));
539 data.Dinv = tmp.inverse();
540 data.UDinv.noalias() = data.U * data.Dinv;
543 I -= data.UDinv * data.U.transpose();
549 return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
552 static std::string classname() {
return std::string(
"JointModelSphericalZYX"); }
553 std::string
shortname()
const {
return classname(); }
559 #endif // ifndef __se3_joint_spherical_ZYX_hpp__
JointDataVariant createData(const JointModelVariant &jmodel)
Visit a JointModelVariant through CreateData visitor to create a JointDataVariant.
void alphaSkew(const Scalar alpha, const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector multiplied by a given scalar. i.e. the antisymmetric matrix representation of the cross product operator ( )
ConstAngularType angular() const
Return the angular part of the force vector.
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...
void cross(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3xIn > &Min, const Eigen::MatrixBase< Matrix3xOut > &Mout)
Applies the cross product onto the columns of M.