GCC Code Coverage Report


Directory: ./
File: include/pinocchio/multibody/joint/joint-model-base.hpp
Date: 2024-08-27 18:20:05
Exec Total Coverage
Lines: 107 121 88.4%
Branches: 34 68 50.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2015-2019 CNRS INRIA
3 // Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5
6 #ifndef __pinocchio_multibody_joint_model_base_hpp__
7 #define __pinocchio_multibody_joint_model_base_hpp__
8
9 #include "pinocchio/multibody/joint/joint-base.hpp"
10 #include "pinocchio/multibody/joint/joint-common-operations.hpp"
11
12 #include "pinocchio/math/matrix-block.hpp"
13
14 #include <limits>
15
16 #define PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, TYPENAME) \
17 typedef Eigen::DenseIndex Index; \
18 typedef TYPENAME traits<Joint>::Scalar Scalar; \
19 typedef TYPENAME traits<Joint>::JointDataDerived JointDataDerived; \
20 typedef TYPENAME traits<Joint>::JointModelDerived JointModelDerived; \
21 typedef TYPENAME traits<Joint>::Constraint_t Constraint_t; \
22 typedef TYPENAME traits<Joint>::Transformation_t Transformation_t; \
23 typedef TYPENAME traits<Joint>::Motion_t Motion_t; \
24 typedef TYPENAME traits<Joint>::Bias_t Bias_t; \
25 typedef TYPENAME traits<Joint>::U_t U_t; \
26 typedef TYPENAME traits<Joint>::D_t D_t; \
27 typedef TYPENAME traits<Joint>::UD_t UD_t; \
28 enum \
29 { \
30 Options = traits<Joint>::Options, \
31 NQ = traits<Joint>::NQ, \
32 NV = traits<Joint>::NV \
33 }; \
34 typedef TYPENAME traits<Joint>::ConfigVector_t ConfigVector_t; \
35 typedef TYPENAME traits<Joint>::TangentVector_t TangentVector_t
36
37 #ifdef __clang__
38
39 #define PINOCCHIO_JOINT_TYPEDEF(Joint) \
40 PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, PINOCCHIO_EMPTY_ARG)
41 #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(Joint) \
42 PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, typename)
43
44 #elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 2)
45
46 #define PINOCCHIO_JOINT_TYPEDEF(Joint) \
47 PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, PINOCCHIO_EMPTY_ARG)
48 #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(Joint) \
49 PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, typename)
50
51 #else
52
53 #define PINOCCHIO_JOINT_TYPEDEF(Joint) PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, typename)
54 #define PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(Joint) \
55 PINOCCHIO_JOINT_MODEL_TYPEDEF_GENERIC(Joint, typename)
56
57 #endif
58
59 #define PINOCCHIO_JOINT_USE_INDEXES(Joint) \
60 typedef JointModelBase<Joint> Base; \
61 using Base::idx_q; \
62 using Base::idx_v
63
64 #define PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelTpl) \
65 template<typename Scalar, int Options, typename NewScalar> \
66 struct CastType<NewScalar, JointModelTpl<Scalar, Options>> \
67 { \
68 typedef JointModelTpl<NewScalar, Options> type; \
69 }
70
71 namespace pinocchio
72 {
73
74 template<typename Derived>
75 struct JointModelBase : NumericalBase<Derived>
76 {
77 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
78
79 typedef typename traits<Derived>::JointDerived JointDerived;
80 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
81
82 12324 JointModelDerived & derived()
83 {
84 12324 return *static_cast<Derived *>(this);
85 }
86 43937445 const JointModelDerived & derived() const
87 {
88 43951220 return *static_cast<const Derived *>(this);
89 }
90
91 35060 JointDataDerived createData() const
92 {
93 35060 return derived().createData();
94 }
95
96 const std::vector<bool> hasConfigurationLimit() const
97 {
98 return derived().hasConfigurationLimit();
99 }
100
101 const std::vector<bool> hasConfigurationLimitInTangent() const
102 {
103 return derived().hasConfigurationLimitInTangent();
104 }
105
106 template<typename ConfigVectorType>
107 1014074 void calc(JointDataDerived & data, const Eigen::MatrixBase<ConfigVectorType> & qs) const
108 {
109 1014074 derived().calc(data, qs.derived());
110 }
111
112 template<typename TangentVectorType>
113 void calc(
114 JointDataDerived & data,
115 const Blank not_used,
116 const Eigen::MatrixBase<TangentVectorType> & vs) const
117 {
118 derived().calc(data, not_used, vs.derived());
119 }
120
121 template<typename ConfigVectorType, typename TangentVectorType>
122 196482 void calc(
123 JointDataDerived & data,
124 const Eigen::MatrixBase<ConfigVectorType> & qs,
125 const Eigen::MatrixBase<TangentVectorType> & vs) const
126 {
127 196482 derived().calc(data, qs.derived(), vs.derived());
128 }
129
130 template<typename VectorLike, typename Matrix6Like>
131 54 void calc_aba(
132 JointDataDerived & data,
133 const Eigen::MatrixBase<VectorLike> & armature,
134 const Eigen::MatrixBase<Matrix6Like> & I,
135 const bool update_I = false) const
136 {
137 108 derived().calc_aba(
138 54 data, armature.derived(), PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I), update_I);
139 }
140
141 33683014 int nv() const
142 {
143 33683014 return derived().nv_impl();
144 }
145 1653471 int nq() const
146 {
147 3306942 return derived().nq_impl();
148 }
149
150 // Default _impl methods are reimplemented by dynamic-size joints.
151 16908046 int nv_impl() const
152 {
153 16908046 return NV;
154 }
155 833690 int nq_impl() const
156 {
157 1667380 return NQ;
158 }
159
160 4848040 int idx_q() const
161 {
162 4848040 return derived().idx_q_impl();
163 }
164 7493814 int idx_v() const
165 {
166 14987628 return derived().idx_v_impl();
167 }
168 646405 JointIndex id() const
169 {
170 1292810 return derived().id_impl();
171 }
172
173 2464344 int idx_q_impl() const
174 {
175 2464344 return i_q;
176 }
177 1896589 int idx_v_impl() const
178 {
179 5812598 return i_v;
180 }
181 646310 JointIndex id_impl() const
182 {
183 1292620 return i_id;
184 }
185
186 12324 void setIndexes(JointIndex id, int q, int v)
187 {
188 12324 derived().setIndexes_impl(id, q, v);
189 }
190
191 12324 void setIndexes_impl(JointIndex id, int q, int v)
192 {
193 12324 i_id = id, i_q = q;
194 12324 i_v = v;
195 }
196
197 28 void disp(std::ostream & os) const
198 {
199 using namespace std;
200
2/4
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
56 os << shortname() << endl
201
4/8
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
28 << " index: " << id() << endl
202
4/8
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
28 << " index q: " << idx_q() << endl
203
4/8
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
28 << " index v: " << idx_v() << endl
204
4/8
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
28 << " nq: " << nq() << endl
205
4/8
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
28 << " nv: " << nv() << endl;
206 }
207
208 28 friend std::ostream & operator<<(std::ostream & os, const JointModelBase<Derived> & joint)
209 {
210 28 joint.disp(os);
211 28 return os;
212 }
213
214 90 std::string shortname() const
215 {
216 90 return derived().shortname();
217 }
218 static std::string classname()
219 {
220 return Derived::classname();
221 }
222
223 template<typename NewScalar>
224 typename CastType<NewScalar, Derived>::type cast() const
225 {
226 return derived().template cast<NewScalar>();
227 }
228
229 template<class OtherDerived>
230 118 bool operator==(const JointModelBase<OtherDerived> & other) const
231 {
232 118 return derived().isEqual(other.derived());
233 }
234
235 template<class OtherDerived>
236 bool operator!=(const JointModelBase<OtherDerived> & other) const
237 {
238 return !(internal::comparison_eq(derived(), other.derived()));
239 }
240
241 template<class OtherDerived>
242 bool isEqual(const JointModelBase<OtherDerived> &) const
243 {
244 return false;
245 }
246
247 236 bool isEqual(const JointModelBase<Derived> & other) const
248 {
249 236 return derived().hasSameIndexes(other.derived());
250 }
251
252 template<class OtherDerived>
253 236 bool hasSameIndexes(const JointModelBase<OtherDerived> & other) const
254 {
255
3/6
✓ Branch 1 taken 118 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 118 times.
✗ Branch 8 not taken.
236 return internal::comparison_eq(other.id(), id())
256
4/8
✓ Branch 1 taken 118 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 118 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 118 times.
✗ Branch 10 not taken.
236 && internal::comparison_eq(other.idx_q(), idx_q())
257
5/10
✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 118 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 118 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 118 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 118 times.
✗ Branch 12 not taken.
472 && internal::comparison_eq(other.idx_v(), idx_v());
258 }
259
260 /* Acces to dedicated segment in robot config space. */
261 // Const access
262 template<typename D>
263 typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
264 382492 jointConfigSelector(const Eigen::MatrixBase<D> & a) const
265 {
266 382492 return derived().jointConfigSelector_impl(a);
267 }
268
269 template<typename D>
270 typename SizeDepType<NQ>::template SegmentReturn<D>::ConstType
271 382492 jointConfigSelector_impl(const Eigen::MatrixBase<D> & a) const
272 {
273 382492 return SizeDepType<NQ>::segment(a.derived(), idx_q(), nq());
274 }
275
276 // Non-const access
277 template<typename D>
278 typename SizeDepType<NQ>::template SegmentReturn<D>::Type
279 262148 jointConfigSelector(Eigen::MatrixBase<D> & a) const
280 {
281 262148 return derived().jointConfigSelector_impl(a);
282 }
283
284 template<typename D>
285 typename SizeDepType<NQ>::template SegmentReturn<D>::Type
286 262148 jointConfigSelector_impl(Eigen::MatrixBase<D> & a) const
287 {
288 262148 return SizeDepType<NQ>::segment(a, idx_q(), nq());
289 }
290
291 /* Acces to dedicated segment in robot config velocity space. */
292 // Const access
293 template<typename D>
294 typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
295 227856 jointVelocitySelector(const Eigen::MatrixBase<D> & a) const
296 {
297 227856 return derived().jointVelocitySelector_impl(a.derived());
298 }
299
300 template<typename D>
301 typename SizeDepType<NV>::template SegmentReturn<D>::ConstType
302 227850 jointVelocitySelector_impl(const Eigen::MatrixBase<D> & a) const
303 {
304 227850 return SizeDepType<NV>::segment(a.derived(), idx_v(), nv());
305 }
306
307 // Non-const access
308 template<typename D>
309 typename SizeDepType<NV>::template SegmentReturn<D>::Type
310 207202 jointVelocitySelector(Eigen::MatrixBase<D> & a) const
311 {
312 207202 return derived().jointVelocitySelector_impl(a.derived());
313 }
314
315 template<typename D>
316 typename SizeDepType<NV>::template SegmentReturn<D>::Type
317 207202 jointVelocitySelector_impl(Eigen::MatrixBase<D> & a) const
318 {
319 207202 return SizeDepType<NV>::segment(a.derived(), idx_v(), nv());
320 }
321
322 /* Acces to dedicated columns in a ForceSet or MotionSet matrix.*/
323 // Const access
324 template<typename D>
325 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
326 2206 jointCols(const Eigen::MatrixBase<D> & A) const
327 {
328 2206 return derived().jointCols_impl(A.derived());
329 }
330
331 template<typename D>
332 typename SizeDepType<NV>::template ColsReturn<D>::ConstType
333 2206 jointCols_impl(const Eigen::MatrixBase<D> & A) const
334 {
335 2206 return SizeDepType<NV>::middleCols(A.derived(), idx_v(), nv());
336 }
337
338 // Non-const access
339 template<typename D>
340 383092 typename SizeDepType<NV>::template ColsReturn<D>::Type jointCols(Eigen::MatrixBase<D> & A) const
341 {
342 383092 return derived().jointCols_impl(A.derived());
343 }
344
345 template<typename D>
346 typename SizeDepType<NV>::template ColsReturn<D>::Type
347 333274 jointCols_impl(Eigen::MatrixBase<D> & A) const
348 {
349 333274 return SizeDepType<NV>::middleCols(A.derived(), idx_v(), nv());
350 }
351
352 /* Acces to dedicated rows in a matrix.*/
353 // Const access
354 template<typename D>
355 typename SizeDepType<NV>::template RowsReturn<D>::ConstType
356 44 jointRows(const Eigen::MatrixBase<D> & A) const
357 {
358 44 return derived().jointRows_impl(A.derived());
359 }
360
361 template<typename D>
362 typename SizeDepType<NV>::template RowsReturn<D>::ConstType
363 44 jointRows_impl(const Eigen::MatrixBase<D> & A) const
364 {
365 44 return SizeDepType<NV>::middleRows(A.derived(), idx_v(), nv());
366 }
367
368 // Non-const access
369 template<typename D>
370 88 typename SizeDepType<NV>::template RowsReturn<D>::Type jointRows(Eigen::MatrixBase<D> & A) const
371 {
372 88 return derived().jointRows_impl(A.derived());
373 }
374
375 template<typename D>
376 typename SizeDepType<NV>::template RowsReturn<D>::Type
377 88 jointRows_impl(Eigen::MatrixBase<D> & A) const
378 {
379 88 return SizeDepType<NV>::middleRows(A.derived(), idx_v(), nv());
380 }
381
382 /// \brief Returns a block of dimension nv()xnv() located at position idx_v(),idx_v() in the
383 /// matrix Mat
384 // Const access
385 template<typename D>
386 typename SizeDepType<NV>::template BlockReturn<D>::ConstType
387 jointBlock(const Eigen::MatrixBase<D> & Mat) const
388 {
389 return derived().jointBlock_impl(Mat.derived());
390 }
391
392 template<typename D>
393 typename SizeDepType<NV>::template BlockReturn<D>::ConstType
394 jointBlock_impl(const Eigen::MatrixBase<D> & Mat) const
395 {
396 return SizeDepType<NV>::block(Mat.derived(), idx_v(), idx_v(), nv(), nv());
397 }
398
399 // Non-const access
400 template<typename D>
401 typename SizeDepType<NV>::template BlockReturn<D>::Type
402 616 jointBlock(Eigen::MatrixBase<D> & Mat) const
403 {
404 616 return derived().jointBlock_impl(Mat.derived());
405 }
406
407 template<typename D>
408 typename SizeDepType<NV>::template BlockReturn<D>::Type
409 308 jointBlock_impl(Eigen::MatrixBase<D> & Mat) const
410 {
411 308 return SizeDepType<NV>::block(Mat.derived(), idx_v(), idx_v(), nv(), nv());
412 }
413
414 protected:
415 /// Default constructor: protected.
416 ///
417 /// Prevent the construction of stand-alone JointModelBase.
418 20330 inline JointModelBase()
419 20330 : i_id(std::numeric_limits<JointIndex>::max())
420 20330 , i_q(-1)
421 20330 , i_v(-1)
422 {
423 20330 }
424
425 /// Copy constructor: protected.
426 ///
427 /// Copy of stand-alone JointModelBase are prevented, but can be used from inhereting
428 /// objects. Copy is done by calling copy operator.
429 74535 inline JointModelBase(const JointModelBase & clone)
430 {
431 74535 *this = clone;
432 74535 }
433
434 /// Copy operator: protected.
435 ///
436 /// Copy of stand-alone JointModelBase are prevented, but can be used from inhereting
437 /// objects.
438 37321 inline JointModelBase & operator=(const JointModelBase & clone)
439 {
440 37321 i_id = clone.i_id;
441 37321 i_q = clone.i_q;
442 37321 i_v = clone.i_v;
443 37321 return *this;
444 }
445
446 // data
447 JointIndex i_id; // ID of the joint in the multibody list.
448 int i_q; // Index of the joint configuration in the joint configuration vector.
449 int i_v; // Index of the joint velocity in the joint velocity vector.
450
451 }; // struct JointModelBase
452
453 } // namespace pinocchio
454
455 #endif // ifndef __pinocchio_multibody_joint_model_base_hpp__
456