19 #ifndef __se3_joint_revolute_hpp__ 20 #define __se3_joint_revolute_hpp__ 22 #include "pinocchio/math/sincos.hpp" 23 #include "pinocchio/spatial/inertia.hpp" 24 #include "pinocchio/multibody/constraint.hpp" 25 #include "pinocchio/multibody/joint/joint-base.hpp" 26 #include "pinocchio/spatial/spatial-axis.hpp" 27 #include "pinocchio/utils/axis-label.hpp" 43 Eigen::Vector3d vector()
const;
44 operator Eigen::Vector3d ()
const {
return vector(); }
50 inline Eigen::Vector3d operator+ (
const Eigen::Vector3d & w1,
const CartesianVector3<0> & wx)
51 {
return Eigen::Vector3d(w1[0]+wx.w,w1[1],w1[2]); }
52 inline Eigen::Vector3d operator+ (
const Eigen::Vector3d & w1,
const CartesianVector3<1> & wy)
53 {
return Eigen::Vector3d(w1[0],w1[1]+wy.w,w1[2]); }
54 inline Eigen::Vector3d operator+ (
const Eigen::Vector3d & w1,
const CartesianVector3<2> & wz)
55 {
return Eigen::Vector3d(w1[0],w1[1],w1[2]+wz.w); }
59 template<
typename _Scalar,
int _Options,
int axis>
62 typedef _Scalar Scalar;
63 enum { Options = _Options };
64 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
65 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
66 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
67 typedef typename EIGEN_REF_CONSTTYPE(Vector6) ToVectorConstReturnType;
68 typedef typename EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
69 typedef Vector3 AngularType;
70 typedef Vector3 LinearType;
71 typedef const Vector3 ConstAngularType;
72 typedef const Vector3 ConstLinearType;
73 typedef Matrix6 ActionMatrixType;
81 template<
typename _Scalar,
int _Options,
int axis>
89 template<
typename OtherScalar>
94 template<
typename MotionDerived>
98 v.angular()[axis] += (OtherScalar)w;
105 template<
typename S1,
int O1,
int axis,
typename MotionDerived>
106 typename MotionDerived::MotionPlain
110 typename MotionDerived::MotionPlain res(m2);
119 template<
typename Scalar,
int Options,
int axis>
121 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
123 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
125 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
128 template<
typename _Scalar,
int _Options,
int axis>
131 typedef _Scalar Scalar;
132 enum { Options = _Options };
133 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
134 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
135 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
136 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
137 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
138 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
139 typedef Matrix3 Angular_t;
140 typedef Vector3 Linear_t;
141 typedef const Matrix3 ConstAngular_t;
142 typedef const Vector3 ConstLinear_t;
143 typedef Matrix6 ActionMatrix_t;
144 typedef Eigen::Quaternion<Scalar,0> Quaternion_t;
153 typedef Eigen::Matrix<Scalar,1,1,Options> JointMotion;
154 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
155 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
156 typedef DenseBase MatrixReturnType;
157 typedef const DenseBase ConstMatrixReturnType;
160 template<
typename _Scalar,
int _Options,
int axis>
164 enum { NV = 1, Options = 0 };
170 template<
typename Vector1Like>
172 operator*(
const Eigen::MatrixBase<Vector1Like> & v)
const 175 template<
typename S1,
int O1>
176 Eigen::Matrix<Scalar,6,1,Options>
179 Eigen::Matrix<Scalar,6,1,Options> res;
180 res.template head<3>() = m.translation().cross(m.rotation().col(axis));
181 res.template tail<3>() = m.rotation().col(axis);
185 int nv_impl()
const {
return NV; }
192 template<
typename Derived>
195 {
return f.
angular().template segment<1>(axis); }
199 typename Eigen::MatrixBase<D>::ConstRowXpr
203 return F.row(ANGULAR + axis);
215 DenseBase matrix_impl()
const 223 template<
typename MotionDerived>
233 template<
typename MotionDerived,
typename S2,
int O2>
234 inline typename MotionDerived::MotionPlain
242 typedef typename MotionDerived::MotionPlain ReturnType;
243 const typename MotionDerived::ConstLinearType & v = m1.linear();
244 const typename MotionDerived::ConstAngularType & w = m1.angular();
245 const S2 & wx = m2.w;
246 return ReturnType(
typename ReturnType::Vector3(0,v[2]*wx,-v[1]*wx),
247 typename ReturnType::Vector3(0,w[2]*wx,-w[1]*wx)
251 template<
typename MotionDerived,
typename S2,
int O2>
252 inline typename MotionDerived::MotionPlain
260 typedef typename MotionDerived::MotionPlain ReturnType;
261 const typename MotionDerived::ConstLinearType & v = m1.linear();
262 const typename MotionDerived::ConstAngularType & w = m1.angular();
263 const S2 & wx = m2.w;
264 return ReturnType(
typename ReturnType::Vector3(-v[2]*wx,0, v[0]*wx),
265 typename ReturnType::Vector3(-w[2]*wx,0, w[0]*wx)
269 template<
typename MotionDerived,
typename S2,
int O2>
270 inline typename MotionDerived::MotionPlain
278 typedef typename MotionDerived::MotionPlain ReturnType;
279 const typename MotionDerived::ConstLinearType & v = m1.linear();
280 const typename MotionDerived::ConstAngularType & w = m1.angular();
281 const S2 & wx = m2.w;
282 return ReturnType(
typename ReturnType::Vector3(v[1]*wx,-v[0]*wx,0),
283 typename ReturnType::Vector3(w[1]*wx,-w[0]*wx,0)
287 template<
typename Scalar,
int Options,
int axis>
290 template<
typename S1,
typename S2,
typename Matrix3Like>
291 static void cartesianRotation(
const S1 & ca,
const S2 & sa,
292 const Eigen::MatrixBase<Matrix3Like> & res);
295 template<
typename Scalar,
int Options>
298 template<
typename S1,
typename S2,
typename Matrix3Like>
299 static void cartesianRotation(
const S1 & ca,
const S2 & sa,
300 const Eigen::MatrixBase<Matrix3Like> & res)
302 Matrix3Like & res_ =
const_cast<Matrix3Like &
>(res.derived());
303 typedef typename Matrix3Like::Scalar OtherScalar;
305 OtherScalar(1), OtherScalar(0), OtherScalar(0),
306 OtherScalar(0), ca, -sa,
307 OtherScalar(0), sa, ca;
311 template<
typename Scalar,
int Options>
314 template<
typename S1,
typename S2,
typename Matrix3Like>
315 static void cartesianRotation(
const S1 & ca,
const S2 & sa,
316 const Eigen::MatrixBase<Matrix3Like> & res)
318 Matrix3Like & res_ =
const_cast<Matrix3Like &
>(res.derived());
319 typedef typename Matrix3Like::Scalar OtherScalar;
321 ca, OtherScalar(0), sa,
322 OtherScalar(0), OtherScalar(1), OtherScalar(0),
323 -sa, OtherScalar(0), ca;
327 template<
typename Scalar,
int Options>
330 template<
typename S1,
typename S2,
typename Matrix3Like>
331 static void cartesianRotation(
const S1 & ca,
const S2 & sa,
332 const Eigen::MatrixBase<Matrix3Like> & res)
334 Matrix3Like & res_ =
const_cast<Matrix3Like &
>(res.derived());
335 typedef typename Matrix3Like::Scalar OtherScalar;
337 ca, -sa, OtherScalar(0),
338 sa, ca, OtherScalar(0),
339 OtherScalar(0), OtherScalar(0), OtherScalar(1);
344 template<
typename S1,
int O1,
typename S2,
int O2>
345 inline Eigen::Matrix<S2,6,1,O2>
355 const typename Inertia::Symmetric3 & I = Y.inertia();
357 Eigen::Matrix<S2,6,1,O2> res;
365 template<
typename S1,
int O1,
typename S2,
int O2>
366 inline Eigen::Matrix<S2,6,1,O2>
376 const typename Inertia::Symmetric3 & I = Y.inertia();
377 Eigen::Matrix<S2,6,1,O2> res;
385 template<
typename S1,
int O1,
typename S2,
int O2>
386 inline Eigen::Matrix<S2,6,1,O2>
396 const typename Inertia::Symmetric3 & I = Y.inertia();
397 Eigen::Matrix<S2,6,1,O2> res; res << -m*y,m*x,0,
405 template<
typename M6Like,
typename S2,
int O2,
int axis>
406 inline const typename M6Like::ConstColXpr
409 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
410 return Y.col(Inertia::ANGULAR + axis);
413 template<
typename _Scalar,
int _Options,
int axis>
420 typedef _Scalar Scalar;
421 enum { Options = _Options };
428 typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
431 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
432 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
433 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
435 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
436 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
439 template<
typename Scalar,
int Options,
int axis>
443 template<
typename Scalar,
int Options,
int axis>
447 template<
typename _Scalar,
int _Options,
int axis>
451 SE3_JOINT_TYPEDEF_TEMPLATE;
469 template<
typename _Scalar,
int _Options,
int axis>
473 SE3_JOINT_TYPEDEF_TEMPLATE;
480 JointDataDerived
createData()
const {
return JointDataDerived(); }
482 template<
typename ConfigVector>
483 void calc(JointDataDerived & data,
484 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 486 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVector);
487 typedef typename ConfigVector::Scalar OtherScalar;
489 const OtherScalar & q = qs[
idx_q()];
490 OtherScalar ca,sa; SINCOS(q,&sa,&ca);
491 JointDerived::cartesianRotation(ca,sa,data.M.rotation());
494 template<
typename ConfigVector,
typename TangentVector>
495 void calc(JointDataDerived & data,
496 const typename Eigen::MatrixBase<ConfigVector> & qs,
497 const typename Eigen::MatrixBase<TangentVector> & vs)
const 499 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TangentVector_t,TangentVector);
500 calc(data,qs.derived());
502 data.v.w = (Scalar)vs[
idx_v()];;
505 template<
typename S2,
int O2>
506 void calc_aba(JointDataDerived & data, Eigen::Matrix<S2,6,6,O2> & I,
const bool update_I)
const 508 data.U = I.col(Inertia::ANGULAR + axis);
509 data.Dinv[0] = Scalar(1)/I(Inertia::ANGULAR + axis,Inertia::ANGULAR + axis);
510 data.UDinv.noalias() = data.U * data.Dinv[0];
513 I -= data.UDinv * data.U.transpose();
519 return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
522 static std::string classname()
524 return std::string(
"JointModelR") + axisLabel<axis>();
526 std::string
shortname()
const {
return classname(); }
544 #endif // ifndef __se3_joint_revolute_hpp__
JointDataVariant createData(const JointModelVariant &jmodel)
Visit a JointModelVariant through CreateData visitor to create a JointDataVariant.
Eigen::MatrixBase< D >::ConstRowXpr operator*(const Eigen::MatrixBase< D > &F) const
[CRBA] MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
ConstAngularType angular() const
Return the angular part of the force vector.
void calc_aba(const JointModelVariant &jmodel, JointDataVariant &jdata, Inertia::Matrix6 &I, const bool update_I)
Visit a JointDataVariant and the corresponding JointModelVariant through JointCalcAbaVisitor to...
std::string shortname(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointShortnameVisitor to get the shortname of the derived joint mod...
int idx_q(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxQVisitor to get the index in the full model configuration s...
Eigen::VectorXd finiteDifferenceIncrement(const Model &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...
int idx_v(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxVVisitor to get the index in the full model tangent space c...