5 #ifndef __pinocchio_joint_composite_hpp__ 6 #define __pinocchio_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;
33 typedef JointCollectionTpl<Scalar,Options> JointCollection;
41 typedef Eigen::Matrix<Scalar,6,Eigen::Dynamic,Options> F_t;
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 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
49 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,Options> ConfigVector_t;
50 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,Options> TangentVector_t;
53 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
57 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
61 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
63 :
public JointDataBase< JointDataCompositeTpl<_Scalar,_Options,JointCollectionTpl> >
65 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
69 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE;
70 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
72 typedef JointCollectionTpl<Scalar,Options> JointCollection;
84 , U(6,0), Dinv(0,0), UDinv(6,0)
90 : joints(joint_data), iMlast(joint_data.size()), pjMi(joint_data.size())
93 , U(6,nv), Dinv(nv,nv), UDinv(6,nv)
118 static std::string classname() {
return std::string(
"JointDataComposite"); }
119 std::string
shortname()
const {
return classname(); }
123 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollectionTpl>
124 inline std::ostream & operator <<(std::ostream & os, const JointDataCompositeTpl<Scalar,Options,JointCollectionTpl> & jdata)
128 os <<
"JointDataComposite containing following models:\n" ;
129 for (
typename JointDataVector::const_iterator it = jdata.joints.begin();
130 it != jdata.joints.end(); ++it)
131 os <<
" " <<
shortname(*it) << std::endl;
136 template<
typename NewScalar,
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
142 template<
typename _Scalar,
int _Options,
template<
typename S,
int O>
class JointCollectionTpl>
144 :
public JointModelBase< JointModelCompositeTpl<_Scalar,_Options,JointCollectionTpl> >
146 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
150 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE;
152 typedef JointCollectionTpl<Scalar,Options> JointCollection;
164 using Base::setIndexes;
185 joints.reserve(size); jointPlacements.reserve(size);
186 m_idx_q.reserve(size); m_idx_v.reserve(size);
187 m_nqs.reserve(size); m_nvs.reserve(size);
196 template<
typename Jo
intModel>
198 const SE3 & placement = SE3::Identity())
199 : joints(1,(JointModelVariant)jmodel.derived())
200 , jointPlacements(1,placement)
203 , m_idx_q(1,0), m_nqs(1,jmodel.
nq())
204 , m_idx_v(1,0), m_nvs(1,jmodel.
nv())
215 , joints(other.joints)
216 , jointPlacements(other.jointPlacements)
219 , m_idx_q(other.m_idx_q), m_nqs(other.m_nqs)
220 , m_idx_v(other.m_idx_v), m_nvs(other.m_nvs)
221 , njoints(other.njoints)
233 template<
typename Jo
intModel>
235 const SE3 & placement = SE3::Identity())
237 joints.push_back((JointModelVariant)jmodel.derived());
238 jointPlacements.push_back(placement);
240 m_nq += jmodel.nq(); m_nv += jmodel.nv();
242 updateJointIndexes();
250 typename JointDataDerived::JointDataVector jdata(joints.size());
251 for (
int i = 0; i < (int)joints.size(); ++i)
252 jdata[(
size_t)i] = ::pinocchio::createData<Scalar,Options,JointCollectionTpl>(joints[(size_t)i]);
253 return JointDataDerived(jdata,
nq(),
nv());
256 template<
typename,
int,
template<
typename S,
int O>
class,
typename>
257 friend struct JointCompositeCalcZeroOrderStep;
259 template<
typename ConfigVectorType>
260 void calc(JointDataDerived & data,
const Eigen::MatrixBase<ConfigVectorType> & qs)
const;
262 template<
typename,
int,
template<
typename S,
int O>
class,
typename,
typename>
263 friend struct JointCompositeCalcFirstOrderStep;
265 template<
typename ConfigVectorType,
typename TangentVectorType>
266 void calc(JointDataDerived & data,
267 const Eigen::MatrixBase<ConfigVectorType> & qs,
268 const Eigen::MatrixBase<TangentVectorType> & vs)
const;
270 template<
typename Matrix6Like>
271 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const 273 data.U.noalias() = I * data.S.matrix();
274 data.StU.noalias() = data.S.matrix().transpose() * data.U;
277 data.Dinv.setIdentity();
278 data.StU.llt().solveInPlace(data.Dinv);
279 data.UDinv.noalias() = data.U * data.Dinv;
282 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
289 for(
typename JointModelVector::const_iterator it = joints.begin();
290 it != joints.end(); ++it)
291 eps = max((Scalar)::pinocchio::finiteDifferenceIncrement(*it),eps);
296 int nv_impl()
const {
return m_nv; }
297 int nq_impl()
const {
return m_nq; }
304 Base::setIndexes_impl(
id, q, v);
305 updateJointIndexes();
308 static std::string classname() {
return std::string(
"JointModelComposite"); }
309 std::string
shortname()
const {
return classname(); }
313 Base::operator=(other);
330 return Base::isEqual(other)
331 &&
nq() == other.nq()
332 &&
nv() == other.nv()
335 && m_nqs == other.
m_nqs 336 && m_nvs == other.
m_nvs 343 template<
typename NewScalar>
347 ReturnType res((
size_t)njoints);
351 res.m_idx_q = m_idx_q;
352 res.m_idx_v = m_idx_v;
355 res.njoints = njoints;
357 res.joints.resize(joints.size());
358 res.jointPlacements.resize(jointPlacements.size());
359 for(
size_t k = 0; k < jointPlacements.size(); ++k)
361 res.joints[k] = joints[k].template cast<NewScalar>();
362 res.jointPlacements[k] = jointPlacements[k].template cast<NewScalar>();
375 jointConfigSelector(
const Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_q,
nq()); }
378 jointConfigSelector( Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_q,
nq()); }
382 jointVelocitySelector(
const Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_v,
nv()); }
385 jointVelocitySelector( Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_v,
nv()); }
389 jointCols(
const Eigen::MatrixBase<D>& A)
const {
return A.middleCols(Base::i_v,
nv()); }
392 jointCols(Eigen::MatrixBase<D>& A)
const {
return A.middleCols(Base::i_v,
nv()); }
396 jointConfigSelector_impl(
const Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_q,
nq()); }
399 jointConfigSelector_impl(Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_q,
nq()); }
402 jointVelocitySelector_impl(
const Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_v,
nv()); }
405 jointVelocitySelector_impl(Eigen::MatrixBase<D>& a)
const {
return a.segment(Base::i_v,
nv()); }
409 jointCols_impl(
const Eigen::MatrixBase<D>& A)
const {
return A.middleCols(Base::i_v,
nv()); }
412 jointCols_impl(Eigen::MatrixBase<D>& A)
const {
return A.middleCols(Base::i_v,
nv()); }
417 friend struct Serialize<JointModelCompositeTpl>;
419 template<
typename,
int,
template<
typename,
int>
class>
420 friend struct JointModelCompositeTpl;
429 m_idx_q.resize(joints.size());
430 m_idx_v.resize(joints.size());
431 m_nqs.resize(joints.size());
432 m_nvs.resize(joints.size());
434 for(
size_t i = 0; i < joints.size(); ++i)
436 JointModelVariant & joint = joints[i];
439 ::pinocchio::setIndexes(joint,i,idx_q,idx_v);
440 m_nqs[i] = ::pinocchio::nq(joint);
441 m_nvs[i] = ::pinocchio::nv(joint);
442 idx_q += m_nqs[i]; idx_v += m_nvs[i];
467 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollectionTpl>
468 inline std::ostream & operator <<(std::ostream & os, const JointModelCompositeTpl<Scalar,Options,JointCollectionTpl> & jmodel)
472 os <<
"JointModelComposite containing following models:\n" ;
473 for (
typename JointModelVector::const_iterator it = jmodel.joints.begin();
474 it != jmodel.joints.end(); ++it)
475 os <<
" " <<
shortname(*it) << std::endl;
482 #include <boost/type_traits.hpp> 486 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
488 :
public integral_constant<bool,true> {};
490 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
492 :
public integral_constant<bool,true> {};
494 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
496 :
public integral_constant<bool,true> {};
498 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
500 :
public integral_constant<bool,true> {};
506 #include "pinocchio/multibody/joint/joint-composite.hxx" 508 #endif // ifndef __pinocchio_joint_composite_hpp__ int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space...
std::vector< int > m_nvs
Dimension of the segment in the tangent vector.
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
std::vector< int > m_idx_v
Index in the tangent vector.
void updateJointIndexes()
Update the indexes of the joints contained in the composition according to the position of the joint ...
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 nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space...
JointModelCompositeTpl< NewScalar, Options, JointCollectionTpl > cast() const
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
ModelTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType finiteDifferenceIncrement(const ModelTpl< Scalar, Options, JointCollectionTpl > &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...
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.
JointModelCompositeTpl()
Default contructor.
JointDataVector joints
Vector of joints.
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
void setIndexes_impl(JointIndex id, int q, int v)
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(const JointModelCompositeTpl &other)
Copy constructor.
container::aligned_vector< Transformation_t > pjMi
Transforms from previous joint to joint i.
container::aligned_vector< Transformation_t > iMlast
Transforms from previous joint to last joint.
std::vector< int > m_nqs
Dimension of the segment in the config vector.
JointModelCompositeTpl(const size_t size)
Default contructor with a defined size.
Main pinocchio namespace.
JointModelVector joints
Vector of joints contained in the joint composite.
container::aligned_vector< SE3 > jointPlacements
Vector of joint placements. Those placements correspond to the origin of the joint relatively to thei...
Common traits structure to fully define base classes for CRTP.
int m_nq
Dimensions of the config and tangent space of the composite joint.
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type...
void calc_aba(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata, const Eigen::MatrixBase< Matrix6Type > &I, const bool update_I)
Visit a JointModelTpl and the corresponding JointDataTpl through JointCalcAbaVisitor to...
int njoints
Number of joints contained in the JointModelComposite.