// // Copyright (c) 2016-2021 CNRS INRIA // #ifndef __pinocchio_joint_generic_hpp__ #define __pinocchio_joint_generic_hpp__ #include "pinocchio/multibody/joint/joint-collection.hpp" #include "pinocchio/multibody/joint/joint-composite.hpp" #include "pinocchio/multibody/joint/joint-basic-visitors.hxx" #include "pinocchio/container/aligned-vector.hpp" #include namespace pinocchio { template class JointCollectionTpl = JointCollectionDefaultTpl> struct JointTpl; typedef JointTpl Joint; template class JointCollectionTpl> struct traits< JointTpl<_Scalar,_Options,JointCollectionTpl> > { enum { Options = _Options, NQ = Eigen::Dynamic, // Dynamic because unknown at compile time NV = Eigen::Dynamic }; typedef _Scalar Scalar; typedef JointCollectionTpl JointCollection; typedef JointDataTpl JointDataDerived; typedef JointModelTpl JointModelDerived; typedef ConstraintTpl Constraint_t; typedef SE3Tpl Transformation_t; typedef MotionTpl Motion_t; typedef MotionTpl Bias_t; // [ABA] typedef Eigen::Matrix U_t; typedef Eigen::Matrix D_t; typedef Eigen::Matrix UD_t; typedef Constraint_t ConstraintTypeConstRef; typedef Constraint_t ConstraintTypeRef; typedef Transformation_t TansformTypeConstRef; typedef Transformation_t TansformTypeRef; typedef Motion_t MotionTypeConstRef; typedef Motion_t MotionTypeRef; typedef Bias_t BiasTypeConstRef; typedef Bias_t BiasTypeRef; typedef U_t UTypeConstRef; typedef U_t UTypeRef; typedef D_t DTypeConstRef; typedef D_t DTypeRef; typedef UD_t UDTypeConstRef; typedef UD_t UDTypeRef; typedef Eigen::Matrix ConfigVector_t; typedef Eigen::Matrix TangentVector_t; }; template class JointCollectionTpl> struct traits< JointDataTpl > { typedef JointTpl JointDerived; }; template class JointCollectionTpl> struct traits< JointModelTpl > { typedef JointTpl JointDerived; }; template class JointCollectionTpl> struct JointDataTpl : public JointDataBase< JointDataTpl<_Scalar,_Options,JointCollectionTpl> > , JointCollectionTpl<_Scalar,_Options>::JointDataVariant { EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef JointTpl<_Scalar,_Options,JointCollectionTpl> JointDerived; typedef JointDataBase Base; PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived); typedef JointCollectionTpl<_Scalar,_Options> JointCollection; typedef typename JointCollection::JointDataVariant JointDataVariant; using Base::operator==; using Base::operator!=; JointDataVariant & toVariant() { return *static_cast(this); } const JointDataVariant & toVariant() const { return *static_cast(this); } Constraint_t S() const { return constraint_xd(*this); } Transformation_t M() const { return joint_transform(*this); } Motion_t v() const { return motion(*this); } Bias_t c() const { return bias(*this); } // [ABA CCRBA] U_t U() const { return u_inertia(*this); } D_t Dinv() const { return dinv_inertia(*this); } UD_t UDinv() const { return udinv_inertia(*this); } JointDataTpl() : JointDataVariant() {} JointDataTpl(const JointDataVariant & jdata_variant) : JointDataVariant(jdata_variant) {} template JointDataTpl(const JointDataBase & jdata) : JointCollection::JointDataVariant((JointDataVariant)jdata.derived()) { BOOST_MPL_ASSERT((boost::mpl::contains)); } // Define all the standard accessors Constraint_t S_accessor() const { return S(); } Transformation_t M_accessor() const { return M(); } Motion_t v_accessor() const { return v(); } Bias_t c_accessor() const { return c(); } U_t U_accessor() const { return U(); } D_t Dinv_accessor() const { return Dinv(); } UD_t UDinv_accessor() const { return UDinv(); } static std::string classname() { return "JointData"; } std::string shortname() const { return ::pinocchio::shortname(*this); } template bool isEqual(const JointDataBase & other) const { return ::pinocchio::isEqual(*this,other.derived()); } bool isEqual(const JointDataTpl & other) const { return Base::isEqual(other) && toVariant() == other.toVariant(); } bool operator==(const JointDataTpl & other) const { return isEqual(other); } bool operator!=(const JointDataTpl & other) const { return !(*this == other); } }; template class JointCollectionTpl> struct CastType< NewScalar, JointModelTpl > { typedef JointModelTpl type; }; template class JointCollectionTpl> struct JointModelTpl : JointModelBase< JointModelTpl<_Scalar,_Options,JointCollectionTpl> > , JointCollectionTpl<_Scalar,_Options>::JointModelVariant { EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef JointTpl<_Scalar,_Options,JointCollectionTpl> JointDerived; PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived); PINOCCHIO_JOINT_USE_INDEXES(JointModelTpl); typedef JointCollectionTpl JointCollection; typedef typename JointCollection::JointDataVariant JointDataVariant; typedef typename JointCollection::JointModelVariant JointModelVariant; using Base::id; using Base::setIndexes; using Base::operator==; using Base::operator!=; JointModelTpl() : JointModelVariant() {} JointModelTpl(const JointModelVariant & jmodel_variant) : JointCollection::JointModelVariant(jmodel_variant) { setIndexes(::pinocchio::id(jmodel_variant), ::pinocchio::nq(jmodel_variant), ::pinocchio::nv(jmodel_variant)); } template JointModelTpl(const JointModelBase & jmodel) : JointModelVariant((JointModelVariant)jmodel.derived()) { BOOST_MPL_ASSERT((boost::mpl::contains)); setIndexes(jmodel.id(),jmodel.nq(),jmodel.nv()); } JointModelVariant & toVariant() { return *static_cast(this); } const JointModelVariant & toVariant() const { return *static_cast(this); } JointDataDerived createData() const { return ::pinocchio::createData(*this); } template bool isEqual(const JointModelBase & other) const { return ::pinocchio::isEqual(*this,other.derived());; } template bool hasSameIndexes(const JointModelBase & other) const { return ::pinocchio::hasSameIndexes(*this,other.derived()); } bool isEqual(const JointModelTpl & other) const { return Base::isEqual(other) && toVariant() == other.toVariant(); } bool operator==(const JointModelTpl & other) const { return isEqual(other); } bool operator!=(const JointModelTpl & other) const { return !(*this == other); } template void calc(JointDataDerived & data, const Eigen::MatrixBase & q) const { calc_zero_order(*this,data,q); } template void calc(JointDataDerived & data, const Eigen::MatrixBase & q, const Eigen::MatrixBase & v) const { calc_first_order(*this,data,q,v); } template void calc_aba(JointDataDerived & data, const Eigen::MatrixBase & I, const bool update_I) const { ::pinocchio::calc_aba(*this,data,PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I),update_I); } std::string shortname() const { return ::pinocchio::shortname(*this); } static std::string classname() { return "JointModel"; } int nq_impl() const { return ::pinocchio::nq(*this); } int nv_impl() const { return ::pinocchio::nv(*this); } int idx_q_impl() const { return ::pinocchio::idx_q(*this); } int idx_v_impl() const { return ::pinocchio::idx_v(*this); } JointIndex id_impl() const { return ::pinocchio::id(*this); } void setIndexes(JointIndex id, int nq, int nv) { ::pinocchio::setIndexes(*this, id, nq, nv); } /// \returns An expression of *this with the Scalar type casted to NewScalar. template JointModelTpl cast() const { return cast_joint(*this); } }; typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointData) JointDataVector; typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointModel) JointModelVector; template class JointCollectionTpl, typename JointDataDerived> bool operator==(const JointDataBase & joint_data, const JointDataTpl & joint_data_generic) { return joint_data_generic == joint_data.derived(); } template class JointCollectionTpl, typename JointDataDerived> bool operator!=(const JointDataBase & joint_data, const JointDataTpl & joint_data_generic) { return joint_data_generic != joint_data.derived(); } template class JointCollectionTpl, typename JointModelDerived> bool operator==(const JointModelBase & joint_model, const JointModelTpl & joint_model_generic) { return joint_model_generic == joint_model.derived(); } template class JointCollectionTpl, typename JointModelDerived> bool operator!=(const JointModelBase & joint_model, const JointModelTpl & joint_model_generic) { return joint_model_generic != joint_model.derived(); } } // namespace pinocchio #endif // ifndef __pinocchio_joint_generic_hpp__