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;
34 typedef JointCollectionTpl<Scalar, Options> JointCollection;
43 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> U_t;
44 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> D_t;
45 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> UD_t;
47 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> ConfigVector_t;
48 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> TangentVector_t;
50 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
53 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
57 typedef _Scalar Scalar;
60 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
64 typedef _Scalar Scalar;
67 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
69 :
public JointDataBase<JointDataCompositeTpl<_Scalar, _Options, JointCollectionTpl>>
71 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
76 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
78 typedef JointCollectionTpl<Scalar, Options> JointCollection;
89 , joint_q(ConfigVector_t::Zero(0))
90 , joint_v(TangentVector_t::Zero(0))
92 , M(Transformation_t::Identity())
104 , iMlast(joint_data.size())
105 , pjMi(joint_data.size())
106 , joint_q(ConfigVector_t::Zero(
nq))
107 , joint_v(TangentVector_t::Zero(
nv))
108 , S(Constraint_t::Zero(
nv))
109 , M(Transformation_t::Identity())
110 , v(Motion_t::Zero())
111 , c(Motion_t::Zero())
112 , U(U_t::Zero(6,
nv))
113 , Dinv(D_t::Zero(
nv,
nv))
114 , UDinv(UD_t::Zero(6,
nv))
115 , StU(D_t::Zero(
nv,
nv))
128 ConfigVector_t joint_q;
129 TangentVector_t joint_v;
142 static std::string classname()
144 return std::string(
"JointDataComposite");
146 std::string shortname()
const
152 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollectionTpl>
153 inline std::ostream & operator<<(
154 std::ostream & os,
const JointDataCompositeTpl<Scalar, Options, JointCollectionTpl> & jdata)
156 typedef typename JointDataCompositeTpl<Scalar, Options, JointCollectionTpl>::JointDataVector
159 os <<
"JointDataComposite containing following models:\n";
160 for (
typename JointDataVector::const_iterator it = jdata.joints.begin();
161 it != jdata.joints.end(); ++it)
162 os <<
" " <<
shortname(*it) << std::endl;
170 template<
typename S,
int O>
class JointCollectionTpl>
176 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
178 :
public JointModelBase<JointModelCompositeTpl<_Scalar, _Options, JointCollectionTpl>>
180 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
186 typedef JointCollectionTpl<Scalar, Options> JointCollection;
200 using Base::setIndexes;
221 jointPlacements.reserve(size);
234 template<
typename Jo
intModel>
238 , jointPlacements(1, placement)
242 ,
m_nqs(1, jmodel.nq())
244 ,
m_nvs(1, jmodel.nv())
257 , jointPlacements(other.jointPlacements)
276 template<
typename Jo
intModel>
281 jointPlacements.push_back(placement);
292 JointDataDerived createData()
const
294 typename JointDataDerived::JointDataVector jdata(
joints.size());
295 for (
int i = 0; i < (int)
joints.size(); ++i)
297 ::pinocchio::createData<Scalar, Options, JointCollectionTpl>(
joints[(
size_t)i]);
298 return JointDataDerived(jdata, nq(), nv());
301 const std::vector<bool> hasConfigurationLimit()
const
303 std::vector<bool> vec;
304 for (
size_t i = 0; i <
joints.size(); ++i)
306 const std::vector<bool> & joint_cf_limit =
joints[i].hasConfigurationLimit();
307 vec.insert(vec.end(), joint_cf_limit.begin(), joint_cf_limit.end());
312 const std::vector<bool> hasConfigurationLimitInTangent()
const
314 std::vector<bool> vec;
315 for (
size_t i = 0; i <
joints.size(); ++i)
317 const std::vector<bool> & joint_cf_limit =
joints[i].hasConfigurationLimitInTangent();
318 vec.insert(vec.end(), joint_cf_limit.begin(), joint_cf_limit.end());
323 template<
typename,
int,
template<
typename S,
int O>
class,
typename>
324 friend struct JointCompositeCalcZeroOrderStep;
326 template<
typename ConfigVectorType>
327 void calc(JointDataDerived & data,
const Eigen::MatrixBase<ConfigVectorType> & qs)
const;
329 template<
typename,
int,
template<
typename S,
int O>
class,
typename,
typename>
330 friend struct JointCompositeCalcFirstOrderStep;
332 template<
typename ConfigVectorType,
typename TangentVectorType>
334 JointDataDerived & data,
335 const Eigen::MatrixBase<ConfigVectorType> & qs,
336 const Eigen::MatrixBase<TangentVectorType> & vs)
const;
338 template<
typename TangentVectorType>
340 JointDataDerived & data,
342 const Eigen::MatrixBase<TangentVectorType> & vs)
const;
344 template<
typename VectorLike,
typename Matrix6Like>
346 JointDataDerived & data,
347 const Eigen::MatrixBase<VectorLike> & armature,
348 const Eigen::MatrixBase<Matrix6Like> & I,
349 const bool update_I)
const
351 data.U.noalias() = I * data.S.matrix();
352 data.StU.noalias() = data.S.matrix().transpose() * data.U;
353 data.StU.diagonal() += armature;
355 internal::PerformStYSInversion<Scalar>::run(data.StU, data.Dinv);
356 data.UDinv.noalias() = data.U * data.Dinv;
359 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
376 Base::setIndexes_impl(
id, q, v);
380 static std::string classname()
382 return std::string(
"JointModelComposite");
384 std::string shortname()
const
389 JointModelCompositeTpl & operator=(
const JointModelCompositeTpl & other)
399 jointPlacements = other.jointPlacements;
406 bool isEqual(
const JointModelCompositeTpl & other)
const
408 return Base::isEqual(other) && internal::comparison_eq(nq(), other.nq())
409 && internal::comparison_eq(nv(), other.nv())
410 && internal::comparison_eq(
m_idx_q, other.m_idx_q)
411 && internal::comparison_eq(
m_idx_v, other.m_idx_v)
412 && internal::comparison_eq(
m_nqs, other.m_nqs)
413 && internal::comparison_eq(
m_nvs, other.m_nvs)
414 && internal::comparison_eq(
joints, other.joints)
415 && internal::comparison_eq(jointPlacements, other.jointPlacements)
416 && internal::comparison_eq(
njoints, other.njoints);
420 template<
typename NewScalar>
424 ReturnType res((
size_t)
njoints);
425 res.setIndexes(
id(), idx_q(), idx_v());
434 res.joints.resize(
joints.size());
435 res.jointPlacements.resize(jointPlacements.size());
436 for (
size_t k = 0; k < jointPlacements.size(); ++k)
438 res.joints[k] =
joints[k].template cast<NewScalar>();
439 res.jointPlacements[k] = jointPlacements[k].template cast<NewScalar>();
453 jointConfigSelector(
const Eigen::MatrixBase<D> & a)
const
455 return a.segment(Base::i_q, nq());
459 jointConfigSelector(Eigen::MatrixBase<D> & a)
const
461 return a.segment(Base::i_q, nq());
465 typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
466 jointVelocitySelector(
const Eigen::MatrixBase<D> & a)
const
468 return a.segment(Base::i_v, nv());
471 typename SizeDepType<NV>::template SegmentReturn<D>::Type
472 jointVelocitySelector(Eigen::MatrixBase<D> & a)
const
474 return a.segment(Base::i_v, nv());
478 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
479 jointCols(
const Eigen::MatrixBase<D> & A)
const
481 return A.middleCols(Base::i_v, nv());
484 typename SizeDepType<NV>::template ColsReturn<D>::Type jointCols(Eigen::MatrixBase<D> & A)
const
486 return A.middleCols(Base::i_v, nv());
490 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::ConstType
491 jointConfigSelector_impl(
const Eigen::MatrixBase<D> & a)
const
493 return a.segment(Base::i_q, nq());
496 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::Type
497 jointConfigSelector_impl(Eigen::MatrixBase<D> & a)
const
499 return a.segment(Base::i_q, nq());
502 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::ConstType
503 jointVelocitySelector_impl(
const Eigen::MatrixBase<D> & a)
const
505 return a.segment(Base::i_v, nv());
508 typename SizeDepType<Eigen::Dynamic>::template SegmentReturn<D>::Type
509 jointVelocitySelector_impl(Eigen::MatrixBase<D> & a)
const
511 return a.segment(Base::i_v, nv());
515 typename SizeDepType<Eigen::Dynamic>::template ColsReturn<D>::ConstType
516 jointCols_impl(
const Eigen::MatrixBase<D> & A)
const
518 return A.middleCols(Base::i_v, nv());
521 typename SizeDepType<Eigen::Dynamic>::template ColsReturn<D>::Type
522 jointCols_impl(Eigen::MatrixBase<D> & A)
const
524 return A.middleCols(Base::i_v, nv());
528 friend struct Serialize<JointModelCompositeTpl>;
530 template<
typename,
int,
template<
typename,
int>
class>
531 friend struct JointModelCompositeTpl;
537 int idx_q = this->idx_q();
538 int idx_v = this->idx_v();
545 for (
size_t i = 0; i <
joints.size(); ++i)
551 ::pinocchio::setIndexes(joint, i,
idx_q,
idx_v);
552 m_nqs[i] = ::pinocchio::nq(joint);
553 m_nvs[i] = ::pinocchio::nv(joint);
578 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollectionTpl>
579 inline std::ostream & operator<<(
585 os <<
"JointModelComposite containing following models:\n";
586 for (
typename JointModelVector::const_iterator it = jmodel.
joints.begin();
587 it != jmodel.
joints.end(); ++it)
588 os <<
" " <<
shortname(*it) << std::endl;
595 #include <boost/type_traits.hpp>
599 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
600 struct has_nothrow_constructor<
602 :
public integral_constant<bool, true>
606 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
608 :
public integral_constant<bool, true>
612 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
613 struct has_nothrow_constructor<
615 :
public integral_constant<bool, true>
619 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
621 :
public integral_constant<bool, true>
629 #include "pinocchio/multibody/joint/joint-composite.hxx"
Main pinocchio namespace.
int idx_v(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxVVisitor to get the index in the full model tangent space corre...
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.
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model.
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.
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.
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.
void setIndexes_impl(JointIndex id, int q, int v)
Update the indexes of subjoints in the stack.
std::vector< int > m_nqs
Dimension of the segment in the config vector.
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.