19 #ifndef __se3_joint_revolute_unaligned_hpp__ 20 #define __se3_joint_revolute_unaligned_hpp__ 22 #include "pinocchio/macros.hpp" 23 #include "pinocchio/multibody/joint/joint-base.hpp" 24 #include "pinocchio/multibody/constraint.hpp" 25 #include "pinocchio/spatial/inertia.hpp" 32 template<
typename _Scalar,
int _Options>
35 typedef _Scalar Scalar;
36 enum { Options = _Options };
37 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
38 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
39 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
40 typedef typename EIGEN_REF_CONSTTYPE(Vector6) ToVectorConstReturnType;
41 typedef typename EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
42 typedef Vector3 AngularType;
43 typedef Vector3 LinearType;
44 typedef const Vector3 ConstAngularType;
45 typedef const Vector3 ConstLinearType;
46 typedef Matrix6 ActionMatrixType;
54 template<
typename _Scalar,
int _Options>
61 template<
typename Vector3Like,
typename OtherScalar>
63 const OtherScalar & w)
73 template<
typename MotionDerived>
76 v.angular() += axis*w;
85 template<
typename S1,
int O1,
typename MotionDerived>
86 inline typename MotionDerived::MotionPlain
89 typename MotionDerived::MotionPlain res(m2);
96 template<
typename _Scalar,
int _Options>
99 typedef _Scalar Scalar;
100 enum { Options = _Options };
101 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
102 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
103 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
104 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
105 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
106 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
107 typedef Matrix3 Angular_t;
108 typedef Vector3 Linear_t;
109 typedef const Matrix3 ConstAngular_t;
110 typedef const Vector3 ConstLinear_t;
111 typedef Matrix6 ActionMatrix_t;
112 typedef Eigen::Quaternion<Scalar,Options> Quaternion_t;
121 typedef Eigen::Matrix<Scalar,1,1,Options> JointMotion;
122 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
123 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
124 typedef DenseBase MatrixReturnType;
125 typedef const DenseBase ConstMatrixReturnType;
128 template<
typename _Scalar,
int _Options>
132 enum { NV = 1, Options = _Options };
139 template<
typename Vector3Like>
146 operator*(
const Eigen::MatrixBase<D> & v)
const 148 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(D,1);
152 template<
typename S1,
int O1>
153 Eigen::Matrix<Scalar,6,1,Options> se3Action(
const SE3Tpl<S1,O1> & m)
const 156 Eigen::Matrix<Scalar,6,1,Options> res;
157 res.template segment<3>(ANGULAR).noalias() = m.rotation() * axis;
158 res.template segment<3>(LINEAR).noalias() = m.translation().cross(res.template segment<3>(ANGULAR));
162 int nv_impl()
const {
return NV; }
169 template<
typename Derived>
175 typedef Eigen::Matrix<
179 ReturnType res; res[0] = ref.axis.dot(f.
angular());
185 #if EIGEN_VERSION_AT_LEAST(3,2,90) 186 const Eigen::Product<
187 Eigen::Transpose<const Vector3>,
188 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type
191 const typename Eigen::ProductReturnType<
192 Eigen::Transpose<const Vector3>,
193 typename Eigen::MatrixBase<const D>::template NRowsBlockXpr<3>::Type
196 operator*(
const Eigen::MatrixBase<D> & F)
198 EIGEN_STATIC_ASSERT(D::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
200 return ref.axis.transpose() * F.template middleRows<3>(ANGULAR);
213 DenseBase matrix_impl()
const 216 S << Vector3::Zero(), axis;
220 template<
typename MotionDerived>
223 const typename MotionDerived::ConstLinearType v = m.linear();
224 const typename MotionDerived::ConstAngularType w = m.angular();
227 res << v.cross(axis), w.cross(axis);
237 template<
typename MotionDerived,
typename S2,
int O2>
238 inline typename MotionDerived::MotionPlain
242 typedef typename MotionDerived::MotionPlain ReturnType;
243 const typename MotionDerived::ConstLinearType v1 = m1.linear();
244 const typename MotionDerived::ConstAngularType w1 = m1.angular();
245 const typename ReturnType::Vector3 w2(m2.axis * m2.w);
246 return ReturnType(v1.cross(w2),w1.cross(w2));
250 template<
typename S1,
int O1,
typename S2,
int O2>
251 inline Eigen::Matrix<S2,6,1,O2>
256 const typename Inertia::Scalar & m = Y.mass();
257 const typename Inertia::Vector3 & c = Y.lever();
258 const typename Inertia::Symmetric3 & I = Y.inertia();
260 Eigen::Matrix<S2,6,1,O2>res;
261 res.template segment<3>(Inertia::LINEAR) = -m*c.cross(cru.axis);
262 res.template segment<3>(Inertia::ANGULAR).noalias() = I*cru.axis;
263 res.template segment<3>(Inertia::ANGULAR) += c.cross(res.template segment<3>(Inertia::LINEAR));
269 template<
typename M6Like,
typename S2,
int O2>
271 #if EIGEN_VERSION_AT_LEAST(3,2,90) 272 const typename Eigen::Product<
273 typename Eigen::internal::remove_const<typename SizeDepType<3>::ColsReturn<M6Like>::ConstType>::type,
277 const typename Eigen::ProductReturnType<
278 typename Eigen::internal::remove_const<typename SizeDepType<3>::ColsReturn<M6Like>::ConstType>::type,
285 return Y.derived().template middleCols<3>(Constraint::ANGULAR) * cru.axis;
290 template<
typename Scalar,
int Options>
291 struct SE3GroupAction< ConstraintRevoluteUnalignedTpl<Scalar,Options> >
292 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
294 template<
typename Scalar,
int Options,
typename MotionDerived>
295 struct MotionAlgebraAction< ConstraintRevoluteUnalignedTpl<Scalar,Options>,MotionDerived >
296 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
301 template<
typename _Scalar,
int _Options>
308 typedef _Scalar Scalar;
309 enum { Options = _Options };
316 typedef Eigen::Matrix<Scalar,6,NV,Options> F_t;
319 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
320 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
321 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
323 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
324 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
328 template<
typename Scalar,
int Options>
332 template<
typename Scalar,
int Options>
336 template<
typename _Scalar,
int _Options>
340 SE3_JOINT_TYPEDEF_TEMPLATE;
355 : M(1),S(Eigen::Vector3d::Constant(NAN)),v(Eigen::Vector3d::Constant(NAN),NAN)
356 , U(), Dinv(), UDinv()
360 : M(1),S(axis),v(axis,NAN)
361 , U(), Dinv(), UDinv()
366 template<
typename _Scalar,
int _Options>
370 SE3_JOINT_TYPEDEF_TEMPLATE;
371 typedef Eigen::Matrix<_Scalar,3,1,_Options> Vector3;
380 template<
typename OtherScalar>
385 assert(axis.isUnitary() &&
"Rotation axis is not unitary");
388 template<
typename Vector3Like>
392 assert(axis.isUnitary() &&
"Rotation axis is not unitary");
395 JointDataDerived
createData()
const {
return JointDataDerived(axis); }
397 template<
typename ConfigVector>
398 void calc(JointDataDerived & data,
399 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 401 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigVector_t,ConfigVector);
402 typedef typename ConfigVector::Scalar OtherScalar;
403 typedef Eigen::AngleAxis<Scalar> AngleAxis;
405 const OtherScalar & q = qs[
idx_q()];
407 data.M.rotation(AngleAxis(q,axis).toRotationMatrix());
410 template<
typename ConfigVector,
typename TangentVector>
411 void calc(JointDataDerived & data,
412 const typename Eigen::MatrixBase<ConfigVector> & qs,
413 const typename Eigen::MatrixBase<TangentVector> & vs)
const 415 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TangentVector_t,TangentVector);
416 calc(data,qs.derived());
418 data.v.w = (Scalar)vs[
idx_v()];
421 template<
typename S2,
int O2>
422 void calc_aba(JointDataDerived & data, Eigen::Matrix<S2,6,6,O2> & I,
const bool update_I)
const 424 data.U.noalias() = I.template middleCols<3>(Motion::ANGULAR) * axis;
425 data.Dinv[0] = (Scalar)(1)/axis.dot(data.U.template segment<3>(Motion::ANGULAR));
426 data.UDinv.noalias() = data.U * data.Dinv;
429 I -= data.UDinv * data.U.transpose();
435 return 2.*sqrt(sqrt(Eigen::NumTraits<Scalar>::epsilon()));
438 static std::string classname() {
return std::string(
"JointModelRevoluteUnaligned"); }
439 std::string
shortname()
const {
return classname(); }
447 #endif // ifndef __se3_joint_revolute_unaligned_hpp__
JointDataVariant createData(const JointModelVariant &jmodel)
Visit a JointModelVariant through CreateData visitor to create a JointDataVariant.
ConstAngularType angular() const
Return the angular part of the force vector.
void calc_aba(const JointModelVariant &jmodel, JointDataVariant &jdata, Inertia::Matrix6 &I, const bool update_I)
Visit a JointDataVariant and the corresponding JointModelVariant through JointCalcAbaVisitor to...
std::string shortname(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointShortnameVisitor to get the shortname of the derived joint mod...
int idx_q(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxQVisitor to get the index in the full model configuration s...
Eigen::VectorXd finiteDifferenceIncrement(const Model &model)
Computes the finite difference increments for each degree of freedom according to the current joint c...
int idx_v(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxVVisitor to get the index in the full model tangent space c...