6 #ifndef __pinocchio_multibody_joint_revolute_unaligned_hpp__
7 #define __pinocchio_multibody_joint_revolute_unaligned_hpp__
9 #include "pinocchio/fwd.hpp"
10 #include "pinocchio/multibody/joint/joint-base.hpp"
11 #include "pinocchio/multibody/joint-motion-subspace.hpp"
12 #include "pinocchio/spatial/inertia.hpp"
14 #include "pinocchio/math/matrix.hpp"
15 #include "pinocchio/math/rotation.hpp"
20 template<
typename Scalar,
int Options = context::Options>
21 struct MotionRevoluteUnalignedTpl;
22 typedef MotionRevoluteUnalignedTpl<context::Scalar> MotionRevoluteUnaligned;
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;
55 typedef Matrix4 HomogeneousMatrixType;
65 template<
typename _Scalar,
int _Options>
68 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
75 template<
typename Vector3Like,
typename OtherScalar>
82 inline PlainReturnType plain()
const
84 return PlainReturnType(PlainReturnType::Vector3::Zero(), m_axis * m_w);
87 template<
typename OtherScalar>
93 template<
typename MotionDerived>
96 v.angular() += m_axis * m_w;
99 template<
typename Derived>
102 other.linear().setZero();
103 other.angular().noalias() = m_axis * m_w;
106 template<
typename S2,
int O2,
typename D2>
110 v.angular().noalias() = m_w * m.rotation() * m_axis;
113 v.linear().noalias() = m.translation().cross(v.angular());
116 template<
typename S2,
int O2>
120 se3Action_impl(m, res);
124 template<
typename S2,
int O2,
typename D2>
130 v3_tmp.noalias() = m_axis.cross(m.translation());
132 v.linear().noalias() = m.rotation().transpose() * v3_tmp;
135 v.angular().noalias() = m.rotation().transpose() * m_axis;
139 template<
typename S2,
int O2>
143 se3ActionInverse_impl(m, res);
147 template<
typename M1,
typename M2>
151 mout.linear().noalias() = v.linear().cross(m_axis);
152 mout.linear() *= m_w;
155 mout.angular().noalias() = v.angular().cross(m_axis);
156 mout.angular() *= m_w;
159 template<
typename M1>
163 motionAction(v, res);
169 return internal::comparison_eq(m_axis, other.m_axis)
170 && internal::comparison_eq(m_w, other.m_w);
173 const Scalar & angularRate()
const
177 Scalar & angularRate()
182 const Vector3 & axis()
const
197 template<
typename S1,
int O1,
typename MotionDerived>
198 inline typename MotionDerived::MotionPlain
201 typename MotionDerived::MotionPlain res(m2);
206 template<
typename MotionDerived,
typename S2,
int O2>
207 inline typename MotionDerived::MotionPlain
208 operator^(
const MotionDense<MotionDerived> & m1,
const MotionRevoluteUnalignedTpl<S2, O2> & m2)
210 return m2.motionAction(m1);
213 template<
typename Scalar,
int Options>
214 struct JointMotionSubspaceRevoluteUnalignedTpl;
216 template<
typename _Scalar,
int _Options>
219 typedef _Scalar Scalar;
231 typedef Eigen::Matrix<Scalar, 1, 1, Options> JointForce;
232 typedef Eigen::Matrix<Scalar, 6, 1, Options> DenseBase;
233 typedef Eigen::Matrix<Scalar, 1, 1, Options> ReducedSquaredMatrix;
235 typedef DenseBase MatrixReturnType;
236 typedef const DenseBase ConstMatrixReturnType;
238 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
240 typedef typename ReducedSquaredMatrix::IdentityReturnType StDiagonalMatrixSOperationReturnType;
243 template<
typename Scalar,
int Options>
246 typedef Eigen::Matrix<Scalar, 6, 1, Options> ReturnType;
249 template<
typename Scalar,
int Options,
typename MotionDerived>
254 typedef Eigen::Matrix<Scalar, 6, 1, Options> ReturnType;
257 template<
typename Scalar,
int Options,
typename ForceDerived>
262 typedef Eigen::Matrix<
263 typename PINOCCHIO_EIGEN_DOT_PRODUCT_RETURN_TYPE(
271 template<
typename Scalar,
int Options,
typename ForceSet>
277 Eigen::Transpose<const Vector3>,
278 typename Eigen::MatrixBase<const ForceSet>::template NRowsBlockXpr<3>::Type>::type ReturnType;
281 template<
typename _Scalar,
int _Options>
285 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
299 template<
typename Vector3Like>
305 template<
typename Vector1Like>
306 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const
308 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like, 1);
309 return JointMotion(m_axis, v[0]);
312 template<
typename S1,
int O1>
313 typename SE3GroupAction<JointMotionSubspaceRevoluteUnalignedTpl>::ReturnType
317 typename SE3GroupAction<JointMotionSubspaceRevoluteUnalignedTpl>::ReturnType ReturnType;
321 res.template segment<3>(ANGULAR).noalias() = m.rotation() * m_axis;
322 res.template segment<3>(LINEAR).noalias() =
323 m.translation().cross(res.template segment<3>(ANGULAR));
327 template<
typename S1,
int O1>
328 typename SE3GroupAction<JointMotionSubspaceRevoluteUnalignedTpl>::ReturnType
332 typename SE3GroupAction<JointMotionSubspaceRevoluteUnalignedTpl>::ReturnType ReturnType;
335 res.template segment<3>(ANGULAR).noalias() = m.rotation().transpose() * m_axis;
336 res.template segment<3>(LINEAR).noalias() =
337 -m.rotation().transpose() * m.translation().cross(m_axis);
355 template<
typename ForceDerived>
356 typename ConstraintForceOp<JointMotionSubspaceRevoluteUnalignedTpl, ForceDerived>::ReturnType
362 res[0] = ref.axis().dot(f.
angular());
367 template<
typename ForceSet>
368 typename ConstraintForceSetOp<JointMotionSubspaceRevoluteUnalignedTpl, ForceSet>::ReturnType
369 operator*(
const Eigen::MatrixBase<ForceSet> & F)
372 ForceSet::RowsAtCompileTime == 6, THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
374 return ref.axis().transpose() * F.template middleRows<3>(ANGULAR);
389 DenseBase matrix_impl()
const
392 S.template segment<3>(LINEAR).setZero();
393 S.template segment<3>(ANGULAR) = m_axis;
397 template<
typename MotionDerived>
398 typename MotionAlgebraAction<JointMotionSubspaceRevoluteUnalignedTpl, MotionDerived>::ReturnType
399 motionAction(
const MotionDense<MotionDerived> & m)
const
401 const typename MotionDerived::ConstLinearType v = m.linear();
402 const typename MotionDerived::ConstAngularType w = m.angular();
405 res.template segment<3>(LINEAR).noalias() = v.cross(m_axis);
406 res.template segment<3>(ANGULAR).noalias() = w.cross(m_axis);
411 const Vector3 & axis()
const
420 bool isEqual(
const JointMotionSubspaceRevoluteUnalignedTpl & other)
const
422 return internal::comparison_eq(m_axis, other.m_axis);
430 template<
typename S1,
int O1,
typename S2,
int O2>
433 typedef Eigen::Matrix<S2, 6, 1, O2> ReturnType;
439 template<
typename S1,
int O1,
typename S2,
int O2>
450 const typename Inertia::Scalar & m = Y.mass();
451 const typename Inertia::Vector3 & c = Y.lever();
452 const typename Inertia::Symmetric3 & I = Y.inertia();
454 res.template segment<3>(Inertia::LINEAR) = -m * c.cross(cru.axis());
455 res.template segment<3>(Inertia::ANGULAR).noalias() = I * cru.axis();
456 res.template segment<3>(Inertia::ANGULAR) +=
457 c.cross(res.template segment<3>(Inertia::LINEAR));
464 template<
typename M6Like,
typename Scalar,
int Options>
466 Eigen::MatrixBase<M6Like>,
470 typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
473 typedef typename Constraint::Vector3 Vector3;
474 typedef const typename MatrixMatrixProduct<M6LikeColsNonConst, Vector3>::type ReturnType;
480 template<
typename M6Like,
typename Scalar,
int Options>
482 Eigen::MatrixBase<M6Like>,
489 static inline ReturnType run(
const Eigen::MatrixBase<M6Like> & Y,
const Constraint & cru)
491 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like, 6, 6);
492 return Y.derived().template middleCols<3>(Constraint::ANGULAR) * cru.axis();
497 template<
typename Scalar,
int Options>
500 template<
typename _Scalar,
int _Options>
508 typedef _Scalar Scalar;
521 typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
522 typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
523 typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
525 typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
526 typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
528 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
531 template<
typename _Scalar,
int _Options>
535 typedef _Scalar Scalar;
538 template<
typename _Scalar,
int _Options>
542 typedef _Scalar Scalar;
545 template<
typename _Scalar,
int _Options>
547 :
public JointDataBase<JointDataRevoluteUnalignedTpl<_Scalar, _Options>>
549 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
552 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
554 ConfigVector_t joint_q;
555 TangentVector_t joint_v;
569 :
joint_q(ConfigVector_t::Zero())
570 ,
joint_v(TangentVector_t::Zero())
571 , M(Transformation_t::Identity())
572 , S(Constraint_t::Vector3::Zero())
573 , v(Constraint_t::Vector3::Zero(), (Scalar)0)
576 , UDinv(UD_t::Zero())
581 template<
typename Vector3Like>
583 :
joint_q(ConfigVector_t::Zero())
584 ,
joint_v(TangentVector_t::Zero())
585 , M(Transformation_t::Identity())
587 , v(axis, (Scalar)NAN)
590 , UDinv(UD_t::Zero())
595 static std::string classname()
597 return std::string(
"JointDataRevoluteUnaligned");
599 std::string shortname()
const
607 template<
typename _Scalar,
int _Options>
609 :
public JointModelBase<JointModelRevoluteUnalignedTpl<_Scalar, _Options>>
611 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
614 typedef Eigen::Matrix<Scalar, 3, 1, _Options> Vector3;
620 using Base::setIndexes;
623 :
axis(Vector3::UnitX())
634 template<
typename Vector3Like>
638 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
642 JointDataDerived createData()
const
644 return JointDataDerived(
axis);
650 return Base::isEqual(other) && internal::comparison_eq(
axis, other.
axis);
653 const std::vector<bool> hasConfigurationLimit()
const
658 const std::vector<bool> hasConfigurationLimitInTangent()
const
663 template<
typename ConfigVector>
664 void calc(JointDataDerived & data,
const typename Eigen::MatrixBase<ConfigVector> & qs)
const
666 data.joint_q[0] = qs[idx_q()];
671 template<
typename TangentVector>
673 calc(JointDataDerived & data,
const Blank,
const typename Eigen::MatrixBase<TangentVector> & vs)
676 data.v.angularRate() =
static_cast<Scalar
>(vs[idx_v()]);
679 template<
typename ConfigVector,
typename TangentVector>
681 JointDataDerived & data,
682 const typename Eigen::MatrixBase<ConfigVector> & qs,
683 const typename Eigen::MatrixBase<TangentVector> & vs)
const
685 calc(data, qs.derived());
687 data.v.angularRate() =
static_cast<Scalar
>(vs[idx_v()]);
690 template<
typename VectorLike,
typename Matrix6Like>
692 JointDataDerived & data,
693 const Eigen::MatrixBase<VectorLike> & armature,
694 const Eigen::MatrixBase<Matrix6Like> & I,
695 const bool update_I)
const
697 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) *
axis;
699 Scalar(1) / (
axis.dot(data.U.template segment<3>(Motion::ANGULAR)) + armature[0]);
700 data.UDinv.noalias() = data.U * data.Dinv;
703 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
706 static std::string classname()
708 return std::string(
"JointModelRevoluteUnaligned");
710 std::string shortname()
const
716 template<
typename NewScalar>
720 ReturnType res(
axis.template cast<NewScalar>());
721 res.setIndexes(
id(), idx_q(), idx_v());
735 #include <boost/type_traits.hpp>
739 template<
typename Scalar,
int Options>
741 :
public integral_constant<bool, true>
745 template<
typename Scalar,
int Options>
747 :
public integral_constant<bool, true>
751 template<
typename Scalar,
int Options>
753 :
public integral_constant<bool, true>
757 template<
typename Scalar,
int Options>
759 :
public integral_constant<bool, true>
ConstAngularType angular() const
Return the angular 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.
Vector3 axis
3d main axis of the joint.
JointModelRevoluteUnalignedTpl< NewScalar, Options > cast() const
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,...
Common traits structure to fully define base classes for CRTP.