19 #ifndef __se3_constraint_hpp__ 20 #define __se3_constraint_hpp__ 23 #include "pinocchio/macros.hpp" 24 #include "pinocchio/spatial/fwd.hpp" 25 #include "pinocchio/spatial/motion.hpp" 26 #include "pinocchio/spatial/act-on-set.hpp" 35 template<
int _Dim,
typename _Scalar,
int _Options=0>
class ConstraintTpl;
37 template<
class Derived>
49 Derived & derived() {
return *
static_cast<Derived*
>(
this); }
50 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
52 Motion operator* (
const JointMotion& vj)
const {
return derived().__mult__(vj); }
54 MatrixReturnType matrix() {
return derived().matrix_impl(); }
55 ConstMatrixReturnType matrix()
const {
return derived().matrix_impl(); }
57 int nv()
const {
return derived().nv_impl(); }
59 template<
class OtherDerived>
61 const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 62 {
return matrix().isApprox(other.matrix(),prec); }
64 void disp(std::ostream & os)
const {
static_cast<const Derived*
>(
this)->disp_impl(os); }
65 friend std::ostream & operator << (std::ostream & os,const ConstraintBase<Derived> & X)
71 template<
typename MotionDerived>
76 template<
int D,
typename T,
int U>
80 typedef Eigen::Matrix<T,3,1,U> Vector3;
81 typedef Eigen::Matrix<T,4,1,U> Vector4;
82 typedef Eigen::Matrix<T,6,1,U> Vector6;
83 typedef Eigen::Matrix<T,3,3,U> Matrix3;
84 typedef Eigen::Matrix<T,4,4,U> Matrix4;
85 typedef Eigen::Matrix<T,6,6,U> Matrix6;
86 typedef Matrix3 Angular_t;
87 typedef Vector3 Linear_t;
88 typedef const Matrix3 ConstAngular_t;
89 typedef const Vector3 ConstLinear_t;
90 typedef Matrix6 ActionMatrix_t;
91 typedef Eigen::Quaternion<T,U> Quaternion_t;
100 typedef Eigen::Matrix<Scalar,D,1,U> JointMotion;
101 typedef Eigen::Matrix<Scalar,D,1,U> JointForce;
102 typedef Eigen::Matrix<Scalar,6,D> DenseBase;
103 typedef typename EIGEN_REF_CONSTTYPE(DenseBase) ConstMatrixReturnType;
104 typedef typename EIGEN_REF_TYPE(DenseBase) MatrixReturnType;
110 template<
int Dim,
typename Scalar,
int Options>
111 struct SE3GroupAction< ConstraintTpl<Dim,Scalar,Options> >
112 {
typedef Eigen::Matrix<Scalar,6,Dim> ReturnType; };
114 template<
int Dim,
typename Scalar,
int Options,
typename MotionDerived>
115 struct MotionAlgebraAction< ConstraintTpl<Dim,Scalar,Options>, MotionDerived >
116 {
typedef Eigen::Matrix<Scalar,6,Dim> ReturnType; };
119 template<
int _Dim,
typename _Scalar,
int _Options>
123 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
128 SPATIAL_TYPEDEF_TEMPLATE(ConstraintTpl);
130 typedef typename Base::JointMotion JointMotion;
131 typedef typename Base::JointForce JointForce;
132 typedef typename Base::DenseBase DenseBase;
133 typedef typename Base::ConstMatrixReturnType ConstMatrixReturnType;
134 typedef typename Base::MatrixReturnType MatrixReturnType;
136 enum { NV = _Dim, Options = _Options };
142 explicit ConstraintTpl(
const Eigen::MatrixBase<D> & _S) : S(_S)
146 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(DenseBase, D);
149 ConstraintTpl() : S()
151 EIGEN_STATIC_ASSERT(_Dim!=Eigen::Dynamic,YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
158 explicit ConstraintTpl(
const int dim) : S(6,dim)
160 EIGEN_STATIC_ASSERT(_Dim==Eigen::Dynamic,YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
166 Motion __mult__(
const JointMotion& vj)
const 173 const ConstraintTpl & ref;
174 Transpose(
const ConstraintTpl & ref ) : ref(ref) {}
176 template<
typename Derived>
178 {
return (ref.S.transpose()*f.
toVector()).eval(); }
181 typename Eigen::Matrix<_Scalar,NV,Eigen::Dynamic>
182 operator*(
const Eigen::MatrixBase<D> & F)
184 return (ref.S.transpose()*F).eval();
191 MatrixReturnType matrix_impl() {
return S; }
192 ConstMatrixReturnType matrix_impl()
const {
return S; }
196 if(NV == Eigen::Dynamic)
197 return (
int)S.cols();
202 template<
typename S2,
int O2>
203 friend typename ConstraintTpl<_Dim,_Scalar,_Options>::DenseBase
206 typedef typename ConstraintTpl::DenseBase ReturnType;
207 ReturnType res(6,S.nv());
208 motionSet::inertiaAction(Y,S.S,res);
212 template<
typename S2,
int O2>
213 friend Eigen::Matrix<_Scalar,6,_Dim>
214 operator*(
const Eigen::Matrix<S2,6,6,O2> & Ymatrix,
const ConstraintTpl & S)
216 typedef Eigen::Matrix<_Scalar,6,_Dim> ReturnType;
217 return ReturnType(Ymatrix*S.matrix());
221 DenseBase se3Action(
const SE3 & m)
const 223 DenseBase res(6,
nv());
224 motionSet::se3Action(m,S,res);
228 DenseBase se3ActionInverse(
const SE3 & m)
const 230 DenseBase res(6,
nv());
231 motionSet::se3ActionInverse(m,S,res);
235 template<
typename MotionDerived>
238 DenseBase res(6,
nv());
239 motionSet::motionAction(v,S,res);
243 void disp_impl(std::ostream & os)
const { os <<
"S =\n" << S << std::endl;}
256 #endif // ifndef __se3_constraint_hpp__
int nv(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNvVisitor to get the dimension of the joint tangent space...
ToVectorConstReturnType toVector() const
Return the force as an Eigen vector.