GCC Code Coverage Report


Directory: ./
File: include/pinocchio/multibody/joint/joint-generic.hpp
Date: 2025-02-12 21:03:38
Exec Total Coverage
Lines: 117 119 98.3%
Branches: 9 14 64.3%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2021 CNRS INRIA
3 //
4
5 #ifndef __pinocchio_multibody_joint_generic_hpp__
6 #define __pinocchio_multibody_joint_generic_hpp__
7
8 #include "pinocchio/multibody/joint/joint-collection.hpp"
9 #include "pinocchio/multibody/joint/joint-composite.hpp"
10 #include "pinocchio/multibody/joint/joint-basic-visitors.hxx"
11 #include "pinocchio/container/aligned-vector.hpp"
12
13 #include <boost/mpl/contains.hpp>
14
15 namespace pinocchio
16 {
17
18 template<
19 typename Scalar,
20 int Options = context::Options,
21 template<typename S, int O> class JointCollectionTpl = JointCollectionDefaultTpl>
22 struct JointTpl;
23 typedef JointTpl<context::Scalar> Joint;
24
25 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
26 struct traits<JointTpl<_Scalar, _Options, JointCollectionTpl>>
27 {
28 enum
29 {
30 Options = _Options,
31 NQ = Eigen::Dynamic, // Dynamic because unknown at compile time
32 NV = Eigen::Dynamic
33 };
34
35 typedef _Scalar Scalar;
36 typedef JointCollectionTpl<Scalar, Options> JointCollection;
37 typedef JointDataTpl<Scalar, Options, JointCollectionTpl> JointDataDerived;
38 typedef JointModelTpl<Scalar, Options, JointCollectionTpl> JointModelDerived;
39
40 typedef JointMotionSubspaceTpl<Eigen::Dynamic, Scalar, Options> Constraint_t;
41 typedef SE3Tpl<Scalar, Options> Transformation_t;
42 typedef MotionTpl<Scalar, Options> Motion_t;
43 typedef MotionTpl<Scalar, Options> Bias_t;
44
45 // [ABA]
46 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> U_t;
47 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> D_t;
48 typedef Eigen::Matrix<Scalar, 6, Eigen::Dynamic, Options> UD_t;
49
50 typedef Constraint_t ConstraintTypeConstRef;
51 typedef Constraint_t ConstraintTypeRef;
52 typedef Transformation_t TansformTypeConstRef;
53 typedef Transformation_t TansformTypeRef;
54 typedef Motion_t MotionTypeConstRef;
55 typedef Motion_t MotionTypeRef;
56 typedef Bias_t BiasTypeConstRef;
57 typedef Bias_t BiasTypeRef;
58 typedef U_t UTypeConstRef;
59 typedef U_t UTypeRef;
60 typedef D_t DTypeConstRef;
61 typedef D_t DTypeRef;
62 typedef UD_t UDTypeConstRef;
63 typedef UD_t UDTypeRef;
64
65 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> ConfigVector_t;
66 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> TangentVector_t;
67
68 typedef ConfigVector_t ConfigVectorTypeConstRef;
69 typedef ConfigVector_t ConfigVectorTypeRef;
70 typedef TangentVector_t TangentVectorTypeConstRef;
71 typedef TangentVector_t TangentVectorTypeRef;
72 };
73
74 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
75 struct traits<JointDataTpl<_Scalar, _Options, JointCollectionTpl>>
76 {
77 typedef JointTpl<_Scalar, _Options, JointCollectionTpl> JointDerived;
78 typedef typename traits<JointDerived>::Scalar Scalar;
79 };
80
81 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
82 struct traits<JointModelTpl<_Scalar, _Options, JointCollectionTpl>>
83 {
84 typedef JointTpl<_Scalar, _Options, JointCollectionTpl> JointDerived;
85 typedef typename traits<JointDerived>::Scalar Scalar;
86 };
87
88 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
89 struct JointDataTpl
90 : public JointDataBase<JointDataTpl<_Scalar, _Options, JointCollectionTpl>>
91 , JointCollectionTpl<_Scalar, _Options>::JointDataVariant
92 {
93 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
94
95 typedef JointTpl<_Scalar, _Options, JointCollectionTpl> JointDerived;
96 typedef JointDataBase<JointDataTpl> Base;
97
98 PINOCCHIO_JOINT_DATA_TYPEDEF_TEMPLATE(JointDerived);
99
100 typedef JointCollectionTpl<_Scalar, _Options> JointCollection;
101 typedef typename JointCollection::JointDataVariant JointDataVariant;
102
103 using Base::operator==;
104 using Base::operator!=;
105
106 JointDataVariant & toVariant()
107 {
108 return *static_cast<JointDataVariant *>(this);
109 }
110 662 const JointDataVariant & toVariant() const
111 {
112 662 return *static_cast<const JointDataVariant *>(this);
113 }
114
115 862 ConfigVector_t joint_q() const
116 {
117 862 return pinocchio::joint_q(*this);
118 }
119 662 TangentVector_t joint_v() const
120 {
121 662 return pinocchio::joint_v(*this);
122 }
123 715 Constraint_t S() const
124 {
125 715 return joint_motin_subspace_xd(*this);
126 }
127 720 Transformation_t M() const
128 {
129 720 return joint_transform(*this);
130 }
131 739 Motion_t v() const
132 {
133 741 return motion(*this);
134 }
135 687 Bias_t c() const
136 {
137 687 return bias(*this);
138 }
139
140 // [ABA CCRBA]
141 824 U_t U() const
142 {
143 824 return u_inertia(*this);
144 }
145 743 D_t Dinv() const
146 {
147 743 return dinv_inertia(*this);
148 }
149 743 UD_t UDinv() const
150 {
151 743 return udinv_inertia(*this);
152 }
153 83 D_t StU() const
154 {
155 83 return stu_inertia(*this);
156 }
157
158 330 JointDataTpl()
159 330 : JointDataVariant()
160 {
161 330 }
162
163 JointDataTpl(const JointDataVariant & jdata_variant)
164 : JointDataVariant(jdata_variant)
165 {
166 }
167
168 template<typename JointDataDerived>
169 44376 JointDataTpl(const JointDataBase<JointDataDerived> & jdata)
170 44376 : JointCollection::JointDataVariant((JointDataVariant)jdata.derived())
171 {
172 BOOST_MPL_ASSERT((boost::mpl::contains<typename JointDataVariant::types, JointDataDerived>));
173 44376 }
174
175 // Define all the standard accessors
176 862 ConfigVector_t joint_q_accessor() const
177 {
178 862 return joint_q();
179 }
180 662 TangentVector_t joint_v_accessor() const
181 {
182 662 return joint_v();
183 }
184 663 Constraint_t S_accessor() const
185 {
186 663 return S();
187 }
188 668 Transformation_t M_accessor() const
189 {
190 668 return M();
191 }
192 664 Motion_t v_accessor() const
193 {
194 666 return v();
195 }
196 662 Bias_t c_accessor() const
197 {
198 662 return c();
199 }
200 662 U_t U_accessor() const
201 {
202 662 return U();
203 }
204 662 D_t Dinv_accessor() const
205 {
206 662 return Dinv();
207 }
208 662 UD_t UDinv_accessor() const
209 {
210 662 return UDinv();
211 }
212 D_t StU_accessor() const
213 {
214 return StU();
215 }
216
217 1 static std::string classname()
218 {
219
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 return "JointData";
220 }
221 25 std::string shortname() const
222 {
223 25 return ::pinocchio::shortname(*this);
224 }
225
226 template<typename JointDataDerived>
227 100 bool isEqual(const JointDataBase<JointDataDerived> & other) const
228 {
229 100 return ::pinocchio::isEqual(*this, other.derived());
230 }
231
232 431 bool isEqual(const JointDataTpl & other) const
233 {
234
3/4
✓ Branch 1 taken 331 times.
✓ Branch 2 taken 100 times.
✓ Branch 6 taken 331 times.
✗ Branch 7 not taken.
431 return Base::isEqual(other) && toVariant() == other.toVariant();
235 }
236
237 431 bool operator==(const JointDataTpl & other) const
238 {
239 431 return isEqual(other);
240 }
241
242 100 bool operator!=(const JointDataTpl & other) const
243 {
244 100 return !(*this == other);
245 }
246 };
247
248 template<
249 typename NewScalar,
250 typename Scalar,
251 int Options,
252 template<typename S, int O> class JointCollectionTpl>
253 struct CastType<NewScalar, JointModelTpl<Scalar, Options, JointCollectionTpl>>
254 {
255 typedef JointModelTpl<NewScalar, Options, JointCollectionTpl> type;
256 };
257
258 template<typename _Scalar, int _Options, template<typename S, int O> class JointCollectionTpl>
259 struct JointModelTpl
260 : JointModelBase<JointModelTpl<_Scalar, _Options, JointCollectionTpl>>
261 , JointCollectionTpl<_Scalar, _Options>::JointModelVariant
262 {
263 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
264
265 typedef JointTpl<_Scalar, _Options, JointCollectionTpl> JointDerived;
266
267 PINOCCHIO_JOINT_TYPEDEF_TEMPLATE(JointDerived);
268 PINOCCHIO_JOINT_USE_INDEXES(JointModelTpl);
269
270 typedef JointCollectionTpl<Scalar, Options> JointCollection;
271 typedef typename JointCollection::JointDataVariant JointDataVariant;
272 typedef typename JointCollection::JointModelVariant JointModelVariant;
273
274 using Base::id;
275 using Base::setIndexes;
276 using Base::operator==;
277 using Base::operator!=;
278
279 2387 JointModelTpl()
280 2387 : JointModelVariant()
281 {
282 2387 }
283
284 JointModelTpl(const JointModelVariant & jmodel_variant)
285 : JointCollection::JointModelVariant(jmodel_variant)
286 {
287 }
288
289 3 const std::vector<bool> hasConfigurationLimit() const
290 {
291 3 return ::pinocchio::hasConfigurationLimit(*this);
292 }
293
294 3 const std::vector<bool> hasConfigurationLimitInTangent() const
295 {
296 3 return ::pinocchio::hasConfigurationLimitInTangent(*this);
297 }
298
299 template<typename JointModelDerived>
300 29658 JointModelTpl(const JointModelBase<JointModelDerived> & jmodel)
301 29658 : JointModelVariant((JointModelVariant)jmodel.derived())
302 {
303 BOOST_MPL_ASSERT(
304 (boost::mpl::contains<typename JointModelVariant::types, JointModelDerived>));
305 29658 }
306
307 JointModelVariant & toVariant()
308 {
309 return *static_cast<JointModelVariant *>(this);
310 }
311
312 6091 const JointModelVariant & toVariant() const
313 {
314 6091 return *static_cast<const JointModelVariant *>(this);
315 }
316
317 33 JointDataDerived createData() const
318 {
319 33 return ::pinocchio::createData<Scalar, Options, JointCollectionTpl>(*this);
320 }
321
322 template<typename JointModelDerived>
323 104 bool isEqual(const JointModelBase<JointModelDerived> & other) const
324 {
325 104 return ::pinocchio::isEqual(*this, other.derived());
326 }
327
328 template<typename JointModelDerived>
329 3100 bool hasSameIndexes(const JointModelBase<JointModelDerived> & other) const
330 {
331 3100 return ::pinocchio::hasSameIndexes(*this, other.derived());
332 }
333
334 3045 bool isEqual(const JointModelTpl & other) const
335 {
336
3/4
✓ Branch 1 taken 1905 times.
✓ Branch 2 taken 4 times.
✓ Branch 6 taken 1905 times.
✗ Branch 7 not taken.
3045 return Base::isEqual(other) && toVariant() == other.toVariant();
337 }
338
339 3041 bool operator==(const JointModelTpl & other) const
340 {
341 3041 return isEqual(other);
342 }
343
344 3 bool operator!=(const JointModelTpl & other) const
345 {
346 3 return !(*this == other);
347 }
348
349 template<typename ConfigVector>
350 31 void calc(JointDataDerived & data, const Eigen::MatrixBase<ConfigVector> & q) const
351 {
352 31 calc_zero_order(*this, data, q.derived());
353 31 }
354
355 template<typename TangentVector>
356 void calc(
357 JointDataDerived & data, const Blank blank, const Eigen::MatrixBase<TangentVector> & v) const
358 {
359 calc_first_order(*this, data, blank, v.derived());
360 }
361
362 template<typename ConfigVector, typename TangentVector>
363 54 void calc(
364 JointDataDerived & data,
365 const Eigen::MatrixBase<ConfigVector> & q,
366 const Eigen::MatrixBase<TangentVector> & v) const
367 {
368 54 calc_first_order(*this, data, q.derived(), v.derived());
369 54 }
370
371 template<typename VectorLike, typename Matrix6Like>
372 50 void calc_aba(
373 JointDataDerived & data,
374 const Eigen::MatrixBase<VectorLike> & armature,
375 const Eigen::MatrixBase<Matrix6Like> & I,
376 const bool update_I) const
377 {
378 50 ::pinocchio::calc_aba(
379 50 *this, data, armature.derived(), PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like, I), update_I);
380 50 }
381
382 61 std::string shortname() const
383 {
384 61 return ::pinocchio::shortname(*this);
385 }
386 1 static std::string classname()
387 {
388
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 return "JointModel";
389 }
390
391 1547396 int nq_impl() const
392 {
393 1547396 return ::pinocchio::nq(*this);
394 }
395 10443672 int nv_impl() const
396 {
397 10446457 return ::pinocchio::nv(*this);
398 }
399
400 1493623 int idx_q_impl() const
401 {
402 1493623 return ::pinocchio::idx_q(*this);
403 }
404 4490455 int idx_v_impl() const
405 {
406 4493449 return ::pinocchio::idx_v(*this);
407 }
408
409 3522 JointIndex id_impl() const
410 {
411 3522 return ::pinocchio::id(*this);
412 }
413
414 14306 void setIndexes(JointIndex id, int nq, int nv)
415 {
416 14306 ::pinocchio::setIndexes(*this, id, nq, nv);
417 14306 }
418
419 /// \returns An expression of *this with the Scalar type casted to NewScalar.
420 template<typename NewScalar>
421 659 JointModelTpl<NewScalar, Options, JointCollectionTpl> cast() const
422 {
423 659 return cast_joint<NewScalar, Scalar, Options, JointCollectionTpl>(*this);
424 }
425 };
426
427 typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointData) JointDataVector;
428 typedef PINOCCHIO_ALIGNED_STD_VECTOR(JointModel) JointModelVector;
429
430 template<
431 typename Scalar,
432 int Options,
433 template<typename S, int O> class JointCollectionTpl,
434 typename JointDataDerived>
435 50 bool operator==(
436 const JointDataBase<JointDataDerived> & joint_data,
437 const JointDataTpl<Scalar, Options, JointCollectionTpl> & joint_data_generic)
438 {
439 50 return joint_data_generic == joint_data.derived();
440 }
441
442 template<
443 typename Scalar,
444 int Options,
445 template<typename S, int O> class JointCollectionTpl,
446 typename JointDataDerived>
447 50 bool operator!=(
448 const JointDataBase<JointDataDerived> & joint_data,
449 const JointDataTpl<Scalar, Options, JointCollectionTpl> & joint_data_generic)
450 {
451
1/2
✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
50 return joint_data_generic != joint_data.derived();
452 }
453
454 template<
455 typename Scalar,
456 int Options,
457 template<typename S, int O> class JointCollectionTpl,
458 typename JointModelDerived>
459 26 bool operator==(
460 const JointModelBase<JointModelDerived> & joint_model,
461 const JointModelTpl<Scalar, Options, JointCollectionTpl> & joint_model_generic)
462 {
463 26 return joint_model_generic == joint_model.derived();
464 }
465
466 template<
467 typename Scalar,
468 int Options,
469 template<typename S, int O> class JointCollectionTpl,
470 typename JointModelDerived>
471 bool operator!=(
472 const JointModelBase<JointModelDerived> & joint_model,
473 const JointModelTpl<Scalar, Options, JointCollectionTpl> & joint_model_generic)
474 {
475 return joint_model_generic != joint_model.derived();
476 }
477
478 } // namespace pinocchio
479
480 #endif // ifndef __pinocchio_multibody_joint_generic_hpp__
481