6 #ifndef __pinocchio_joint_prismatic_hpp__
7 #define __pinocchio_joint_prismatic_hpp__
9 #include "pinocchio/macros.hpp"
10 #include "pinocchio/multibody/joint/joint-base.hpp"
11 #include "pinocchio/multibody/constraint.hpp"
12 #include "pinocchio/spatial/inertia.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;
58 template<
typename _Scalar,
int _Options,
int _axis>
60 :
MotionBase < MotionPrismaticTpl<_Scalar,_Options,_axis> >
62 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
65 enum { axis = _axis };
67 typedef SpatialAxis<_axis+LINEAR> Axis;
68 typedef typename Axis::CartesianAxis3 CartesianAxis3;
70 MotionPrismaticTpl() {}
71 MotionPrismaticTpl(
const Scalar & v) : m_v(v) {}
73 inline PlainReturnType plain()
const {
return Axis() * m_v; }
75 template<
typename OtherScalar>
76 MotionPrismaticTpl __mult__(
const OtherScalar & alpha)
const
78 return MotionPrismaticTpl(alpha*m_v);
81 template<
typename Derived>
82 void addTo(MotionDense<Derived> & other)
const
84 typedef typename MotionDense<Derived>::Scalar OtherScalar;
85 other.linear()[_axis] += (OtherScalar) m_v;
88 template<
typename MotionDerived>
89 void setTo(MotionDense<MotionDerived> & other)
const
91 for(Eigen::DenseIndex k = 0; k < 3; ++k)
92 other.linear()[k] = k == axis ? m_v : (Scalar)0;
93 other.angular().setZero();
96 template<
typename S2,
int O2,
typename D2>
97 void se3Action_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
99 v.angular().setZero();
100 v.linear().noalias() = m_v * (m.rotation().col(axis));
103 template<
typename S2,
int O2>
104 MotionPlain se3Action_impl(
const SE3Tpl<S2,O2> & m)
const
107 se3Action_impl(m,res);
111 template<
typename S2,
int O2,
typename D2>
112 void se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
115 v.linear().noalias() = m_v * (m.rotation().transpose().col(axis));
118 v.angular().setZero();
121 template<
typename S2,
int O2>
122 MotionPlain se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m)
const
125 se3ActionInverse_impl(m,res);
129 template<
typename M1,
typename M2>
130 void motionAction(
const MotionDense<M1> & v, MotionDense<M2> & mout)
const
133 CartesianAxis3::alphaCross(-m_v,v.angular(),mout.linear());
136 mout.angular().setZero();
139 template<
typename M1>
140 MotionPlain motionAction(
const MotionDense<M1> & v)
const
147 Scalar & linearRate() {
return m_v; }
148 const Scalar & linearRate()
const {
return m_v; }
150 bool isEqual_impl(
const MotionPrismaticTpl & other)
const
152 return m_v == other.m_v;
160 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
161 typename MotionDerived::MotionPlain
162 operator+(
const MotionPrismaticTpl<Scalar,Options,axis> & m1,
163 const MotionDense<MotionDerived> & m2)
165 typename MotionDerived::MotionPlain res(m2);
170 template<
typename MotionDerived,
typename S2,
int O2,
int axis>
172 typename MotionDerived::MotionPlain
173 operator^(
const MotionDense<MotionDerived> & m1,
const MotionPrismaticTpl<S2,O2,axis> & m2)
175 return m2.motionAction(m1);
180 template<
typename _Scalar,
int _Options,
int _axis>
189 typedef _Scalar Scalar;
191 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
192 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
193 typedef typename Matrix3::IdentityReturnType AngularType;
194 typedef AngularType AngularRef;
195 typedef AngularType ConstAngularRef;
196 typedef Vector3 LinearType;
197 typedef const Vector3 LinearRef;
198 typedef const Vector3 ConstLinearRef;
203 template<
typename Scalar,
int Options,
int axis>
207 template<
typename _Scalar,
int _Options,
int axis>
210 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
214 typedef typename Axis::CartesianAxis3 CartesianAxis3;
217 TransformPrismaticTpl(
const Scalar & displacement)
218 : m_displacement(displacement)
221 PlainType plain()
const
223 PlainType res(PlainType::Identity());
224 res.rotation().setIdentity();
225 res.translation()[axis] = m_displacement;
230 operator PlainType()
const {
return plain(); }
232 template<
typename S2,
int O2>
233 typename SE3GroupAction<TransformPrismaticTpl>::ReturnType
234 se3action(
const SE3Tpl<S2,O2> & m)
const
236 typedef typename SE3GroupAction<TransformPrismaticTpl>::ReturnType ReturnType;
238 res.translation()[axis] += m_displacement;
243 const Scalar & displacement()
const {
return m_displacement; }
244 Scalar & displacement() {
return m_displacement; }
246 ConstLinearRef translation()
const {
return CartesianAxis3()*displacement(); };
247 AngularType rotation()
const {
return AngularType(3,3); }
249 bool isEqual(
const TransformPrismaticTpl & other)
const
251 return m_displacement == other.m_displacement;
256 Scalar m_displacement;
261 template<
typename _Scalar,
int _Options,
int axis>
264 typedef _Scalar Scalar;
265 enum { Options = _Options };
271 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
272 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
273 typedef DenseBase MatrixReturnType;
274 typedef const DenseBase ConstMatrixReturnType;
277 template<
typename Scalar,
int Options,
int axis>
279 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
281 template<
typename Scalar,
int Options,
int axis,
typename MotionDerived>
283 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
285 template<
typename Scalar,
int Options,
int axis,
typename ForceDerived>
289 template<
typename Scalar,
int Options,
int axis,
typename ForceSet>
291 {
typedef typename Eigen::MatrixBase<ForceSet>::ConstRowXpr ReturnType; };
293 template<
typename _Scalar,
int _Options,
int axis>
295 :
ConstraintBase < ConstraintPrismaticTpl <_Scalar,_Options,axis> >
297 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
301 typedef SpatialAxis<LINEAR+axis> Axis;
303 ConstraintPrismaticTpl() {};
305 template<
typename Vector1Like>
306 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const
308 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like,1);
309 assert(v.size() == 1);
310 return JointMotion(v[0]);
313 template<
typename S2,
int O2>
314 typename SE3GroupAction<ConstraintPrismaticTpl>::ReturnType
315 se3Action(
const SE3Tpl<S2,O2> & m)
const
317 typename SE3GroupAction<ConstraintPrismaticTpl>::ReturnType res;
318 MotionRef<DenseBase> v(res);
319 v.linear() = m.rotation().col(axis);
320 v.angular().setZero();
324 template<
typename S2,
int O2>
325 typename SE3GroupAction<ConstraintPrismaticTpl>::ReturnType
326 se3ActionInverse(
const SE3Tpl<S2,O2> & m)
const
328 typename SE3GroupAction<ConstraintPrismaticTpl>::ReturnType res;
329 MotionRef<DenseBase> v(res);
330 v.linear() = m.rotation().transpose().col(axis);
331 v.angular().setZero();
335 int nv_impl()
const {
return NV; }
342 template<
typename ForceDerived>
343 typename ConstraintForceOp<ConstraintPrismaticTpl,ForceDerived>::ReturnType
345 {
return f.
linear().template segment<1>(axis); }
348 template<
typename Derived>
349 typename ConstraintForceSetOp<ConstraintPrismaticTpl,Derived>::ReturnType
350 operator*(
const Eigen::MatrixBase<Derived> & F )
353 return F.row(LINEAR+axis);
365 DenseBase matrix_impl()
const
373 template<
typename MotionDerived>
374 typename MotionAlgebraAction<ConstraintPrismaticTpl,MotionDerived>::ReturnType
375 motionAction(
const MotionDense<MotionDerived> & m)
const
377 typename MotionAlgebraAction<ConstraintPrismaticTpl,MotionDerived>::ReturnType res;
378 MotionRef<DenseBase> v(res);
383 bool isEqual(
const ConstraintPrismaticTpl &)
const {
return true; }
387 template<
typename S1,
int O1,
typename S2,
int O2,
int axis>
390 typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
396 template<
typename S1,
int O1,
typename S2,
int O2>
402 static inline ReturnType run(
const Inertia & Y,
412 res << m, S1(0), S1(0), S1(0), m*z, -m*y;
418 template<
typename S1,
int O1,
typename S2,
int O2>
424 static inline ReturnType run(
const Inertia & Y,
435 res << S1(0), m, S1(0), -m*z, S1(0), m*x;
441 template<
typename S1,
int O1,
typename S2,
int O2>
447 static inline ReturnType run(
const Inertia & Y,
458 res << S1(0), S1(0), m, m*y, -m*x, S1(0);
465 template<
typename M6Like,
typename S2,
int O2,
int axis>
468 typedef typename M6Like::ConstColXpr ReturnType;
474 template<
typename M6Like,
typename Scalar,
int Options,
int axis>
479 static inline ReturnType run(
const Eigen::MatrixBase<M6Like> & Y,
482 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
483 return Y.derived().col(Inertia::LINEAR + axis);
488 template<
typename _Scalar,
int _Options,
int _axis>
491 typedef _Scalar Scalar;
500 template<
typename _Scalar,
int _Options,
int axis>
507 typedef _Scalar Scalar;
508 enum { Options = _Options };
517 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
518 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
519 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
521 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
523 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
524 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
527 template<
typename Scalar,
int Options,
int axis>
531 template<
typename Scalar,
int Options,
int axis>
535 template<
typename _Scalar,
int _Options,
int axis>
538 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
540 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
541 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
558 , UDinv(UD_t::Zero())
561 static std::string classname()
563 return std::string(
"JointDataP") + axisLabel<axis>();
565 std::string shortname()
const {
return classname(); }
569 template<
typename NewScalar,
typename Scalar,
int Options,
int axis>
575 template<
typename _Scalar,
int _Options,
int axis>
577 :
public JointModelBase< JointModelPrismaticTpl<_Scalar,_Options,axis> >
579 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
581 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
587 using Base::setIndexes;
589 JointDataDerived createData()
const {
return JointDataDerived(); }
591 const std::vector<bool> hasConfigurationLimit()
const
596 const std::vector<bool> hasConfigurationLimitInTangent()
const
601 template<
typename ConfigVector>
602 void calc(JointDataDerived & data,
603 const typename Eigen::MatrixBase<ConfigVector> & qs)
const
605 typedef typename ConfigVector::Scalar Scalar;
606 const Scalar & q = qs[
idx_q()];
607 data.M.displacement() = q;
610 template<
typename ConfigVector,
typename TangentVector>
611 void calc(JointDataDerived & data,
612 const typename Eigen::MatrixBase<ConfigVector> & qs,
613 const typename Eigen::MatrixBase<TangentVector> & vs)
const
615 calc(data,qs.derived());
617 typedef typename TangentVector::Scalar S2;
618 const S2 & v = vs[
idx_v()];
619 data.v.linearRate() = v;
622 template<
typename Matrix6Like>
623 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const
625 data.U = I.col(Inertia::LINEAR + axis);
626 data.Dinv[0] = Scalar(1)/I(Inertia::LINEAR + axis, Inertia::LINEAR + axis);
627 data.UDinv.noalias() = data.U * data.Dinv[0];
630 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
633 static std::string classname()
635 return std::string(
"JointModelP") + axisLabel<axis>();
637 std::string shortname()
const {
return classname(); }
640 template<
typename NewScalar>
651 typedef JointPrismaticTpl<double,0,0> JointPX;
652 typedef JointDataPrismaticTpl<double,0,0> JointDataPX;
653 typedef JointModelPrismaticTpl<double,0,0> JointModelPX;
655 typedef JointPrismaticTpl<double,0,1> JointPY;
656 typedef JointDataPrismaticTpl<double,0,1> JointDataPY;
657 typedef JointModelPrismaticTpl<double,0,1> JointModelPY;
659 typedef JointPrismaticTpl<double,0,2> JointPZ;
660 typedef JointDataPrismaticTpl<double,0,2> JointDataPZ;
661 typedef JointModelPrismaticTpl<double,0,2> JointModelPZ;
665 #include <boost/type_traits.hpp>
669 template<
typename Scalar,
int Options,
int axis>
671 :
public integral_constant<bool,true> {};
673 template<
typename Scalar,
int Options,
int axis>
675 :
public integral_constant<bool,true> {};
677 template<
typename Scalar,
int Options,
int axis>
679 :
public integral_constant<bool,true> {};
681 template<
typename Scalar,
int Options,
int axis>
683 :
public integral_constant<bool,true> {};
686 #endif // ifndef __pinocchio_joint_prismatic_hpp__