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" 24 template<
typename Scalar,
int Options>
30 template<
typename Scalar,
int Options,
typename MotionDerived>
37 template<
typename _Scalar,
int _Options>
40 typedef _Scalar Scalar;
41 enum { Options = _Options };
42 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
43 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
44 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
45 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
46 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
47 typedef Vector3 AngularType;
48 typedef Vector3 LinearType;
49 typedef const Vector3 ConstAngularType;
50 typedef const Vector3 ConstLinearType;
51 typedef Matrix6 ActionMatrixType;
59 template<
typename _Scalar,
int _Options>
62 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
68 template<
typename Vector3Like>
73 Vector3 & operator() () {
return w; }
74 const Vector3 & operator() ()
const {
return w; }
81 template<
typename MotionDerived>
87 template<
typename Derived>
90 other.linear().setZero();
104 template<
typename MotionDerived>
107 return other.angular() == w && other.linear().isZero(0);
110 template<
typename S2,
int O2,
typename D2>
114 v.angular().noalias() = m.rotation() * w;
117 v.linear().noalias() = m.translation().cross(v.angular());
120 template<
typename S2,
int O2>
124 se3Action_impl(m,res);
128 template<
typename S2,
int O2,
typename D2>
134 v3_tmp.noalias() = w.cross(m.translation());
135 v.linear().noalias() = m.rotation().transpose() * v3_tmp;
138 v.angular().noalias() = m.rotation().transpose() * 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(w);
156 mout.angular().noalias() = v.angular().cross(w);
159 template<
typename M1>
171 template<
typename S1,
int O1,
typename MotionDerived>
172 inline typename MotionDerived::MotionPlain
175 return typename MotionDerived::MotionPlain(m2.linear(),m2.angular() + m1.w);
180 template<
typename _Scalar,
int _Options>
183 typedef _Scalar Scalar;
184 enum { Options = _Options };
185 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
186 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
187 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
188 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
189 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
190 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
191 typedef Matrix3 Angular_t;
192 typedef Vector3 Linear_t;
193 typedef const Matrix3 ConstAngular_t;
194 typedef const Vector3 ConstLinear_t;
195 typedef Matrix6 ActionMatrix_t;
196 typedef Eigen::Quaternion<Scalar,Options> Quaternion_t;
206 typedef Eigen::Matrix<Scalar,3,1,Options> JointForce;
207 typedef Eigen::Matrix<Scalar,6,3,Options> DenseBase;
208 typedef DenseBase MatrixReturnType;
209 typedef const DenseBase ConstMatrixReturnType;
212 template<
typename _Scalar,
int _Options>
214 :
public ConstraintBase< ConstraintSphericalTpl<_Scalar,_Options> >
216 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
220 enum { NV = 3, Options = _Options };
225 int nv_impl()
const {
return NV; }
227 template<
typename Vector3Like>
228 JointMotion __mult__(
const Eigen::MatrixBase<Vector3Like> & w)
const 230 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3);
231 return JointMotion(w);
236 template<
typename Derived>
242 template<
typename MatrixDerived>
244 operator*(
const Eigen::MatrixBase<MatrixDerived> & F)
const 247 return F.derived().template middleRows<3>(Inertia::ANGULAR);
253 DenseBase matrix_impl()
const 256 S.template block <3,3>(LINEAR,0).setZero();
257 S.template block <3,3>(ANGULAR,0).setIdentity();
261 template<
typename S1,
int O1>
262 Eigen::Matrix<S1,6,3,O1> se3Action(
const SE3Tpl<S1,O1> & m)
const 264 Eigen::Matrix<S1,6,3,O1> X_subspace;
265 cross(m.translation(),m.rotation(),X_subspace.template block<3,3>(LINEAR,0));
266 X_subspace.template block<3,3>(ANGULAR,0) = m.rotation();
271 template<
typename MotionDerived>
274 const typename MotionDerived::ConstLinearType v = m.linear();
275 const typename MotionDerived::ConstAngularType w = m.angular();
278 skew(v,res.template middleRows<3>(LINEAR));
279 skew(w,res.template middleRows<3>(ANGULAR));
286 template<
typename MotionDerived,
typename S2,
int O2>
287 inline typename MotionDerived::MotionPlain
291 return m2.motionAction(m1);
295 template<
typename S1,
int O1,
typename S2,
int O2>
296 inline Eigen::Matrix<S2,6,3,O2>
301 typedef typename Inertia::Symmetric3
Symmetric3;
302 Eigen::Matrix<S2,6,3,O2> M;
304 M.template block<3,3>(Inertia::LINEAR,0) =
alphaSkew(-Y.mass(), Y.lever());
305 M.template block<3,3>(Inertia::ANGULAR,0) = (Y.inertia() -
typename Symmetric3::AlphaSkewSquare(Y.mass(), Y.lever())).matrix();
310 template<
typename M6Like,
typename S2,
int O2>
312 operator*(
const Eigen::MatrixBase<M6Like> & Y,
316 return Y.derived().template middleCols<3>(Constraint::ANGULAR);
321 template<
typename S1,
int O1>
322 struct SE3GroupAction< ConstraintSphericalTpl<S1,O1> >
323 {
typedef Eigen::Matrix<S1,6,3,O1> ReturnType; };
325 template<
typename S1,
int O1,
typename MotionDerived>
326 struct MotionAlgebraAction< ConstraintSphericalTpl<S1,O1>,MotionDerived >
327 {
typedef Eigen::Matrix<S1,6,3,O1> ReturnType; };
332 template<
typename _Scalar,
int _Options>
339 typedef _Scalar Scalar;
340 enum { Options = _Options };
347 typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
350 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
351 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
352 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
354 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
356 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
357 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
360 template<
typename Scalar,
int Options>
364 template<
typename Scalar,
int Options>
368 template<
typename _Scalar,
int _Options>
371 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
374 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE;
375 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
391 static std::string classname() {
return std::string(
"JointDataSpherical"); }
392 std::string
shortname()
const {
return classname(); }
397 template<
typename _Scalar,
int _Options>
399 :
public JointModelBase< JointModelSphericalTpl<_Scalar,_Options> >
401 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
404 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE;
410 using Base::setIndexes;
412 JointDataDerived
createData()
const {
return JointDataDerived(); }
414 template<
typename ConfigVectorLike>
415 inline void forwardKinematics(Transformation_t & M,
const Eigen::MatrixBase<ConfigVectorLike> & q_joint)
const 417 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVectorLike);
418 typedef typename Eigen::Quaternion<typename ConfigVectorLike::Scalar,PINOCCHIO_EIGEN_PLAIN_TYPE(ConfigVectorLike)::Options> Quaternion;
419 typedef Eigen::Map<const Quaternion> ConstQuaternionMap;
421 ConstQuaternionMap quat(q_joint.derived().data());
423 assert(math::fabs(quat.coeffs().squaredNorm()-1.) <= 1e-4);
425 M.rotation(quat.matrix());
426 M.translation().setZero();
429 template<
typename QuaternionDerived>
430 void calc(JointDataDerived & data,
431 const typename Eigen::QuaternionBase<QuaternionDerived> & quat)
const 433 data.M.rotation(quat.matrix());
436 template<
typename ConfigVector>
438 void calc(JointDataDerived & data,
439 const typename Eigen::PlainObjectBase<ConfigVector> & qs)
const 441 typedef typename Eigen::Quaternion<typename ConfigVector::Scalar,ConfigVector::Options> Quaternion;
442 typedef Eigen::Map<const Quaternion> ConstQuaternionMap;
444 ConstQuaternionMap quat(qs.template segment<NQ>(
idx_q()).data());
448 template<
typename ConfigVector>
450 void calc(JointDataDerived & data,
451 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 453 typedef typename Eigen::Quaternion<Scalar,Options> Quaternion;
455 const Quaternion quat(qs.template segment<NQ>(
idx_q()));
459 template<
typename ConfigVector,
typename TangentVector>
460 void calc(JointDataDerived & data,
461 const typename Eigen::MatrixBase<ConfigVector> & qs,
462 const typename Eigen::MatrixBase<TangentVector> & vs)
const 464 calc(data,qs.derived());
466 data.v() = vs.template segment<NV>(
idx_v());
469 template<
typename Matrix6Like>
470 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const 472 data.U = I.template block<6,3>(0,Inertia::ANGULAR);
475 data.Dinv.setIdentity();
476 data.U.template middleRows<3>(Inertia::ANGULAR).llt().solveInPlace(data.Dinv);
478 data.UDinv.template middleRows<3>(Inertia::ANGULAR).setIdentity();
479 data.UDinv.template middleRows<3>(Inertia::LINEAR).noalias() = data.U.template block<3,3>(Inertia::LINEAR, 0) * data.Dinv;
483 Matrix6Like & I_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I);
484 I_.template block<3,3>(Inertia::LINEAR,Inertia::LINEAR)
485 -= data.UDinv.template middleRows<3>(Inertia::LINEAR) * I_.template block<3,3> (Inertia::ANGULAR, Inertia::LINEAR);
486 I_.template block<6,3>(0,Inertia::ANGULAR).setZero();
487 I_.template block<3,3>(Inertia::ANGULAR,Inertia::LINEAR).setZero();
494 return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
497 static std::string classname() {
return std::string(
"JointModelSpherical"); }
498 std::string
shortname()
const {
return classname(); }
501 template<
typename NewScalar>
515 #include <boost/type_traits.hpp> 519 template<
typename Scalar,
int Options>
521 :
public integral_constant<bool,true> {};
523 template<
typename Scalar,
int Options>
525 :
public integral_constant<bool,true> {};
527 template<
typename Scalar,
int Options>
529 :
public integral_constant<bool,true> {};
531 template<
typename Scalar,
int Options>
533 :
public integral_constant<bool,true> {};
536 #endif // ifndef __pinocchio_joint_spherical_hpp__
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
int idx_v(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxVVisitor to get the index in the full model tangent space corre...
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
ModelTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType finiteDifferenceIncrement(const ModelTpl< Scalar, Options, JointCollectionTpl > &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Update the joint placements according to the current joint configuration.
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
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.
ConstAngularType angular() const
Return the angular part of the force vector.
JointModelSphericalTpl< NewScalar, Options > cast() const
Main pinocchio namespace.
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. i.e. the antisymmetric matrix representation of the cross product operator ( )
Common traits structure to fully define base classes for CRTP.
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...
void calc_aba(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata, const Eigen::MatrixBase< Matrix6Type > &I, const bool update_I)
Visit a JointModelTpl and the corresponding JointDataTpl through JointCalcAbaVisitor to...