GCC Code Coverage Report


Directory: ./
File: include/pinocchio/bindings/python/multibody/joint/joints-models.hpp
Date: 2024-08-27 18:20:05
Exec Total Coverage
Lines: 121 138 87.7%
Branches: 95 198 48.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2015-2022 CNRS INRIA
3 //
4
5 #ifndef __pinocchio_python_joints_models_hpp__
6 #define __pinocchio_python_joints_models_hpp__
7
8 #include <boost/python.hpp>
9
10 #include "pinocchio/multibody/joint/joint-collection.hpp"
11 #include "pinocchio/multibody/joint/joint-composite.hpp"
12 #include "pinocchio/multibody/joint/joint-generic.hpp"
13
14 #include <eigenpy/eigen-to-python.hpp>
15
16 namespace pinocchio
17 {
18 namespace python
19 {
20 namespace bp = boost::python;
21
22 // generic expose_joint_model : do nothing special
23 template<class T>
24 360 bp::class_<T> & expose_joint_model(bp::class_<T> & cl)
25 {
26 360 return cl;
27 }
28
29 // specialization for JointModelRevolute
30 template<>
31 bp::class_<context::JointModelRX> &
32 20 expose_joint_model<context::JointModelRX>(bp::class_<context::JointModelRX> & cl)
33 {
34 return cl
35
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
36 40 bp::args("self"), "Init JointModelRX with the X axis ([1, 0, 0]) as rotation axis."))
37
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
38 "getMotionAxis", &context::JointModelRX::getMotionAxis,
39 40 "Rotation axis of the JointModelRX.");
40 }
41
42 template<>
43 bp::class_<context::JointModelRY> &
44 20 expose_joint_model<context::JointModelRY>(bp::class_<context::JointModelRY> & cl)
45 {
46 return cl
47
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
48 40 bp::args("self"), "Init JointModelRY with the Y axis ([0, 1, 0]) as rotation axis."))
49
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
50 "getMotionAxis", &context::JointModelRY::getMotionAxis,
51 40 "Rotation axis of the JointModelRY.");
52 }
53
54 template<>
55 bp::class_<context::JointModelRZ> &
56 20 expose_joint_model<context::JointModelRZ>(bp::class_<context::JointModelRZ> & cl)
57 {
58 return cl
59
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
60 40 bp::args("self"), "Init JointModelRZ with the Z axis ([0, 0, 1]) as rotation axis"))
61
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
62 "getMotionAxis", &context::JointModelRZ::getMotionAxis,
63 40 "Rotation axis of the JointModelRZ.");
64 }
65
66 // specialization for JointModelRevoluteUnaligned
67 template<>
68 bp::class_<context::JointModelRevoluteUnaligned> &
69 20 expose_joint_model<context::JointModelRevoluteUnaligned>(
70 bp::class_<context::JointModelRevoluteUnaligned> & cl)
71 {
72 return cl
73
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<context::Scalar, context::Scalar, context::Scalar>(
74 40 bp::args("self", "x", "y", "z"),
75 "Init JointModelRevoluteUnaligned from the components x, y, z of the axis"))
76
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<const context::Vector3s &>(
77
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self", "axis"),
78 "Init JointModelRevoluteUnaligned from an axis with x-y-z components"))
79 40 .def_readwrite(
80
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 "axis", &context::JointModelRevoluteUnaligned::axis,
81 40 "Rotation axis of the JointModelRevoluteUnaligned.");
82 }
83
84 // specialization for JointModelRevoluteUnbounded
85 template<>
86 bp::class_<context::JointModelRUBX> &
87 20 expose_joint_model<context::JointModelRUBX>(bp::class_<context::JointModelRUBX> & cl)
88 {
89 return cl
90
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
91 40 bp::args("self"), "Init JointModelRUBX with the X axis ([1, 0, 0]) as rotation axis"))
92
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
93 "getMotionAxis", &context::JointModelRUBX::getMotionAxis,
94 40 "Rotation axis of the JointModelRUBX.");
95 }
96
97 template<>
98 bp::class_<context::JointModelRUBY> &
99 20 expose_joint_model<context::JointModelRUBY>(bp::class_<context::JointModelRUBY> & cl)
100 {
101 return cl
102
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
103 40 bp::args("self"), "Init JointModelRUBY with the Y axis ([0, 1, 0]) as rotation axis"))
104
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
105 "getMotionAxis", &context::JointModelRUBY::getMotionAxis,
106 40 "Rotation axis of the JointModelRUBY.");
107 }
108
109 template<>
110 bp::class_<context::JointModelRUBZ> &
111 20 expose_joint_model<context::JointModelRUBZ>(bp::class_<context::JointModelRUBZ> & cl)
112 {
113 return cl
114
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
115 40 bp::args("self"), "Init JointModelRUBZ with the Z axis ([0, 0, 1]) as rotation axis"))
116
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
117 "getMotionAxis", &context::JointModelRUBZ::getMotionAxis,
118 40 "Rotation axis of the JointModelRUBZ.");
119 }
120
121 // specialization for JointModelPrismatic
122 template<>
123 bp::class_<context::JointModelPX> &
124 20 expose_joint_model<context::JointModelPX>(bp::class_<context::JointModelPX> & cl)
125 {
126 return cl
127
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
128 40 bp::args("self"), "Init JointModelPX with the X axis ([1, 0, 0]) as rotation axis"))
129
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
130 "getMotionAxis", &context::JointModelPX::getMotionAxis,
131 40 "Rotation axis of the JointModelPX.");
132 }
133
134 template<>
135 bp::class_<context::JointModelPY> &
136 20 expose_joint_model<context::JointModelPY>(bp::class_<context::JointModelPY> & cl)
137 {
138 return cl
139
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
140 40 bp::args("self"), "Init JointModelPY with the Y axis ([0, 1, 0]) as rotation axis"))
141
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
142 "getMotionAxis", &context::JointModelPY::getMotionAxis,
143 40 "Rotation axis of the JointModelPY.");
144 }
145
146 template<>
147 bp::class_<context::JointModelPZ> &
148 20 expose_joint_model<context::JointModelPZ>(bp::class_<context::JointModelPZ> & cl)
149 {
150 return cl
151
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
152 40 bp::args("self"), "Init JointModelPZ with the Z axis ([0, 0, 1]) as rotation axis"))
153
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
154 "getMotionAxis", &context::JointModelPZ::getMotionAxis,
155 40 "Rotation axis of the JointModelPZ.");
156 }
157
158 // specialization for JointModelPrismaticUnaligned
159 template<>
160 bp::class_<context::JointModelPrismaticUnaligned> &
161 20 expose_joint_model<context::JointModelPrismaticUnaligned>(
162 bp::class_<context::JointModelPrismaticUnaligned> & cl)
163 {
164 return cl
165
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<context::Scalar, context::Scalar, context::Scalar>(
166 40 bp::args("self", "x", "y", "z"),
167 "Init JointModelPrismaticUnaligned from the components x, y, z of the axis"))
168
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<const context::Vector3s &>(
169
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self", "axis"),
170 "Init JointModelPrismaticUnaligned from an axis with x-y-z components"))
171 40 .def_readwrite(
172
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 "axis", &context::JointModelPrismaticUnaligned::axis,
173 40 "Translation axis of the JointModelPrismaticUnaligned.");
174 }
175
176 // specialization for JointModelHelicalUnaligned
177 template<>
178 bp::class_<context::JointModelHelicalUnaligned> &
179 20 expose_joint_model<context::JointModelHelicalUnaligned>(
180 bp::class_<context::JointModelHelicalUnaligned> & cl)
181 {
182 return cl
183
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<context::Scalar, context::Scalar, context::Scalar, context::Scalar>(
184 40 bp::args("self", "x", "y", "z", "pitch"),
185 "Init JointModelHelicalUnaligned from the components x, y, z of the axis and the pitch"))
186
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<const context::Vector3s &, context::Scalar>(
187
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self", "axis", "pitch"),
188 "Init JointModelHelicalUnaligned from an axis with x-y-z components and the pitch"))
189 40 .def_readwrite(
190
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 "axis", &context::JointModelHelicalUnaligned::axis,
191 "Translation axis of the JointModelHelicalUnaligned.")
192 40 .def_readwrite(
193
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 "pitch", &context::JointModelHelicalUnaligned::m_pitch,
194 40 "Pitch h of the JointModelHelicalUnaligned.");
195 }
196
197 // specialization for JointModelHelical
198 template<>
199 bp::class_<context::JointModelHX> &
200 20 expose_joint_model<context::JointModelHX>(bp::class_<context::JointModelHX> & cl)
201 {
202 return cl
203
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<context::Scalar>(
204 40 bp::args("self", "pitch"),
205 "Init JointModelHX with pitch value and the X axis ([1, 0, 0]) as a rotation axis."))
206
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
207
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self"),
208 "Init JointModelHX with pitch 0.0 and the X axis ([1, 0, 0]) as a rotation axis."))
209
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
210 "getMotionAxis", &context::JointModelHX::getMotionAxis,
211 "Rotation axis of the JointModelHX.")
212
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("pitch", &context::JointModelHX::m_pitch, "Pitch h of the JointModelHX.");
213 }
214
215 template<>
216 bp::class_<context::JointModelHY> &
217 20 expose_joint_model<context::JointModelHY>(bp::class_<context::JointModelHY> & cl)
218 {
219 return cl
220
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<context::Scalar>(
221 40 bp::args("self", "pitch"),
222 "Init JointModelHY with pitch value and the Y axis ([0, 1, 0]) as a rotation axis."))
223
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
224
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self"),
225 "Init JointModelHY with pitch 0.0 and the Y axis ([0, 1, 0]) as a rotation axis."))
226
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
227 "getMotionAxis", &context::JointModelHY::getMotionAxis,
228 "Rotation axis of the JointModelHY.")
229
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("pitch", &context::JointModelHY::m_pitch, "Pitch h of the JointModelHY.");
230 }
231
232 template<>
233 bp::class_<context::JointModelHZ> &
234 20 expose_joint_model<context::JointModelHZ>(bp::class_<context::JointModelHZ> & cl)
235 {
236 return cl
237
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<context::Scalar>(
238 40 bp::args("self", "pitch"),
239 "Init JointModelHZ with pitch value and the Z axis ([0, 0, 1]) as a rotation axis."))
240
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<>(
241
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self"),
242 "Init JointModelHZ with pitch 0.0 and the Z axis ([0, 0, 1]) as a rotation axis."))
243
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
244 "getMotionAxis", &context::JointModelHZ::getMotionAxis,
245 "Rotation axis of the JointModelHZ.")
246
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("pitch", &context::JointModelHZ::m_pitch, "Pitch h of the JointModelHZ.");
247 }
248
249 // specialization for JointModelUniversal
250 template<>
251 bp::class_<context::JointModelUniversal> &
252 20 expose_joint_model<context::JointModelUniversal>(bp::class_<context::JointModelUniversal> & cl)
253 {
254 return cl
255
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<
256 context::Scalar, context::Scalar, context::Scalar, context::Scalar, context::Scalar,
257 context::Scalar>(
258 40 bp::args("self", "x1", "y1", "z1", "x2", "y2", "z2"),
259 "Init JointModelUniversal from the components x, y, z of the axes"))
260
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<const context::Vector3s &, const context::Vector3s &>(
261
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 bp::args("self", "axis1", "axis2"),
262 "Init JointModelUniversal from two axes with x-y-z components"))
263 40 .def_readwrite(
264
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 "axis1", &context::JointModelUniversal::axis1,
265 "First rotation axis of the JointModelUniversal.")
266 40 .def_readwrite(
267
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 "axis2", &context::JointModelUniversal::axis2,
268 40 "Second rotation axis of the JointModelUniversal.");
269 }
270
271 // specialization for JointModelComposite
272
273 struct JointModelCompositeAddJointVisitor
274 : public boost::static_visitor<context::JointModelComposite &>
275 {
276 context::JointModelComposite & m_joint_composite;
277 const context::SE3 & m_joint_placement;
278
279 JointModelCompositeAddJointVisitor(
280 context::JointModelComposite & joint_composite, const context::SE3 & joint_placement)
281 : m_joint_composite(joint_composite)
282 , m_joint_placement(joint_placement)
283 {
284 }
285
286 template<typename JointModelDerived>
287 context::JointModelComposite & operator()(JointModelDerived & jmodel) const
288 {
289 return m_joint_composite.addJoint(jmodel, m_joint_placement);
290 }
291 }; // struct JointModelCompositeAddJointVisitor
292
293 static context::JointModelComposite & addJoint_proxy(
294 context::JointModelComposite & joint_composite,
295 const context::JointModel & jmodel,
296 const context::SE3 & joint_placement = context::SE3::Identity())
297 {
298 return boost::apply_visitor(
299 JointModelCompositeAddJointVisitor(joint_composite, joint_placement), jmodel.toVariant());
300 }
301
302 struct JointModelCompositeConstructorVisitor
303 : public boost::static_visitor<context::JointModelComposite *>
304 {
305 const context::SE3 & m_joint_placement;
306
307 JointModelCompositeConstructorVisitor(const context::SE3 & joint_placement)
308 : m_joint_placement(joint_placement)
309 {
310 }
311
312 template<typename JointModelDerived>
313 context::JointModelComposite * operator()(JointModelDerived & jmodel) const
314 {
315 return new context::JointModelComposite(jmodel, m_joint_placement);
316 }
317 }; // struct JointModelCompositeConstructorVisitor
318
319 static context::JointModelComposite * init_proxy1(const context::JointModel & jmodel)
320 {
321 return boost::apply_visitor(
322 JointModelCompositeConstructorVisitor(context::SE3::Identity()), jmodel);
323 }
324
325 static context::JointModelComposite *
326 init_proxy2(const context::JointModel & jmodel, const context::SE3 & joint_placement)
327 {
328 return boost::apply_visitor(JointModelCompositeConstructorVisitor(joint_placement), jmodel);
329 }
330
331 template<>
332 bp::class_<context::JointModelComposite> &
333 20 expose_joint_model<context::JointModelComposite>(bp::class_<context::JointModelComposite> & cl)
334 {
335 return cl
336
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
20 .def(bp::init<const size_t>(
337 40 bp::args("self", "size"), "Init JointModelComposite with a defined size"))
338
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
339 "__init__",
340
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 bp::make_constructor(init_proxy1, bp::default_call_policies(), bp::args("joint_model")),
341 "Init JointModelComposite from a joint")
342
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
343 "__init__",
344
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 bp::make_constructor(
345
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 init_proxy2, bp::default_call_policies(), bp::args("joint_model", "joint_placement")),
346 "Init JointModelComposite from a joint and a placement")
347
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .add_property("joints", &context::JointModelComposite::joints)
348
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .add_property("jointPlacements", &context::JointModelComposite::jointPlacements)
349
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .add_property("njoints", &context::JointModelComposite::njoints)
350
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 .def(
351 "addJoint", &addJoint_proxy,
352
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
40 (bp::arg("self"), bp::arg("joint_model"),
353
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
40 bp::arg("joint_placement") = context::SE3::Identity()),
354 20 "Add a joint to the vector of joints.", bp::return_internal_reference<>())
355
356 #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
357
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 .def(bp::self == bp::self)
358
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
40 .def(bp::self != bp::self)
359 #endif
360
361 ;
362 }
363 } // namespace python
364 } // namespace pinocchio
365
366 #endif // ifndef __pinocchio_python_joint_models_hpp__
367