5 #ifndef __pinocchio_multibody_joint_mimic_hpp__
6 #define __pinocchio_multibody_joint_mimic_hpp__
8 #include "pinocchio/macros.hpp"
9 #include "pinocchio/multibody/joint/joint-base.hpp"
14 template<
class Constra
int>
15 struct ScaledJointMotionSubspace;
17 template<
class Constra
int>
38 typedef ReducedSquaredMatrix StDiagonalMatrixSOperationReturnType;
41 template<
class Constra
int>
44 typedef typename SE3GroupAction<Constraint>::ReturnType ReturnType;
47 template<
class Constra
int,
typename MotionDerived>
50 typedef typename MotionAlgebraAction<Constraint, MotionDerived>::ReturnType ReturnType;
53 template<
class Constra
int,
typename ForceDerived>
56 typedef typename Constraint::Scalar Scalar;
57 typedef typename ConstraintForceOp<Constraint, ForceDerived>::ReturnType OriginalReturnType;
59 typedef typename ScalarMatrixProduct<Scalar, OriginalReturnType>::type IdealReturnType;
60 typedef Eigen::Matrix<
62 IdealReturnType::RowsAtCompileTime,
63 IdealReturnType::ColsAtCompileTime,
68 template<
class Constra
int,
typename ForceSet>
71 typedef typename Constraint::Scalar Scalar;
72 typedef typename ConstraintForceSetOp<Constraint, ForceSet>::ReturnType OriginalReturnType;
73 typedef typename ScalarMatrixProduct<Scalar, OriginalReturnType>::type IdealReturnType;
74 typedef Eigen::Matrix<
77 ForceSet::ColsAtCompileTime,
78 Constraint::Options | Eigen::RowMajor>
82 template<
class Constra
int>
85 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
95 typedef typename SE3GroupAction<Constraint>::ReturnType SE3ActionReturnType;
102 : m_scaling_factor(scaling_factor)
107 : m_constraint(constraint)
108 , m_scaling_factor(scaling_factor)
113 : m_constraint(other.m_constraint)
114 , m_scaling_factor(other.m_scaling_factor)
120 m_constraint = other.m_constraint;
121 m_scaling_factor = other.m_scaling_factor;
125 template<
typename VectorLike>
126 JointMotion __mult__(
const Eigen::MatrixBase<VectorLike> & v)
const
128 assert(v.size() == nv());
129 JointMotion jm = m_constraint * v;
130 return jm * m_scaling_factor;
133 template<
typename S1,
int O1>
136 SE3ActionReturnType res = m_constraint.se3Action(m);
137 return m_scaling_factor * res;
140 template<
typename S1,
int O1>
141 SE3ActionReturnType se3ActionInverse(
const SE3Tpl<S1, O1> & m)
const
143 SE3ActionReturnType res = m_constraint.se3ActionInverse(m);
144 return m_scaling_factor * res;
149 return m_constraint.nv();
160 template<
typename Derived>
161 typename ConstraintForceOp<ScaledJointMotionSubspace, Derived>::ReturnType
167 typename ConstraintForceOp<ScaledJointMotionSubspace, Derived>::ReturnType ReturnType;
168 return ReturnType(ref.m_scaling_factor * (ref.m_constraint.transpose() * f));
172 template<
typename Derived>
173 typename ConstraintForceSetOp<ScaledJointMotionSubspace, Derived>::ReturnType
177 typename ConstraintForceSetOp<ScaledJointMotionSubspace, Derived>::ReturnType ReturnType;
178 return ReturnType(ref.m_scaling_factor * (ref.m_constraint.transpose() * F));
183 TransposeConst transpose()
const
185 return TransposeConst(*
this);
188 DenseBase matrix_impl()
const
190 DenseBase S = m_scaling_factor * m_constraint.matrix();
194 template<
typename MotionDerived>
195 typename MotionAlgebraAction<ScaledJointMotionSubspace, MotionDerived>::ReturnType
196 motionAction(
const MotionDense<MotionDerived> & m)
const
198 typedef typename MotionAlgebraAction<ScaledJointMotionSubspace, MotionDerived>::ReturnType
200 ReturnType res = m_scaling_factor * m_constraint.motionAction(m);
204 inline const Scalar & scaling()
const
206 return m_scaling_factor;
208 inline Scalar & scaling()
210 return m_scaling_factor;
213 inline const Constraint & constraint()
const
217 inline Constraint & constraint()
222 bool isEqual(
const ScaledJointMotionSubspace & other)
const
224 return internal::comparison_eq(m_constraint, other.m_constraint)
225 && internal::comparison_eq(m_scaling_factor, other.m_scaling_factor);
229 Constraint m_constraint;
230 Scalar m_scaling_factor;
235 template<
typename ParentConstra
int>
243 const Constraint & constraint_ = constraint.derived();
244 return (constraint_.constraint().transpose() * constraint_.constraint())
245 * (constraint_.scaling() * constraint_.scaling());
250 template<
typename S1,
int O1,
typename _Constra
int>
255 typedef typename Constraint::Scalar Scalar;
259 typedef OriginalReturnType ReturnType;
265 template<
typename S1,
int O1,
typename _Constra
int>
272 static inline ReturnType run(
const Inertia & Y,
const Constraint & scaled_constraint)
274 return scaled_constraint.scaling() * (Y * scaled_constraint.constraint());
279 template<
typename M6Like,
typename _Constra
int>
283 typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(OriginalReturnType) ReturnType;
289 template<
typename M6Like,
typename _Constra
int>
296 static inline ReturnType
297 run(
const Eigen::MatrixBase<M6Like> & Y,
const Constraint & scaled_constraint)
299 return scaled_constraint.scaling() * (Y.derived() * scaled_constraint.constraint());
304 template<
class Jo
int>
306 template<
class Jo
intModel>
308 template<
class Jo
intData>
311 template<
class Jo
int>
344 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
347 template<
class Jo
int>
354 template<
class Jo
int>
361 template<
class Jo
intData>
364 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
369 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
372 : m_scaling((Scalar)0)
373 ,
joint_q(ConfigVector_t::Zero())
374 ,
joint_v(TangentVector_t::Zero())
385 : m_jdata_ref(jdata.derived())
387 , S(m_jdata_ref.S, scaling)
393 m_jdata_ref = other.m_jdata_ref;
394 m_scaling = other.m_scaling;
397 S = Constraint_t(m_jdata_ref.S, other.m_scaling);
404 return Base::isEqual(other) && internal::comparison_eq(m_jdata_ref, other.m_jdata_ref)
405 && internal::comparison_eq(m_scaling, other.m_scaling)
410 static std::string classname()
412 return std::string(
"JointDataMimic<") + JointData::classname() + std::string(
">");
415 std::string shortname()
const
417 return std::string(
"JointDataMimic<") + m_jdata_ref.shortname() + std::string(
">");
421 ConfigVectorTypeConstRef joint_q_accessor()
const
425 ConfigVectorTypeRef joint_q_accessor()
430 TangentVectorTypeConstRef joint_v_accessor()
const
434 TangentVectorTypeRef joint_v_accessor()
439 ConstraintTypeConstRef S_accessor()
const
443 ConstraintTypeRef S_accessor()
448 TansformTypeConstRef M_accessor()
const
450 return m_jdata_ref.M;
452 TansformTypeRef M_accessor()
454 return m_jdata_ref.M;
457 MotionTypeConstRef v_accessor()
const
459 return m_jdata_ref.v;
461 MotionTypeRef v_accessor()
463 return m_jdata_ref.v;
466 BiasTypeConstRef c_accessor()
const
468 return m_jdata_ref.c;
470 BiasTypeRef c_accessor()
472 return m_jdata_ref.c;
475 UTypeConstRef U_accessor()
const
477 return m_jdata_ref.U;
479 UTypeRef U_accessor()
481 return m_jdata_ref.U;
484 DTypeConstRef Dinv_accessor()
const
486 return m_jdata_ref.Dinv;
488 DTypeRef Dinv_accessor()
490 return m_jdata_ref.Dinv;
493 UDTypeConstRef UDinv_accessor()
const
495 return m_jdata_ref.UDinv;
497 UDTypeRef UDinv_accessor()
499 return m_jdata_ref.UDinv;
502 DTypeConstRef StU_accessor()
const
504 return m_jdata_ref.StU;
506 DTypeRef StU_accessor()
508 return m_jdata_ref.StU;
511 template<
class Jo
intModel>
523 const Scalar & scaling()
const
532 ConfigVector_t & jointConfiguration()
536 const ConfigVector_t & jointConfiguration()
const
541 TangentVector_t & jointVelocity()
545 const TangentVector_t & jointVelocity()
const
565 template<
typename NewScalar,
typename Jo
intModel>
572 template<
class Jo
intModel>
575 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
579 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
587 using Base::setIndexes;
595 : m_jmodel_ref(jmodel.derived())
603 return *
static_cast<Base *
>(
this);
605 const Base & base()
const
607 return *
static_cast<const Base *
>(
this);
610 inline int nq_impl()
const
614 inline int nv_impl()
const
619 inline int idx_q_impl()
const
621 return m_jmodel_ref.idx_q();
623 inline int idx_v_impl()
const
625 return m_jmodel_ref.idx_v();
628 void setIndexes_impl(JointIndex
id,
int ,
int )
631 Base::i_q = m_jmodel_ref.idx_q();
632 Base::i_v = m_jmodel_ref.idx_v();
635 JointDataDerived createData()
const
637 return JointDataDerived(m_jmodel_ref.createData(), scaling());
640 const std::vector<bool> hasConfigurationLimit()
const
642 return m_jmodel_ref.hasConfigurationLimit();
645 const std::vector<bool> hasConfigurationLimitInTangent()
const
647 return m_jmodel_ref.hasConfigurationLimitInTangent();
650 template<
typename ConfigVector>
651 EIGEN_DONT_INLINE
void
652 calc(JointDataDerived & jdata,
const typename Eigen::MatrixBase<ConfigVector> & qs)
const
656 AffineTransform::run(qs.head(m_jmodel_ref.nq()), m_scaling, m_offset, jdata.joint_q);
657 m_jmodel_ref.calc(jdata.m_jdata_ref, jdata.joint_q);
660 template<
typename TangentVector>
661 EIGEN_DONT_INLINE
void calc(
662 JointDataDerived & jdata,
664 const typename Eigen::MatrixBase<TangentVector> & vs)
const
666 jdata.joint_v = m_scaling * vs.head(m_jmodel_ref.nv());
667 m_jmodel_ref.calc(jdata.m_jdata_ref, blank, jdata.joint_v);
670 template<
typename ConfigVector,
typename TangentVector>
671 EIGEN_DONT_INLINE
void calc(
672 JointDataDerived & jdata,
673 const typename Eigen::MatrixBase<ConfigVector> & qs,
674 const typename Eigen::MatrixBase<TangentVector> & vs)
const
678 AffineTransform::run(qs.head(m_jmodel_ref.nq()), m_scaling, m_offset, jdata.joint_q);
679 jdata.joint_v = m_scaling * vs.head(m_jmodel_ref.nv());
680 m_jmodel_ref.calc(jdata.m_jdata_ref, jdata.joint_q, jdata.joint_v);
683 template<
typename VectorLike,
typename Matrix6Like>
685 JointDataDerived & data,
686 const Eigen::MatrixBase<VectorLike> & armature,
687 const Eigen::MatrixBase<Matrix6Like> & I,
688 const bool update_I)
const
691 m_jmodel_ref.calc_aba(
692 data.m_jdata_ref, armature, PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I), update_I);
695 static std::string classname()
697 return std::string(
"JointModelMimic<") + JointModel::classname() + std::string(
">");
701 std::string shortname()
const
703 return std::string(
"JointModelMimic<") + m_jmodel_ref.shortname() + std::string(
">");
707 template<
typename NewScalar>
713 m_jmodel_ref.template cast<NewScalar>(), pinocchio::cast<NewScalar>(m_scaling),
714 pinocchio::cast<NewScalar>(m_offset));
715 res.setIndexes(
id(), idx_q(), idx_v());
723 JointModel & jmodel()
728 const Scalar & scaling()
const
737 const Scalar & offset()
const
748 JointModel m_jmodel_ref;
749 Scalar m_scaling, m_offset;
755 typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
756 jointConfigSelector_impl(
const Eigen::MatrixBase<D> & a)
const
758 return SizeDepType<NQ>::segment(a.derived(), m_jmodel_ref.idx_q(), m_jmodel_ref.nq());
763 typename SizeDepType<NQ>::template SegmentReturn<D>::Type
764 jointConfigSelector_impl(Eigen::MatrixBase<D> & a)
const
766 return SizeDepType<NQ>::segment(a.derived(), m_jmodel_ref.idx_q(), m_jmodel_ref.nq());
772 typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
773 jointVelocitySelector_impl(
const Eigen::MatrixBase<D> & a)
const
775 return SizeDepType<NV>::segment(a.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv());
780 typename SizeDepType<NV>::template SegmentReturn<D>::Type
781 jointVelocitySelector_impl(Eigen::MatrixBase<D> & a)
const
783 return SizeDepType<NV>::segment(a.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv());
789 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
790 jointCols_impl(
const Eigen::MatrixBase<D> & A)
const
792 return SizeDepType<NV>::middleCols(A.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv());
797 typename SizeDepType<NV>::template ColsReturn<D>::Type
798 jointCols_impl(Eigen::MatrixBase<D> & A)
const
800 return SizeDepType<NV>::middleCols(A.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv());
806 typename SizeDepType<NV>::template RowsReturn<D>::ConstType
807 jointRows_impl(
const Eigen::MatrixBase<D> & A)
const
809 return SizeDepType<NV>::middleRows(A.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv());
814 typename SizeDepType<NV>::template RowsReturn<D>::Type
815 jointRows_impl(Eigen::MatrixBase<D> & A)
const
817 return SizeDepType<NV>::middleRows(A.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv());
824 typename SizeDepType<NV>::template BlockReturn<D>::ConstType
828 Mat.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv(),
838 Mat.derived(), m_jmodel_ref.idx_v(), m_jmodel_ref.idx_v(), m_jmodel_ref.nv(),
Main pinocchio namespace.
JointIndex id(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdVisitor to get the index of the joint in the kinematic chain.
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type....
Return type of the Constraint::Transpose * Force operation.
Return type of the Constraint::Transpose * ForceSet operation.
bool isEqual(const JointDataBase< JointDataMimic< JointData > > &other) const
 
ConfigVector_t joint_q
Transform configuration vector.
TangentVector_t joint_v
Transform velocity vector.
CastType< NewScalar, JointModelMimic >::type cast() const
SizeDepType< NV >::template BlockReturn< D >::ConstType jointBlock_impl(const Eigen::MatrixBase< D > &Mat) const
Returns a block of dimension nv()xnv() located at position idx_v(),idx_v() in the matrix Mat.
Return type of the ation of a Motion onto an object of type D.
Forward declaration of the multiplication operation return type. Should be overloaded,...
ConstraintForceSetOp< ScaledJointMotionSubspace, Derived >::ReturnType operator*(const Eigen::MatrixBase< Derived > &F) const
[CRBA] MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
Common traits structure to fully define base classes for CRTP.