6 #ifndef __pinocchio_joint_revolute_unaligned_hpp__
7 #define __pinocchio_joint_revolute_unaligned_hpp__
9 #include "pinocchio/fwd.hpp"
10 #include "pinocchio/multibody/joint/joint-base.hpp"
11 #include "pinocchio/multibody/constraint.hpp"
12 #include "pinocchio/spatial/inertia.hpp"
13 #include "pinocchio/math/matrix.hpp"
21 template<
typename Scalar,
int Options>
27 template<
typename Scalar,
int Options,
typename MotionDerived>
33 template<
typename _Scalar,
int _Options>
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>
60 :
MotionBase< MotionRevoluteUnalignedTpl<_Scalar,_Options> >
62 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
67 template<
typename Vector3Like,
typename OtherScalar>
68 MotionRevoluteUnalignedTpl(
const Eigen::MatrixBase<Vector3Like> & axis,
69 const OtherScalar & w)
74 inline PlainReturnType plain()
const
76 return PlainReturnType(PlainReturnType::Vector3::Zero(),
80 template<
typename OtherScalar>
81 MotionRevoluteUnalignedTpl __mult__(
const OtherScalar & alpha)
const
83 return MotionRevoluteUnalignedTpl(m_axis,alpha*m_w);
86 template<
typename MotionDerived>
87 inline void addTo(MotionDense<MotionDerived> & v)
const
89 v.angular() += m_axis*m_w;
92 template<
typename Derived>
93 void setTo(MotionDense<Derived> & other)
const
95 other.linear().setZero();
96 other.angular().noalias() = m_axis*m_w;
99 template<
typename S2,
int O2,
typename D2>
100 void se3Action_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
103 v.angular().noalias() = m_w * m.rotation() * m_axis;
106 v.linear().noalias() = m.translation().cross(v.angular());
109 template<
typename S2,
int O2>
110 MotionPlain se3Action_impl(
const SE3Tpl<S2,O2> & m)
const
113 se3Action_impl(m,res);
117 template<
typename S2,
int O2,
typename D2>
118 void se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m, MotionDense<D2> & v)
const
123 v3_tmp.noalias() = m_axis.cross(m.translation());
125 v.linear().noalias() = m.rotation().transpose() * v3_tmp;
128 v.angular().noalias() = m.rotation().transpose() * m_axis;
132 template<
typename S2,
int O2>
133 MotionPlain se3ActionInverse_impl(
const SE3Tpl<S2,O2> & m)
const
136 se3ActionInverse_impl(m,res);
140 template<
typename M1,
typename M2>
141 void motionAction(
const MotionDense<M1> & v, MotionDense<M2> & mout)
const
144 mout.linear().noalias() = v.linear().cross(m_axis);
145 mout.linear() *= m_w;
148 mout.angular().noalias() = v.angular().cross(m_axis);
149 mout.angular() *= m_w;
152 template<
typename M1>
153 MotionPlain motionAction(
const MotionDense<M1> & v)
const
160 bool isEqual_impl(
const MotionRevoluteUnalignedTpl & other)
const
162 return m_axis == other.m_axis && m_w == other.m_w;
165 const Scalar & angularRate()
const {
return m_w; }
166 Scalar & angularRate() {
return m_w; }
168 const Vector3 & axis()
const {
return m_axis; }
169 Vector3 & axis() {
return m_axis; }
177 template<
typename S1,
int O1,
typename MotionDerived>
178 inline typename MotionDerived::MotionPlain
179 operator+(
const MotionRevoluteUnalignedTpl<S1,O1> & m1,
180 const MotionDense<MotionDerived> & m2)
182 typename MotionDerived::MotionPlain res(m2);
187 template<
typename MotionDerived,
typename S2,
int O2>
188 inline typename MotionDerived::MotionPlain
189 operator^(
const MotionDense<MotionDerived> & m1,
190 const MotionRevoluteUnalignedTpl<S2,O2> & m2)
192 return m2.motionAction(m1);
197 template<
typename _Scalar,
int _Options>
200 typedef _Scalar Scalar;
201 enum { Options = _Options };
207 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
208 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
209 typedef DenseBase MatrixReturnType;
210 typedef const DenseBase ConstMatrixReturnType;
212 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
215 template<
typename Scalar,
int Options>
217 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
219 template<
typename Scalar,
int Options,
typename MotionDerived>
221 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
223 template<
typename Scalar,
int Options,
typename ForceDerived>
230 template<
typename Scalar,
int Options,
typename ForceSet>
235 typename Eigen::MatrixBase<const ForceSet>::template NRowsBlockXpr<3>::Type
239 template<
typename _Scalar,
int _Options>
241 :
ConstraintBase< ConstraintRevoluteUnalignedTpl<_Scalar,_Options> >
243 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
248 typedef typename traits<ConstraintRevoluteUnalignedTpl>::Vector3 Vector3;
250 ConstraintRevoluteUnalignedTpl() {}
252 template<
typename Vector3Like>
253 ConstraintRevoluteUnalignedTpl(
const Eigen::MatrixBase<Vector3Like> & axis)
257 template<
typename Vector1Like>
258 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const
260 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like,1);
261 return JointMotion(m_axis,v[0]);
264 template<
typename S1,
int O1>
265 typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType
266 se3Action(
const SE3Tpl<S1,O1> & m)
const
268 typedef typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType ReturnType;
272 res.template segment<3>(ANGULAR).noalias() = m.rotation() * m_axis;
273 res.template segment<3>(LINEAR).noalias() = m.translation().cross(res.template segment<3>(ANGULAR));
277 template<
typename S1,
int O1>
278 typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType
279 se3ActionInverse(
const SE3Tpl<S1,O1> & m)
const
281 typedef typename SE3GroupAction<ConstraintRevoluteUnalignedTpl>::ReturnType ReturnType;
284 res.template segment<3>(ANGULAR).noalias() = m.rotation().transpose() * m_axis;
285 res.template segment<3>(LINEAR).noalias() = -m.rotation().transpose() * m.translation().cross(m_axis);
289 int nv_impl()
const {
return NV; }
296 template<
typename ForceDerived>
297 typename ConstraintForceOp<ConstraintRevoluteUnalignedTpl,ForceDerived>::ReturnType
300 typedef typename ConstraintForceOp<ConstraintRevoluteUnalignedTpl,ForceDerived>::ReturnType ReturnType;
302 res[0] = ref.axis().dot(f.
angular());
307 template<
typename ForceSet>
308 typename ConstraintForceSetOp<ConstraintRevoluteUnalignedTpl,ForceSet>::ReturnType
309 operator*(
const Eigen::MatrixBase<ForceSet> & F)
311 EIGEN_STATIC_ASSERT(ForceSet::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
313 return ref.axis().transpose() * F.template middleRows<3>(ANGULAR);
326 DenseBase matrix_impl()
const
329 S.template segment<3>(LINEAR).setZero();
330 S.template segment<3>(ANGULAR) = m_axis;
334 template<
typename MotionDerived>
335 typename MotionAlgebraAction<ConstraintRevoluteUnalignedTpl,MotionDerived>::ReturnType
336 motionAction(
const MotionDense<MotionDerived> & m)
const
338 const typename MotionDerived::ConstLinearType v = m.linear();
339 const typename MotionDerived::ConstAngularType w = m.angular();
342 res.template segment<3>(LINEAR).noalias() = v.cross(m_axis);
343 res.template segment<3>(ANGULAR).noalias() = w.cross(m_axis);
348 const Vector3 & axis()
const {
return m_axis; }
349 Vector3 & axis() {
return m_axis; }
351 bool isEqual(
const ConstraintRevoluteUnalignedTpl & other)
const
353 return m_axis == other.m_axis;
362 template<
typename S1,
int O1,
typename S2,
int O2>
365 typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
371 template<
typename S1,
int O1,
typename S2,
int O2>
377 static inline ReturnType run(
const Inertia & Y,
383 const typename Inertia::Scalar & m = Y.mass();
384 const typename Inertia::Vector3 & c = Y.lever();
385 const typename Inertia::Symmetric3 & I = Y.inertia();
387 res.template segment<3>(Inertia::LINEAR) = -m*c.cross(cru.axis());
388 res.template segment<3>(Inertia::ANGULAR).noalias() = I*cru.axis();
389 res.template segment<3>(Inertia::ANGULAR) += c.cross(res.template segment<3>(Inertia::LINEAR));
396 template<
typename M6Like,
typename Scalar,
int Options>
400 typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
403 typedef typename Constraint::Vector3 Vector3;
410 template<
typename M6Like,
typename Scalar,
int Options>
416 static inline ReturnType run(
const Eigen::MatrixBase<M6Like> & Y,
419 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
420 return Y.derived().template middleCols<3>(Constraint::ANGULAR) * cru.axis();
427 template<
typename _Scalar,
int _Options>
434 typedef _Scalar Scalar;
435 enum { Options = _Options };
444 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
445 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
446 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
448 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
450 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
451 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
455 template<
typename Scalar,
int Options>
459 template<
typename Scalar,
int Options>
463 template<
typename _Scalar,
int _Options>
465 :
public JointDataBase< JointDataRevoluteUnalignedTpl<_Scalar,_Options> >
467 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
469 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
470 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
483 : M(Transformation_t::Identity())
484 , S(Constraint_t::Vector3::Zero())
485 , v(Constraint_t::Vector3::Zero(),(Scalar)0)
488 , UDinv(UD_t::Zero())
491 template<
typename Vector3Like>
492 JointDataRevoluteUnalignedTpl(
const Eigen::MatrixBase<Vector3Like> & axis)
493 : M(Transformation_t::Identity())
495 , v(axis,(Scalar)NAN)
498 , UDinv(UD_t::Zero())
501 static std::string classname() {
return std::string(
"JointDataRevoluteUnaligned"); }
502 std::string shortname()
const {
return classname(); }
506 PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelRevoluteUnalignedTpl);
507 template<
typename _Scalar,
int _Options>
508 struct JointModelRevoluteUnalignedTpl
509 :
public JointModelBase< JointModelRevoluteUnalignedTpl<_Scalar,_Options> >
511 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
512 typedef JointRevoluteUnalignedTpl<_Scalar,_Options> JointDerived;
513 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
514 typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
516 typedef JointModelBase<JointModelRevoluteUnalignedTpl> Base;
520 using Base::setIndexes;
522 JointModelRevoluteUnalignedTpl():
axis(Vector3::UnitX()) {}
524 JointModelRevoluteUnalignedTpl(
const Scalar & x,
533 template<
typename Vector3Like>
534 JointModelRevoluteUnalignedTpl(
const Eigen::MatrixBase<Vector3Like> &
axis)
537 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
541 JointDataDerived createData()
const {
return JointDataDerived(
axis); }
544 bool isEqual(
const JointModelRevoluteUnalignedTpl & other)
const
546 return Base::isEqual(other) &&
axis == other.axis;
549 const std::vector<bool> hasConfigurationLimit()
const
554 const std::vector<bool> hasConfigurationLimitInTangent()
const
559 template<
typename ConfigVector>
560 void calc(JointDataDerived & data,
561 const typename Eigen::MatrixBase<ConfigVector> & qs)
const
563 typedef typename ConfigVector::Scalar OtherScalar;
564 typedef Eigen::AngleAxis<Scalar> AngleAxis;
566 const OtherScalar & q = qs[
idx_q()];
571 template<
typename ConfigVector,
typename TangentVector>
572 void calc(JointDataDerived & data,
573 const typename Eigen::MatrixBase<ConfigVector> & qs,
574 const typename Eigen::MatrixBase<TangentVector> & vs)
const
576 calc(data,qs.derived());
578 data.v.angularRate() =
static_cast<Scalar
>(vs[
idx_v()]);
581 template<
typename Matrix6Like>
582 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const
584 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) *
axis;
585 data.Dinv[0] = (Scalar)(1)/
axis.dot(data.U.template segment<3>(Motion::ANGULAR));
586 data.UDinv.noalias() = data.U * data.Dinv;
589 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
592 static std::string classname() {
return std::string(
"JointModelRevoluteUnaligned"); }
593 std::string shortname()
const {
return classname(); }
596 template<
typename NewScalar>
600 ReturnType res(
axis.template cast<NewScalar>());
615 #include <boost/type_traits.hpp>
619 template<
typename Scalar,
int Options>
621 :
public integral_constant<bool,true> {};
623 template<
typename Scalar,
int Options>
625 :
public integral_constant<bool,true> {};
627 template<
typename Scalar,
int Options>
629 :
public integral_constant<bool,true> {};
631 template<
typename Scalar,
int Options>
633 :
public integral_constant<bool,true> {};
637 #endif // ifndef __pinocchio_joint_revolute_unaligned_hpp__