pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
joint-prismatic-unaligned.hpp
1//
2// Copyright (c) 2015-2020 CNRS INRIA
3// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4//
5
6#ifndef __pinocchio_multibody_joint_prismatic_unaligned_hpp__
7#define __pinocchio_multibody_joint_prismatic_unaligned_hpp__
8
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/joint-motion-subspace.hpp"
13#include "pinocchio/spatial/inertia.hpp"
14#include "pinocchio/math/matrix.hpp"
15
16namespace pinocchio
17{
18
19 template<typename Scalar, int Options = context::Options>
20 struct MotionPrismaticUnalignedTpl;
21 typedef MotionPrismaticUnalignedTpl<context::Scalar> MotionPrismaticUnaligned;
22
23 template<typename Scalar, int Options>
28
29 template<typename Scalar, int Options, typename MotionDerived>
34
35 template<typename _Scalar, int _Options>
37 {
38 typedef _Scalar Scalar;
39 enum
40 {
41 Options = _Options
42 };
43 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
44 typedef Eigen::Matrix<Scalar, 6, 1, Options> Vector6;
45 typedef Eigen::Matrix<Scalar, 4, 4, Options> Matrix4;
46 typedef Eigen::Matrix<Scalar, 6, 6, Options> Matrix6;
47 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
48 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
49 typedef Vector3 AngularType;
50 typedef Vector3 LinearType;
51 typedef const Vector3 ConstAngularType;
52 typedef const Vector3 ConstLinearType;
53 typedef Matrix6 ActionMatrixType;
54 typedef Matrix4 HomogeneousMatrixType;
57 enum
58 {
59 LINEAR = 0,
60 ANGULAR = 3
61 };
62 }; // traits MotionPrismaticUnalignedTpl
63
64 template<typename _Scalar, int _Options>
65 struct MotionPrismaticUnalignedTpl : MotionBase<MotionPrismaticUnalignedTpl<_Scalar, _Options>>
66 {
68 MOTION_TYPEDEF_TPL(MotionPrismaticUnalignedTpl);
69
71 {
72 }
73
74 template<typename Vector3Like, typename S2>
75 MotionPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis, const S2 & v)
76 : m_axis(axis)
77 , m_v(v)
78 {
80 }
81
82 inline PlainReturnType plain() const
83 {
84 return PlainReturnType(m_axis * m_v, PlainReturnType::Vector3::Zero());
85 }
86
87 template<typename OtherScalar>
88 MotionPrismaticUnalignedTpl __mult__(const OtherScalar & alpha) const
89 {
90 return MotionPrismaticUnalignedTpl(m_axis, alpha * m_v);
91 }
92
93 template<typename Derived>
94 void addTo(MotionDense<Derived> & other) const
95 {
96 other.linear() += m_axis * m_v;
97 }
98
99 template<typename Derived>
100 void setTo(MotionDense<Derived> & other) const
101 {
102 other.linear().noalias() = m_axis * m_v;
103 other.angular().setZero();
104 }
105
106 template<typename S2, int O2, typename D2>
107 void se3Action_impl(const SE3Tpl<S2, O2> & m, MotionDense<D2> & v) const
108 {
109 v.linear().noalias() = m_v * (m.rotation() * m_axis); // TODO: check efficiency
110 v.angular().setZero();
111 }
112
113 template<typename S2, int O2>
114 MotionPlain se3Action_impl(const SE3Tpl<S2, O2> & m) const
115 {
116 MotionPlain res;
117 se3Action_impl(m, res);
118 return res;
119 }
120
121 template<typename S2, int O2, typename D2>
122 void se3ActionInverse_impl(const SE3Tpl<S2, O2> & m, MotionDense<D2> & v) const
123 {
124 // Linear
125 v.linear().noalias() = m_v * (m.rotation().transpose() * m_axis);
126
127 // Angular
128 v.angular().setZero();
129 }
130
131 template<typename S2, int O2>
132 MotionPlain se3ActionInverse_impl(const SE3Tpl<S2, O2> & m) const
133 {
134 MotionPlain res;
135 se3ActionInverse_impl(m, res);
136 return res;
137 }
138
139 template<typename M1, typename M2>
140 void motionAction(const MotionDense<M1> & v, MotionDense<M2> & mout) const
141 {
142 // Linear
143 mout.linear().noalias() = v.angular().cross(m_axis);
144 mout.linear() *= m_v;
145
146 // Angular
147 mout.angular().setZero();
148 }
149
150 template<typename M1>
151 MotionPlain motionAction(const MotionDense<M1> & v) const
152 {
153 MotionPlain res;
154 motionAction(v, res);
155 return res;
156 }
157
158 bool isEqual_impl(const MotionPrismaticUnalignedTpl & other) const
159 {
160 return internal::comparison_eq(m_axis, other.m_axis)
161 && internal::comparison_eq(m_v, other.m_v);
162 }
163
164 const Scalar & linearRate() const
165 {
166 return m_v;
167 }
168 Scalar & linearRate()
169 {
170 return m_v;
171 }
172
173 const Vector3 & axis() const
174 {
175 return m_axis;
176 }
177 Vector3 & axis()
178 {
179 return m_axis;
180 }
181
182 protected:
183 Vector3 m_axis;
184 Scalar m_v;
185 }; // struct MotionPrismaticUnalignedTpl
186
187 template<typename Scalar, int Options, typename MotionDerived>
188 inline typename MotionDerived::MotionPlain operator+(
190 {
191 typedef typename MotionDerived::MotionPlain ReturnType;
192 return ReturnType(m1.linearRate() * m1.axis() + m2.linear(), m2.angular());
193 }
194
195 template<typename MotionDerived, typename S2, int O2>
196 inline typename MotionDerived::MotionPlain
197 operator^(const MotionDense<MotionDerived> & m1, const MotionPrismaticUnalignedTpl<S2, O2> & m2)
198 {
199 return m2.motionAction(m1);
200 }
201
202 template<typename Scalar, int Options>
203 struct JointMotionSubspacePrismaticUnalignedTpl;
204
205 template<typename _Scalar, int _Options>
207 {
208 typedef _Scalar Scalar;
209 enum
210 {
211 Options = _Options
212 };
213 enum
214 {
215 LINEAR = 0,
216 ANGULAR = 3
217 };
218
220 typedef Eigen::Matrix<Scalar, 1, 1, Options> JointForce;
221 typedef Eigen::Matrix<Scalar, 6, 1, Options> DenseBase;
222 typedef Eigen::Matrix<Scalar, 1, 1, Options> ReducedSquaredMatrix;
223 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
224
225 typedef DenseBase MatrixReturnType;
226 typedef const DenseBase ConstMatrixReturnType;
227
228 typedef typename ReducedSquaredMatrix::IdentityReturnType StDiagonalMatrixSOperationReturnType;
229 }; // traits JointMotionSubspacePrismaticUnalignedTpl
230
231 template<typename Scalar, int Options>
233 {
234 typedef Eigen::Matrix<Scalar, 6, 1, Options> ReturnType;
235 };
236
237 template<typename Scalar, int Options, typename MotionDerived>
241 {
242 typedef Eigen::Matrix<Scalar, 6, 1, Options> ReturnType;
243 };
244
245 template<typename Scalar, int Options, typename ForceDerived>
247 {
248 typedef
250 typedef Eigen::Matrix<
251 typename PINOCCHIO_EIGEN_DOT_PRODUCT_RETURN_TYPE(
253 1,
254 1,
255 Options>
256 ReturnType;
257 };
258
259 template<typename Scalar, int Options, typename ForceSet>
261 {
262 typedef
264 typedef typename MatrixMatrixProduct<
265 Eigen::Transpose<const Vector3>,
266 typename Eigen::MatrixBase<const ForceSet>::template NRowsBlockXpr<3>::Type>::type ReturnType;
267 };
268
269 template<typename _Scalar, int _Options>
271 : JointMotionSubspaceBase<JointMotionSubspacePrismaticUnalignedTpl<_Scalar, _Options>>
272 {
274 PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(JointMotionSubspacePrismaticUnalignedTpl)
275
276 enum
277 {
278 NV = 1
279 };
280
282
284 {
285 }
286
287 template<typename Vector3Like>
288 JointMotionSubspacePrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
289 : m_axis(axis)
290 {
292 }
293
294 template<typename Vector1Like>
295 JointMotion __mult__(const Eigen::MatrixBase<Vector1Like> & v) const
296 {
298 return JointMotion(m_axis, v[0]);
299 }
300
301 template<typename S1, int O1>
302 typename SE3GroupAction<JointMotionSubspacePrismaticUnalignedTpl>::ReturnType
303 se3Action(const SE3Tpl<S1, O1> & m) const
304 {
305 typename SE3GroupAction<JointMotionSubspacePrismaticUnalignedTpl>::ReturnType res;
307 v.linear().noalias() = m.rotation() * m_axis;
308 v.angular().setZero();
309 return res;
310 }
311
312 template<typename S1, int O1>
313 typename SE3GroupAction<JointMotionSubspacePrismaticUnalignedTpl>::ReturnType
314 se3ActionInverse(const SE3Tpl<S1, O1> & m) const
315 {
316 typename SE3GroupAction<JointMotionSubspacePrismaticUnalignedTpl>::ReturnType res;
318 v.linear().noalias() = m.rotation().transpose() * m_axis;
319 v.angular().setZero();
320 return res;
321 }
322
323 int nv_impl() const
324 {
325 return NV;
326 }
327
329 : JointMotionSubspaceTransposeBase<JointMotionSubspacePrismaticUnalignedTpl>
330 {
333 : ref(ref)
334 {
335 }
336
337 template<typename ForceDerived>
339 operator*(const ForceDense<ForceDerived> & f) const
340 {
341 typedef typename ConstraintForceOp<
343 ReturnType res;
344 res[0] = ref.axis().dot(f.linear());
345 return res;
346 }
347
348 /* [CRBA] MatrixBase operator* (Constraint::Transpose S, ForceSet::Block) */
349 template<typename ForceSet>
351 operator*(const Eigen::MatrixBase<ForceSet> & F)
352 {
354 ForceSet::RowsAtCompileTime == 6, THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
355 /* Return ax.T * F[1:3,:] */
356 return ref.axis().transpose() * F.template middleRows<3>(LINEAR);
357 }
358 };
359
360 TransposeConst transpose() const
361 {
362 return TransposeConst(*this);
363 }
364
365 /* CRBA joint operators
366 * - ForceSet::Block = ForceSet
367 * - ForceSet operator* (Inertia Y,Constraint S)
368 * - MatrixBase operator* (Constraint::Transpose S, ForceSet::Block)
369 * - SE3::act(ForceSet::Block)
370 */
371 DenseBase matrix_impl() const
372 {
373 DenseBase S;
374 S.template segment<3>(LINEAR) = m_axis;
375 S.template segment<3>(ANGULAR).setZero();
376 return S;
377 }
378
379 template<typename MotionDerived>
380 DenseBase motionAction(const MotionDense<MotionDerived> & v) const
381 {
382 DenseBase res;
383 res.template segment<3>(LINEAR).noalias() = v.angular().cross(m_axis);
384 res.template segment<3>(ANGULAR).setZero();
385
386 return res;
387 }
388
389 const Vector3 & axis() const
390 {
391 return m_axis;
392 }
393 Vector3 & axis()
394 {
395 return m_axis;
396 }
397
398 bool isEqual(const JointMotionSubspacePrismaticUnalignedTpl & other) const
399 {
400 return internal::comparison_eq(m_axis, other.m_axis);
401 }
402
403 protected:
404 Vector3 m_axis;
405
406 }; // struct JointMotionSubspacePrismaticUnalignedTpl
407
408 template<typename S1, int O1, typename S2, int O2>
410 {
411 typedef Eigen::Matrix<S2, 6, 1, O2> ReturnType;
412 };
413
414 /* [CRBA] ForceSet operator* (Inertia Y,Constraint S) */
415 namespace impl
416 {
417 template<typename S1, int O1, typename S2, int O2>
419 {
422 typedef typename MultiplicationOp<Inertia, Constraint>::ReturnType ReturnType;
423
424 static inline ReturnType run(const Inertia & Y, const Constraint & cpu)
425 {
426 ReturnType res;
427 /* YS = [ m -mcx ; mcx I-mcxcx ] [ 0 ; w ] = [ mcxw ; Iw -mcxcxw ] */
428 const S1 & m = Y.mass();
429 const typename Inertia::Vector3 & c = Y.lever();
430
431 res.template segment<3>(Constraint::LINEAR).noalias() = m * cpu.axis();
432 res.template segment<3>(Constraint::ANGULAR).noalias() =
433 c.cross(res.template segment<3>(Constraint::LINEAR));
434
435 return res;
436 }
437 };
438 } // namespace impl
439
440 template<typename M6Like, typename Scalar, int Options>
442 Eigen::MatrixBase<M6Like>,
444 {
445 typedef typename SizeDepType<3>::ColsReturn<M6Like>::ConstType M6LikeCols;
446 typedef typename Eigen::internal::remove_const<M6LikeCols>::type M6LikeColsNonConst;
447
449 typedef typename Constraint::Vector3 Vector3;
450 typedef const typename MatrixMatrixProduct<M6LikeColsNonConst, Vector3>::type ReturnType;
451 };
452
453 /* [ABA] operator* (Inertia Y,Constraint S) */
454 namespace impl
455 {
456 template<typename M6Like, typename Scalar, int Options>
458 Eigen::MatrixBase<M6Like>,
460 {
462 typedef
463 typename MultiplicationOp<Eigen::MatrixBase<M6Like>, Constraint>::ReturnType ReturnType;
464 static inline ReturnType run(const Eigen::MatrixBase<M6Like> & Y, const Constraint & cru)
465 {
467 return Y.derived().template middleCols<3>(Constraint::LINEAR) * cru.axis();
468 }
469 };
470 } // namespace impl
471
472 template<typename Scalar, int Options>
474
475 template<typename _Scalar, int _Options>
477 {
478 enum
479 {
480 NQ = 1,
481 NV = 1,
482 NVExtended = 1
483 };
484 typedef _Scalar Scalar;
485 enum
486 {
487 Options = _Options
488 };
495
496 // [ABA]
497 typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
498 typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
499 typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
500
501 typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
502 typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
503
504 typedef boost::mpl::true_ is_mimicable_t;
505
506 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
507 };
508
509 template<typename _Scalar, int _Options>
515
516 template<typename _Scalar, int _Options>
518 : public JointDataBase<JointDataPrismaticUnalignedTpl<_Scalar, _Options>>
519 {
522 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
523 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
524
525 ConfigVector_t joint_q;
526 TangentVector_t joint_v;
527
528 Transformation_t M;
529 Constraint_t S;
530 Motion_t v;
531 Bias_t c;
532
533 // [ABA] specific data
534 U_t U;
535 D_t Dinv;
536 UD_t UDinv;
537 D_t StU;
538
540 : joint_q(ConfigVector_t::Zero())
541 , joint_v(TangentVector_t::Zero())
542 , M(Transformation_t::Vector3::Zero())
543 , S(Constraint_t::Vector3::Zero())
544 , v(Constraint_t::Vector3::Zero(), (Scalar)0)
545 , U(U_t::Zero())
546 , Dinv(D_t::Zero())
547 , UDinv(UD_t::Zero())
548 , StU(D_t::Zero())
549 {
550 }
551
552 template<typename Vector3Like>
553 JointDataPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
554 : joint_q(ConfigVector_t::Zero())
555 , joint_v(TangentVector_t::Zero())
556 , M(Transformation_t::Vector3::Zero())
557 , S(axis)
558 , v(axis, (Scalar)0)
559 , U(U_t::Zero())
560 , Dinv(D_t::Zero())
561 , UDinv(UD_t::Zero())
562 , StU(D_t::Zero())
563 {
564 }
565
566 static std::string classname()
567 {
568 return std::string("JointDataPrismaticUnaligned");
569 }
570 std::string shortname() const
571 {
572 return classname();
573 }
574
575 }; // struct JointDataPrismaticUnalignedTpl
576
577 template<typename _Scalar, int _Options>
583
584 PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelPrismaticUnalignedTpl);
585 template<typename _Scalar, int _Options>
587 : public JointModelBase<JointModelPrismaticUnalignedTpl<_Scalar, _Options>>
588 {
591 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
592
594 using Base::id;
595 using Base::idx_q;
596 using Base::idx_v;
597 using Base::idx_vExtended;
598 using Base::setIndexes;
599
600 typedef Eigen::Matrix<Scalar, 3, 1, _Options> Vector3;
601
603 : axis(Vector3::UnitX())
604 {
605 }
606 JointModelPrismaticUnalignedTpl(const Scalar & x, const Scalar & y, const Scalar & z)
607 : axis(x, y, z)
608 {
610 assert(isUnitary(axis) && "Translation axis is not unitary");
611 }
612
613 template<typename Vector3Like>
614 JointModelPrismaticUnalignedTpl(const Eigen::MatrixBase<Vector3Like> & axis)
615 : axis(axis)
616 {
618 assert(isUnitary(axis) && "Translation axis is not unitary");
619 }
620
621 JointDataDerived createData() const
622 {
623 return JointDataDerived(axis);
624 }
625
626 const std::vector<bool> hasConfigurationLimit() const
627 {
628 return {true};
629 }
630
631 const std::vector<bool> hasConfigurationLimitInTangent() const
632 {
633 return {true};
634 }
635
636 using Base::isEqual;
637 bool isEqual(const JointModelPrismaticUnalignedTpl & other) const
638 {
639 return Base::isEqual(other) && internal::comparison_eq(axis, other.axis);
640 }
641
642 template<typename ConfigVector>
643 void calc(JointDataDerived & data, const typename Eigen::MatrixBase<ConfigVector> & qs) const
644 {
645 data.joint_q[0] = qs[idx_q()];
646 data.M.translation().noalias() = axis * data.joint_q[0];
647 }
648
649 template<typename TangentVector>
650 void
651 calc(JointDataDerived & data, const Blank, const typename Eigen::MatrixBase<TangentVector> & vs)
652 const
653 {
654 data.joint_v[0] = vs[idx_v()];
655 data.v.linearRate() = data.joint_v[0];
656 }
657
658 template<typename ConfigVector, typename TangentVector>
659 void calc(
660 JointDataDerived & data,
661 const typename Eigen::MatrixBase<ConfigVector> & qs,
662 const typename Eigen::MatrixBase<TangentVector> & vs) const
663 {
664 calc(data, qs.derived());
665
666 data.joint_v[0] = vs[idx_v()];
667 data.v.linearRate() = data.joint_v[0];
668 }
669
670 template<typename VectorLike, typename Matrix6Like>
671 void calc_aba(
672 JointDataDerived & data,
673 const Eigen::MatrixBase<VectorLike> & armature,
674 const Eigen::MatrixBase<Matrix6Like> & I,
675 const bool update_I) const
676 {
677 data.U.noalias() = I.template block<6, 3>(0, Inertia::LINEAR) * axis;
678 data.Dinv[0] =
679 Scalar(1) / (axis.dot(data.U.template segment<3>(Inertia::LINEAR)) + armature[0]);
680 data.UDinv.noalias() = data.U * data.Dinv;
681
682 if (update_I)
683 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
684 }
685
686 static std::string classname()
687 {
688 return std::string("JointModelPrismaticUnaligned");
689 }
690 std::string shortname() const
691 {
692 return classname();
693 }
694
696 template<typename NewScalar>
698 {
700 ReturnType res(axis.template cast<NewScalar>());
701 res.setIndexes(id(), idx_q(), idx_v(), idx_vExtended());
702 return res;
703 }
704
705 // data
706
710 Vector3 axis;
711 }; // struct JointModelPrismaticUnalignedTpl
712
713 template<typename Scalar, int Options>
715 {
717 };
718} // namespace pinocchio
719
720#include <boost/type_traits.hpp>
721
722namespace boost
723{
724 template<typename Scalar, int Options>
725 struct has_nothrow_constructor<::pinocchio::JointModelPrismaticUnalignedTpl<Scalar, Options>>
726 : public integral_constant<bool, true>
727 {
728 };
729
730 template<typename Scalar, int Options>
731 struct has_nothrow_copy<::pinocchio::JointModelPrismaticUnalignedTpl<Scalar, Options>>
732 : public integral_constant<bool, true>
733 {
734 };
735
736 template<typename Scalar, int Options>
737 struct has_nothrow_constructor<::pinocchio::JointDataPrismaticUnalignedTpl<Scalar, Options>>
738 : public integral_constant<bool, true>
739 {
740 };
741
742 template<typename Scalar, int Options>
743 struct has_nothrow_copy<::pinocchio::JointDataPrismaticUnalignedTpl<Scalar, Options>>
744 : public integral_constant<bool, true>
745 {
746 };
747} // namespace boost
748
749#endif // ifndef __pinocchio_multibody_joint_prismatic_unaligned_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
void normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
JointDataTpl< Scalar, Options, JointCollectionTpl >::TangentVector_t joint_v(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataVariant through JointConfigVisitor to get the joint velocity vector.
JointDataTpl< Scalar, Options, JointCollectionTpl >::ConfigVector_t joint_q(const JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata)
Visit a JointDataVariant through JointConfigVisitor to get the joint configuration vector.
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.
Definition matrix.hpp:155
Blank type.
Definition fwd.hpp:77
Assign the correct configuration vector space affine transformation according to the joint type....
Return type of the Constraint::Transpose * Force operation.
Return type of the Constraint::Transpose * ForceSet operation.
JointModelPrismaticUnalignedTpl< NewScalar, Options > cast() const
Linear affine transformation of the configuration vector. Valide for most common joints which are evo...
Return type of the ation of a Motion onto an object of type D.
Definition motion.hpp:46
Forward declaration of the multiplication operation return type. Should be overloaded,...
Definition binary-op.hpp:15
Common traits structure to fully define base classes for CRTP.
Definition fwd.hpp:72