6 #ifndef __pinocchio_joint_prismatic_unaligned_hpp__ 7 #define __pinocchio_joint_prismatic_unaligned_hpp__ 9 #include "pinocchio/macros.hpp" 10 #include "pinocchio/multibody/joint/joint-base.hpp" 11 #include "pinocchio/multibody/joint/joint-translation.hpp" 12 #include "pinocchio/multibody/constraint.hpp" 13 #include "pinocchio/spatial/inertia.hpp" 14 #include "pinocchio/math/matrix.hpp" 22 template<
typename Scalar,
int Options>
28 template<
typename Scalar,
int Options,
typename MotionDerived>
34 template<
typename _Scalar,
int _Options>
37 typedef _Scalar Scalar;
38 enum { Options = _Options };
39 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
40 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
41 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
42 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
43 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
44 typedef Vector3 AngularType;
45 typedef Vector3 LinearType;
46 typedef const Vector3 ConstAngularType;
47 typedef const Vector3 ConstLinearType;
48 typedef Matrix6 ActionMatrixType;
57 template<
typename _Scalar,
int _Options>
59 :
MotionBase < MotionPrismaticUnalignedTpl<_Scalar,_Options> >
61 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
66 template<
typename Vector3Like,
typename S2>
69 : m_axis(axis), m_v(v)
70 { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3); }
75 PlainReturnType::Vector3::Zero());
78 template<
typename OtherScalar>
84 template<
typename Derived>
87 other.linear() += m_axis * m_v;
90 template<
typename Derived>
93 other.linear().noalias() = m_axis*m_v;
94 other.angular().setZero();
97 template<
typename S2,
int O2,
typename D2>
100 v.linear().noalias() = m_v * (m.rotation() * m_axis);
101 v.angular().setZero();
104 template<
typename S2,
int O2>
108 se3Action_impl(m,res);
112 template<
typename S2,
int O2,
typename D2>
116 v.linear().noalias() = m_v * (m.rotation().transpose() * m_axis);
119 v.angular().setZero();
122 template<
typename S2,
int O2>
126 se3ActionInverse_impl(m,res);
130 template<
typename M1,
typename M2>
134 mout.linear().noalias() = v.angular().cross(m_axis);
135 mout.linear() *= m_v;
138 mout.angular().setZero();
141 template<
typename M1>
151 return m_axis == other.m_axis && m_v == other.m_v;
154 const Scalar & linearRate()
const {
return m_v; }
155 Scalar & linearRate() {
return m_v; }
157 const Vector3 & axis()
const {
return m_axis; }
158 Vector3 & axis() {
return m_axis; }
166 template<
typename Scalar,
int Options,
typename MotionDerived>
167 inline typename MotionDerived::MotionPlain
170 typedef typename MotionDerived::MotionPlain ReturnType;
171 return ReturnType(m1.linearRate() * m1.axis() + m2.linear(), m2.angular());
174 template<
typename MotionDerived,
typename S2,
int O2>
175 inline typename MotionDerived::MotionPlain
179 return m2.motionAction(m1);
184 template<
typename _Scalar,
int _Options>
187 typedef _Scalar Scalar;
188 enum { Options = _Options };
194 typedef Eigen::Matrix<Scalar,1,1,Options> JointForce;
195 typedef Eigen::Matrix<Scalar,6,1,Options> DenseBase;
196 typedef DenseBase MatrixReturnType;
197 typedef const DenseBase ConstMatrixReturnType;
199 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
202 template<
typename Scalar,
int Options>
204 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
206 template<
typename Scalar,
int Options,
typename MotionDerived>
208 {
typedef Eigen::Matrix<Scalar,6,1,Options> ReturnType; };
210 template<
typename Scalar,
int Options,
typename ForceDerived>
214 typedef Eigen::Matrix<typename PINOCCHIO_EIGEN_DOT_PRODUCT_RETURN_TYPE(Vector3,typename ForceDense<ForceDerived>::ConstAngularType),1,1,Options> ReturnType;
217 template<
typename Scalar,
int Options,
typename ForceSet>
222 typename Eigen::MatrixBase<const ForceSet>::template NRowsBlockXpr<3>::Type
226 template<
typename _Scalar,
int _Options>
228 :
ConstraintBase< ConstraintPrismaticUnalignedTpl<_Scalar,_Options> >
230 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
239 template<
typename Vector3Like>
242 { EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3); }
244 template<
typename Vector1Like>
245 JointMotion __mult__(
const Eigen::MatrixBase<Vector1Like> & v)
const 247 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector1Like,1);
248 return JointMotion(m_axis,v[0]);
251 template<
typename S1,
int O1>
257 v.linear().noalias() = m.rotation()*m_axis;
258 v.angular().setZero();
262 template<
typename S1,
int O1>
268 v.linear().noalias() = m.rotation().transpose()*m_axis;
269 v.angular().setZero();
273 int nv_impl()
const {
return NV; }
280 template<
typename ForceDerived>
281 typename ConstraintForceOp<ConstraintPrismaticUnalignedTpl,ForceDerived>::ReturnType
284 typedef typename ConstraintForceOp<ConstraintPrismaticUnalignedTpl,ForceDerived>::ReturnType ReturnType;
286 res[0] = ref.axis().dot(f.
linear());
291 template<
typename ForceSet>
292 typename ConstraintForceSetOp<ConstraintPrismaticUnalignedTpl,ForceSet>::ReturnType
293 operator*(
const Eigen::MatrixBase<ForceSet> & F)
295 EIGEN_STATIC_ASSERT(ForceSet::RowsAtCompileTime==6,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
297 return ref.axis().transpose() * F.template middleRows<3>(LINEAR);
310 DenseBase matrix_impl()
const 313 S.template segment<3>(LINEAR) = m_axis;
314 S.template segment<3>(ANGULAR).setZero();
318 template<
typename MotionDerived>
322 res.template segment<3>(LINEAR).noalias() = v.angular().cross(m_axis);
323 res.template segment<3>(ANGULAR).setZero();
328 const Vector3 & axis()
const {
return m_axis; }
329 Vector3 & axis() {
return m_axis; }
333 return m_axis == other.m_axis;
342 template<
typename S1,
int O1,
typename S2,
int O2>
345 typedef Eigen::Matrix<S2,6,1,O2> ReturnType;
351 template<
typename S1,
int O1,
typename S2,
int O2>
358 static inline ReturnType run(
const Inertia & Y,
359 const Constraint & cpu)
363 const S1 & m = Y.mass();
364 const typename Inertia::Vector3 & c = Y.lever();
366 res.template segment<3>(Constraint::LINEAR).noalias() = m*cpu.axis();
367 res.template segment<3>(Constraint::ANGULAR).noalias() = c.cross(res.template segment<3>(Constraint::LINEAR));
374 template<
typename M6Like,
typename Scalar,
int Options>
378 typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
381 typedef typename Constraint::Vector3 Vector3;
382 typedef const typename MatrixMatrixProduct<M6LikeColsNonConst,Vector3>::type ReturnType;
388 template<
typename M6Like,
typename Scalar,
int Options>
393 static inline ReturnType run(
const Eigen::MatrixBase<M6Like> & Y,
394 const Constraint & cru)
396 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M6Like,6,6);
397 return Y.derived().template middleCols<3>(Constraint::LINEAR) * cru.axis();
404 template<
typename _Scalar,
int _Options>
411 typedef _Scalar Scalar;
412 enum { Options = _Options };
421 typedef Eigen::Matrix<Scalar,6,NV,Options> U_t;
422 typedef Eigen::Matrix<Scalar,NV,NV,Options> D_t;
423 typedef Eigen::Matrix<Scalar,6,NV,Options> UD_t;
425 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
427 typedef Eigen::Matrix<Scalar,NQ,1,Options> ConfigVector_t;
428 typedef Eigen::Matrix<Scalar,NV,1,Options> TangentVector_t;
431 template<
typename Scalar,
int Options>
435 template<
typename _Scalar,
int _Options>
437 :
public JointDataBase< JointDataPrismaticUnalignedTpl<_Scalar,_Options> >
439 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
441 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
442 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
455 : M(Transformation_t::Vector3::Zero())
456 , S(Constraint_t::Vector3::Zero())
457 , v(Constraint_t::Vector3::Zero(),(Scalar)0)
460 , UDinv(UD_t::Zero())
463 template<
typename Vector3Like>
467 , v(axis,(Scalar)NAN)
468 , U(), Dinv(), UDinv()
471 static std::string classname() {
return std::string(
"JointDataPrismaticUnaligned"); }
472 std::string
shortname()
const {
return classname(); }
476 template<
typename Scalar,
int Options>
481 template<
typename _Scalar,
int _Options>
483 :
public JointModelBase< JointModelPrismaticUnalignedTpl<_Scalar,_Options> >
485 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
487 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
493 using Base::setIndexes;
495 typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
504 assert(
isUnitary(axis) &&
"Translation axis is not unitary");
507 template<
typename Vector3Like>
511 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector3Like);
512 assert(
isUnitary(axis) &&
"Translation axis is not unitary");
515 JointDataDerived
createData()
const {
return JointDataDerived(axis); }
520 return Base::isEqual(other) && axis == other.
axis;
523 template<
typename ConfigVector>
524 void calc(JointDataDerived & data,
525 const typename Eigen::MatrixBase<ConfigVector> & qs)
const 527 typedef typename ConfigVector::Scalar Scalar;
528 const Scalar & q = qs[
idx_q()];
530 data.M.translation().noalias() = axis * q;
533 template<
typename ConfigVector,
typename TangentVector>
534 void calc(JointDataDerived & data,
535 const typename Eigen::MatrixBase<ConfigVector> & qs,
536 const typename Eigen::MatrixBase<TangentVector> & vs)
const 538 calc(data,qs.derived());
540 typedef typename TangentVector::Scalar S2;
541 const S2 & v = vs[
idx_v()];
542 data.v.linearRate() = v;
545 template<
typename Matrix6Like>
546 void calc_aba(JointDataDerived & data,
const Eigen::MatrixBase<Matrix6Like> & I,
const bool update_I)
const 548 data.U.noalias() = I.template block<6,3> (0,Inertia::LINEAR) * axis;
549 data.Dinv[0] = Scalar(1)/axis.dot(data.U.template segment <3> (Inertia::LINEAR));
550 data.UDinv.noalias() = data.U * data.Dinv;
553 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,I) -= data.UDinv * data.U.transpose();
556 static std::string classname() {
return std::string(
"JointModelPrismaticUnaligned"); }
557 std::string
shortname()
const {
return classname(); }
560 template<
typename NewScalar>
564 ReturnType res(axis.template cast<NewScalar>());
579 #include <boost/type_traits.hpp> 583 template<
typename Scalar,
int Options>
585 :
public integral_constant<bool,true> {};
587 template<
typename Scalar,
int Options>
589 :
public integral_constant<bool,true> {};
591 template<
typename Scalar,
int Options>
593 :
public integral_constant<bool,true> {};
595 template<
typename Scalar,
int Options>
597 :
public integral_constant<bool,true> {};
601 #endif // ifndef __pinocchio_joint_prismatic_unaligned_hpp__
Forward declaration of the multiplication operation return type. Should be overloaded, otherwise it will procude a compilation error.
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...
Return type of the Constraint::Transpose * ForceSet operation.
Return type of the ation of a Motion onto an object of type D.
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
bool isUnitary(const Eigen::MatrixBase< MatrixLike > &mat, const typename MatrixLike::RealScalar &prec=Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
Check whether the input matrix is Unitary within the given precision.
std::string shortname(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointShortnameVisitor to get the shortname of the derived joint model...
JointModelPrismaticUnalignedTpl< NewScalar, Options > cast() const
Main pinocchio namespace.
Common traits structure to fully define base classes for CRTP.
ConstLinearType linear() const
Return the linear part of the force vector.
Vector3 axis
3d main axis of the joint.
Return type of the Constraint::Transpose * Force operation.
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...
MultiplicationOp< InertiaTpl< Scalar, Options >, ConstraintDerived >::ReturnType operator*(const InertiaTpl< Scalar, Options > &Y, const ConstraintBase< ConstraintDerived > &constraint)
.