6 #ifndef __pinocchio_multibody_joint_spherical_ZYX_hpp__
7 #define __pinocchio_multibody_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/joint-motion-subspace.hpp"
13 #include "pinocchio/math/sincos.hpp"
14 #include "pinocchio/math/matrix.hpp"
15 #include "pinocchio/spatial/inertia.hpp"
16 #include "pinocchio/spatial/skew.hpp"
20 template<
typename Scalar,
int Options>
21 struct JointMotionSubspaceSphericalZYXTpl;
23 template<
typename _Scalar,
int _Options>
26 typedef _Scalar Scalar;
39 typedef Eigen::Matrix<Scalar, 3, 1, Options> JointForce;
40 typedef Eigen::Matrix<Scalar, 6, 3, Options> DenseBase;
41 typedef Eigen::Matrix<Scalar, 3, 3, Options> ReducedSquaredMatrix;
43 typedef DenseBase MatrixReturnType;
44 typedef const DenseBase ConstMatrixReturnType;
46 typedef ReducedSquaredMatrix StDiagonalMatrixSOperationReturnType;
49 template<
typename _Scalar,
int _Options>
53 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
61 typedef Eigen::Matrix<Scalar, 3, 3, Options> Matrix3;
67 template<
typename Matrix3Like>
71 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3Like, 3, 3);
74 template<
typename Vector3Like>
75 JointMotion __mult__(
const Eigen::MatrixBase<Vector3Like> & v)
const
77 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like, 3);
78 return JointMotion(m_S * v);
81 Matrix3 & operator()()
85 const Matrix3 & operator()()
const
104 template<
typename Derived>
106 Eigen::Transpose<const Matrix3>,
107 Eigen::Block<const typename ForceDense<Derived>::Vector6, 3, 1>>::type
110 return ref.m_S.transpose() * phi.
angular();
116 typename Eigen::Transpose<const Matrix3>,
117 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type>::type
118 operator*(
const Eigen::MatrixBase<D> & F)
const
121 D::RowsAtCompileTime == 6, THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
122 return ref.m_S.transpose() * F.template middleRows<3>(ANGULAR);
131 DenseBase matrix_impl()
const
134 S.template middleRows<3>(LINEAR).setZero();
135 S.template middleRows<3>(ANGULAR) = m_S;
143 template<
typename S1,
int O1>
144 Eigen::Matrix<Scalar, 6, 3, Options> se3Action(
const SE3Tpl<S1, O1> & m)
const
152 Eigen::Matrix<Scalar, 6, 3, Options> result;
155 result.template middleRows<3>(ANGULAR).noalias() = m.rotation() * m_S;
159 m.translation(), result.template middleRows<3>(Motion::ANGULAR),
160 result.template middleRows<3>(LINEAR));
165 template<
typename S1,
int O1>
166 Eigen::Matrix<Scalar, 6, 3, Options> se3ActionInverse(
const SE3Tpl<S1, O1> & m)
const
168 Eigen::Matrix<Scalar, 6, 3, Options> result;
171 cross(m.translation(), m_S, result.template middleRows<3>(ANGULAR));
172 result.template middleRows<3>(LINEAR).noalias() =
173 -m.rotation().transpose() * result.template middleRows<3>(ANGULAR);
176 result.template middleRows<3>(ANGULAR).noalias() = m.rotation().transpose() * m_S;
181 template<
typename MotionDerived>
182 DenseBase motionAction(
const MotionDense<MotionDerived> & m)
const
184 const typename MotionDerived::ConstLinearType v = m.linear();
185 const typename MotionDerived::ConstAngularType w = m.angular();
188 cross(v, m_S, res.template middleRows<3>(LINEAR));
189 cross(w, m_S, res.template middleRows<3>(ANGULAR));
194 Matrix3 & angularSubspace()
198 const Matrix3 & angularSubspace()
const
203 bool isEqual(
const JointMotionSubspaceSphericalZYXTpl & other)
const
205 return internal::comparison_eq(m_S, other.m_S);
215 template<
typename Scalar,
int Options>
223 return constraint.matrix().transpose() * constraint.matrix();
229 template<
typename S1,
int O1,
typename S2,
int O2>
230 Eigen::Matrix<S1, 6, 3, O1>
235 Eigen::Matrix<S1, 6, 3, O1> M;
236 alphaSkew(-Y.mass(), Y.lever(), M.template middleRows<3>(Constraint::LINEAR));
237 M.template middleRows<3>(Constraint::ANGULAR) =
238 (Y.inertia() -
typename Symmetric3::AlphaSkewSquare(Y.mass(), Y.lever())).matrix();
240 return (M * S.angularSubspace()).eval();
245 template<
typename Matrix6Like,
typename S2,
int O2>
246 const typename MatrixMatrixProduct<
247 typename Eigen::internal::remove_const<
248 typename SizeDepType<3>::ColsReturn<Matrix6Like>::ConstType>::type,
249 typename JointMotionSubspaceSphericalZYXTpl<S2, O2>::Matrix3>::type
251 const Eigen::MatrixBase<Matrix6Like> & Y,
const JointMotionSubspaceSphericalZYXTpl<S2, O2> & S)
253 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix6Like, 6, 6);
254 return Y.derived().template middleCols<3>(Inertia::ANGULAR) * S.angularSubspace();
257 template<
typename S1,
int O1>
264 typedef Eigen::Matrix<S1, 6, 3, O1> ReturnType;
267 template<
typename S1,
int O1,
typename MotionDerived>
270 typedef Eigen::Matrix<S1, 6, 3, O1> ReturnType;
273 template<
typename Scalar,
int Options>
276 template<
typename _Scalar,
int _Options>
284 typedef _Scalar Scalar;
297 typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
298 typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
299 typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
301 typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
302 typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
304 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
307 template<
typename _Scalar,
int _Options>
311 typedef _Scalar Scalar;
314 template<
typename _Scalar,
int _Options>
318 typedef _Scalar Scalar;
321 template<
typename _Scalar,
int _Options>
323 :
public JointDataBase<JointDataSphericalZYXTpl<_Scalar, _Options>>
325 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
328 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
330 ConfigVector_t joint_q;
331 TangentVector_t joint_v;
345 :
joint_q(ConfigVector_t::Zero())
346 ,
joint_v(TangentVector_t::Zero())
347 , S(Constraint_t::Matrix3::Zero())
348 , M(Transformation_t::Identity())
349 , v(Motion_t::Vector3::Zero())
350 , c(Bias_t::Vector3::Zero())
353 , UDinv(UD_t::Zero())
358 static std::string classname()
360 return std::string(
"JointDataSphericalZYX");
362 std::string shortname()
const
370 template<
typename _Scalar,
int _Options>
372 :
public JointModelBase<JointModelSphericalZYXTpl<_Scalar, _Options>>
374 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
382 using Base::setIndexes;
384 JointDataDerived createData()
const
386 return JointDataDerived();
389 const std::vector<bool> hasConfigurationLimit()
const
391 return {
true,
true,
true};
394 const std::vector<bool> hasConfigurationLimitInTangent()
const
396 return {
true,
true,
true};
399 template<
typename ConfigVector>
400 void calc(JointDataDerived & data,
const typename Eigen::MatrixBase<ConfigVector> & qs)
const
402 data.joint_q = qs.template segment<NQ>(idx_q());
405 SINCOS(data.joint_q(0), &s0, &c0);
407 SINCOS(data.joint_q(1), &s1, &c1);
409 SINCOS(data.joint_q(2), &s2, &c2);
411 data.M.rotation() << c0 * c1, c0 * s1 * s2 - s0 * c2, c0 * s1 * c2 + s0 * s2, s0 * c1,
412 s0 * s1 * s2 + c0 * c2, s0 * s1 * c2 - c0 * s2, -s1, c1 * s2, c1 * c2;
414 data.S.angularSubspace() << -s1, Scalar(0), Scalar(1), c1 * s2, c2, Scalar(0), c1 * c2, -s2,
418 template<
typename TangentVector>
420 calc(JointDataDerived & data,
const Blank,
const typename Eigen::MatrixBase<TangentVector> & vs)
423 data.joint_v = vs.template segment<NV>(idx_v());
424 data.v().noalias() = data.S.angularSubspace() * data.joint_v;
435 template<
typename ConfigVector,
typename TangentVector>
437 JointDataDerived & data,
438 const typename Eigen::MatrixBase<ConfigVector> & qs,
439 const typename Eigen::MatrixBase<TangentVector> & vs)
const
441 data.joint_q = qs.template segment<NQ>(idx_q());
444 SINCOS(data.joint_q(0), &s0, &c0);
446 SINCOS(data.joint_q(1), &s1, &c1);
448 SINCOS(data.joint_q(2), &s2, &c2);
450 data.M.rotation() << c0 * c1, c0 * s1 * s2 - s0 * c2, c0 * s1 * c2 + s0 * s2, s0 * c1,
451 s0 * s1 * s2 + c0 * c2, s0 * s1 * c2 - c0 * s2, -s1, c1 * s2, c1 * c2;
453 data.S.angularSubspace() << -s1, Scalar(0), Scalar(1), c1 * s2, c2, Scalar(0), c1 * c2, -s2,
456 data.joint_v = vs.template segment<NV>(idx_v());
457 data.v().noalias() = data.S.angularSubspace() * data.joint_v;
459 #define q_dot data.joint_v
460 data.c()(0) = -c1 * q_dot(0) * q_dot(1);
462 -s1 * s2 * q_dot(0) * q_dot(1) + c1 * c2 * q_dot(0) * q_dot(2) - s2 * q_dot(1) * q_dot(2);
464 -s1 * c2 * q_dot(0) * q_dot(1) - c1 * s2 * q_dot(0) * q_dot(2) - c2 * q_dot(1) * q_dot(2);
468 template<
typename VectorLike,
typename Matrix6Like>
470 JointDataDerived & data,
471 const Eigen::MatrixBase<VectorLike> & armature,
472 const Eigen::MatrixBase<Matrix6Like> & I,
473 const bool update_I)
const
475 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) * data.S.angularSubspace();
477 data.S.angularSubspace().transpose() * data.U.template middleRows<3>(Motion::ANGULAR);
478 data.StU.diagonal() += armature;
480 internal::PerformStYSInversion<Scalar>::run(data.StU, data.Dinv);
482 data.UDinv.noalias() = data.U * data.Dinv;
485 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
488 static std::string classname()
490 return std::string(
"JointModelSphericalZYX");
492 std::string shortname()
const
498 template<
typename NewScalar>
503 res.setIndexes(
id(), idx_q(), idx_v());
511 #include <boost/type_traits.hpp>
515 template<
typename Scalar,
int Options>
517 :
public integral_constant<bool, true>
521 template<
typename Scalar,
int Options>
523 :
public integral_constant<bool, true>
527 template<
typename Scalar,
int Options>
529 :
public integral_constant<bool, true>
533 template<
typename Scalar,
int Options>
535 :
public integral_constant<bool, true>
ConstAngularType angular() const
Return the angular part of the force vector.
Main pinocchio namespace.
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.
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....
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.
JointModelSphericalZYXTpl< NewScalar, Options > cast() const
Return type of the ation of a Motion onto an object of type D.
Common traits structure to fully define base classes for CRTP.