6 #ifndef __pinocchio_joint_revolute_hpp__
7 #define __pinocchio_joint_revolute_hpp__
9 #include "pinocchio/math/sincos.hpp"
10 #include "pinocchio/spatial/inertia.hpp"
11 #include "pinocchio/multibody/constraint.hpp"
12 #include "pinocchio/multibody/joint/joint-base.hpp"
13 #include "pinocchio/spatial/spatial-axis.hpp"
14 #include "pinocchio/utils/axis-label.hpp"
21 template<
typename Scalar,
int Options,
int axis>
27 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
33 template<
typename _Scalar,
int _Options,
int axis>
36 typedef _Scalar Scalar;
37 enum { Options = _Options };
38 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
39 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
40 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
41 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
42 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
43 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
44 typedef Vector3 AngularType;
45 typedef Vector3 LinearType;
46 typedef const Vector3 ConstAngularType;
47 typedef const Vector3 ConstLinearType;
48 typedef Matrix6 ActionMatrixType;
49 typedef Matrix4 HomogeneousMatrixType;
60 template<
typename _Scalar,
int _Options,
int _axis>
69 typedef _Scalar Scalar;
71 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
72 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
73 typedef Matrix3 AngularType;
74 typedef Matrix3 AngularRef;
75 typedef Matrix3 ConstAngularRef;
76 typedef typename Vector3::ConstantReturnType LinearType;
77 typedef typename Vector3::ConstantReturnType LinearRef;
78 typedef const typename Vector3::ConstantReturnType ConstLinearRef;
83 template<
typename Scalar,
int Options,
int axis>
87 template<
typename _Scalar,
int _Options,
int axis>
90 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
94 TransformRevoluteTpl(
const Scalar & sin,
const Scalar & cos)
95 : m_sin(sin), m_cos(cos)
98 PlainType plain()
const
100 PlainType res(PlainType::Identity());
101 _setRotation (res.rotation());
105 operator PlainType()
const {
return plain(); }
107 template<
typename S2,
int O2>
108 typename SE3GroupAction<TransformRevoluteTpl>::ReturnType
109 se3action(
const SE3Tpl<S2,O2> & m)
const
111 typedef typename SE3GroupAction<TransformRevoluteTpl>::ReturnType ReturnType;
117 res.rotation().col(0) = m.rotation().col(0);
118 res.rotation().col(1).noalias() = m_cos * m.rotation().col(1) + m_sin * m.rotation().col(2);
119 res.rotation().col(2).noalias() = res.rotation().col(0).cross(res.rotation().col(1));
124 res.rotation().col(2).noalias() = m_cos * m.rotation().col(2) + m_sin * m.rotation().col(0);
125 res.rotation().col(1) = m.rotation().col(1);
126 res.rotation().col(0).noalias() = res.rotation().col(1).cross(res.rotation().col(2));
131 res.rotation().col(0).noalias() = m_cos * m.rotation().col(0) + m_sin * m.rotation().col(1);
132 res.rotation().col(1).noalias() = res.rotation().col(2).cross(res.rotation().col(0));
133 res.rotation().col(2) = m.rotation().col(2);
138 assert(
false &&
"must nerver happened");
142 res.translation() = m.translation();
146 const Scalar & sin()
const {
return m_sin; }
147 Scalar & sin() {
return m_sin; }
149 const Scalar & cos()
const {
return m_cos; }
150 Scalar & cos() {
return m_cos; }
152 template<
typename OtherScalar>
153 void setValues(
const OtherScalar & sin,
const OtherScalar & cos)
154 { m_sin = sin; m_cos = cos; }
156 LinearType translation()
const {
return LinearType::PlainObject::Zero(3); };
157 AngularType rotation()
const {
158 AngularType m(AngularType::Identity(3));
163 bool isEqual(
const TransformRevoluteTpl & other)
const
165 return m_cos == other.m_cos && m_sin == other.m_sin;
171 inline void _setRotation (
typename PlainType::AngularRef& rot)
const
177 rot.coeffRef(1,1) = m_cos; rot.coeffRef(1,2) = -m_sin;
178 rot.coeffRef(2,1) = m_sin; rot.coeffRef(2,2) = m_cos;
183 rot.coeffRef(0,0) = m_cos; rot.coeffRef(0,2) = m_sin;
184 rot.coeffRef(2,0) = -m_sin; rot.coeffRef(2,2) = m_cos;
189 rot.coeffRef(0,0) = m_cos; rot.coeffRef(0,1) = -m_sin;
190 rot.coeffRef(1,0) = m_sin; rot.coeffRef(1,1) = m_cos;
195 assert(
false &&
"must nerver happened");
202 template<
typename _Scalar,
int _Options,
int axis>
203 struct MotionRevoluteTpl
204 : MotionBase< MotionRevoluteTpl<_Scalar,_Options,axis> >
206 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
208 MOTION_TYPEDEF_TPL(MotionRevoluteTpl);
209 typedef SpatialAxis<axis+ANGULAR> Axis;
210 typedef typename Axis::CartesianAxis3 CartesianAxis3;
212 MotionRevoluteTpl() {}
214 MotionRevoluteTpl(
const Scalar & w) : m_w(w) {}
216 template<
typename Vector1Like>
217 MotionRevoluteTpl(
const Eigen::MatrixBase<Vector1Like> & v)
220 using namespace Eigen;
221 EIGEN_STATIC_ASSERT_SIZE_1x1(Vector1Like);
224 inline PlainReturnType plain()
const {
return Axis() * m_w; }
226 template<
typename OtherScalar>
227 MotionRevoluteTpl __mult__(
const OtherScalar & alpha)
const
229 return MotionRevoluteTpl(alpha*m_w);
232 template<
typename MotionDerived>
233 void setTo(MotionDense<MotionDerived> & m)
const
235 m.linear().setZero();
236 for(Eigen::DenseIndex k = 0; k < 3; ++k)
237 m.angular()[k] = k == axis ? m_w : (Scalar)0;
240 template<
typename MotionDerived>
241 inline void addTo(MotionDense<MotionDerived> & v)
const
243 typedef typename MotionDense<MotionDerived>::Scalar OtherScalar;
244 v.angular()[axis] += (OtherScalar)m_w;
247 template<
typename S2,
int O2,
typename D2>
248 inline void se3Action_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
250 v.angular().noalias() = m.rotation().col(axis) * m_w;
251 v.linear().noalias() = m.translation().cross(v.angular());
254 template<
typename S2,
int O2>
255 MotionPlain se3Action_impl(
const SE3Tpl<S2,O2> & m)
const
258 se3Action_impl(m,res);
262 template<
typename S2,
int O2,
typename D2>
263 void se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m,
264 MotionDense<D2> & v)
const
267 CartesianAxis3::alphaCross(m_w,m.translation(),v.angular());
268 v.linear().noalias() = m.rotation().transpose() * v.angular();
271 v.angular().noalias() = m.rotation().transpose().col(axis) * m_w;
274 template<
typename S2,
int O2>
275 MotionPlain se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m)
const
278 se3ActionInverse_impl(m,res);
282 template<
typename M1,
typename M2>
284 void motionAction(
const MotionDense<M1> & v, MotionDense<M2> & mout)
const
287 CartesianAxis3::alphaCross(-m_w,v.linear(),mout.linear());
290 CartesianAxis3::alphaCross(-m_w,v.angular(),mout.angular());
293 template<
typename M1>
294 MotionPlain motionAction(
const MotionDense<M1> & v)
const
301 Scalar & angularRate() {
return m_w; }
302 const Scalar & angularRate()
const {
return m_w; }
304 bool isEqual_impl(
const MotionRevoluteTpl & other)
const
306 return m_w == other.m_w;
314 template<
typename S1,
int O1,
int axis,
typename MotionDerived>
315 typename MotionDerived::MotionPlain
316 operator+(
const MotionRevoluteTpl<S1,O1,axis> & m1,
317 const MotionDense<MotionDerived> & m2)
319 typename MotionDerived::MotionPlain res(m2);
324 template<
typename MotionDerived,
typename S2,
int O2,
int axis>
326 typename MotionDerived::MotionPlain
327 operator^(
const MotionDense<MotionDerived> & m1,
const MotionRevoluteTpl<S2,O2,axis>& m2)
329 return m2.motionAction(m1);
334 template<
typename Scalar,
int Options,
int axis>
336 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
338 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
340 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
342 template<
typename Scalar,
int Options,
int axis,
typename ForceDerived>
346 template<
typename Scalar,
int Options,
int axis,
typename ForceSet>
348 {
typedef typename Eigen::MatrixBase<ForceSet>::ConstRowXpr ReturnType; };
350 template<
typename _Scalar,
int _Options,
int axis>
353 typedef _Scalar Scalar;
354 enum { Options = _Options };
360 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
361 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
362 typedef DenseBase MatrixReturnType;
363 typedef const DenseBase ConstMatrixReturnType;
366 template<
typename _Scalar,
int _Options,
int axis>
370 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
375 typedef SpatialAxis<ANGULAR+axis> Axis;
377 ConstraintRevoluteTpl() {}
379 template<
typename Vector1Like>
380 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const
381 {
return JointMotion(v[0]); }
383 template<
typename S1,
int O1>
384 typename SE3GroupAction<ConstraintRevoluteTpl>::ReturnType
385 se3Action(
const SE3Tpl<S1,O1> & m)
const
387 typedef typename SE3GroupAction<ConstraintRevoluteTpl>::ReturnType ReturnType;
389 res.template segment<3>(LINEAR) = m.translation().cross(m.rotation().col(axis));
390 res.template segment<3>(ANGULAR) = m.rotation().col(axis);
394 template<
typename S1,
int O1>
395 typename SE3GroupAction<ConstraintRevoluteTpl>::ReturnType
396 se3ActionInverse(
const SE3Tpl<S1,O1> & m)
const
398 typedef typename SE3GroupAction<ConstraintRevoluteTpl>::ReturnType ReturnType;
399 typedef typename Axis::CartesianAxis3 CartesianAxis3;
401 res.template segment<3>(LINEAR).noalias() = m.rotation().transpose()*CartesianAxis3::cross(m.translation());
402 res.template segment<3>(ANGULAR) = m.rotation().transpose().col(axis);
406 int nv_impl()
const {
return NV; }
413 template<
typename ForceDerived>
414 typename ConstraintForceOp<ConstraintRevoluteTpl,ForceDerived>::ReturnType
416 {
return f.
angular().template segment<1>(axis); }
419 template<
typename Derived>
420 typename ConstraintForceSetOp<ConstraintRevoluteTpl,Derived>::ReturnType
424 return F.row(ANGULAR + axis);
428 TransposeConst transpose()
const {
return TransposeConst(*
this); }
436 DenseBase matrix_impl()
const
439 MotionRef<DenseBase> v(S);
444 template<
typename MotionDerived>
445 typename MotionAlgebraAction<ConstraintRevoluteTpl,MotionDerived>::ReturnType
446 motionAction(
const MotionDense<MotionDerived> & m)
const
448 typedef typename MotionAlgebraAction<ConstraintRevoluteTpl,MotionDerived>::ReturnType ReturnType;
450 MotionRef<ReturnType> v(res);
455 bool isEqual(
const ConstraintRevoluteTpl &)
const {
return true; }
459 template<
typename _Scalar,
int _Options,
int _axis>
462 typedef _Scalar Scalar;
471 template<
typename S1,
int O1,
typename S2,
int O2,
int axis>
474 typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
480 template<
typename S1,
int O1,
typename S2,
int O2>
486 static inline ReturnType run(
const Inertia & Y,
497 const typename Inertia::Symmetric3 & I = Y.inertia();
511 template<
typename S1,
int O1,
typename S2,
int O2>
517 static inline ReturnType run(
const Inertia & Y,
528 const typename Inertia::Symmetric3 & I = Y.inertia();
542 template<
typename S1,
int O1,
typename S2,
int O2>
548 static inline ReturnType run(
const Inertia & Y,
559 const typename Inertia::Symmetric3 & I = Y.inertia();
574 template<
typename M6Like,
typename S2,
int O2,
int axis>
577 typedef typename M6Like::ConstColXpr ReturnType;
583 template<
typename M6Like,
typename Scalar,
int Options,
int axis>
588 static inline ReturnType run(
const Eigen::MatrixBase<M6Like> & Y,
591 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
592 return Y.col(Inertia::ANGULAR + axis);
597 template<
typename _Scalar,
int _Options,
int axis>
604 typedef _Scalar Scalar;
605 enum { Options = _Options };
614 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
615 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
616 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
618 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
620 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
621 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
624 template<
typename Scalar,
int Options,
int axis>
628 template<
typename Scalar,
int Options,
int axis>
632 template<
typename _Scalar,
int _Options,
int axis>
635 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
637 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
638 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
651 : M((Scalar)0,(Scalar)1)
655 , UDinv(UD_t::Zero())
658 static std::string classname()
660 return std::string(
"JointDataR") + axisLabel<axis>();
662 std::string
shortname()
const {
return classname(); }
666 template<
typename NewScalar,
typename Scalar,
int Options,
int axis>
672 template<
typename _Scalar,
int _Options,
int axis>
674 :
public JointModelBase< JointModelRevoluteTpl<_Scalar,_Options,axis> >
676 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
678 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
684 using Base::setIndexes;
686 JointDataDerived
createData()
const {
return JointDataDerived(); }
688 JointModelRevoluteTpl() {}
700 template<
typename ConfigVector>
702 void calc(JointDataDerived & data,
703 const typename Eigen::MatrixBase<ConfigVector> & qs)
const
705 typedef typename ConfigVector::Scalar OtherScalar;
707 const OtherScalar & q = qs[
idx_q()];
708 OtherScalar ca,sa;
SINCOS(q,&sa,&ca);
709 data.M.setValues(sa,ca);
712 template<
typename ConfigVector,
typename TangentVector>
714 void calc(JointDataDerived & data,
715 const typename Eigen::MatrixBase<ConfigVector> & qs,
716 const typename Eigen::MatrixBase<TangentVector> & vs)
const
718 calc(data,qs.derived());
720 data.v.angularRate() =
static_cast<Scalar
>(vs[
idx_v()]);
723 template<
typename Matrix6Like>
724 void calc_aba(JointDataDerived & data,
725 const Eigen::MatrixBase<Matrix6Like> & I,
726 const bool update_I)
const
728 data.U = I.col(Inertia::ANGULAR + axis);
729 data.Dinv[0] = Scalar(1)/I(Inertia::ANGULAR + axis,Inertia::ANGULAR + axis);
730 data.UDinv.noalias() = data.U * data.Dinv[0];
733 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
736 static std::string classname()
738 return std::string(
"JointModelR") + axisLabel<axis>();
740 std::string
shortname()
const {
return classname(); }
743 template<
typename NewScalar>
754 typedef JointRevoluteTpl<double,0,0> JointRX;
755 typedef JointDataRevoluteTpl<double,0,0> JointDataRX;
756 typedef JointModelRevoluteTpl<double,0,0> JointModelRX;
758 typedef JointRevoluteTpl<double,0,1> JointRY;
759 typedef JointDataRevoluteTpl<double,0,1> JointDataRY;
760 typedef JointModelRevoluteTpl<double,0,1> JointModelRY;
762 typedef JointRevoluteTpl<double,0,2> JointRZ;
763 typedef JointDataRevoluteTpl<double,0,2> JointDataRZ;
764 typedef JointModelRevoluteTpl<double,0,2> JointModelRZ;
768 #include <boost/type_traits.hpp>
772 template<
typename Scalar,
int Options,
int axis>
774 :
public integral_constant<bool,true> {};
776 template<
typename Scalar,
int Options,
int axis>
778 :
public integral_constant<bool,true> {};
780 template<
typename Scalar,
int Options,
int axis>
782 :
public integral_constant<bool,true> {};
784 template<
typename Scalar,
int Options,
int axis>
786 :
public integral_constant<bool,true> {};
789 #endif // ifndef __pinocchio_joint_revolute_hpp__