6 #ifndef __pinocchio_joint_spherical_ZYX_hpp__ 7 #define __pinocchio_joint_spherical_ZYX_hpp__ 9 #include "pinocchio/macros.hpp" 10 #include "pinocchio/multibody/joint/joint-base.hpp" 11 #include "pinocchio/multibody/joint/joint-spherical.hpp" 12 #include "pinocchio/multibody/constraint.hpp" 13 #include "pinocchio/math/sincos.hpp" 14 #include "pinocchio/spatial/inertia.hpp" 15 #include "pinocchio/spatial/skew.hpp" 21 template <
typename _Scalar,
int _Options>
24 typedef _Scalar Scalar;
25 enum { Options = _Options };
26 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
27 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
28 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
29 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
30 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
31 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
32 typedef Matrix3 Angular_t;
33 typedef Vector3 Linear_t;
34 typedef const Matrix3 ConstAngular_t;
35 typedef const Vector3 ConstLinear_t;
36 typedef Matrix6 ActionMatrix_t;
37 typedef Eigen::Quaternion<Scalar,Options> Quaternion_t;
47 typedef Eigen::Matrix<Scalar,3,1,Options> JointForce;
48 typedef Eigen::Matrix<Scalar,6,3,Options> DenseBase;
50 typedef DenseBase MatrixReturnType;
51 typedef const DenseBase ConstMatrixReturnType;
54 template<
typename _Scalar,
int _Options>
57 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
61 enum { NV = 3, Options = _Options };
68 template<
typename Matrix3Like>
71 { EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3Like,3,3); }
73 template<
typename Vector3Like>
74 JointMotion __mult__(
const Eigen::MatrixBase<Vector3Like> & v)
const 76 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3);
77 return JointMotion(S_minimal * v);
80 Matrix3 & operator() () {
return S_minimal; }
81 const Matrix3 & operator() ()
const {
return S_minimal; }
83 int nv_impl()
const {
return NV; }
90 template<
typename Derived>
91 #if EIGEN_VERSION_AT_LEAST(3,2,90) 92 const typename Eigen::Product<
93 Eigen::Transpose<const Matrix3>,
94 Eigen::Block<const typename ForceDense<Derived>::Vector6,3,1>
97 const typename Eigen::ProductReturnType<
98 Eigen::Transpose<const Matrix3>,
100 Eigen::Block<const typename ForceDense<Derived>::Vector6,3,1>
105 return ref.S_minimal.transpose() * phi.
angular();
110 #if EIGEN_VERSION_AT_LEAST(3,2,90) 111 const typename Eigen::Product<
112 typename Eigen::Transpose<const Matrix3>,
113 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type
116 const typename Eigen::ProductReturnType<
117 typename Eigen::Transpose<const Matrix3>,
118 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type
121 operator* (
const Eigen::MatrixBase<D> & F)
const 123 EIGEN_STATIC_ASSERT(D::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
124 return ref.S_minimal.transpose () * F.template middleRows<3>(ANGULAR);
130 DenseBase matrix_impl()
const 133 S.template middleRows<3>(LINEAR).setZero();
134 S.template middleRows<3>(ANGULAR) = S_minimal;
142 template<
typename S1,
int O1>
143 Eigen::Matrix<Scalar,6,3,Options>
152 Eigen::Matrix<Scalar,6,3,Options> result;
153 result.template middleRows<3>(ANGULAR).noalias() = m.rotation () * S_minimal;
154 for(
int k = 0; k < 3; ++k)
155 result.template middleRows<3>(LINEAR).col(k) =
156 m.translation().cross(result.template middleRows<3>(Motion::ANGULAR).col(k));
161 template<
typename MotionDerived>
164 const typename MotionDerived::ConstLinearType v = m.linear();
165 const typename MotionDerived::ConstAngularType w = m.angular();
168 cross(v,S_minimal,res.template middleRows<3>(LINEAR));
169 cross(w,S_minimal,res.template middleRows<3>(ANGULAR));
180 template <
typename S1,
int O1,
typename S2,
int O2>
181 Eigen::Matrix<S1,6,3,O1>
187 Eigen::Matrix<S1,6,3,O1> M;
188 alphaSkew (-Y.mass(),Y.lever(),M.template middleRows<3>(Constraint::LINEAR));
189 M.template middleRows<3>(Constraint::ANGULAR) = (Y.inertia () -
190 typename Symmetric3::AlphaSkewSquare(Y.mass (), Y.lever ())).matrix();
192 return (M * S.S_minimal).eval();
197 template<
typename Matrix6Like,
typename S2,
int O2>
198 #if EIGEN_VERSION_AT_LEAST(3,2,90) 199 const typename Eigen::Product<
200 typename Eigen::internal::remove_const<typename SizeDepType<3>::ColsReturn<Matrix6Like>::ConstType>::type,
204 const typename Eigen::ProductReturnType<
205 typename Eigen::internal::remove_const<typename SizeDepType<3>::ColsReturn<Matrix6Like>::ConstType>::type,
209 operator*(
const Eigen::MatrixBase<Matrix6Like> & Y,
212 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix6Like,6,6);
213 return Y.derived().template middleCols<3>(Inertia::ANGULAR) * S.S_minimal;
218 template<
typename S1,
int O1>
219 struct SE3GroupAction< ConstraintSphericalZYXTpl<S1,O1> >
225 typedef Eigen::Matrix<S1,6,3,O1> ReturnType;
228 template<
typename S1,
int O1,
typename MotionDerived>
229 struct MotionAlgebraAction< ConstraintSphericalZYXTpl<S1,O1>, MotionDerived >
231 typedef Eigen::Matrix<S1,6,3,O1> ReturnType;
237 template<
typename _Scalar,
int _Options>
244 typedef _Scalar Scalar;
245 enum { Options = _Options };
252 typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
255 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
256 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
257 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
259 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
261 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
262 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
265 template<
typename Scalar,
int Options>
269 template<
typename Scalar,
int Options>
273 template<
typename _Scalar,
int _Options>
276 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
278 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE;
279 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
296 static std::string classname() {
return std::string(
"JointDataSphericalZYX"); }
297 std::string
shortname()
const {
return classname(); }
302 template<
typename _Scalar,
int _Options>
304 :
public JointModelBase< JointModelSphericalZYXTpl<_Scalar,_Options> >
306 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
308 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE;
314 using Base::setIndexes;
316 JointDataDerived
createData()
const {
return JointDataDerived(); }
318 template<
typename ConfigVector>
319 void calc(JointDataDerived & data,
320 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 322 typename ConfigVector::template ConstFixedSegmentReturnType<NQ>::Type & q = qs.template segment<NQ>(
idx_q());
324 typedef typename ConfigVector::Scalar S2;
326 S2 c0,s0;
SINCOS(q(0), &s0, &c0);
327 S2 c1,s1;
SINCOS(q(1), &s1, &c1);
328 S2 c2,s2;
SINCOS(q(2), &s2, &c2);
330 data.M.rotation () << c0 * c1,
331 c0 * s1 * s2 - s0 * c2,
332 c0 * s1 * c2 + s0 * s2,
334 s0 * s1 * s2 + c0 * c2,
335 s0 * s1 * c2 - c0 * s2,
341 << -s1, Scalar(0), Scalar(1),
342 c1 * s2, c2, Scalar(0),
343 c1 * c2, -s2, Scalar(0);
346 template<
typename ConfigVector,
typename TangentVector>
347 void calc(JointDataDerived & data,
348 const typename Eigen::MatrixBase<ConfigVector> & qs,
349 const typename Eigen::MatrixBase<TangentVector> & vs)
const 351 typename ConfigVector::template ConstFixedSegmentReturnType<NQ>::Type & q = qs.template segment<NQ>(
idx_q());
353 typedef typename ConfigVector::Scalar S2;
355 S2 c0,s0;
SINCOS(q(0), &s0, &c0);
356 S2 c1,s1;
SINCOS(q(1), &s1, &c1);
357 S2 c2,s2;
SINCOS(q(2), &s2, &c2);
359 data.M.rotation () << c0 * c1,
360 c0 * s1 * s2 - s0 * c2,
361 c0 * s1 * c2 + s0 * s2,
363 s0 * s1 * s2 + c0 * c2,
364 s0 * s1 * c2 - c0 * s2,
370 << -s1, Scalar(0), Scalar(1),
371 c1 * s2, c2, Scalar(0),
372 c1 * c2, -s2, Scalar(0);
374 typename TangentVector::template ConstFixedSegmentReturnType<NV>::Type
375 & q_dot = vs.template segment<NV>(
idx_v());
377 data.v().noalias() = data.S.S_minimal * q_dot;
379 data.c()(0) = -c1 * q_dot(0) * q_dot(1);
380 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);
381 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);
384 template<
typename Matrix6Like>
385 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const 387 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) * data.S.S_minimal;
388 data.StU.noalias() = data.S.S_minimal.transpose() * data.U.template middleRows<3>(Motion::ANGULAR);
391 data.Dinv.setIdentity();
392 data.StU.llt().solveInPlace(data.Dinv);
394 data.UDinv.noalias() = data.U * data.Dinv;
397 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
403 return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
406 static std::string classname() {
return std::string(
"JointModelSphericalZYX"); }
407 std::string
shortname()
const {
return classname(); }
410 template<
typename NewScalar>
423 #include <boost/type_traits.hpp> 427 template<
typename Scalar,
int Options>
429 :
public integral_constant<bool,true> {};
431 template<
typename Scalar,
int Options>
433 :
public integral_constant<bool,true> {};
435 template<
typename Scalar,
int Options>
437 :
public integral_constant<bool,true> {};
439 template<
typename Scalar,
int Options>
441 :
public integral_constant<bool,true> {};
444 #endif // ifndef __pinocchio_joint_spherical_ZYX_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...
void SINCOS(const Scalar &a, Scalar *sa, Scalar *ca)
Computes sin/cos values of a given input scalar.
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
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.
ConstAngularType angular() const
Return the angular part of the force vector.
Main pinocchio namespace.
JointModelSphericalZYXTpl< NewScalar, Options > cast() const
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 ( )
Common traits structure to fully define base classes for CRTP.
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...