pinocchio  3.9.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
joint-mimic.hpp
1//
2// Copyright (c) 2019-2021 INRIA
3//
4
5#ifndef __pinocchio_multibody_joint_mimic_hpp__
6#define __pinocchio_multibody_joint_mimic_hpp__
7
8#include "pinocchio/multibody/joint/fwd.hpp"
9#include "pinocchio/multibody/joint/joint-collection.hpp"
10#include "pinocchio/macros.hpp"
11#include "pinocchio/multibody/joint/joint-base.hpp"
12#include "pinocchio/multibody/joint/joint-basic-visitors.hpp"
13
14namespace pinocchio
15{
16 template<typename _Scalar, int _Options, int MaxDim>
18
19 template<typename _Scalar, int _Options, int _MaxDim>
20 struct traits<ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>>
21 {
22 enum
23 {
24 MaxDim = _MaxDim
25 };
27 RefJointMotionSubspace;
28 typedef typename traits<RefJointMotionSubspace>::Scalar Scalar;
29 enum
30 {
32 };
33 enum
34 {
37 };
38 typedef typename traits<RefJointMotionSubspace>::JointMotion JointMotion;
39 typedef typename traits<RefJointMotionSubspace>::JointForce JointForce;
40 typedef typename traits<RefJointMotionSubspace>::DenseBase DenseBase;
41 typedef typename traits<RefJointMotionSubspace>::MatrixReturnType MatrixReturnType;
42 typedef typename traits<RefJointMotionSubspace>::ConstMatrixReturnType ConstMatrixReturnType;
43 }; // traits ScaledJointMotionSubspaceTpl
44
45 template<typename _Scalar, int _Options, int _MaxDim>
46 struct SE3GroupAction<ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>>
47 {
48 typedef typename SE3GroupAction<typename traits<
50 ReturnType;
51 };
52
53 template<typename _Scalar, int _Options, int _MaxDim, typename MotionDerived>
55 ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>,
56 MotionDerived>
57 {
58 typedef typename MotionAlgebraAction<
59 typename traits<
61 MotionDerived>::ReturnType ReturnType;
62 };
63
64 template<typename _Scalar, int _Options, int _MaxDim, typename ForceDerived>
65 struct ConstraintForceOp<ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>, ForceDerived>
66 {
67 typedef
68 typename ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>::RefJointMotionSubspace
69 RefJointMotionSubspace;
70 typedef
71 typename ConstraintForceOp<RefJointMotionSubspace, ForceDerived>::ReturnType RefReturnType;
72 typedef typename ScalarMatrixProduct<_Scalar, RefReturnType>::type ReturnType;
73 };
74
75 template<typename _Scalar, int _Options, int _MaxDim, typename ForceSet>
76 struct ConstraintForceSetOp<ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>, ForceSet>
77 {
78 typedef
79 typename ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>::RefJointMotionSubspace
80 RefJointMotionSubspace;
81 typedef
82 typename ConstraintForceSetOp<RefJointMotionSubspace, ForceSet>::ReturnType RefReturnType;
83 typedef typename ScalarMatrixProduct<_Scalar, RefReturnType>::type ReturnType;
84 };
85
86 template<typename _Scalar, int _Options, int _MaxDim>
87 struct ScaledJointMotionSubspaceTpl
88 : JointMotionSubspaceBase<ScaledJointMotionSubspaceTpl<_Scalar, _Options, _MaxDim>>
89 {
90 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
91
92 PINOCCHIO_CONSTRAINT_TYPEDEF_TPL(ScaledJointMotionSubspaceTpl)
93 enum
94 {
95 NV = Eigen::Dynamic,
96 MaxDim = _MaxDim
97 };
99 using Base::nv;
100
102 RefJointMotionSubspace RefJointMotionSubspace;
103 typedef typename SE3GroupAction<RefJointMotionSubspace>::ReturnType SE3ActionReturnType;
104
105 ScaledJointMotionSubspaceTpl()
106 : m_constraint(0)
107 , m_scaling_factor(Scalar(1))
108 {
109 }
110
111 explicit ScaledJointMotionSubspaceTpl(const Scalar & scaling_factor)
112 : m_constraint(0)
113 , m_scaling_factor(scaling_factor)
114 {
115 }
116
117 template<typename ConstraintTpl>
118 ScaledJointMotionSubspaceTpl(const ConstraintTpl & constraint, const Scalar & scaling_factor)
119 : m_constraint(constraint)
120 , m_scaling_factor(scaling_factor)
121 {
122 }
123
124 ScaledJointMotionSubspaceTpl(const ScaledJointMotionSubspaceTpl & other)
125 : m_constraint(other.m_constraint)
126 , m_scaling_factor(other.m_scaling_factor)
127 {
128 }
129
130 ScaledJointMotionSubspaceTpl & operator=(const ScaledJointMotionSubspaceTpl & other)
131 {
132 m_constraint = other.m_constraint;
133 m_scaling_factor = other.m_scaling_factor;
134 return *this;
135 }
136
137 template<typename VectorLike>
138 JointMotion __mult__(const Eigen::MatrixBase<VectorLike> & v) const
139 {
140
141 assert(v.size() == nv());
142 JointMotion jm = m_constraint * v;
143 return m_scaling_factor * jm;
144 }
145
146 template<typename S1, int O1>
147 SE3ActionReturnType se3Action(const SE3Tpl<S1, O1> & m) const
148 {
149 return m_scaling_factor * m_constraint.se3Action(m);
150 }
151
152 template<typename S1, int O1>
153 SE3ActionReturnType se3ActionInverse(const SE3Tpl<S1, O1> & m) const
154 {
155 return m_scaling_factor * m_constraint.se3ActionInverse(m);
156 }
157
158 int nv_impl() const
159 {
160 return m_constraint.nv();
161 }
162
163 struct TransposeConst
164 {
165 const ScaledJointMotionSubspaceTpl & ref;
166 explicit TransposeConst(const ScaledJointMotionSubspaceTpl & ref)
167 : ref(ref)
168 {
169 }
170
171 template<typename Derived>
172 // typename ConstraintForceOp<ScaledJointMotionSubspaceTpl, Derived>::ReturnType
173 JointForce operator*(const ForceDense<Derived> & f) const
174 {
175 return ref.m_scaling_factor * (ref.m_constraint.transpose() * f);
176 }
177
179 template<typename Derived>
180 typename ConstraintForceSetOp<ScaledJointMotionSubspaceTpl, Derived>::ReturnType
181 operator*(const Eigen::MatrixBase<Derived> & F) const
182 {
183 return ref.m_scaling_factor * (ref.m_constraint.transpose() * F);
184 }
185
186 }; // struct TransposeConst
187
188 TransposeConst transpose() const
189 {
190 return TransposeConst(*this);
191 }
192
193 const DenseBase & matrix_impl() const
194 {
195 S = m_scaling_factor * m_constraint.matrix_impl();
196 return S;
197 }
198
199 DenseBase & matrix_impl()
200 {
201 S = m_scaling_factor * m_constraint.matrix_impl();
202 return S;
203 }
204
205 template<typename MotionDerived>
206 typename MotionAlgebraAction<ScaledJointMotionSubspaceTpl, MotionDerived>::ReturnType
207 motionAction(const MotionDense<MotionDerived> & m) const
208 {
209 return m_scaling_factor * m_constraint.motionAction(m);
210 }
211
212 inline const Scalar & scaling() const
213 {
214 return m_scaling_factor;
215 }
216 inline Scalar & scaling()
217 {
218 return m_scaling_factor;
219 }
220
221 inline const RefJointMotionSubspace & constraint() const
222 {
223 return m_constraint.derived();
224 }
225 inline RefJointMotionSubspace & constraint()
226 {
227 return m_constraint.derived();
228 }
229
230 bool isEqual(const ScaledJointMotionSubspaceTpl & other) const
231 {
232 return m_constraint == other.m_constraint && m_scaling_factor == other.m_scaling_factor;
233 }
234
235 protected:
236 RefJointMotionSubspace m_constraint;
237 Scalar m_scaling_factor;
238 mutable DenseBase S;
239 }; // struct ScaledJointMotionSubspaceTpl
240
241 template<typename S1, int O1, typename S2, int O2, int MD2>
243 {
244 typedef InertiaTpl<S1, O1> Inertia;
246 typedef typename Constraint::Scalar Scalar;
247
248 typedef Eigen::Matrix<S2, 6, Eigen::Dynamic, O2, 6, MD2> ReturnType;
249 };
250
251 /* [CRBA] ForceSet operator* (Inertia Y,Constraint S) */
252 namespace impl
253 {
254 template<typename S1, int O1, typename S2, int O2, int MD2>
256 {
257 typedef InertiaTpl<S1, O1> Inertia;
259 typedef typename MultiplicationOp<Inertia, Constraint>::ReturnType ReturnType;
260
261 static inline ReturnType run(const Inertia & Y, const Constraint & scaled_constraint)
262 {
263 return scaled_constraint.scaling() * (Y * scaled_constraint.constraint());
264 }
265 };
266 } // namespace impl
267
268 template<typename M6Like, typename S2, int O2, int MD2>
269 struct MultiplicationOp<Eigen::MatrixBase<M6Like>, ScaledJointMotionSubspaceTpl<S2, O2, MD2>>
270 {
271 typedef ScaledJointMotionSubspaceTpl<S2, O2, MD2> MotionSubspace;
272 typedef Eigen::Matrix<S2, 6, Eigen::Dynamic, O2, 6, MD2> ReturnType;
273 };
274
275 /* [ABA] operator* (Inertia Y,Constraint S) */
276 namespace impl
277 {
278 template<typename M6Like, typename S2, int O2, int MD2>
279 struct LhsMultiplicationOp<Eigen::MatrixBase<M6Like>, ScaledJointMotionSubspaceTpl<S2, O2, MD2>>
280 {
282 typedef
283 typename MultiplicationOp<Eigen::MatrixBase<M6Like>, Constraint>::ReturnType ReturnType;
284
285 static inline ReturnType
286 run(const Eigen::MatrixBase<M6Like> & Y, const Constraint & scaled_constraint)
287 {
288 return scaled_constraint.scaling() * (Y.derived() * scaled_constraint.constraint());
289 }
290 };
291 } // namespace impl
292
293 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
295 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
296 struct JointModelMimicTpl;
297 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
298 struct JointDataMimicTpl;
299
300 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
301 struct traits<JointMimicTpl<_Scalar, _Options, JointCollectionTpl>>
302 {
303 typedef _Scalar Scalar;
304
305 enum
306 {
307 Options = _Options,
308 NQ = Eigen::Dynamic,
309 NV = Eigen::Dynamic,
310 NVExtended = Eigen::Dynamic,
311 MaxNVMimicked = 6
312 };
313
314 typedef JointCollectionTpl<Scalar, Options> JointCollection;
317
319 typedef SE3Tpl<Scalar, Options> Transformation_t;
320 typedef MotionTpl<Scalar, Options> Motion_t;
321 typedef MotionTpl<Scalar, Options> Bias_t;
322
323 // [ABA]
324 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> U_t;
325 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> D_t;
326 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> UD_t;
327
328 typedef const Constraint_t & ConstraintTypeConstRef;
329 typedef Constraint_t & ConstraintTypeRef;
330 typedef Transformation_t TansformTypeConstRef;
331 typedef Transformation_t TansformTypeRef;
332 typedef Motion_t MotionTypeConstRef;
333 typedef Motion_t MotionTypeRef;
334 typedef Bias_t BiasTypeConstRef;
335 typedef Bias_t BiasTypeRef;
336 typedef U_t UTypeConstRef;
337 typedef U_t UTypeRef;
338 typedef D_t DTypeConstRef;
339 typedef D_t DTypeRef;
340 typedef UD_t UDTypeConstRef;
341 typedef UD_t UDTypeRef;
342
343 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> ConfigVector_t;
344 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> TangentVector_t;
345
346 typedef const ConfigVector_t & ConfigVectorTypeConstRef;
347 typedef ConfigVector_t & ConfigVectorTypeRef;
348 typedef const TangentVector_t TangentVectorTypeConstRef;
349 typedef TangentVector_t & TangentVectorTypeRef;
350
351 typedef boost::mpl::false_ is_mimicable_t;
352 };
353
354 template<typename _Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
355 struct traits<JointDataMimicTpl<_Scalar, Options, JointCollectionTpl>>
356 {
358 typedef _Scalar Scalar;
359 };
360
361 template<typename _Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
362 struct traits<JointModelMimicTpl<_Scalar, Options, JointCollectionTpl>>
363 {
365 typedef _Scalar Scalar;
366 };
367
368 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
369 struct JointDataMimicTpl
370 : public JointDataBase<JointDataMimicTpl<_Scalar, _Options, JointCollectionTpl>>
371 {
372 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
373
376 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
377
379 typedef typename RefJointData::JointDataVariant RefJointDataVariant;
380
381 JointDataMimicTpl()
382 : S((Scalar)0)
383 {
384 joint_q.resize(0, 1);
385 joint_q_transformed.resize(0, 1);
386 joint_v.resize(0, 1);
387 joint_v_transformed.resize(0, 1);
388 }
389
390 JointDataMimicTpl(
391 const RefJointData & jdata, const Scalar & scaling, const int & nq, const int & nv)
392 : m_jdata_mimicking(checkMimic(jdata.derived()))
393 , S(m_jdata_mimicking.S(), scaling)
394 {
395 joint_q.resize(nq, 1);
396 joint_q_transformed.resize(nq, 1);
397 joint_v.resize(nv, 1);
398 joint_v_transformed.resize(nv, 1);
399 }
400
401 JointDataMimicTpl(const JointDataMimicTpl & other)
402 {
403 *this = other;
404 }
405
406 JointDataMimicTpl & operator=(const JointDataMimicTpl & other)
407 {
408 m_jdata_mimicking = other.m_jdata_mimicking;
409 joint_q = other.joint_q;
411 joint_v = other.joint_v;
413 S = Constraint_t(other.S);
414 return *this;
415 }
416
417 using Base::isEqual;
418 bool isEqual(const JointDataMimicTpl & other) const
419 {
420 return Base::isEqual(other) && m_jdata_mimicking == other.m_jdata_mimicking
423 }
424
425 static std::string classname()
426 {
427 return std::string("JointDataMimic");
428 }
429
430 std::string shortname() const
431 {
432 return classname();
433 }
434
435 // // Accessors
436 ConstraintTypeConstRef S_accessor() const
437 {
438 return S;
439 }
440 ConstraintTypeRef S_accessor()
441 {
442 return S;
443 }
444
445 Transformation_t M_accessor() const
446 {
447 return m_jdata_mimicking.M();
448 }
449
450 Motion_t v_accessor() const
451 {
452 return m_jdata_mimicking.v();
453 }
454
455 Bias_t c_accessor() const
456 {
457 return m_jdata_mimicking.c();
458 }
459
460 U_t U_accessor() const
461 {
462 return m_jdata_mimicking.U();
463 }
464
465 D_t Dinv_accessor() const
466 {
467 return m_jdata_mimicking.Dinv();
468 }
469
470 UD_t UDinv_accessor() const
471 {
472 return m_jdata_mimicking.UDinv();
473 }
474
475 D_t StU_accessor() const
476 {
477 return m_jdata_mimicking.StU();
478 }
479
480 friend struct JointModelMimicTpl<_Scalar, _Options, JointCollectionTpl>;
481
482 const RefJointData & jdata() const
483 {
484 return m_jdata_mimicking;
485 }
486 RefJointData & jdata()
487 {
488 return m_jdata_mimicking;
489 }
490
491 ConfigVectorTypeRef joint_q_accessor()
492 {
493 return joint_q;
494 }
495 ConfigVectorTypeConstRef joint_q_accessor() const
496 {
497 return joint_q;
498 }
499
500 ConfigVector_t & q_transformed()
501 {
503 }
504 const ConfigVector_t & q_transformed() const
505 {
507 }
508 TangentVectorTypeRef joint_v_accessor()
509 {
510 return joint_v;
511 }
512 TangentVectorTypeConstRef joint_v_accessor() const
513 {
514 return joint_v;
515 }
516
517 TangentVector_t & v_transformed()
518 {
520 }
521 const TangentVector_t & v_transformed() const
522 {
524 }
525
526 void disp(std::ostream & os) const
527 {
528 Base::disp(os);
529 os << " Mimicking joint data: " << m_jdata_mimicking.shortname() << std::endl;
530 }
531
532 RefJointData m_jdata_mimicking;
533
535 ConfigVector_t joint_q;
537 ConfigVector_t joint_q_transformed;
539 TangentVector_t joint_v;
541 TangentVector_t joint_v_transformed;
542 // data
543 Constraint_t S;
544 }; // struct JointDataMimicTpl
545
546 template<
547 typename NewScalar,
548 typename Scalar,
549 int Options,
550 template<typename S, int O> class JointCollectionTpl>
551 struct CastType<NewScalar, JointModelMimicTpl<Scalar, Options, JointCollectionTpl>>
552 {
554 };
555
556 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
557 struct JointModelMimicTpl
558 : public JointModelBase<JointModelMimicTpl<_Scalar, _Options, JointCollectionTpl>>
559 {
560 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
561
564 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
565 enum
566 {
568 };
569
570 typedef JointCollectionTpl<Scalar, Options> JointCollection;
572
573 typedef SE3Tpl<Scalar, Options> SE3;
574 typedef MotionTpl<Scalar, Options> Motion;
575 typedef InertiaTpl<Scalar, Options> Inertia;
576
577 using Base::id;
578 using Base::idx_q;
579 using Base::idx_v;
580 using Base::idx_vExtended;
581 using Base::nq;
582 using Base::nv;
583 using Base::nvExtended;
584 using Base::setIndexes;
585
586 JointModelMimicTpl()
587 {
588 }
589
590 template<typename JointModel>
591 JointModelMimicTpl(
592 const JointModelBase<JointModel> & jmodel, const Scalar & scaling, const Scalar & offset)
593 : JointModelMimicTpl(jmodel, jmodel, scaling, offset)
594 {
595 }
596
597 template<typename JointModelMimicking, typename JointModelMimicked>
598 JointModelMimicTpl(
599 const JointModelBase<JointModelMimicking> & jmodel_mimicking,
600 const JointModelBase<JointModelMimicked> & jmodel_mimicked,
601 const Scalar & scaling,
602 const Scalar & offset)
603 : m_jmodel_mimicking(checkMimic((JointModel)jmodel_mimicking.derived()))
604 , m_scaling(scaling)
605 , m_offset(offset)
606 , m_nqExtended(jmodel_mimicking.nq())
607 , m_nvExtended(jmodel_mimicking.nvExtended())
608 {
609 // Throw in case nq and nv from mimicking and mimicked are different
610 PINOCCHIO_CHECK_ARGUMENT_SIZE(
611 jmodel_mimicking.nq(), jmodel_mimicked.nq(),
612 "Mimicking and mimicked configuration spaces have different sizes");
613 PINOCCHIO_CHECK_ARGUMENT_SIZE(
614 jmodel_mimicking.nv(), jmodel_mimicked.nv(),
615 "Mimicking and mimicked tangent spaces have different sizes");
616 PINOCCHIO_CHECK_ARGUMENT_SIZE(
617 jmodel_mimicking.nvExtended(), jmodel_mimicked.nvExtended(),
618 "Mimicking and mimicked extended tangent spaces have different sizes");
619
621 jmodel_mimicked.id(), jmodel_mimicked.idx_q(), jmodel_mimicked.idx_v(),
622 jmodel_mimicked.idx_vExtended());
623 }
624
625 Base & base()
626 {
627 return *static_cast<Base *>(this);
628 }
629 const Base & base() const
630 {
631 return *static_cast<const Base *>(this);
632 }
633
634 inline int nq_impl() const
635 {
636 return 0;
637 }
638 inline int nv_impl() const
639 {
640 return 0;
641 }
642 inline int nvExtended_impl() const
643 {
644 return m_nvExtended;
645 }
646
652 void setIndexes_impl(JointIndex id, int /*q*/, int /*v*/, int vExtended)
653 {
654 PINOCCHIO_THROW(
655 (id > m_jmodel_mimicking.id()), std::invalid_argument,
656 "Mimic joint index is lower than its directing joint. Should never happen");
657 Base::i_id = id;
658 // Base::i_q = q;
659 // Base::i_v = v;
660 Base::i_vExtended = vExtended;
661 }
662
672 void setMimicIndexes(JointIndex id, int q, int v, int vExtended)
673 {
674 // Set idx_q, idx_v to zero because only the corresponding subsegment of q,v are passed to the
675 // m_jmodel_mimicking, thus, its indexes starts at 0
676 m_jmodel_mimicking.setIndexes(id, 0, 0, vExtended);
677
678 // idx_q, idx_v are kept separately to extract the subsegment
679 Base::i_q = q;
680 Base::i_v = v;
681 }
682
683 JointDataDerived createData() const
684 {
685 return JointDataDerived(
686 m_jmodel_mimicking.createData(), scaling(), m_nqExtended, m_nvExtended);
687 }
688
689 const std::vector<bool> hasConfigurationLimit() const
690 {
691 return {};
692 }
693
694 const std::vector<bool> hasConfigurationLimitInTangent() const
695 {
696 return {};
697 }
698
699 template<typename ConfigVector>
700 PINOCCHIO_DONT_INLINE void
701 calc(JointDataDerived & jdata, const typename Eigen::MatrixBase<ConfigVector> & qs) const
702 {
703 jdata.joint_q = qs.segment(Base::i_q, m_nqExtended);
705 m_jmodel_mimicking, jdata.joint_q, m_scaling, m_offset, jdata.joint_q_transformed);
706 m_jmodel_mimicking.calc(jdata.m_jdata_mimicking, jdata.joint_q_transformed);
707 }
708
709 template<typename ConfigVector, typename TangentVector>
710 PINOCCHIO_DONT_INLINE void calc(
711 JointDataDerived & jdata,
712 const typename Eigen::MatrixBase<ConfigVector> & qs,
713 const typename Eigen::MatrixBase<TangentVector> & vs) const
714 {
715 jdata.joint_q = qs.segment(Base::i_q, m_nqExtended);
716 jdata.joint_v = vs.segment(Base::i_v, m_nvExtended);
718 m_jmodel_mimicking, jdata.joint_q, m_scaling, m_offset, jdata.joint_q_transformed);
719 jdata.joint_v_transformed = m_scaling * jdata.joint_v;
720
721 m_jmodel_mimicking.calc(
722 jdata.m_jdata_mimicking, jdata.joint_q_transformed, jdata.joint_v_transformed);
723 }
724
725 template<typename VectorLike, typename Matrix6Like>
726 void calc_aba(
727 JointDataDerived &,
728 const Eigen::MatrixBase<VectorLike> &,
729 const Eigen::MatrixBase<Matrix6Like> &,
730 const bool) const
731 {
732 assert(
733 false
734 && "Joint Mimic is not supported for aba yet. Remove it from your model if you want to use "
735 "this function");
736 }
737
738 static std::string classname()
739 {
740 return std::string("JointModelMimic");
741 }
742
743 std::string shortname() const
744 {
745 return classname();
746 }
747
749 template<typename NewScalar>
751 {
753 ReturnType res(
754 m_jmodel_mimicking.template cast<NewScalar>(),
755 ScalarCast<NewScalar, Scalar>::cast(m_scaling),
756 ScalarCast<NewScalar, Scalar>::cast(m_offset));
757 res.setIndexes(id(), Base::i_q, Base::i_v, Base::i_vExtended);
758 res.setMimicIndexes(m_jmodel_mimicking.id(), Base::i_q, Base::i_v, Base::i_vExtended);
759 return res;
760 }
761
762 const JointModel & jmodel() const
763 {
764 return m_jmodel_mimicking;
765 }
766 JointModel & jmodel()
767 {
768 return m_jmodel_mimicking;
769 }
770
771 const Scalar & scaling() const
772 {
773 return m_scaling;
774 }
775 Scalar & scaling()
776 {
777 return m_scaling;
778 }
779
780 const Scalar & offset() const
781 {
782 return m_offset;
783 }
784 Scalar & offset()
785 {
786 return m_offset;
787 }
788
789 protected:
790 // data
791 JointModel m_jmodel_mimicking;
792 Scalar m_scaling, m_offset;
793 int m_nqExtended, m_nvExtended;
794
795 public:
796 /* Acces to dedicated segment in robot config space. */
797 // Const access
798 template<typename D>
799 typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
800 JointMappedConfigSelector_impl(const Eigen::MatrixBase<D> & a) const
801 {
802 return SizeDepType<NQ>::segment(a.derived(), Base::i_q, m_nqExtended);
803 }
804
805 // Non-const access
806 template<typename D>
807 typename SizeDepType<NQ>::template SegmentReturn<D>::Type
808 JointMappedConfigSelector_impl(Eigen::MatrixBase<D> & a) const
809 {
810 return SizeDepType<NQ>::segment(a.derived(), Base::i_q, m_nqExtended);
811 }
812 /* Acces to dedicated segment in robot tangent space. */
813 // Const access
814 template<typename D>
815 typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
816 JointMappedVelocitySelector_impl(const Eigen::MatrixBase<D> & a) const
817 {
818 return SizeDepType<NQ>::segment(a.derived(), Base::i_v, m_nvExtended);
819 }
820
821 // Non-const access
822 template<typename D>
823 typename SizeDepType<NQ>::template SegmentReturn<D>::Type
824 JointMappedVelocitySelector_impl(Eigen::MatrixBase<D> & a) const
825 {
826 return SizeDepType<NQ>::segment(a.derived(), Base::i_v, m_nvExtended);
827 }
828
829 /* Acces to dedicated columns in a ForceSet or MotionSet matrix.*/
830 // Const access
831 template<typename D>
832 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
833 jointCols_impl(const Eigen::MatrixBase<D> & A) const
834 {
835 return SizeDepType<NV>::middleCols(A.derived(), Base::i_v, m_nvExtended);
836 }
837
838 // Non-const access
839 template<typename D>
840 typename SizeDepType<NV>::template ColsReturn<D>::Type
841 jointCols_impl(Eigen::MatrixBase<D> & A) const
842 {
843 return SizeDepType<NV>::middleCols(A.derived(), Base::i_v, m_nvExtended);
844 }
845
846 /* Acces to dedicated rows in a matrix.*/
847 // Const access
848 template<typename D>
849 typename SizeDepType<NV>::template RowsReturn<D>::ConstType
850 jointRows_impl(const Eigen::MatrixBase<D> & A) const
851 {
852 return SizeDepType<NV>::middleRows(A.derived(), Base::i_v, m_nvExtended);
853 }
854
855 // Non-const access
856 template<typename D>
857 typename SizeDepType<NV>::template RowsReturn<D>::Type
858 jointRows_impl(Eigen::MatrixBase<D> & A) const
859 {
860 return SizeDepType<NV>::middleRows(A.derived(), Base::i_v, m_nvExtended);
861 }
862
863 // /// \brief Returns a block of dimension nv()xnv() located at position idx_v(),idx_v() in the
864 // matrix Mat
865 // // Const access
866 template<typename D>
867 typename SizeDepType<NV>::template BlockReturn<D>::ConstType
868 jointBlock_impl(const Eigen::MatrixBase<D> & Mat) const
869 {
870 return SizeDepType<NV>::block(
871 Mat.derived(), Base::i_v, Base::i_v, m_nvExtended, m_nvExtended);
872 }
873
874 // Non-const access
875 template<typename D>
876 typename SizeDepType<NV>::template BlockReturn<D>::Type
877 jointBlock_impl(Eigen::MatrixBase<D> & Mat) const
878 {
879 return SizeDepType<NV>::block(
880 Mat.derived(), Base::i_v, Base::i_v, m_nvExtended, m_nvExtended);
881 }
882
883 void disp(std::ostream & os) const
884 {
885 Base::disp(os);
886 os << " Mimicking joint type: " << m_jmodel_mimicking.shortname() << std::endl;
887 os << " Mimicked joint id: " << m_jmodel_mimicking.id() << std::endl;
888 os << " Mimic scaling: " << m_scaling << std::endl;
889 os << " Mimic offset: " << m_offset << std::endl;
890 }
891
892 }; // struct JointModelMimicTpl
893
894} // namespace pinocchio
895
896#include <boost/type_traits.hpp>
897
898namespace boost
899{
900 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
901 struct has_nothrow_constructor<
902 ::pinocchio::JointModelMimicTpl<Scalar, Options, JointCollectionTpl>>
903 : public integral_constant<bool, true>
904 {
905 };
906
907 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
908 struct has_nothrow_copy<::pinocchio::JointModelMimicTpl<Scalar, Options, JointCollectionTpl>>
909 : public integral_constant<bool, true>
910 {
911 };
912
913 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
914 struct has_nothrow_constructor<
915 ::pinocchio::JointDataMimicTpl<Scalar, Options, JointCollectionTpl>>
916 : public integral_constant<bool, true>
917 {
918 };
919
920 template<typename Scalar, int Options, template<typename S, int O> class JointCollectionTpl>
921 struct has_nothrow_copy<::pinocchio::JointDataMimicTpl<Scalar, Options, JointCollectionTpl>>
922 : public integral_constant<bool, true>
923 {
924 };
925} // namespace boost
926
927#endif // ifndef __pinocchio_multibody_joint_mimic_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space.
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space.
void configVectorAffineTransform(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, const Eigen::MatrixBase< ConfigVectorIn > &qIn, const Scalar &scaling, const Scalar &offset, const Eigen::MatrixBase< ConfigVectorOut > &qOut)
Apply the correct affine transform, on a joint configuration, depending on the joint type.
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type....
Definition fwd.hpp:99
Return type of the Constraint::Transpose * Force operation.
Return type of the Constraint::Transpose * ForceSet operation.
bool isEqual(const JointDataBase< JointDataMimicTpl > &other) const
ConfigVector_t joint_q
original configuration vector
TangentVector_t joint_v
original velocity vector
TangentVector_t joint_v_transformed
Transform velocity vector.
ConfigVector_t joint_q_transformed
Transformed configuration vector.
void setMimicIndexes(JointIndex id, int q, int v, int vExtended)
Specific way for mimic joints to set the mimicked q,v indexes. Used for manipulating tree (e....
void setIndexes_impl(JointIndex id, int, int, int vExtended)
CastType< NewScalar, JointModelMimicTpl >::type cast() const
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
ConstraintForceSetOp< ScaledJointMotionSubspaceTpl, Derived >::ReturnType operator*(const Eigen::MatrixBase< Derived > &F) const
[CRBA] MatrixBase operator* (RefConstraint::Transpose S, ForceSet::Block)
Common traits structure to fully define base classes for CRTP.
Definition fwd.hpp:72