19 #ifndef __se3_joint_base_hpp__ 20 #define __se3_joint_base_hpp__ 22 #include "pinocchio/multibody/fwd.hpp" 23 #include "pinocchio/multibody/joint/fwd.hpp" 32 #define SE3_JOINT_TYPEDEF_ARG(prefix) \ 34 typedef prefix traits<JointDerived>::Scalar Scalar; \ 35 typedef prefix traits<JointDerived>::JointDataDerived JointDataDerived; \ 36 typedef prefix traits<JointDerived>::JointModelDerived JointModelDerived; \ 37 typedef prefix traits<JointDerived>::Constraint_t Constraint_t; \ 38 typedef prefix traits<JointDerived>::Transformation_t Transformation_t; \ 39 typedef prefix traits<JointDerived>::Motion_t Motion_t; \ 40 typedef prefix traits<JointDerived>::Bias_t Bias_t; \ 41 typedef prefix traits<JointDerived>::F_t F_t; \ 42 typedef prefix traits<JointDerived>::U_t U_t; \ 43 typedef prefix traits<JointDerived>::D_t D_t; \ 44 typedef prefix traits<JointDerived>::UD_t UD_t; \ 46 NQ = traits<JointDerived>::NQ, \ 47 NV = traits<JointDerived>::NV \ 49 typedef prefix traits<JointDerived>::ConfigVector_t ConfigVector_t; \ 50 typedef prefix traits<JointDerived>::TangentVector_t TangentVector_t 52 #define SE3_JOINT_TYPEDEF SE3_JOINT_TYPEDEF_ARG() 53 #define SE3_JOINT_TYPEDEF_TEMPLATE SE3_JOINT_TYPEDEF_ARG(typename) 55 #elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 2) 57 #define SE3_JOINT_TYPEDEF_NOARG() \ 59 typedef traits<JointDerived>::Scalar Scalar; \ 60 typedef traits<JointDerived>::JointDataDerived JointDataDerived; \ 61 typedef traits<JointDerived>::JointModelDerived JointModelDerived; \ 62 typedef traits<JointDerived>::Constraint_t Constraint_t; \ 63 typedef traits<JointDerived>::Transformation_t Transformation_t; \ 64 typedef traits<JointDerived>::Motion_t Motion_t; \ 65 typedef traits<JointDerived>::Bias_t Bias_t; \ 66 typedef traits<JointDerived>::F_t F_t; \ 67 typedef traits<JointDerived>::U_t U_t; \ 68 typedef traits<JointDerived>::D_t D_t; \ 69 typedef traits<JointDerived>::UD_t UD_t; \ 71 NQ = traits<JointDerived>::NQ, \ 72 NV = traits<JointDerived>::NV \ 74 typedef traits<JointDerived>::ConfigVector_t ConfigVector_t; \ 75 typedef traits<JointDerived>::TangentVector_t TangentVector_t 77 #define SE3_JOINT_TYPEDEF_ARG(prefix) \ 79 typedef prefix traits<JointDerived>::Scalar Scalar; 80 typedef prefix traits<JointDerived>::JointDataDerived JointDataDerived; \
81 typedef prefix traits<JointDerived>::JointModelDerived JointModelDerived; \
82 typedef prefix traits<JointDerived>::Constraint_t Constraint_t; \
83 typedef prefix traits<JointDerived>::Transformation_t Transformation_t; \
84 typedef prefix traits<JointDerived>::Motion_t Motion_t; \
85 typedef prefix traits<JointDerived>::Bias_t Bias_t; \
86 typedef prefix traits<JointDerived>::F_t F_t; \
87 typedef prefix traits<JointDerived>::U_t U_t; \
88 typedef prefix traits<JointDerived>::D_t D_t; \
89 typedef prefix traits<JointDerived>::UD_t UD_t; \
91 NQ = traits<JointDerived>::NQ, \
92 NV = traits<JointDerived>::NV \
94 typedef prefix traits<JointDerived>::ConfigVector_t ConfigVector_t; \
95 typedef prefix traits<JointDerived>::TangentVector_t TangentVector_t
97 #define SE3_JOINT_TYPEDEF SE3_JOINT_TYPEDEF_NOARG() 98 #define SE3_JOINT_TYPEDEF_TEMPLATE SE3_JOINT_TYPEDEF_ARG(typename) 102 #define SE3_JOINT_TYPEDEF_ARG() \ 104 typedef typename traits<JointDerived>::Scalar Scalar; \ 105 typedef typename traits<JointDerived>::JointDataDerived JointDataDerived; \ 106 typedef typename traits<JointDerived>::JointModelDerived JointModelDerived; \ 107 typedef typename traits<JointDerived>::Constraint_t Constraint_t; \ 108 typedef typename traits<JointDerived>::Transformation_t Transformation_t; \ 109 typedef typename traits<JointDerived>::Motion_t Motion_t; \ 110 typedef typename traits<JointDerived>::Bias_t Bias_t; \ 111 typedef typename traits<JointDerived>::F_t F_t; \ 112 typedef typename traits<JointDerived>::U_t U_t; \ 113 typedef typename traits<JointDerived>::D_t D_t; \ 114 typedef typename traits<JointDerived>::UD_t UD_t; \ 116 NQ = traits<JointDerived>::NQ, \ 117 NV = traits<JointDerived>::NV \ 119 typedef typename traits<JointDerived>::ConfigVector_t ConfigVector_t; \ 120 typedef typename traits<JointDerived>::TangentVector_t TangentVector_t 122 #define SE3_JOINT_TYPEDEF SE3_JOINT_TYPEDEF_ARG() 123 #define SE3_JOINT_TYPEDEF_TEMPLATE SE3_JOINT_TYPEDEF_ARG() 127 #define SE3_JOINT_USE_INDEXES \ 128 typedef JointModelBase<JointModelDerived> Base; \ 133 template<
typename Derived>
136 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
139 SE3_JOINT_TYPEDEF_TEMPLATE;
141 JointDataDerived& derived() {
return *
static_cast<Derived*
>(
this); }
142 const JointDataDerived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
144 const Constraint_t & S()
const {
return derived().S; }
145 const Transformation_t & M()
const {
return derived().M; }
146 const Motion_t & v()
const {
return derived().v; }
147 const Bias_t & c()
const {
return derived().c; }
148 F_t & F() {
return derived().F; }
150 const U_t & U()
const {
return derived().U; }
151 U_t & U() {
return derived().U; }
152 const D_t & Dinv()
const {
return derived().Dinv; }
153 const UD_t & UDinv()
const {
return derived().UDinv; }
168 typedef typename Mat::template FixedSegmentReturnType<NV>::Type Type;
169 typedef typename Mat::template ConstFixedSegmentReturnType<NV>::Type ConstType;
174 typedef typename Mat::template NColsBlockXpr<NV>::Type Type;
175 typedef typename Mat::template ConstNColsBlockXpr<NV>::Type ConstType;
184 typedef typename Mat::SegmentReturnType Type;
185 typedef typename Mat::ConstSegmentReturnType ConstType;
190 typedef typename Mat::ColsBlockXpr Type;
191 typedef typename Mat::ConstColsBlockXpr ConstType;
195 template<
typename Derived>
198 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
201 SE3_JOINT_TYPEDEF_TEMPLATE;
204 JointModelDerived& derived() {
return *
static_cast<Derived*
>(
this); }
205 const JointModelDerived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
207 JointDataDerived createData()
const {
return derived().createData(); }
209 void calc(JointDataDerived& data,
210 const Eigen::VectorXd & qs)
const 211 { derived().calc(data,qs); }
213 void calc(JointDataDerived& data,
214 const Eigen::VectorXd & qs,
215 const Eigen::VectorXd & vs)
const 216 { derived().calc(data,qs,vs); }
218 void calc_aba(JointDataDerived & data,
219 Inertia::Matrix6 & I,
220 const bool update_I =
false)
const 221 { derived().calc_aba(data, I, update_I); }
230 {
return derived().finiteDifferenceIncrement(); }
240 ConfigVector_t
integrate(
const Eigen::VectorXd & q,
const Eigen::VectorXd & v)
const 241 {
return derived().integrate_impl(q, v); }
253 ConfigVector_t
interpolate(
const Eigen::VectorXd & q0,
const Eigen::VectorXd & q1,
double u)
const 254 {
return derived().interpolate_impl(q0, q1, u); }
266 {
return derived().random_impl(); }
278 const ConfigVector_t & upper_pos_limit)
const 279 {
return derived().randomConfiguration_impl(lower_pos_limit, upper_pos_limit); }
290 TangentVector_t
difference(
const Eigen::VectorXd & q0,
const Eigen::VectorXd & q1)
const 291 {
return derived().difference_impl(q0, q1); }
301 double distance(
const Eigen::VectorXd & q0,
const Eigen::VectorXd & q1)
const 302 {
return derived().distance_impl(q0, q1); }
310 {
return derived().neutralConfiguration_impl(); }
318 {
return derived().normalize_impl(q); }
331 bool isSameConfiguration(
const Eigen::VectorXd & q1,
const Eigen::VectorXd & q2,
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 332 {
return derived().isSameConfiguration_impl(q1,q2, prec); }
338 int nv()
const {
return derived().nv_impl(); }
339 int nq()
const {
return derived().nq_impl(); }
341 int nv_impl()
const {
return NV; }
342 int nq_impl()
const {
return NQ; }
344 int idx_q()
const {
return i_q; }
345 int idx_v()
const {
return i_v; }
346 JointIndex id()
const {
return i_id; }
348 void setIndexes(JointIndex
id,
int q,
int v) { derived().setIndexes_impl(
id, q, v); }
350 void setIndexes_impl(JointIndex
id,
int q,
int v) { i_id = id, i_q = q; i_v = v; }
352 void disp(std::ostream & os)
const 356 << shortname() << endl
357 <<
" index: " << i_id << endl
358 <<
" index q: " << i_q << endl
359 <<
" index v: " << i_v << endl
360 <<
" nq: " << nq() << endl
361 <<
" nv: " << nv() << endl
365 friend std::ostream & operator << (std::ostream & os, const JointModelBase<Derived> & joint)
371 std::string shortname()
const {
return derived().shortname(); }
372 static std::string classname() {
return Derived::classname(); }
374 template <
class OtherDerived>
377 template <
class OtherDerived>
382 return other.id() == id() && other.idx_q() == idx_q() && other.idx_v() == idx_v();
389 jointConfigSelector(
const Eigen::MatrixBase<D>& a)
const {
return derived().jointConfigSelector_impl(a); }
392 jointConfigSelector_impl(
const Eigen::MatrixBase<D>& a)
const {
return a.template segment<NQ>(i_q); }
396 jointConfigSelector( Eigen::MatrixBase<D>& a)
const {
return derived().jointConfigSelector_impl(a); }
399 jointConfigSelector_impl( Eigen::MatrixBase<D>& a)
const {
return a.template segment<NQ>(i_q); }
405 jointVelocitySelector(
const Eigen::MatrixBase<D>& a)
const {
return derived().jointVelocitySelector_impl(a); }
408 jointVelocitySelector_impl(
const Eigen::MatrixBase<D>& a)
const {
return a.template segment<NV>(i_v); }
412 jointVelocitySelector( Eigen::MatrixBase<D>& a)
const {
return derived().jointVelocitySelector_impl(a); }
415 jointVelocitySelector_impl( Eigen::MatrixBase<D>& a)
const {
return a.template segment<NV>(i_v); }
419 jointCols(
const Eigen::MatrixBase<D>& A)
const {
return derived().jointCols_impl(A); }
422 jointCols_impl(
const Eigen::MatrixBase<D>& A)
const {
return A.template middleCols<NV>(i_v); }
425 jointCols(Eigen::MatrixBase<D>& A)
const {
return derived().jointCols_impl(A); }
428 jointCols_impl(Eigen::MatrixBase<D>& A)
const {
return A.template middleCols<NV>(i_v); }
460 #endif // ifndef __se3_joint_base_hpp__
JointModelBase(const JointModelBase &clone)
JointDataBase()
Default constructor: protected.
void normalize_impl(Eigen::VectorXd &) const
Default implementation of normalize.
ConfigVector_t randomConfiguration(const ConfigVector_t &lower_pos_limit, const ConfigVector_t &upper_pos_limit) const
Generate a configuration vector uniformly sampled among provided limits.
ConfigVector_t random() const
Generate a random joint configuration, normalizing quaternions when necessary.
void normalize(Eigen::VectorXd &q) const
Normalize a configuration.
bool isSameConfiguration(const Eigen::VectorXd &q1, const Eigen::VectorXd &q2, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
Check if two configurations are equivalent within the given precision.
ConfigVector_t::Scalar finiteDifferenceIncrement() const
Return the resolution of the finite differerence increment according to the Scalar type...
ConfigVector_t neutralConfiguration() const
Get neutral configuration of joint.
TangentVector_t difference(const Eigen::VectorXd &q0, const Eigen::VectorXd &q1) const
the tangent vector that must be integrated during one unit time to go from q0 to q1 ...
ConfigVector_t interpolate(const Eigen::VectorXd &q0, const Eigen::VectorXd &q1, double u) const
Interpolation between two joint's configurations.
ConfigVector_t integrate(const Eigen::VectorXd &q, const Eigen::VectorXd &v) const
Integrate joint's configuration for a tangent vector during one unit time.
double distance(const Eigen::VectorXd &q0, const Eigen::VectorXd &q1) const
Distance between two configurations of the joint.