5 #ifndef __pinocchio_multibody_joint_composite_hpp__
6 #define __pinocchio_multibody_joint_composite_hpp__
8 #include "pinocchio/multibody/joint/fwd.hpp"
9 #include "pinocchio/multibody/joint/joint-collection.hpp"
10 #include "pinocchio/multibody/joint/joint-basic-visitors.hpp"
11 #include "pinocchio/container/aligned-vector.hpp"
12 #include "pinocchio/spatial/act-on-set.hpp"
14 #include "pinocchio/serialization/fwd.hpp"
19 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
22 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
25 typedef _Scalar Scalar;
32 NVExtended = Eigen::Dynamic
35 typedef JointCollectionTpl<Scalar, Options> JointCollection;
44 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> U_t;
45 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> D_t;
46 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> UD_t;
48 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> ConfigVector_t;
49 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> TangentVector_t;
51 typedef boost::mpl::false_ is_mimicable_t;
53 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
56 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
60 typedef _Scalar Scalar;
63 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
67 typedef _Scalar Scalar;
70 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
72 :
public JointDataBase<JointDataCompositeTpl<_Scalar, _Options, JointCollectionTpl>>
74 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
79 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
81 typedef JointCollectionTpl<Scalar, Options> JointCollection;
92 , joint_q(ConfigVector_t::Zero(0))
93 , joint_v(TangentVector_t::Zero(0))
95 , M(Transformation_t::Identity())
107 , iMlast(joint_data.size())
108 , pjMi(joint_data.size())
109 , joint_q(ConfigVector_t::Zero(
nq))
110 , joint_v(TangentVector_t::Zero(
nv))
111 , S(Constraint_t::Zero(
nv))
112 , M(Transformation_t::Identity())
113 , v(Motion_t::Zero())
114 , c(Motion_t::Zero())
115 , U(U_t::Zero(6,
nv))
116 , Dinv(D_t::Zero(
nv,
nv))
117 , UDinv(UD_t::Zero(6,
nv))
118 , StU(D_t::Zero(
nv,
nv))
131 ConfigVector_t joint_q;
132 TangentVector_t joint_v;
145 static std::string classname()
147 return std::string(
"JointDataComposite");
149 std::string shortname()
const
154 void disp(std::ostream & os)
const
156 os <<
"JointDataComposite containing following models:\n";
157 for (
typename JointDataVector::const_iterator it =
joints.begin(); it !=
joints.end(); ++it)
158 os <<
" " << it->shortname() << std::endl;
166 template<
typename S,
int O>
class JointCollectionTpl>
172 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
174 :
public JointModelBase<JointModelCompositeTpl<_Scalar, _Options, JointCollectionTpl>>
176 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
182 typedef JointCollectionTpl<Scalar, Options> JointCollection;
194 using Base::idx_vExtended;
197 using Base::nvExtended;
198 using Base::setIndexes;
221 jointPlacements.reserve(size);
236 template<
typename Jo
intModel>
240 , jointPlacements(1, placement)
243 , m_nvExtended(jmodel.nvExtended())
262 , jointPlacements(other.jointPlacements)
265 , m_nvExtended(other.m_nvExtended)
284 template<
typename Jo
intModel>
289 jointPlacements.push_back(placement);
293 m_nvExtended += jmodel.nvExtended();
301 JointDataDerived createData()
const
303 typename JointDataDerived::JointDataVector jdata(
joints.size());
304 for (
int i = 0; i < (int)
joints.size(); ++i)
306 ::pinocchio::createData<Scalar, Options, JointCollectionTpl>(
joints[(
size_t)i]);
307 return JointDataDerived(jdata,
nq(),
nv());
310 const std::vector<bool> hasConfigurationLimit()
const
312 std::vector<bool> vec;
313 for (
size_t i = 0; i <
joints.size(); ++i)
315 const std::vector<bool> & joint_cf_limit =
joints[i].hasConfigurationLimit();
316 vec.insert(vec.end(), joint_cf_limit.begin(), joint_cf_limit.end());
321 const std::vector<bool> hasConfigurationLimitInTangent()
const
323 std::vector<bool> vec;
324 for (
size_t i = 0; i <
joints.size(); ++i)
326 const std::vector<bool> & joint_cf_limit =
joints[i].hasConfigurationLimitInTangent();
327 vec.insert(vec.end(), joint_cf_limit.begin(), joint_cf_limit.end());
332 template<
typename,
int,
template<
typename S,
int O>
class,
typename>
333 friend struct JointCompositeCalcZeroOrderStep;
335 template<
typename ConfigVectorType>
336 void calc(JointDataDerived & data,
const Eigen::MatrixBase<ConfigVectorType> & qs)
const;
338 template<
typename,
int,
template<
typename S,
int O>
class,
typename,
typename>
339 friend struct JointCompositeCalcFirstOrderStep;
341 template<
typename ConfigVectorType,
typename TangentVectorType>
343 JointDataDerived & data,
344 const Eigen::MatrixBase<ConfigVectorType> & qs,
345 const Eigen::MatrixBase<TangentVectorType> & vs)
const;
347 template<
typename TangentVectorType>
349 JointDataDerived & data,
351 const Eigen::MatrixBase<TangentVectorType> & vs)
const;
353 template<
typename VectorLike,
typename Matrix6Like>
355 JointDataDerived & data,
356 const Eigen::MatrixBase<VectorLike> & armature,
357 const Eigen::MatrixBase<Matrix6Like> & I,
358 const bool update_I)
const
360 data.U.noalias() = I * data.S.matrix();
361 data.StU.noalias() = data.S.matrix().transpose() * data.U;
362 data.StU.diagonal() += armature;
364 internal::PerformStYSInversion<Scalar>::run(data.StU, data.Dinv);
365 data.UDinv.noalias() = data.U * data.Dinv;
368 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
379 int nvExtended_impl()
const
389 Base::setIndexes_impl(
id, q, v, vExtended);
393 static std::string classname()
395 return std::string(
"JointModelComposite");
397 std::string shortname()
const
402 JointModelCompositeTpl & operator=(
const JointModelCompositeTpl & other)
407 m_nvExtended = other.m_nvExtended;
415 jointPlacements = other.jointPlacements;
422 bool isEqual(
const JointModelCompositeTpl & other)
const
424 return Base::isEqual(other) && internal::comparison_eq(
nq(), other.nq())
425 && internal::comparison_eq(
nv(), other.nv())
426 && internal::comparison_eq(nvExtended(), other.nvExtended())
427 && internal::comparison_eq(
m_idx_q, other.m_idx_q)
428 && internal::comparison_eq(
m_idx_v, other.m_idx_v)
430 && internal::comparison_eq(
m_nqs, other.m_nqs)
431 && internal::comparison_eq(
m_nvs, other.m_nvs)
432 && internal::comparison_eq(
m_nvExtendeds, other.m_nvExtendeds)
433 && internal::comparison_eq(
joints, other.joints)
434 && internal::comparison_eq(jointPlacements, other.jointPlacements)
435 && internal::comparison_eq(
njoints, other.njoints);
439 template<
typename NewScalar>
443 ReturnType res((
size_t)
njoints);
444 res.setIndexes(
id(), idx_q(), idx_v(), idx_vExtended());
447 res.m_nvExtended = m_nvExtended;
456 res.joints.resize(
joints.size());
457 res.jointPlacements.resize(jointPlacements.size());
458 for (
size_t k = 0; k < jointPlacements.size(); ++k)
460 res.joints[k] =
joints[k].template cast<NewScalar>();
461 res.jointPlacements[k] = jointPlacements[k].template cast<NewScalar>();
475 JointMappedConfigSelector(
const Eigen::MatrixBase<D> & a)
const
477 return a.segment(Base::i_q,
nq());
481 JointMappedConfigSelector(Eigen::MatrixBase<D> & a)
const
483 return a.segment(Base::i_q,
nq());
487 typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
488 jointConfigSelector(
const Eigen::MatrixBase<D> & a)
const
490 return a.segment(Base::i_q, nq());
493 typename SizeDepType<NQ>::template SegmentReturn<D>::Type
494 jointConfigSelector(Eigen::MatrixBase<D> & a)
const
496 return a.segment(Base::i_q,
nq());
500 typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
501 JointMappedVelocitySelector(
const Eigen::MatrixBase<D> & a)
const
503 return a.segment(Base::i_v,
nv());
506 typename SizeDepType<NV>::template SegmentReturn<D>::Type
507 JointMappedVelocitySelector(Eigen::MatrixBase<D> & a)
const
509 return a.segment(Base::i_v,
nv());
513 typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
514 jointVelocitySelector(
const Eigen::MatrixBase<D> & a)
const
516 return a.segment(Base::i_v,
nv());
519 typename SizeDepType<NV>::template SegmentReturn<D>::Type
520 jointVelocitySelector(Eigen::MatrixBase<D> & a)
const
522 return a.segment(Base::i_v,
nv());
526 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
527 jointCols(
const Eigen::MatrixBase<D> & A)
const
529 return A.middleCols(Base::i_v,
nv());
532 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
533 jointExtendedModelCols(
const Eigen::MatrixBase<D> & A)
const
535 return A.middleCols(Base::i_vExtended, nvExtended());
538 typename SizeDepType<NV>::template ColsReturn<D>::Type jointCols(Eigen::MatrixBase<D> & A)
const
540 return A.middleCols(Base::i_v,
nv());
543 typename SizeDepType<NV>::template ColsReturn<D>::Type
544 jointExtendedModelCols(Eigen::MatrixBase<D> & A)
const
546 return A.middleCols(Base::i_vExtended, nvExtended());
550 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::ConstType
551 jointConfigSelector_impl(
const Eigen::MatrixBase<D> & a)
const
553 return a.segment(Base::i_q,
nq());
556 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::Type
557 jointConfigSelector_impl(Eigen::MatrixBase<D> & a)
const
559 return a.segment(Base::i_q,
nq());
563 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::ConstType
564 JointMappedConfigSelector_impl(
const Eigen::MatrixBase<D> & a)
const
566 return a.segment(Base::i_q,
nq());
569 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::Type
570 JointMappedConfigSelector_impl(Eigen::MatrixBase<D> & a)
const
572 return a.segment(Base::i_q,
nq());
576 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::ConstType
577 JointMappedVelocitySelector_impl(
const Eigen::MatrixBase<D> & a)
const
579 return a.segment(Base::i_v,
nv());
582 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::Type
583 JointMappedVelocitySelector_impl(Eigen::MatrixBase<D> & a)
const
585 return a.segment(Base::i_v,
nv());
589 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::ConstType
590 jointVelocitySelector_impl(
const Eigen::MatrixBase<D> & a)
const
592 return a.segment(Base::i_v,
nv());
595 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::Type
596 jointVelocitySelector_impl(Eigen::MatrixBase<D> & a)
const
598 return a.segment(Base::i_v,
nv());
602 typename SizeDepType<Eigen::Dynamic>::template ColsReturn<D>::ConstType
603 jointCols_impl(
const Eigen::MatrixBase<D> & A)
const
605 return A.middleCols(Base::i_v,
nv());
608 typename SizeDepType<Eigen::Dynamic>::template ColsReturn<D>::ConstType
609 jointExtendedModelCols_impl(
const Eigen::MatrixBase<D> & A)
const
611 return A.middleCols(Base::i_vExtended, nvExtended());
614 typename SizeDepType<Eigen::Dynamic>::template ColsReturn<D>::Type
615 jointCols_impl(Eigen::MatrixBase<D> & A)
const
617 return A.middleCols(Base::i_v,
nv());
620 typename SizeDepType<Eigen::Dynamic>::template ColsReturn<D>::Type
621 jointExtendedModelCols_impl(Eigen::MatrixBase<D> & A)
const
623 return A.middleCols(Base::i_vExtended, nvExtended());
626 void disp(std::ostream & os)
const
628 typedef typename JointModelCompositeTpl<Scalar, Options, JointCollectionTpl>::JointModelVector
631 os <<
"JointModelComposite containing following models:\n";
632 for (
typename JointModelVector::const_iterator it =
joints.begin(); it !=
joints.end(); ++it)
633 os <<
" " << it->shortname() << std::endl;
637 friend struct Serialize<JointModelCompositeTpl>;
639 template<
typename,
int,
template<
typename,
int>
class>
640 friend struct JointModelCompositeTpl;
646 int idx_q = this->idx_q();
647 int idx_v = this->idx_v();
648 int idx_vExtended = this->idx_vExtended();
657 for (
size_t i = 0; i <
joints.size(); ++i)
665 m_nqs[i] = ::pinocchio::nq(joint);
666 m_nvs[i] = ::pinocchio::nv(joint);
699 #include <boost/type_traits.hpp>
703 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
704 struct has_nothrow_constructor<
706 :
public integral_constant<bool, true>
710 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
712 :
public integral_constant<bool, true>
716 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
717 struct has_nothrow_constructor<
719 :
public integral_constant<bool, true>
723 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
725 :
public integral_constant<bool, true>
733 #include "pinocchio/multibody/joint/joint-composite.hxx"
Main pinocchio namespace.
int idx_vExtended(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdvExtendedVisitor to get the index in the model extended tangent ...
int idx_v(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxVVisitor to get the index in the model tangent space correspond...
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space.
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space.
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type....
JointDataVector joints
Vector of joints.
PINOCCHIO_ALIGNED_STD_VECTOR(Transformation_t) pjMi
Transforms from previous joint to joint i.
PINOCCHIO_ALIGNED_STD_VECTOR(Transformation_t) iMlast
Transforms from previous joint to last joint.
JointModelBase & operator=(const JointModelBase &clone)
JointModelCompositeTpl(const size_t size)
Default contructor with a defined size.
void setIndexes_impl(JointIndex id, int q, int v, int vExtended)
Update the indexes of subjoints in the stack.
JointModelDerived & addJoint(const JointModelBase< JointModel > &jmodel, const SE3 &placement=SE3::Identity())
Add a joint to the vector of joints.
JointModelCompositeTpl()
Default contructor.
JointModelCompositeTpl(const JointModelCompositeTpl &other)
Copy constructor.
PINOCCHIO_ALIGNED_STD_VECTOR(SE3) jointPlacements
Vector of joint placements. Those placements correspond to the origin of the joint relatively to thei...
std::vector< int > m_idx_q
Keep information of both the dimension and the position of the joints in the composition.
std::vector< int > m_nvExtendeds
Dimension of the segment in the jacobian matrix.
JointModelCompositeTpl(const JointModelBase< JointModel > &jmodel, const SE3 &placement=SE3::Identity())
Constructor with one joint.
std::vector< int > m_nvs
Dimension of the segment in the tangent vector.
JointModelVector joints
Vector of joints contained in the joint composite.
std::vector< int > m_nqs
Dimension of the segment in the config vector.
std::vector< int > m_idx_vExtended
Index in the jacobian matrix.
JointModelCompositeTpl< NewScalar, Options, JointCollectionTpl > cast() const
std::vector< int > m_idx_v
Index in the tangent vector.
int njoints
Number of joints contained in the JointModelComposite.
void updateJointIndexes()
Update the indexes of the joints contained in the composition according to the position of the joint ...
int m_nq
Dimensions of the config and tangent space of the composite joint.
Common traits structure to fully define base classes for CRTP.