pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
joint-translation.hpp
1//
2// Copyright (c) 2015-2020 CNRS INRIA
3// Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4//
5
6#ifndef __pinocchio_multibody_joint_translation_hpp__
7#define __pinocchio_multibody_joint_translation_hpp__
8
9#include "pinocchio/macros.hpp"
10#include "pinocchio/multibody/joint/joint-base.hpp"
11#include "pinocchio/multibody/joint-motion-subspace.hpp"
12#include "pinocchio/spatial/inertia.hpp"
13#include "pinocchio/spatial/skew.hpp"
14
15namespace pinocchio
16{
17
18 template<typename Scalar, int Options = context::Options>
19 struct MotionTranslationTpl;
20 typedef MotionTranslationTpl<context::Scalar> MotionTranslation;
21
22 template<typename Scalar, int Options>
23 struct SE3GroupAction<MotionTranslationTpl<Scalar, Options>>
24 {
26 };
27
28 template<typename Scalar, int Options, typename MotionDerived>
33
34 template<typename _Scalar, int _Options>
36 {
37 typedef _Scalar Scalar;
38 enum
39 {
40 Options = _Options
41 };
42 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
43 typedef Eigen::Matrix<Scalar, 6, 1, Options> Vector6;
44 typedef Eigen::Matrix<Scalar, 4, 4, Options> Matrix4;
45 typedef Eigen::Matrix<Scalar, 6, 6, Options> Matrix6;
46 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
47 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
48 typedef Vector3 AngularType;
49 typedef Vector3 LinearType;
50 typedef const Vector3 ConstAngularType;
51 typedef const Vector3 ConstLinearType;
52 typedef Matrix6 ActionMatrixType;
53 typedef Matrix4 HomogeneousMatrixType;
56 enum
57 {
58 LINEAR = 0,
59 ANGULAR = 3
60 };
61 }; // traits MotionTranslationTpl
62
63 template<typename _Scalar, int _Options>
64 struct MotionTranslationTpl : MotionBase<MotionTranslationTpl<_Scalar, _Options>>
65 {
67
68 MOTION_TYPEDEF_TPL(MotionTranslationTpl);
69
71 {
72 }
73
74 template<typename Vector3Like>
75 MotionTranslationTpl(const Eigen::MatrixBase<Vector3Like> & v)
76 : m_v(v)
77 {
78 }
79
81 : m_v(other.m_v)
82 {
83 }
84
85 Vector3 & operator()()
86 {
87 return m_v;
88 }
89 const Vector3 & operator()() const
90 {
91 return m_v;
92 }
93
94 inline PlainReturnType plain() const
95 {
96 return PlainReturnType(m_v, PlainReturnType::Vector3::Zero());
97 }
98
99 bool isEqual_impl(const MotionTranslationTpl & other) const
100 {
101 return internal::comparison_eq(m_v, other.m_v);
102 }
103
105 {
106 m_v = other.m_v;
107 return *this;
108 }
109
110 template<typename Derived>
111 void addTo(MotionDense<Derived> & other) const
112 {
113 other.linear() += m_v;
114 }
115
116 template<typename Derived>
117 void setTo(MotionDense<Derived> & other) const
118 {
119 other.linear() = m_v;
120 other.angular().setZero();
121 }
122
123 template<typename S2, int O2, typename D2>
124 void se3Action_impl(const SE3Tpl<S2, O2> & m, MotionDense<D2> & v) const
125 {
126 v.angular().setZero();
127 v.linear().noalias() = m.rotation() * m_v; // TODO: check efficiency
128 }
129
130 template<typename S2, int O2>
131 MotionPlain se3Action_impl(const SE3Tpl<S2, O2> & m) const
132 {
133 MotionPlain res;
134 se3Action_impl(m, res);
135 return res;
136 }
137
138 template<typename S2, int O2, typename D2>
139 void se3ActionInverse_impl(const SE3Tpl<S2, O2> & m, MotionDense<D2> & v) const
140 {
141 // Linear
142 v.linear().noalias() = m.rotation().transpose() * m_v;
143
144 // Angular
145 v.angular().setZero();
146 }
147
148 template<typename S2, int O2>
149 MotionPlain se3ActionInverse_impl(const SE3Tpl<S2, O2> & m) const
150 {
151 MotionPlain res;
152 se3ActionInverse_impl(m, res);
153 return res;
154 }
155
156 template<typename M1, typename M2>
157 void motionAction(const MotionDense<M1> & v, MotionDense<M2> & mout) const
158 {
159 // Linear
160 mout.linear().noalias() = v.angular().cross(m_v);
161
162 // Angular
163 mout.angular().setZero();
164 }
165
166 template<typename M1>
167 MotionPlain motionAction(const MotionDense<M1> & v) const
168 {
169 MotionPlain res;
170 motionAction(v, res);
171 return res;
172 }
173
174 const Vector3 & linear() const
175 {
176 return m_v;
177 }
178 Vector3 & linear()
179 {
180 return m_v;
181 }
182
183 protected:
184 Vector3 m_v;
185
186 }; // struct MotionTranslationTpl
187
188 template<typename S1, int O1, typename MotionDerived>
189 inline typename MotionDerived::MotionPlain
191 {
192 return typename MotionDerived::MotionPlain(m2.linear() + m1.linear(), m2.angular());
193 }
194
195 template<typename Scalar, int Options>
196 struct TransformTranslationTpl;
197
198 template<typename _Scalar, int _Options>
200 {
201 enum
202 {
203 Options = _Options,
204 LINEAR = 0,
205 ANGULAR = 3
206 };
207 typedef _Scalar Scalar;
209 typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
210 typedef Eigen::Matrix<Scalar, 3, 3, Options> Matrix3;
211 typedef typename Matrix3::IdentityReturnType AngularType;
212 typedef AngularType AngularRef;
213 typedef AngularType ConstAngularRef;
214 typedef Vector3 LinearType;
215 typedef LinearType & LinearRef;
216 typedef const LinearType & ConstLinearRef;
217 typedef typename traits<PlainType>::ActionMatrixType ActionMatrixType;
218 typedef typename traits<PlainType>::HomogeneousMatrixType HomogeneousMatrixType;
219 }; // traits TransformTranslationTpl
220
221 template<typename Scalar, int Options>
223 {
224 typedef typename traits<TransformTranslationTpl<Scalar, Options>>::PlainType ReturnType;
225 };
226
227 template<typename _Scalar, int _Options>
228 struct TransformTranslationTpl : SE3Base<TransformTranslationTpl<_Scalar, _Options>>
229 {
231 PINOCCHIO_SE3_TYPEDEF_TPL(TransformTranslationTpl);
232 typedef typename traits<TransformTranslationTpl>::Vector3 Vector3;
233
235 {
236 }
237
238 template<typename Vector3Like>
239 TransformTranslationTpl(const Eigen::MatrixBase<Vector3Like> & translation)
240 : m_translation(translation)
241 {
242 }
243
244 PlainType plain() const
245 {
246 PlainType res(PlainType::Identity());
247 res.rotation().setIdentity();
248 res.translation() = translation();
249
250 return res;
251 }
252
253 operator PlainType() const
254 {
255 return plain();
256 }
257
258 template<typename S2, int O2>
259 typename SE3GroupAction<TransformTranslationTpl>::ReturnType
260 se3action(const SE3Tpl<S2, O2> & m) const
261 {
262 typedef typename SE3GroupAction<TransformTranslationTpl>::ReturnType ReturnType;
263 ReturnType res(m);
264 res.translation() += translation();
265
266 return res;
267 }
268
269 ConstLinearRef translation() const
270 {
271 return m_translation;
272 }
273 LinearRef translation()
274 {
275 return m_translation;
276 }
277
278 AngularType rotation() const
279 {
280 return AngularType(3, 3);
281 }
282
283 bool isEqual(const TransformTranslationTpl & other) const
284 {
285 return internal::comparison_eq(m_translation, other.m_translation);
286 }
287
288 protected:
289 LinearType m_translation;
290 };
291
292 template<typename Scalar, int Options>
294
295 template<typename _Scalar, int _Options>
297 {
298 typedef _Scalar Scalar;
299
300 enum
301 {
302 Options = _Options
303 };
304 enum
305 {
306 LINEAR = 0,
307 ANGULAR = 3
308 };
309
311 typedef Eigen::Matrix<Scalar, 3, 1, Options> JointForce;
312 typedef Eigen::Matrix<Scalar, 6, 3, Options> DenseBase;
313 typedef Eigen::Matrix<Scalar, 3, 3, Options> ReducedSquaredMatrix;
314
315 typedef DenseBase MatrixReturnType;
316 typedef const DenseBase ConstMatrixReturnType;
317
318 typedef typename ReducedSquaredMatrix::IdentityReturnType StDiagonalMatrixSOperationReturnType;
319 }; // traits JointMotionSubspaceTranslationTpl
320
321 template<typename _Scalar, int _Options>
323 : JointMotionSubspaceBase<JointMotionSubspaceTranslationTpl<_Scalar, _Options>>
324 {
326
327 PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(JointMotionSubspaceTranslationTpl)
328
329 enum
330 {
331 NV = 3
332 };
333
335 {
336 }
337
338 // template<typename S1, int O1>
339 // Motion operator*(const MotionTranslationTpl<S1,O1> & vj) const
340 // { return Motion(vj(), Motion::Vector3::Zero()); }
341
342 template<typename Vector3Like>
343 JointMotion __mult__(const Eigen::MatrixBase<Vector3Like> & v) const
344 {
346 return JointMotion(v);
347 }
348
349 int nv_impl() const
350 {
351 return NV;
352 }
353
354 struct ConstraintTranspose : JointMotionSubspaceTransposeBase<JointMotionSubspaceTranslationTpl>
355 {
358 : ref(ref)
359 {
360 }
361
362 template<typename Derived>
364 {
365 return phi.linear();
366 }
367
368 /* [CRBA] MatrixBase operator* (Constraint::Transpose S, ForceSet::Block) */
369 template<typename MatrixDerived>
370 const typename SizeDepType<3>::RowsReturn<MatrixDerived>::ConstType
371 operator*(const Eigen::MatrixBase<MatrixDerived> & F) const
372 {
373 assert(F.rows() == 6);
374 return F.derived().template middleRows<3>(LINEAR);
375 }
376
377 }; // struct ConstraintTranspose
378
379 ConstraintTranspose transpose() const
380 {
381 return ConstraintTranspose(*this);
382 }
383
384 DenseBase matrix_impl() const
385 {
386 DenseBase S;
387 S.template middleRows<3>(LINEAR).setIdentity();
388 S.template middleRows<3>(ANGULAR).setZero();
389 return S;
390 }
391
392 template<typename S1, int O1>
393 Eigen::Matrix<S1, 6, 3, O1> se3Action(const SE3Tpl<S1, O1> & m) const
394 {
395 Eigen::Matrix<S1, 6, 3, O1> M;
396 M.template middleRows<3>(LINEAR) = m.rotation();
397 M.template middleRows<3>(ANGULAR).setZero();
398
399 return M;
400 }
401
402 template<typename S1, int O1>
403 Eigen::Matrix<S1, 6, 3, O1> se3ActionInverse(const SE3Tpl<S1, O1> & m) const
404 {
405 Eigen::Matrix<S1, 6, 3, O1> M;
406 M.template middleRows<3>(LINEAR) = m.rotation().transpose();
407 M.template middleRows<3>(ANGULAR).setZero();
408
409 return M;
410 }
411
412 template<typename MotionDerived>
413 DenseBase motionAction(const MotionDense<MotionDerived> & m) const
414 {
415 const typename MotionDerived::ConstAngularType w = m.angular();
416
417 DenseBase res;
418 skew(w, res.template middleRows<3>(LINEAR));
419 res.template middleRows<3>(ANGULAR).setZero();
420
421 return res;
422 }
423
424 bool isEqual(const JointMotionSubspaceTranslationTpl &) const
425 {
426 return true;
427 }
428
429 }; // struct JointMotionSubspaceTranslationTpl
430
431 template<typename MotionDerived, typename S2, int O2>
432 inline typename MotionDerived::MotionPlain
433 operator^(const MotionDense<MotionDerived> & m1, const MotionTranslationTpl<S2, O2> & m2)
434 {
435 return m2.motionAction(m1);
436 }
437
438 /* [CRBA] ForceSet operator* (Inertia Y,Constraint S) */
439 template<typename S1, int O1, typename S2, int O2>
440 inline Eigen::Matrix<S2, 6, 3, O2>
441 operator*(const InertiaTpl<S1, O1> & Y, const JointMotionSubspaceTranslationTpl<S2, O2> &)
442 {
443 typedef JointMotionSubspaceTranslationTpl<S2, O2> Constraint;
444 Eigen::Matrix<S2, 6, 3, O2> M;
445 alphaSkew(Y.mass(), Y.lever(), M.template middleRows<3>(Constraint::ANGULAR));
446 M.template middleRows<3>(Constraint::LINEAR).setZero();
447 M.template middleRows<3>(Constraint::LINEAR).diagonal().fill(Y.mass());
448
449 return M;
450 }
451
452 /* [ABA] Y*S operator*/
453 template<typename M6Like, typename S2, int O2>
454 inline const typename SizeDepType<3>::ColsReturn<M6Like>::ConstType
455 operator*(const Eigen::MatrixBase<M6Like> & Y, const JointMotionSubspaceTranslationTpl<S2, O2> &)
456 {
457 typedef JointMotionSubspaceTranslationTpl<S2, O2> Constraint;
458 return Y.derived().template middleCols<3>(Constraint::LINEAR);
459 }
460
461 template<typename S1, int O1>
463 {
464 typedef Eigen::Matrix<S1, 6, 3, O1> ReturnType;
465 };
466
467 template<typename S1, int O1, typename MotionDerived>
469 {
470 typedef Eigen::Matrix<S1, 6, 3, O1> ReturnType;
471 };
472
473 template<typename Scalar, int Options>
475
476 template<typename _Scalar, int _Options>
478 {
479 enum
480 {
481 NQ = 3,
482 NV = 3,
483 NVExtended = 3
484 };
485 typedef _Scalar Scalar;
486 enum
487 {
488 Options = _Options
489 };
496
497 // [ABA]
498 typedef Eigen::Matrix<Scalar, 6, NV, Options> U_t;
499 typedef Eigen::Matrix<Scalar, NV, NV, Options> D_t;
500 typedef Eigen::Matrix<Scalar, 6, NV, Options> UD_t;
501
502 typedef Eigen::Matrix<Scalar, NQ, 1, Options> ConfigVector_t;
503 typedef Eigen::Matrix<Scalar, NV, 1, Options> TangentVector_t;
504
505 typedef boost::mpl::false_ is_mimicable_t;
506
507 PINOCCHIO_JOINT_DATA_BASE_ACCESSOR_DEFAULT_RETURN_TYPE
508 }; // traits JointTranslationTpl
509
510 template<typename _Scalar, int _Options>
516
517 template<typename _Scalar, int _Options>
523
524 template<typename _Scalar, int _Options>
525 struct JointDataTranslationTpl : public JointDataBase<JointDataTranslationTpl<_Scalar, _Options>>
526 {
528
530 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
531 PINOCCHIO_JOINT_DATA_BASE_DEFAULT_ACCESSOR
532
533 ConfigVector_t joint_q;
534 TangentVector_t joint_v;
535
536 Constraint_t S;
537 Transformation_t M;
538 Motion_t v;
539 Bias_t c;
540
541 // [ABA] specific data
542 U_t U;
543 D_t Dinv;
544 UD_t UDinv;
545 D_t StU;
546
548 : joint_q(ConfigVector_t::Zero())
549 , joint_v(TangentVector_t::Zero())
550 , M(Transformation_t::Vector3::Zero())
551 , v(Motion_t::Vector3::Zero())
552 , U(U_t::Zero())
553 , Dinv(D_t::Zero())
554 , UDinv(UD_t::Zero())
555 , StU(D_t::Zero())
556 {
557 }
558
559 static std::string classname()
560 {
561 return std::string("JointDataTranslation");
562 }
563 std::string shortname() const
564 {
565 return classname();
566 }
567 }; // struct JointDataTranslationTpl
568
569 PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelTranslationTpl);
570 template<typename _Scalar, int _Options>
572 : public JointModelBase<JointModelTranslationTpl<_Scalar, _Options>>
573 {
575
577 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
578
580 using Base::id;
581 using Base::idx_q;
582 using Base::idx_v;
583 using Base::idx_vExtended;
584 using Base::setIndexes;
585
586 JointDataDerived createData() const
587 {
588 return JointDataDerived();
589 }
590
591 const std::vector<bool> hasConfigurationLimit() const
592 {
593 return {true, true, true};
594 }
595
596 const std::vector<bool> hasConfigurationLimitInTangent() const
597 {
598 return {true, true, true};
599 }
600
601 template<typename ConfigVector>
602 void calc(JointDataDerived & data, const typename Eigen::MatrixBase<ConfigVector> & qs) const
603 {
604 data.joint_q = this->jointConfigSelector(qs);
605 data.M.translation() = data.joint_q;
606 }
607
608 template<typename TangentVector>
609 void
610 calc(JointDataDerived & data, const Blank, const typename Eigen::MatrixBase<TangentVector> & vs)
611 const
612 {
613 data.joint_v = this->jointVelocitySelector(vs);
614 data.v.linear() = data.joint_v;
615 }
616
617 template<typename ConfigVector, typename TangentVector>
618 void calc(
619 JointDataDerived & data,
620 const typename Eigen::MatrixBase<ConfigVector> & qs,
621 const typename Eigen::MatrixBase<TangentVector> & vs) const
622 {
623 calc(data, qs.derived());
624
625 data.joint_v = this->jointVelocitySelector(vs);
626 data.v.linear() = data.joint_v;
627 }
628
629 template<typename VectorLike, typename Matrix6Like>
630 void calc_aba(
631 JointDataDerived & data,
632 const Eigen::MatrixBase<VectorLike> & armature,
633 const Eigen::MatrixBase<Matrix6Like> & I,
634 const bool update_I) const
635 {
636 data.U = I.template middleCols<3>(Inertia::LINEAR);
637
638 data.StU = data.U.template middleRows<3>(Inertia::LINEAR);
639 data.StU.diagonal() += armature;
640
641 internal::PerformStYSInversion<Scalar>::run(data.StU, data.Dinv);
642
643 data.UDinv.noalias() = data.U * data.Dinv;
644
645 if (update_I)
646 PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I).noalias() -= data.UDinv * data.U.transpose();
647 }
648
649 static std::string classname()
650 {
651 return std::string("JointModelTranslation");
652 }
653 std::string shortname() const
654 {
655 return classname();
656 }
657
659 template<typename NewScalar>
661 {
663 ReturnType res;
664 res.setIndexes(id(), idx_q(), idx_v(), idx_vExtended());
665 return res;
666 }
667
668 }; // struct JointModelTranslationTpl
669
670 template<typename Scalar, int Options>
672 {
674 };
675} // namespace pinocchio
676
677#include <boost/type_traits.hpp>
678
679namespace boost
680{
681 template<typename Scalar, int Options>
682 struct has_nothrow_constructor<::pinocchio::JointModelTranslationTpl<Scalar, Options>>
683 : public integral_constant<bool, true>
684 {
685 };
686
687 template<typename Scalar, int Options>
688 struct has_nothrow_copy<::pinocchio::JointModelTranslationTpl<Scalar, Options>>
689 : public integral_constant<bool, true>
690 {
691 };
692
693 template<typename Scalar, int Options>
694 struct has_nothrow_constructor<::pinocchio::JointDataTranslationTpl<Scalar, Options>>
695 : public integral_constant<bool, true>
696 {
697 };
698
699 template<typename Scalar, int Options>
700 struct has_nothrow_copy<::pinocchio::JointDataTranslationTpl<Scalar, Options>>
701 : public integral_constant<bool, true>
702 {
703 };
704} // namespace boost
705
706#endif // ifndef __pinocchio_multibody_joint_translation_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
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.
void alphaSkew(const Scalar alpha, const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector multiplied by a given scalar....
Definition skew.hpp:134
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.
void skew(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector, i.e. the antisymmetric matrix representation o...
Definition skew.hpp:22
Blank type.
Definition fwd.hpp:77
Assign the correct configuration vector space affine transformation according to the joint type....
JointModelTranslationTpl< 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
Base class for rigid transformation.
Definition se3-base.hpp:31
Common traits structure to fully define base classes for CRTP.
Definition fwd.hpp:72