6 #ifndef __pinocchio_multibody_joint_spherical_hpp__
7 #define __pinocchio_multibody_joint_spherical_hpp__
9 #include "pinocchio/macros.hpp"
10 #include "pinocchio/multibody/joint/joint-base.hpp"
11 #include "pinocchio/multibody/joint-motion-subspace.hpp"
12 #include "pinocchio/math/sincos.hpp"
13 #include "pinocchio/spatial/inertia.hpp"
14 #include "pinocchio/spatial/skew.hpp"
19 template<
typename Scalar,
int Options = context::Options>
20 struct MotionSphericalTpl;
21 typedef MotionSphericalTpl<context::Scalar> MotionSpherical;
23 template<
typename Scalar,
int Options>
29 template<
typename Scalar,
int Options,
typename MotionDerived>
35 template<
typename _Scalar,
int _Options>
38 typedef _Scalar Scalar;
43 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
44 typedef Eigen::Matrix<Scalar, 6, 1, Options> Vector6;
45 typedef Eigen::Matrix<Scalar, 4, 4, Options> Matrix4;
46 typedef Eigen::Matrix<Scalar, 6, 6, Options> Matrix6;
47 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
48 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
49 typedef Vector3 AngularType;
50 typedef Vector3 LinearType;
51 typedef const Vector3 ConstAngularType;
52 typedef const Vector3 ConstLinearType;
53 typedef Matrix6 ActionMatrixType;
54 typedef Matrix4 HomogeneousMatrixType;
64 template<
typename _Scalar,
int _Options>
67 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
75 template<
typename Vector3Like>
81 Vector3 & operator()()
85 const Vector3 & operator()()
const
90 inline PlainReturnType plain()
const
92 return PlainReturnType(PlainReturnType::Vector3::Zero(), m_w);
95 template<
typename MotionDerived>
98 other.angular() += m_w;
101 template<
typename Derived>
104 other.linear().setZero();
105 other.angular() = m_w;
115 return internal::comparison_eq(m_w, other.m_w);
118 template<
typename MotionDerived>
121 return internal::comparison_eq(other.angular(), m_w) && other.linear().isZero(0);
124 template<
typename S2,
int O2,
typename D2>
128 v.angular().noalias() = m.rotation() * m_w;
131 v.linear().noalias() = m.translation().cross(v.angular());
134 template<
typename S2,
int O2>
138 se3Action_impl(m, res);
142 template<
typename S2,
int O2,
typename D2>
148 v3_tmp.noalias() = m_w.cross(m.translation());
149 v.linear().noalias() = m.rotation().transpose() * v3_tmp;
152 v.angular().noalias() = m.rotation().transpose() * m_w;
155 template<
typename S2,
int O2>
159 se3ActionInverse_impl(m, res);
163 template<
typename M1,
typename M2>
167 mout.linear().noalias() = v.linear().cross(m_w);
170 mout.angular().noalias() = v.angular().cross(m_w);
173 template<
typename M1>
177 motionAction(v, res);
181 const Vector3 & angular()
const
194 template<
typename S1,
int O1,
typename MotionDerived>
195 inline typename MotionDerived::MotionPlain
198 return typename MotionDerived::MotionPlain(m2.linear(), m2.angular() + m1.angular());
201 template<
typename Scalar,
int Options>
202 struct JointMotionSubspaceSphericalTpl;
204 template<
typename _Scalar,
int _Options>
207 typedef _Scalar Scalar;
218 typedef Eigen::Matrix<Scalar, 3, 1, Options> JointForce;
219 typedef Eigen::Matrix<Scalar, 6, 3, Options> DenseBase;
220 typedef Eigen::Matrix<Scalar, 3, 3, Options> ReducedSquaredMatrix;
222 typedef DenseBase MatrixReturnType;
223 typedef const DenseBase ConstMatrixReturnType;
225 typedef typename ReducedSquaredMatrix::IdentityReturnType StDiagonalMatrixSOperationReturnType;
228 template<
typename _Scalar,
int _Options>
232 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
250 template<
typename Vector3Like>
251 JointMotion __mult__(
const Eigen::MatrixBase<Vector3Like> & w)
const
253 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like, 3);
254 return JointMotion(w);
259 template<
typename Derived>
266 template<
typename MatrixDerived>
268 operator*(
const Eigen::MatrixBase<MatrixDerived> & F)
const
270 assert(F.rows() == 6);
271 return F.derived().template middleRows<3>(Inertia::ANGULAR);
280 DenseBase matrix_impl()
const
283 S.template block<3, 3>(LINEAR, 0).setZero();
284 S.template block<3, 3>(ANGULAR, 0).setIdentity();
288 template<
typename S1,
int O1>
289 Eigen::Matrix<S1, 6, 3, O1> se3Action(
const SE3Tpl<S1, O1> & m)
const
291 Eigen::Matrix<S1, 6, 3, O1> X_subspace;
292 cross(m.translation(), m.rotation(), X_subspace.template middleRows<3>(LINEAR));
293 X_subspace.template middleRows<3>(ANGULAR) = m.rotation();
298 template<
typename S1,
int O1>
299 Eigen::Matrix<S1, 6, 3, O1> se3ActionInverse(
const SE3Tpl<S1, O1> & m)
const
301 Eigen::Matrix<S1, 6, 3, O1> X_subspace;
302 XAxis::cross(m.translation(), X_subspace.template middleRows<3>(ANGULAR).col(0));
303 YAxis::cross(m.translation(), X_subspace.template middleRows<3>(ANGULAR).col(1));
304 ZAxis::cross(m.translation(), X_subspace.template middleRows<3>(ANGULAR).col(2));
306 X_subspace.template middleRows<3>(LINEAR).noalias() =
307 m.rotation().transpose() * X_subspace.template middleRows<3>(ANGULAR);
308 X_subspace.template middleRows<3>(ANGULAR) = m.rotation().transpose();
313 template<
typename MotionDerived>
314 DenseBase motionAction(
const MotionDense<MotionDerived> & m)
const
316 const typename MotionDerived::ConstLinearType v = m.linear();
317 const typename MotionDerived::ConstAngularType w = m.angular();
320 skew(v, res.template middleRows<3>(LINEAR));
321 skew(w, res.template middleRows<3>(ANGULAR));
326 bool isEqual(
const JointMotionSubspaceSphericalTpl &)
const
333 template<
typename MotionDerived,
typename S2,
int O2>
334 inline typename MotionDerived::MotionPlain
335 operator^(
const MotionDense<MotionDerived> & m1,
const MotionSphericalTpl<S2, O2> & m2)
337 return m2.motionAction(m1);
341 template<
typename S1,
int O1,
typename S2,
int O2>
342 inline Eigen::Matrix<S2, 6, 3, O2>
343 operator*(
const InertiaTpl<S1, O1> & Y,
const JointMotionSubspaceSphericalTpl<S2, O2> &)
345 typedef InertiaTpl<S1, O1> Inertia;
346 typedef typename Inertia::Symmetric3 Symmetric3;
347 Eigen::Matrix<S2, 6, 3, O2> M;
349 M.template block<3, 3>(Inertia::LINEAR, 0) =
alphaSkew(-Y.mass(), Y.lever());
350 M.template block<3, 3>(Inertia::ANGULAR, 0) =
351 (Y.inertia() -
typename Symmetric3::AlphaSkewSquare(Y.mass(), Y.lever())).matrix();
356 template<
typename M6Like,
typename S2,
int O2>
357 inline typename SizeDepType<3>::ColsReturn<M6Like>::ConstType
358 operator*(
const Eigen::MatrixBase<M6Like> & Y,
const JointMotionSubspaceSphericalTpl<S2, O2> &)
360 typedef JointMotionSubspaceSphericalTpl<S2, O2> Constraint;
361 return Y.derived().template middleCols<3>(Constraint::ANGULAR);
364 template<
typename S1,
int O1>
367 typedef Eigen::Matrix<S1, 6, 3, O1> ReturnType;
370 template<
typename S1,
int O1,
typename MotionDerived>
373 typedef Eigen::Matrix<S1, 6, 3, O1> ReturnType;
376 template<
typename Scalar,
int Options>
379 template<
typename _Scalar,
int _Options>
387 typedef _Scalar Scalar;
400 typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
401 typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
402 typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
404 typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
405 typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
407 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
410 template<
typename _Scalar,
int _Options>
414 typedef _Scalar Scalar;
417 template<
typename _Scalar,
int _Options>
421 typedef _Scalar Scalar;
424 template<
typename _Scalar,
int _Options>
427 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
431 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
433 ConfigVector_t joint_q;
434 TangentVector_t joint_v;
448 :
joint_q(Scalar(0), Scalar(0), Scalar(0), Scalar(1))
449 ,
joint_v(TangentVector_t::Zero())
450 , M(Transformation_t::Identity())
451 , v(Motion_t::Vector3::Zero())
454 , UDinv(UD_t::Zero())
459 static std::string classname()
461 return std::string(
"JointDataSpherical");
463 std::string shortname()
const
471 template<
typename _Scalar,
int _Options>
474 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
483 using Base::setIndexes;
485 JointDataDerived createData()
const
487 return JointDataDerived();
490 const std::vector<bool> hasConfigurationLimit()
const
492 return {
false,
false,
false,
false};
495 const std::vector<bool> hasConfigurationLimitInTangent()
const
497 return {
false,
false,
false};
500 template<
typename ConfigVectorLike>
501 inline void forwardKinematics(
502 Transformation_t & M,
const Eigen::MatrixBase<ConfigVectorLike> & q_joint)
const
504 typedef typename ConfigVectorLike::Scalar Scalar;
505 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t, ConfigVectorLike);
507 typename Eigen::Quaternion<Scalar, PINOCCHIO_EIGEN_PLAIN_TYPE(ConfigVectorLike)::Options>
509 typedef Eigen::Map<const Quaternion> ConstQuaternionMap;
511 ConstQuaternionMap quat(q_joint.derived().data());
514 assert(math::fabs(
static_cast<Scalar
>(quat.coeffs().squaredNorm() - 1)) <= 1e-4);
516 M.rotation(quat.matrix());
517 M.translation().setZero();
520 template<
typename QuaternionDerived>
522 JointDataDerived & data,
const typename Eigen::QuaternionBase<QuaternionDerived> & quat)
const
524 data.joint_q = quat.coeffs();
525 data.M.rotation(quat.matrix());
528 template<
typename ConfigVector>
529 EIGEN_DONT_INLINE
void
530 calc(JointDataDerived & data,
const typename Eigen::PlainObjectBase<ConfigVector> & qs)
const
532 typedef typename Eigen::Quaternion<typename ConfigVector::Scalar, ConfigVector::Options>
534 typedef Eigen::Map<const Quaternion> ConstQuaternionMap;
536 ConstQuaternionMap quat(qs.template segment<NQ>(idx_q()).data());
540 template<
typename ConfigVector>
541 EIGEN_DONT_INLINE
void
542 calc(JointDataDerived & data,
const typename Eigen::MatrixBase<ConfigVector> & qs)
const
544 typedef typename Eigen::Quaternion<Scalar, Options> Quaternion;
546 const Quaternion quat(qs.template segment<NQ>(idx_q()));
550 template<
typename TangentVector>
552 calc(JointDataDerived & data,
const Blank,
const typename Eigen::MatrixBase<TangentVector> & vs)
555 data.joint_v = vs.template segment<NV>(idx_v());
556 data.v.angular() = data.joint_v;
559 template<
typename ConfigVector,
typename TangentVector>
561 JointDataDerived & data,
562 const typename Eigen::MatrixBase<ConfigVector> & qs,
563 const typename Eigen::MatrixBase<TangentVector> & vs)
const
565 calc(data, qs.derived());
566 data.joint_v = vs.template segment<NV>(idx_v());
567 data.v.angular() = data.joint_v;
570 template<
typename VectorLike,
typename Matrix6Like>
572 JointDataDerived & data,
573 const Eigen::MatrixBase<VectorLike> & armature,
574 const Eigen::MatrixBase<Matrix6Like> & I,
575 const bool update_I)
const
577 data.U = I.template block<6, 3>(0, Inertia::ANGULAR);
578 data.StU = data.U.template middleRows<3>(Inertia::ANGULAR);
579 data.StU.diagonal() += armature;
581 internal::PerformStYSInversion<Scalar>::run(data.StU, data.Dinv);
582 data.UDinv.noalias() = data.U * data.Dinv;
585 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
588 static std::string classname()
590 return std::string(
"JointModelSpherical");
592 std::string shortname()
const
598 template<
typename NewScalar>
603 res.setIndexes(
id(), idx_q(), idx_v());
611 #include <boost/type_traits.hpp>
615 template<
typename Scalar,
int Options>
617 :
public integral_constant<bool, true>
621 template<
typename Scalar,
int Options>
623 :
public integral_constant<bool, true>
627 template<
typename Scalar,
int Options>
629 :
public integral_constant<bool, true>
633 template<
typename Scalar,
int Options>
635 :
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 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.
void skew(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector, i.e. the antisymmetric matrix representation o...
JointModelSphericalTpl< 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.