6 #ifndef __pinocchio_joint_base_hpp__ 7 #define __pinocchio_joint_base_hpp__ 9 #include "pinocchio/multibody/fwd.hpp" 10 #include "pinocchio/multibody/joint/fwd.hpp" 17 #define PINOCCHIO_JOINT_TYPEDEF_GENERIC(TYPENAME) \ 18 typedef Eigen::DenseIndex Index; \ 19 typedef TYPENAME traits<JointDerived>::Scalar Scalar; \ 20 typedef TYPENAME traits<JointDerived>::JointDataDerived JointDataDerived; \ 21 typedef TYPENAME traits<JointDerived>::JointModelDerived JointModelDerived; \ 22 typedef TYPENAME traits<JointDerived>::Constraint_t Constraint_t; \ 23 typedef TYPENAME traits<JointDerived>::Transformation_t Transformation_t; \ 24 typedef TYPENAME traits<JointDerived>::Motion_t Motion_t; \ 25 typedef TYPENAME traits<JointDerived>::Bias_t Bias_t; \ 26 typedef TYPENAME traits<JointDerived>::F_t F_t; \ 27 typedef TYPENAME traits<JointDerived>::U_t U_t; \ 28 typedef TYPENAME traits<JointDerived>::D_t D_t; \ 29 typedef TYPENAME traits<JointDerived>::UD_t UD_t; \ 31 Options = traits<JointDerived>::Options, \ 32 NQ = traits<JointDerived>::NQ, \ 33 NV = traits<JointDerived>::NV \ 35 typedef TYPENAME traits<JointDerived>::ConfigVector_t ConfigVector_t; \ 36 typedef TYPENAME traits<JointDerived>::TangentVector_t TangentVector_t 38 #define PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(TYPENAME) \ 39 PINOCCHIO_JOINT_TYPEDEF_GENERIC(TYPENAME); \ 40 typedef TYPENAME traits<JointDerived>::ConstraintTypeConstRef ConstraintTypeConstRef; \ 41 typedef TYPENAME traits<JointDerived>::TansformTypeConstRef TansformTypeConstRef; \ 42 typedef TYPENAME traits<JointDerived>::MotionTypeConstRef MotionTypeConstRef; \ 43 typedef TYPENAME traits<JointDerived>::BiasTypeConstRef BiasTypeConstRef; \ 44 typedef TYPENAME traits<JointDerived>::UTypeConstRef UTypeConstRef; \ 45 typedef TYPENAME traits<JointDerived>::UTypeRef UTypeRef; \ 46 typedef TYPENAME traits<JointDerived>::DTypeConstRef DTypeConstRef; \ 47 typedef TYPENAME traits<JointDerived>::UDTypeConstRef UDTypeConstRef 51 #define PINOCCHIO_JOINT_TYPEDEF PINOCCHIO_JOINT_TYPEDEF_GENERIC(PINOCCHIO_EMPTY_ARG) 52 #define PINOCCHIO_JOINT_DATA_TYPEDEF PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(PINOCCHIO_EMPTY_ARG) 54 #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE PINOCCHIO_JOINT_TYPEDEF_GENERIC(typename) 55 #define PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(typename) 57 #elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 2) 59 #define PINOCCHIO_JOINT_TYPEDEF PINOCCHIO_JOINT_TYPEDEF_GENERIC(PINOCCHIO_EMPTY_ARG) 60 #define PINOCCHIO_JOINT_DATA_TYPEDEF PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(PINOCCHIO_EMPTY_ARG) 62 #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE PINOCCHIO_JOINT_TYPEDEF_GENERIC(typename) 63 #define PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(typename) 67 #define PINOCCHIO_JOINT_TYPEDEF PINOCCHIO_JOINT_TYPEDEF_GENERIC(typename) 68 #define PINOCCHIO_JOINT_DATA_TYPEDEF PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(typename) 70 #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE PINOCCHIO_JOINT_TYPEDEF_GENERIC(typename) 71 #define PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE PINOCCHIO_JOINT_DATA_TYPEDEF_GENERIC(typename) 75 #define PINOCCHIO_JOINT_USE_INDEXES \ 76 typedef JointModelBase<JointModelDerived> Base; \ 80 #define PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelTpl) \ 81 template<typename Scalar, int Options, typename NewScalar> \ 82 struct CastType< NewScalar, JointModelTpl<Scalar,Options> > \ 83 { typedef JointModelTpl<NewScalar,Options> type; } 86 #define PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR \ 87 ConstraintTypeConstRef S_accessor() const { return S; } \ 88 TansformTypeConstRef M_accessor() const { return M; } \ 89 MotionTypeConstRef v_accessor() const { return v; } \ 90 BiasTypeConstRef c_accessor() const { return c; } \ 91 UTypeConstRef U_accessor() const { return U; } \ 92 UTypeRef U_accessor() { return U; } \ 93 DTypeConstRef Dinv_accessor() const { return Dinv; } \ 94 UDTypeConstRef UDinv_accessor() const { return UDinv; } 96 #define PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE \ 97 typedef const Constraint_t & ConstraintTypeConstRef; \ 98 typedef const Transformation_t & TansformTypeConstRef; \ 99 typedef const Motion_t & MotionTypeConstRef; \ 100 typedef const Bias_t & BiasTypeConstRef; \ 101 typedef const U_t & UTypeConstRef; \ 102 typedef U_t & UTypeRef; \ 103 typedef const D_t & DTypeConstRef; \ 104 typedef const UD_t & UDTypeConstRef; 106 template<
typename Derived>
109 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
112 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE;
114 Derived & derived() {
return *
static_cast<Derived*
>(
this); }
115 const Derived & derived()
const {
return *
static_cast<const Derived*
>(
this); }
117 ConstraintTypeConstRef S()
const {
return derived().S_accessor(); }
118 TansformTypeConstRef M()
const {
return derived().M_accessor(); }
119 MotionTypeConstRef v()
const {
return derived().v_accessor(); }
120 BiasTypeConstRef c()
const {
return derived().c_accessor(); }
121 F_t & F() {
return derived().F; }
123 UTypeConstRef U()
const {
return derived().U_accessor(); }
124 UTypeRef U() {
return derived().U_accessor(); }
125 DTypeConstRef Dinv()
const {
return derived().Dinv_accessor(); }
126 UDTypeConstRef UDinv()
const {
return derived().UDinv_accessor(); }
128 std::string shortname()
const {
return derived().shortname(); }
129 static std::string classname() {
return Derived::classname(); }
131 void disp(std::ostream & os)
const 137 friend std::ostream & operator << (std::ostream & os, const JointDataBase<Derived> & joint)
156 typedef typename Mat::template FixedSegmentReturnType<NV>::Type Type;
157 typedef typename Mat::template ConstFixedSegmentReturnType<NV>::Type ConstType;
161 static typename SegmentReturn<D>::ConstType
162 segment(
const Eigen::MatrixBase<D> & mat,
163 typename Eigen::DenseBase<D>::Index start,
164 typename Eigen::DenseBase<D>::Index size = NV)
166 PINOCCHIO_UNUSED_VARIABLE(size);
167 return mat.template segment<NV>(start);
171 static typename SegmentReturn<D>::Type
172 segment(Eigen::MatrixBase<D> & mat,
173 typename Eigen::DenseBase<D>::Index start,
174 typename Eigen::DenseBase<D>::Index size = NV)
176 PINOCCHIO_UNUSED_VARIABLE(size);
177 return mat.template segment<NV>(start);
183 typedef typename Mat::template NColsBlockXpr<NV>::Type Type;
184 typedef typename Mat::template ConstNColsBlockXpr<NV>::Type ConstType;
188 static typename ColsReturn<D>::ConstType
189 middleCols(
const Eigen::MatrixBase<D> & mat,
190 typename Eigen::DenseBase<D>::Index start,
191 typename Eigen::DenseBase<D>::Index size = NV)
193 PINOCCHIO_UNUSED_VARIABLE(size);
194 return mat.template middleCols<NV>(start);
198 static typename ColsReturn<D>::Type
199 middleCols(Eigen::MatrixBase<D> & mat,
200 typename Eigen::DenseBase<D>::Index start,
201 typename Eigen::DenseBase<D>::Index size = NV)
203 PINOCCHIO_UNUSED_VARIABLE(size);
204 return mat.template middleCols<NV>(start);
210 typedef typename Mat::template NRowsBlockXpr<NV>::Type Type;
211 typedef typename Mat::template ConstNRowsBlockXpr<NV>::Type ConstType;
215 static typename RowsReturn<D>::ConstType
216 middleRows(
const Eigen::MatrixBase<D> & mat,
217 typename Eigen::DenseBase<D>::Index start,
218 typename Eigen::DenseBase<D>::Index size = NV)
220 PINOCCHIO_UNUSED_VARIABLE(size);
221 return mat.template middleRows<NV>(start);
225 static typename RowsReturn<D>::Type
226 middleRows(Eigen::MatrixBase<D> & mat,
227 typename Eigen::DenseBase<D>::Index start,
228 typename Eigen::DenseBase<D>::Index size = NV)
230 PINOCCHIO_UNUSED_VARIABLE(size);
231 return mat.template middleRows<NV>(start);
237 typedef Eigen::Block<Mat, NV, NV> Type;
238 typedef const Eigen::Block<const Mat, NV, NV> ConstType;
242 static typename BlockReturn<D>::ConstType
243 block(
const Eigen::MatrixBase<D> & mat,
244 typename Eigen::DenseBase<D>::Index row_id,
245 typename Eigen::DenseBase<D>::Index col_id,
246 typename Eigen::DenseBase<D>::Index row_size_block = NV,
247 typename Eigen::DenseBase<D>::Index col_size_block = NV)
249 PINOCCHIO_UNUSED_VARIABLE(row_size_block);
250 PINOCCHIO_UNUSED_VARIABLE(col_size_block);
251 return mat.template block<NV,NV>(row_id,col_id);
255 static typename BlockReturn<D>::Type
256 block(Eigen::MatrixBase<D> & mat,
257 typename Eigen::DenseBase<D>::Index row_id,
258 typename Eigen::DenseBase<D>::Index col_id,
259 typename Eigen::DenseBase<D>::Index row_size_block = NV,
260 typename Eigen::DenseBase<D>::Index col_size_block = NV)
262 PINOCCHIO_UNUSED_VARIABLE(row_size_block);
263 PINOCCHIO_UNUSED_VARIABLE(col_size_block);
264 return mat.template block<NV,NV>(row_id,col_id);
274 typedef typename Mat::SegmentReturnType Type;
275 typedef typename Mat::ConstSegmentReturnType ConstType;
279 static typename SegmentReturn<D>::ConstType
280 segment(
const Eigen::MatrixBase<D> & mat,
281 typename Eigen::DenseBase<D>::Index start,
282 typename Eigen::DenseBase<D>::Index size)
284 return mat.segment(start,size);
288 static typename SegmentReturn<D>::Type
289 segment(Eigen::MatrixBase<D> & mat,
290 typename Eigen::DenseBase<D>::Index start,
291 typename Eigen::DenseBase<D>::Index size)
293 return mat.segment(start,size);
299 typedef typename Mat::ColsBlockXpr Type;
300 typedef typename Mat::ConstColsBlockXpr ConstType;
304 static typename ColsReturn<D>::ConstType
305 middleCols(
const Eigen::MatrixBase<D> & mat,
306 typename Eigen::DenseBase<D>::Index start,
307 typename Eigen::DenseBase<D>::Index size)
309 return mat.middleCols(start,size);
313 static typename ColsReturn<D>::Type
314 middleCols(Eigen::MatrixBase<D> & mat,
315 typename Eigen::DenseBase<D>::Index start,
316 typename Eigen::DenseBase<D>::Index size)
318 return mat.middleCols(start,size);
324 typedef typename Mat::RowsBlockXpr Type;
325 typedef typename Mat::ConstRowsBlockXpr ConstType;
329 static typename RowsReturn<D>::ConstType
330 middleRows(
const Eigen::MatrixBase<D> & mat,
331 typename Eigen::DenseBase<D>::Index start,
332 typename Eigen::DenseBase<D>::Index size)
334 return mat.middleRows(start,size);
338 static typename RowsReturn<D>::Type
339 middleRows(Eigen::MatrixBase<D> & mat,
340 typename Eigen::DenseBase<D>::Index start,
341 typename Eigen::DenseBase<D>::Index size)
343 return mat.middleRows(start,size);
349 typedef Eigen::Block<Mat> Type;
350 typedef const Eigen::Block<const Mat> ConstType;
354 static typename BlockReturn<D>::ConstType
355 block(
const Eigen::MatrixBase<D> & mat,
356 typename Eigen::DenseBase<D>::Index row_id,
357 typename Eigen::DenseBase<D>::Index col_id,
358 typename Eigen::DenseBase<D>::Index row_size_block,
359 typename Eigen::DenseBase<D>::Index col_size_block)
361 return mat.block(row_id,col_id,row_size_block,col_size_block);
365 static typename BlockReturn<D>::Type
366 block(Eigen::MatrixBase<D> & mat,
367 typename Eigen::DenseBase<D>::Index row_id,
368 typename Eigen::DenseBase<D>::Index col_id,
369 typename Eigen::DenseBase<D>::Index row_size_block,
370 typename Eigen::DenseBase<D>::Index col_size_block)
372 return mat.block(row_id,col_id,row_size_block,col_size_block);
376 template<
typename Derived>
379 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
382 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE;
384 JointModelDerived & derived() {
return *
static_cast<Derived*
>(
this); }
385 const JointModelDerived & derived()
const {
return *
static_cast<const Derived*
>(
this); }
387 JointDataDerived
createData()
const {
return derived().createData(); }
389 template<
typename ConfigVectorType>
390 void calc(JointDataDerived & data,
391 const Eigen::MatrixBase<ConfigVectorType> & qs)
const 393 derived().calc(data,qs.derived());
396 template<
typename ConfigVectorType,
typename TangentVectorType>
397 void calc(JointDataDerived & data,
398 const Eigen::MatrixBase<ConfigVectorType> & qs,
399 const Eigen::MatrixBase<TangentVectorType> & vs)
const 401 derived().calc(data,qs.derived(),vs.derived());
405 template<
typename Matrix6Type>
406 void calc_aba(JointDataDerived & data,
407 const Eigen::MatrixBase<Matrix6Type> & I,
408 const bool update_I =
false)
const 410 derived().calc_aba(data, PINOCCHIO_EIGEN_CONST_CAST(Matrix6Type,I), update_I);
420 {
return derived().finiteDifferenceIncrement(); }
426 int nv()
const {
return derived().nv_impl(); }
427 int nq()
const {
return derived().nq_impl(); }
430 int nv_impl()
const {
return NV; }
431 int nq_impl()
const {
return NQ; }
433 int idx_q()
const {
return i_q; }
434 int idx_v()
const {
return i_v; }
435 JointIndex
id()
const {
return i_id; }
437 void setIndexes(JointIndex
id,
int q,
int v) { derived().setIndexes_impl(
id, q, v); }
439 void setIndexes_impl(JointIndex
id,
int q,
int v) { i_id =
id, i_q = q; i_v = v; }
441 void disp(std::ostream & os)
const 446 <<
" index: " << i_id << endl
447 <<
" index q: " << i_q << endl
448 <<
" index v: " << i_v << endl
449 <<
" nq: " <<
nq() << endl
450 <<
" nv: " <<
nv() << endl
454 friend std::ostream & operator << (std::ostream & os, const JointModelBase<Derived> & joint)
460 std::string
shortname()
const {
return derived().shortname(); }
461 static std::string classname() {
return Derived::classname(); }
463 template<
typename NewScalar>
465 {
return derived().template cast<NewScalar>(); }
467 template <
class OtherDerived>
469 {
return derived().isEqual(other.derived()); }
471 template <
class OtherDerived>
473 {
return !(derived() == other.derived()); }
475 template <
class OtherDerived>
480 return other.id() ==
id()
481 && other.idx_q() ==
idx_q()
482 && other.idx_v() ==
idx_v();
489 jointConfigSelector(
const Eigen::MatrixBase<D>& a)
const 490 {
return derived().jointConfigSelector_impl(a); }
494 jointConfigSelector_impl(
const Eigen::MatrixBase<D>& a)
const 500 jointConfigSelector( Eigen::MatrixBase<D>& a)
const 501 {
return derived().jointConfigSelector_impl(a); }
505 jointConfigSelector_impl( Eigen::MatrixBase<D>& a)
const 512 jointVelocitySelector(
const Eigen::MatrixBase<D>& a)
const 513 {
return derived().jointVelocitySelector_impl(a); }
517 jointVelocitySelector_impl(
const Eigen::MatrixBase<D>& a)
const 523 jointVelocitySelector( Eigen::MatrixBase<D>& a)
const 524 {
return derived().jointVelocitySelector_impl(a); }
528 jointVelocitySelector_impl( Eigen::MatrixBase<D>& a)
const 533 jointCols(
const Eigen::MatrixBase<D>& A)
const 534 {
return derived().jointCols_impl(A); }
538 jointCols_impl(
const Eigen::MatrixBase<D>& A)
const 543 jointCols(Eigen::MatrixBase<D>& A)
const 544 {
return derived().jointCols_impl(A); }
548 jointCols_impl(Eigen::MatrixBase<D>& A)
const 553 jointRows(
const Eigen::MatrixBase<D>& A)
const 554 {
return derived().jointRows_impl(A); }
558 jointRows_impl(
const Eigen::MatrixBase<D>& A)
const 563 jointRows(Eigen::MatrixBase<D>& A)
const 564 {
return derived().jointRows_impl(A); }
568 jointRows_impl(Eigen::MatrixBase<D>& A)
const 575 {
return derived().jointBlock_impl(Mat); }
579 jointBlock_impl(
const Eigen::MatrixBase<D> & Mat)
const 584 jointBlock(Eigen::MatrixBase<D> & Mat)
const 585 {
return derived().jointBlock_impl(Mat); }
589 jointBlock_impl(Eigen::MatrixBase<D> & Mat)
const 598 : i_id(
std::numeric_limits<JointIndex>::max()), i_q(-1), i_v(-1) {}
623 #endif // ifndef __pinocchio_joint_base_hpp__ int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space...
SizeDepType< NV >::template BlockReturn< D >::ConstType jointBlock(const Eigen::MatrixBase< D > &Mat) const
Returns a block of dimension nv()xnv() located at position i_v,i_v in the matrix Mat.
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
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...
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
JointIndex id(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdVisitor to get the index of the joint in the kinematic chain...
Source from #include <cppad/example/cppad_eigen.hpp>
JointDataBase()
Default constructor: protected.
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
JointModelBase & operator=(const JointModelBase &clone)
Scalar finiteDifferenceIncrement() const
Return the resolution of the finite differerence increment according to the Scalar type...
Main pinocchio namespace.
JointModelBase(const JointModelBase &clone)
void setIndexes(JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointIndex id, int q, int v)
Visit a JointModelTpl through JointSetIndexesVisitor to set the indexes of the joint in the kinematic...
Common traits structure to fully define base classes for CRTP.
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...