5 #ifndef __pinocchio_multibody_joint_helical_unaligned_hpp__
6 #define __pinocchio_multibody_joint_helical_unaligned_hpp__
8 #include "pinocchio/fwd.hpp"
9 #include "pinocchio/multibody/joint/joint-base.hpp"
10 #include "pinocchio/multibody/joint-motion-subspace.hpp"
11 #include "pinocchio/spatial/inertia.hpp"
13 #include "pinocchio/math/matrix.hpp"
14 #include "pinocchio/math/rotation.hpp"
21 template<
typename Scalar,
int Options>
22 struct MotionHelicalUnalignedTpl;
24 template<
typename Scalar,
int Options>
30 template<
typename Scalar,
int Options,
typename MotionDerived>
36 template<
typename _Scalar,
int _Options>
39 typedef _Scalar Scalar;
44 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
45 typedef Eigen::Matrix<Scalar, 6, 1, Options> Vector6;
46 typedef Eigen::Matrix<Scalar, 4, 4, Options> Matrix4;
47 typedef Eigen::Matrix<Scalar, 6, 6, Options> Matrix6;
48 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
49 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
50 typedef Vector3 AngularType;
51 typedef Vector3 LinearType;
52 typedef const Vector3 ConstAngularType;
53 typedef const Vector3 ConstLinearType;
54 typedef Matrix6 ActionMatrixType;
57 typedef Matrix4 HomogeneousMatrixType;
65 template<
typename _Scalar,
int _Options>
68 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
76 template<
typename Vector3Like,
typename OtherScalar>
78 const Eigen::MatrixBase<Vector3Like> & axis,
const OtherScalar & w,
const OtherScalar & v)
85 inline PlainReturnType plain()
const
87 return PlainReturnType(m_axis * m_v, m_axis * m_w);
90 template<
typename OtherScalar>
96 template<
typename MotionDerived>
99 for (Eigen::DenseIndex k = 0; k < 3; ++k)
101 m.angular().noalias() = m_axis * m_w;
102 m.linear().noalias() = m_axis * m_v;
106 template<
typename MotionDerived>
109 v.angular() += m_axis * m_w;
110 v.linear() += m_axis * m_v;
113 template<
typename S2,
int O2,
typename D2>
116 v.angular().noalias() = m_w * m.rotation() * m_axis;
117 v.linear().noalias() = m.translation().cross(v.angular()) + m_v * m.rotation() * m_axis;
120 template<
typename S2,
int O2>
124 se3Action_impl(m, res);
128 template<
typename S2,
int O2,
typename D2>
132 v.angular().noalias() = m_axis.cross(m.translation());
134 v.linear().noalias() =
135 m.rotation().transpose() * v.angular() + m_v * (m.rotation().transpose() * m_axis);
138 v.angular().noalias() = m.rotation().transpose() * m_axis * m_w;
141 template<
typename S2,
int O2>
145 se3ActionInverse_impl(m, res);
149 template<
typename M1,
typename M2>
153 mout.linear().noalias() = v.linear().cross(m_axis);
154 mout.linear() *= m_w;
155 mout.angular().noalias() = v.angular().cross(m_axis);
156 mout.angular() *= m_v;
157 mout.linear() += mout.angular();
160 mout.angular().noalias() = v.angular().cross(m_axis);
161 mout.angular() *= m_w;
164 template<
typename M1>
168 motionAction(v, res);
172 Scalar & angularRate()
176 const Scalar & angularRate()
const
181 Scalar & linearRate()
185 const Scalar & linearRate()
const
194 const Vector3 & axis()
const
201 return internal::comparison_eq(m_axis, other.m_axis)
202 && internal::comparison_eq(m_w, other.m_w) && internal::comparison_eq(m_v, other.m_v);
211 template<
typename S1,
int O1,
typename MotionDerived>
212 typename MotionDerived::MotionPlain
215 typename MotionDerived::MotionPlain res(m2);
220 template<
typename MotionDerived,
typename S2,
int O2>
221 EIGEN_STRONG_INLINE
typename MotionDerived::MotionPlain
222 operator^(
const MotionDense<MotionDerived> & m1,
const MotionHelicalUnalignedTpl<S2, O2> & m2)
224 return m2.motionAction(m1);
227 template<
typename Scalar,
int Options>
228 struct JointMotionSubspaceHelicalUnalignedTpl;
230 template<
typename Scalar,
int Options>
233 typedef Eigen::Matrix<Scalar, 6, 1, Options> ReturnType;
236 template<
typename Scalar,
int Options,
typename MotionDerived>
239 typedef Eigen::Matrix<Scalar, 6, 1, Options> ReturnType;
242 template<
typename Scalar,
int Options,
typename ForceDerived>
245 typedef typename Eigen::Matrix<Scalar, 1, 1> ReturnType;
248 template<
typename Scalar,
int Options,
typename ForceSet>
251 typedef typename Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> ReturnType;
254 template<
typename _Scalar,
int _Options>
257 typedef _Scalar Scalar;
269 typedef Eigen::Matrix<Scalar, 1, 1, Options> JointForce;
270 typedef Eigen::Matrix<Scalar, 6, 1, Options> DenseBase;
271 typedef Eigen::Matrix<Scalar, 1, 1, Options> ReducedSquaredMatrix;
273 typedef DenseBase MatrixReturnType;
274 typedef const DenseBase ConstMatrixReturnType;
276 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
278 typedef typename ReducedSquaredMatrix::IdentityReturnType StDiagonalMatrixSOperationReturnType;
281 template<
typename _Scalar,
int _Options>
285 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
299 template<
typename Vector3Like>
301 const Eigen::MatrixBase<Vector3Like> & axis,
const Scalar & h)
307 template<
typename Vector1Like>
308 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const
310 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like, 1);
311 assert(v.size() == 1);
312 return JointMotion(m_axis, v[0], Scalar(v[0] * m_pitch));
315 template<
typename S1,
int O1>
316 typename SE3GroupAction<JointMotionSubspaceHelicalUnalignedTpl>::ReturnType
320 typename SE3GroupAction<JointMotionSubspaceHelicalUnalignedTpl>::ReturnType ReturnType;
322 res.template segment<3>(ANGULAR).noalias() = m.rotation() * m_axis;
323 res.template segment<3>(LINEAR).noalias() =
324 m.translation().cross(res.template segment<3>(ANGULAR)) + m_pitch * (m.rotation() * m_axis);
328 template<
typename S1,
int O1>
329 typename SE3GroupAction<JointMotionSubspaceHelicalUnalignedTpl>::ReturnType
333 typename SE3GroupAction<JointMotionSubspaceHelicalUnalignedTpl>::ReturnType ReturnType;
336 res.template segment<3>(ANGULAR).noalias() = m.rotation().transpose() * m_axis;
337 res.template segment<3>(LINEAR).noalias() =
338 -m.rotation().transpose() * m.translation().cross(m_axis)
339 + m.rotation().transpose() * m_axis * m_pitch;
357 template<
typename ForceDerived>
358 typename ConstraintForceOp<JointMotionSubspaceHelicalUnalignedTpl, ForceDerived>::ReturnType
364 res[0] = ref.axis().dot(f.
angular()) + ref.axis().dot(f.
linear()) * ref.m_pitch;
369 template<
typename Derived>
370 typename ConstraintForceSetOp<JointMotionSubspaceHelicalUnalignedTpl, Derived>::ReturnType
373 assert(F.rows() == 6);
375 ref.axis().transpose() * F.template middleRows<3>(ANGULAR)
376 + (ref.axis().transpose() * F.template middleRows<3>(LINEAR) * ref.m_pitch));
380 TransposeConst transpose()
const
382 return TransposeConst(*
this);
391 DenseBase matrix_impl()
const
394 S.template segment<3>(LINEAR) = m_axis * m_pitch;
395 S.template segment<3>(ANGULAR) = m_axis;
399 template<
typename MotionDerived>
400 typename MotionAlgebraAction<JointMotionSubspaceHelicalUnalignedTpl, MotionDerived>::ReturnType
401 motionAction(
const MotionDense<MotionDerived> & m)
const
403 const typename MotionDerived::ConstLinearType v = m.linear();
404 const typename MotionDerived::ConstAngularType w = m.angular();
407 res.template segment<3>(LINEAR).noalias() = v.cross(m_axis);
408 res.template segment<3>(ANGULAR).noalias() = w.cross(m_axis * m_pitch);
409 res.template segment<3>(LINEAR).noalias() += res.template segment<3>(ANGULAR);
410 res.template segment<3>(ANGULAR).noalias() = w.cross(m_axis);
415 bool isEqual(
const JointMotionSubspaceHelicalUnalignedTpl & other)
const
417 return internal::comparison_eq(m_axis, other.m_axis)
418 && internal::comparison_eq(m_pitch, other.m_pitch);
425 const Vector3 & axis()
const
434 const Scalar & h()
const
444 template<
typename _Scalar,
int _Options>
445 Eigen::Matrix<_Scalar, 1, 1, _Options> operator*(
446 const typename JointMotionSubspaceHelicalUnalignedTpl<_Scalar, _Options>::TransposeConst &
448 const JointMotionSubspaceHelicalUnalignedTpl<_Scalar, _Options> & S)
450 Eigen::Matrix<_Scalar, 1, 1, _Options> res;
451 res(0) = (S_transpose.ref.axis() * S_transpose.ref.h()).dot(S.axis() * S.h())
452 + (S_transpose.ref.axis().dot(S.axis()));
456 template<
typename S1,
int O1,
typename S2,
int O2>
459 typedef Eigen::Matrix<S2, 6, 1, O2> ReturnType;
465 template<
typename S1,
int O1,
typename S2,
int O2>
470 typedef typename JointMotionSubspaceHelicalUnalignedTpl<S2, O2>::Vector3 Vector3;
477 const S2 & m_pitch = cru.h();
478 const typename Inertia::Scalar & m = Y.mass();
479 const typename Inertia::Vector3 & c = Y.lever();
480 const typename Inertia::Symmetric3 & I = Y.inertia();
482 res.template segment<3>(Inertia::LINEAR) = -m * c.cross(cru.axis());
483 res.template segment<3>(Inertia::ANGULAR).noalias() = I * cru.axis();
484 res.template segment<3>(Inertia::ANGULAR) += c.cross(cru.axis()) * m * m_pitch;
485 res.template segment<3>(Inertia::ANGULAR) +=
486 c.cross(res.template segment<3>(Inertia::LINEAR));
487 res.template segment<3>(Inertia::LINEAR) += m * m_pitch * cru.axis();
493 template<
typename M6Like,
typename Scalar,
int Options>
495 Eigen::MatrixBase<M6Like>,
498 typedef const Eigen::Matrix<Scalar, 6, 1> ReturnType;
504 template<
typename M6Like,
typename Scalar,
int Options>
506 Eigen::MatrixBase<M6Like>,
510 typedef Eigen::Matrix<Scalar, 6, 1> ReturnType;
511 static inline ReturnType run(
const Eigen::MatrixBase<M6Like> & Y,
const Constraint & cru)
513 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like, 6, 6);
514 return Y.derived().template middleCols<3>(Constraint::ANGULAR) * cru.axis()
515 + Y.derived().template middleCols<3>(Constraint::LINEAR) * cru.axis() * cru.h();
520 template<
typename Scalar,
int Options>
523 template<
typename _Scalar,
int _Options>
531 typedef _Scalar Scalar;
544 typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
545 typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
546 typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
548 typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
549 typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
551 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
554 template<
typename _Scalar,
int _Options>
558 typedef _Scalar Scalar;
561 template<
typename _Scalar,
int _Options>
565 typedef _Scalar Scalar;
568 template<
typename _Scalar,
int _Options>
570 :
public JointDataBase<JointDataHelicalUnalignedTpl<_Scalar, _Options>>
572 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
575 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
577 ConfigVector_t joint_q;
578 TangentVector_t joint_v;
592 :
joint_q(ConfigVector_t::Zero())
593 ,
joint_v(TangentVector_t::Zero())
594 , S(Constraint_t::Vector3::Zero(), (Scalar)0)
595 , M(Transformation_t::Identity())
596 , v(Constraint_t::Vector3::Zero(), (Scalar)0, (Scalar)0)
599 , UDinv(UD_t::Zero())
604 template<
typename Vector3Like>
606 :
joint_q(ConfigVector_t::Zero())
607 ,
joint_v(TangentVector_t::Zero())
609 , M(Transformation_t::Identity())
610 , v(axis, (Scalar)0, (Scalar)0)
613 , UDinv(UD_t::Zero())
618 static std::string classname()
620 return std::string(
"JointDataHelicalUnaligned");
622 std::string shortname()
const
630 template<
typename _Scalar,
int _Options>
632 :
public JointModelBase<JointModelHelicalUnalignedTpl<_Scalar, _Options>>
634 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
637 typedef Eigen::Matrix<Scalar, 3, 1, _Options> Vector3;
643 using Base::setIndexes;
649 template<
typename Vector3Like>
654 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
655 assert(
isUnitary(axis) &&
"Rotation axis is not unitary");
659 const Scalar & x,
const Scalar & y,
const Scalar & z,
const Scalar & h)
664 assert(
isUnitary(axis) &&
"Rotation axis is not unitary");
667 template<
typename Vector3Like>
672 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
673 assert(
isUnitary(axis) &&
"Rotation axis is not unitary");
676 const std::vector<bool> hasConfigurationLimit()
const
681 const std::vector<bool> hasConfigurationLimitInTangent()
const
686 JointDataDerived createData()
const
688 return JointDataDerived();
694 return Base::isEqual(other) && internal::comparison_eq(axis, other.axis)
695 && internal::comparison_eq(m_pitch, other.m_pitch);
698 template<
typename ConfigVector>
699 void calc(JointDataDerived & data,
const typename Eigen::MatrixBase<ConfigVector> & qs)
const
701 data.joint_q[0] = qs[idx_q()];
704 data.M.translation() = axis * data.joint_q[0] * m_pitch;
705 data.S.h() = m_pitch;
706 data.S.axis() = axis;
709 template<
typename TangentVector>
711 calc(JointDataDerived & data,
const Blank,
const typename Eigen::MatrixBase<TangentVector> & vs)
714 data.v.angularRate() =
static_cast<Scalar
>(vs[idx_v()]);
715 data.v.axis() = axis;
716 data.v.linearRate() =
static_cast<Scalar
>(vs[idx_v()] * m_pitch);
719 template<
typename ConfigVector,
typename TangentVector>
721 JointDataDerived & data,
722 const typename Eigen::MatrixBase<ConfigVector> & qs,
723 const typename Eigen::MatrixBase<TangentVector> & vs)
const
725 calc(data, qs.derived());
726 data.v.angularRate() =
static_cast<Scalar
>(vs[idx_v()]);
727 data.v.axis() = axis;
728 data.v.linearRate() =
static_cast<Scalar
>(vs[idx_v()] * m_pitch);
731 template<
typename VectorLike,
typename Matrix6Like>
733 JointDataDerived & data,
734 const Eigen::MatrixBase<VectorLike> & armature,
735 const Eigen::MatrixBase<Matrix6Like> & I,
736 const bool update_I)
const
738 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) * axis
739 + m_pitch * I.template middleCols<3>(Motion::LINEAR) * axis;
740 data.StU[0] = axis.dot(data.U.template segment<3>(Motion::ANGULAR))
741 + m_pitch * axis.dot(data.U.template segment<3>(Motion::LINEAR)) + armature[0];
742 data.Dinv[0] = Scalar(1) / data.StU[0];
743 data.UDinv.noalias() = data.U * data.Dinv;
745 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
748 static std::string classname()
750 return std::string(
"JointModelHelicalUnaligned");
752 std::string shortname()
const
758 template<
typename NewScalar>
763 res.setIndexes(
id(), idx_q(), idx_v());
774 #include <boost/type_traits.hpp>
778 template<
typename Scalar,
int Options>
780 :
public integral_constant<bool, true>
784 template<
typename Scalar,
int Options>
786 :
public integral_constant<bool, true>
790 template<
typename Scalar,
int Options>
792 :
public integral_constant<bool, true>
796 template<
typename Scalar,
int Options>
798 :
public integral_constant<bool, true>
ConstAngularType angular() const
Return the angular part of the force vector.
ConstLinearType linear() const
Return the linear part of the force vector.
Main pinocchio namespace.
bool isUnitary(const Eigen::MatrixBase< MatrixLike > &mat, const typename MatrixLike::RealScalar &prec=Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
Check whether the input matrix is Unitary within the given precision.
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 normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
void toRotationMatrix(const Eigen::MatrixBase< Vector3 > &axis, const Scalar &cos_value, const Scalar &sin_value, const Eigen::MatrixBase< Matrix3 > &res)
Computes a rotation matrix from a vector and values of sin and cos orientations values.
Return type of the Constraint::Transpose * Force operation.
Return type of the Constraint::Transpose * ForceSet operation.
JointModelHelicalUnalignedTpl< NewScalar, Options > cast() const
ConstraintForceSetOp< JointMotionSubspaceHelicalUnalignedTpl, Derived >::ReturnType operator*(const Eigen::MatrixBase< Derived > &F) const
[CRBA] MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
Return type of the ation of a Motion onto an object of type D.
Forward declaration of the multiplication operation return type. Should be overloaded,...
Cast scalar type from type FROM to type TO.
Common traits structure to fully define base classes for CRTP.