6 #ifndef __pinocchio_constraint_hpp__ 7 #define __pinocchio_constraint_hpp__ 10 #include "pinocchio/macros.hpp" 11 #include "pinocchio/spatial/fwd.hpp" 12 #include "pinocchio/spatial/motion.hpp" 13 #include "pinocchio/spatial/act-on-set.hpp" 22 template<
int _Dim,
typename _Scalar,
int _Options=0>
class ConstraintTpl;
24 template<
class Derived>
36 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
38 Derived & derived() {
return *
static_cast<Derived*
>(
this); }
39 const Derived & derived()
const {
return *
static_cast<const Derived*
>(
this); }
41 template<
typename VectorLike>
42 JointMotion operator*(
const Eigen::MatrixBase<VectorLike> & vj)
const 43 {
return derived().__mult__(vj); }
45 MatrixReturnType matrix() {
return derived().matrix_impl(); }
46 ConstMatrixReturnType matrix()
const {
return derived().matrix_impl(); }
48 int nv()
const {
return derived().nv_impl(); }
50 template<
class OtherDerived>
52 const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 53 {
return matrix().isApprox(other.matrix(),prec); }
55 void disp(std::ostream & os)
const {
static_cast<const Derived*
>(
this)->disp_impl(os); }
56 friend std::ostream & operator << (std::ostream & os,const ConstraintBase<Derived> & X)
62 template<
typename MotionDerived>
64 {
return derived().motionAction(v); }
68 template<
int _Dim,
typename _Scalar,
int _Options>
71 typedef _Scalar Scalar;
78 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
79 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
80 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
81 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
82 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
83 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
84 typedef Matrix3 Angular_t;
85 typedef Vector3 Linear_t;
86 typedef const Matrix3 ConstAngular_t;
87 typedef const Vector3 ConstLinear_t;
88 typedef Matrix6 ActionMatrix_t;
89 typedef Eigen::Quaternion<Scalar,Options> Quaternion_t;
96 typedef Eigen::Matrix<Scalar,Dim,1,Options> JointForce;
97 typedef Eigen::Matrix<Scalar,6,Dim,Options> DenseBase;
99 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(DenseBase) ConstMatrixReturnType;
100 typedef typename PINOCCHIO_EIGEN_REF_TYPE(DenseBase) MatrixReturnType;
106 template<
int Dim,
typename Scalar,
int Options>
107 struct SE3GroupAction< ConstraintTpl<Dim,Scalar,Options> >
108 {
typedef Eigen::Matrix<Scalar,6,Dim> ReturnType; };
110 template<
int Dim,
typename Scalar,
int Options,
typename MotionDerived>
111 struct MotionAlgebraAction< ConstraintTpl<Dim,Scalar,Options>, MotionDerived >
112 {
typedef Eigen::Matrix<Scalar,6,Dim> ReturnType; };
115 template<
int _Dim,
typename _Scalar,
int _Options>
120 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
125 SPATIAL_TYPEDEF_TEMPLATE(ConstraintTpl);
128 typedef typename Base::JointForce JointForce;
129 typedef typename Base::DenseBase DenseBase;
130 typedef typename Base::ConstMatrixReturnType ConstMatrixReturnType;
131 typedef typename Base::MatrixReturnType MatrixReturnType;
133 enum { NV = _Dim, Options = _Options };
139 explicit ConstraintTpl(
const Eigen::MatrixBase<D> & _S) : S(_S)
143 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(DenseBase, D);
146 ConstraintTpl() : S()
148 EIGEN_STATIC_ASSERT(_Dim!=Eigen::Dynamic,YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
152 explicit ConstraintTpl(
const int dim) : S(6,dim)
154 EIGEN_STATIC_ASSERT(_Dim==Eigen::Dynamic,YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
157 template<
typename VectorLike>
158 JointMotion __mult__(
const Eigen::MatrixBase<VectorLike> & vj)
const 160 return JointMotion(S*vj);
165 const ConstraintTpl & ref;
166 Transpose(
const ConstraintTpl & ref ) : ref(ref) {}
168 template<
typename Derived>
170 {
return (ref.S.transpose()*f.
toVector()).eval(); }
173 typename Eigen::Matrix<Scalar,NV,Eigen::Dynamic>
174 operator*(
const Eigen::MatrixBase<D> & F)
176 return (ref.S.transpose()*F).eval();
183 MatrixReturnType matrix_impl() {
return S; }
184 ConstMatrixReturnType matrix_impl()
const {
return S; }
186 int nv_impl()
const {
return (
int)S.cols(); }
188 template<
typename S2,
int O2>
189 friend typename ConstraintTpl<_Dim,_Scalar,_Options>::DenseBase
192 typedef typename ConstraintTpl::DenseBase ReturnType;
193 ReturnType res(6,S.nv());
198 template<
typename S2,
int O2>
199 friend Eigen::Matrix<_Scalar,6,_Dim>
200 operator*(
const Eigen::Matrix<S2,6,6,O2> & Ymatrix,
const ConstraintTpl & S)
202 typedef Eigen::Matrix<_Scalar,6,_Dim> ReturnType;
203 return ReturnType(Ymatrix*S.matrix());
207 DenseBase se3Action(
const SE3 & m)
const 209 DenseBase res(6,
nv());
214 DenseBase se3ActionInverse(
const SE3 & m)
const 216 DenseBase res(6,
nv());
221 template<
typename MotionDerived>
224 DenseBase res(6,
nv());
229 void disp_impl(std::ostream & os)
const { os <<
"S =\n" << S << std::endl;}
242 #endif // ifndef __pinocchio_constraint_hpp__ int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space...
static void motionAction(const MotionDense< MotionDerived > &v, const Eigen::MatrixBase< Mat > &iF, Eigen::MatrixBase< MatRet > const &jF)
Action of a motion on a set of motions, represented by a 6xN matrix whose columns represent a spatial...
static void se3ActionInverse(const SE3Tpl< Scalar, Options > &m, const Eigen::MatrixBase< Mat > &iV, Eigen::MatrixBase< MatRet > const &jV)
Inverse SE3 action on a set of motions, represented by a 6xN matrix whose column represent a spatial ...
ToVectorConstReturnType toVector() const
Return the force as an Eigen vector.
Main pinocchio namespace.
Common traits structure to fully define base classes for CRTP.
static void inertiaAction(const InertiaTpl< Scalar, Options > &I, const Eigen::MatrixBase< Mat > &iF, Eigen::MatrixBase< MatRet > const &jF)
Action of an Inertia matrix on a set of motions, represented by a 6xN matrix whose columns represent ...
static void se3Action(const SE3Tpl< Scalar, Options > &m, const Eigen::MatrixBase< Mat > &iV, Eigen::MatrixBase< MatRet > const &jV)
SE3 action on a set of motions, represented by a 6xN matrix whose column represent a spatial motion...