6 #ifndef __pinocchio_joint_spherical_hpp__
7 #define __pinocchio_joint_spherical_hpp__
9 #include "pinocchio/macros.hpp"
10 #include "pinocchio/multibody/joint/joint-base.hpp"
11 #include "pinocchio/multibody/constraint.hpp"
12 #include "pinocchio/math/sincos.hpp"
13 #include "pinocchio/spatial/inertia.hpp"
14 #include "pinocchio/spatial/skew.hpp"
22 template<
typename Scalar,
int Options>
28 template<
typename Scalar,
int Options,
typename MotionDerived>
34 template<
typename _Scalar,
int _Options>
37 typedef _Scalar Scalar;
38 enum { Options = _Options };
39 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
40 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
41 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
42 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
43 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
44 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
45 typedef Vector3 AngularType;
46 typedef Vector3 LinearType;
47 typedef const Vector3 ConstAngularType;
48 typedef const Vector3 ConstLinearType;
49 typedef Matrix6 ActionMatrixType;
50 typedef Matrix4 HomogeneousMatrixType;
59 template<
typename _Scalar,
int _Options>
61 :
MotionBase< MotionSphericalTpl<_Scalar,_Options> >
63 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
69 template<
typename Vector3Like>
70 MotionSphericalTpl(
const Eigen::MatrixBase<Vector3Like> & w)
74 Vector3 & operator() () {
return m_w; }
75 const Vector3 & operator() ()
const {
return m_w; }
77 inline PlainReturnType plain()
const
79 return PlainReturnType(PlainReturnType::Vector3::Zero(), m_w);
82 template<
typename MotionDerived>
83 void addTo(MotionDense<MotionDerived> & other)
const
85 other.angular() += m_w;
88 template<
typename Derived>
89 void setTo(MotionDense<Derived> & other)
const
91 other.linear().setZero();
92 other.angular() = m_w;
95 MotionSphericalTpl __plus__(
const MotionSphericalTpl & other)
const
97 return MotionSphericalTpl(m_w + other.m_w);
100 bool isEqual_impl(
const MotionSphericalTpl & other)
const
102 return m_w == other.m_w;
105 template<
typename MotionDerived>
106 bool isEqual_impl(
const MotionDense<MotionDerived> & other)
const
108 return other.angular() == m_w && other.linear().isZero(0);
111 template<
typename S2,
int O2,
typename D2>
112 void se3Action_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
115 v.angular().noalias() = m.rotation() * m_w;
118 v.linear().noalias() = m.translation().cross(v.angular());
121 template<
typename S2,
int O2>
122 MotionPlain se3Action_impl(
const SE3Tpl<S2,O2> & m)
const
125 se3Action_impl(m,res);
129 template<
typename S2,
int O2,
typename D2>
130 void se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
135 v3_tmp.noalias() = m_w.cross(m.translation());
136 v.linear().noalias() = m.rotation().transpose() * v3_tmp;
139 v.angular().noalias() = m.rotation().transpose() * m_w;
142 template<
typename S2,
int O2>
143 MotionPlain se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m)
const
146 se3ActionInverse_impl(m,res);
150 template<
typename M1,
typename M2>
151 void motionAction(
const MotionDense<M1> & v, MotionDense<M2> & mout)
const
154 mout.linear().noalias() = v.linear().cross(m_w);
157 mout.angular().noalias() = v.angular().cross(m_w);
160 template<
typename M1>
161 MotionPlain motionAction(
const MotionDense<M1> & v)
const
168 const Vector3 & angular()
const {
return m_w; }
169 Vector3 & angular() {
return m_w; }
176 template<
typename S1,
int O1,
typename MotionDerived>
177 inline typename MotionDerived::MotionPlain
178 operator+(
const MotionSphericalTpl<S1,O1> & m1,
const MotionDense<MotionDerived> & m2)
180 return typename MotionDerived::MotionPlain(m2.linear(),m2.angular() + m1.angular());
185 template<
typename _Scalar,
int _Options>
188 typedef _Scalar Scalar;
189 enum { Options = _Options };
195 typedef Eigen::Matrix<Scalar,3,1,Options> JointForce;
196 typedef Eigen::Matrix<Scalar,6,3,Options> DenseBase;
197 typedef DenseBase MatrixReturnType;
198 typedef const DenseBase ConstMatrixReturnType;
201 template<
typename _Scalar,
int _Options>
203 :
public ConstraintBase< ConstraintSphericalTpl<_Scalar,_Options> >
205 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
213 int nv_impl()
const {
return NV; }
215 template<
typename Vector3Like>
216 JointMotion __mult__(
const Eigen::MatrixBase<Vector3Like> & w)
const
218 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3);
219 return JointMotion(w);
224 template<
typename Derived>
230 template<
typename MatrixDerived>
232 operator*(
const Eigen::MatrixBase<MatrixDerived> & F)
const
235 return F.derived().template middleRows<3>(Inertia::ANGULAR);
241 DenseBase matrix_impl()
const
244 S.template block <3,3>(LINEAR,0).setZero();
245 S.template block <3,3>(ANGULAR,0).setIdentity();
249 template<
typename S1,
int O1>
250 Eigen::Matrix<S1,6,3,O1> se3Action(
const SE3Tpl<S1,O1> & m)
const
252 Eigen::Matrix<S1,6,3,O1> X_subspace;
253 cross(m.translation(),m.rotation(),X_subspace.template middleRows<3>(LINEAR));
254 X_subspace.template middleRows<3>(ANGULAR) = m.rotation();
259 template<
typename S1,
int O1>
260 Eigen::Matrix<S1,6,3,O1> se3ActionInverse(
const SE3Tpl<S1,O1> & m)
const
262 Eigen::Matrix<S1,6,3,O1> X_subspace;
263 AxisX::cross(m.translation(),X_subspace.template middleRows<3>(ANGULAR).col(0));
264 AxisY::cross(m.translation(),X_subspace.template middleRows<3>(ANGULAR).col(1));
265 AxisZ::cross(m.translation(),X_subspace.template middleRows<3>(ANGULAR).col(2));
267 X_subspace.template middleRows<3>(LINEAR).noalias()
268 = m.rotation().transpose() * X_subspace.template middleRows<3>(ANGULAR);
269 X_subspace.template middleRows<3>(ANGULAR) = m.rotation().transpose();
274 template<
typename MotionDerived>
275 DenseBase motionAction(
const MotionDense<MotionDerived> & m)
const
277 const typename MotionDerived::ConstLinearType v = m.linear();
278 const typename MotionDerived::ConstAngularType w = m.angular();
281 skew(v,res.template middleRows<3>(LINEAR));
282 skew(w,res.template middleRows<3>(ANGULAR));
287 bool isEqual(
const ConstraintSphericalTpl &)
const {
return true; }
291 template<
typename MotionDerived,
typename S2,
int O2>
292 inline typename MotionDerived::MotionPlain
293 operator^(
const MotionDense<MotionDerived> & m1,
294 const MotionSphericalTpl<S2,O2> & m2)
296 return m2.motionAction(m1);
300 template<
typename S1,
int O1,
typename S2,
int O2>
301 inline Eigen::Matrix<S2,6,3,O2>
303 const ConstraintSphericalTpl<S2,O2> &)
305 typedef InertiaTpl<S1,O1> Inertia;
306 typedef typename Inertia::Symmetric3 Symmetric3;
307 Eigen::Matrix<S2,6,3,O2> M;
309 M.template block<3,3>(Inertia::LINEAR,0) =
alphaSkew(-Y.mass(), Y.lever());
310 M.template block<3,3>(Inertia::ANGULAR,0) = (Y.inertia() -
typename Symmetric3::AlphaSkewSquare(Y.mass(), Y.lever())).matrix();
315 template<
typename M6Like,
typename S2,
int O2>
316 inline typename SizeDepType<3>::ColsReturn<M6Like>::ConstType
317 operator*(
const Eigen::MatrixBase<M6Like> & Y,
318 const ConstraintSphericalTpl<S2,O2> &)
320 typedef ConstraintSphericalTpl<S2,O2> Constraint;
321 return Y.derived().template middleCols<3>(Constraint::ANGULAR);
324 template<
typename S1,
int O1>
326 {
typedef Eigen::Matrix<S1,6,3,O1> ReturnType; };
328 template<
typename S1,
int O1,
typename MotionDerived>
330 {
typedef Eigen::Matrix<S1,6,3,O1> ReturnType; };
334 template<
typename _Scalar,
int _Options>
341 typedef _Scalar Scalar;
342 enum { Options = _Options };
351 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
352 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
353 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
355 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
357 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
358 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
361 template<
typename Scalar,
int Options>
365 template<
typename Scalar,
int Options>
369 template<
typename _Scalar,
int _Options>
372 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
375 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
376 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
389 : M(Transformation_t::Identity())
390 , v(Motion_t::Vector3::Zero())
393 , UDinv(UD_t::Zero())
396 static std::string classname() {
return std::string(
"JointDataSpherical"); }
397 std::string shortname()
const {
return classname(); }
401 PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelSphericalTpl);
402 template<
typename _Scalar,
int _Options>
403 struct JointModelSphericalTpl
404 :
public JointModelBase< JointModelSphericalTpl<_Scalar,_Options> >
406 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
408 typedef JointSphericalTpl<_Scalar,_Options> JointDerived;
409 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
411 typedef JointModelBase<JointModelSphericalTpl> Base;
415 using Base::setIndexes;
417 JointDataDerived createData()
const {
return JointDataDerived(); }
419 const std::vector<bool> hasConfigurationLimit()
const
421 return {
false,
false,
false,
false};
424 const std::vector<bool> hasConfigurationLimitInTangent()
const
426 return {
false,
false,
false};
429 template<
typename ConfigVectorLike>
430 inline void forwardKinematics(Transformation_t & M,
const Eigen::MatrixBase<ConfigVectorLike> & q_joint)
const
432 typedef typename ConfigVectorLike::Scalar Scalar;
433 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVectorLike);
434 typedef typename Eigen::Quaternion<Scalar,PINOCCHIO_EIGEN_PLAIN_TYPE(ConfigVectorLike)::Options> Quaternion;
435 typedef Eigen::Map<const Quaternion> ConstQuaternionMap;
437 ConstQuaternionMap quat(q_joint.derived().data());
439 assert(math::fabs(
static_cast<Scalar
>(quat.coeffs().squaredNorm()-1)) <= 1e-4);
441 M.rotation(quat.matrix());
442 M.translation().setZero();
445 template<
typename QuaternionDerived>
446 void calc(JointDataDerived & data,
447 const typename Eigen::QuaternionBase<QuaternionDerived> & quat)
const
449 data.M.rotation(quat.matrix());
452 template<
typename ConfigVector>
454 void calc(JointDataDerived & data,
455 const typename Eigen::PlainObjectBase<ConfigVector> & qs)
const
457 typedef typename Eigen::Quaternion<typename ConfigVector::Scalar,ConfigVector::Options> Quaternion;
458 typedef Eigen::Map<const Quaternion> ConstQuaternionMap;
460 ConstQuaternionMap quat(qs.template segment<NQ>(
idx_q()).data());
464 template<
typename ConfigVector>
466 void calc(JointDataDerived & data,
467 const typename Eigen::MatrixBase<ConfigVector> & qs)
const
469 typedef typename Eigen::Quaternion<Scalar,Options> Quaternion;
471 const Quaternion quat(qs.template segment<NQ>(
idx_q()));
475 template<
typename ConfigVector,
typename TangentVector>
476 void calc(JointDataDerived & data,
477 const typename Eigen::MatrixBase<ConfigVector> & qs,
478 const typename Eigen::MatrixBase<TangentVector> & vs)
const
480 calc(data,qs.derived());
482 data.v.angular() = vs.template segment<NV>(
idx_v());
485 template<
typename Matrix6Like>
486 void calc_aba(JointDataDerived & data,
487 const Eigen::MatrixBase<Matrix6Like> & I,
488 const bool update_I)
const
490 data.U = I.template block<6,3>(0,Inertia::ANGULAR);
495 internal::PerformStYSInversion<Scalar>::run(data.U.template middleRows<3>(Inertia::ANGULAR),data.Dinv);
497 data.UDinv.template middleRows<3>(Inertia::ANGULAR).setIdentity();
498 data.UDinv.template middleRows<3>(Inertia::LINEAR).noalias() = data.U.template block<3,3>(Inertia::LINEAR, 0) * data.Dinv;
502 Matrix6Like & I_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I);
503 I_.template block<3,3>(Inertia::LINEAR,Inertia::LINEAR)
504 -= data.UDinv.template middleRows<3>(Inertia::LINEAR) * I_.template block<3,3> (Inertia::ANGULAR, Inertia::LINEAR);
505 I_.template block<6,3>(0,Inertia::ANGULAR).setZero();
506 I_.template block<3,3>(Inertia::ANGULAR,Inertia::LINEAR).setZero();
510 static std::string classname() {
return std::string(
"JointModelSpherical"); }
511 std::string shortname()
const {
return classname(); }
514 template<
typename NewScalar>
527 #include <boost/type_traits.hpp>
531 template<
typename Scalar,
int Options>
533 :
public integral_constant<bool,true> {};
535 template<
typename Scalar,
int Options>
537 :
public integral_constant<bool,true> {};
539 template<
typename Scalar,
int Options>
541 :
public integral_constant<bool,true> {};
543 template<
typename Scalar,
int Options>
545 :
public integral_constant<bool,true> {};
548 #endif // ifndef __pinocchio_joint_spherical_hpp__