pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
joints-models.hpp
1//
2// Copyright (c) 2015-2022 CNRS INRIA
3//
4
5#pragma once
6
7#include <boost/python.hpp>
8
9#include "pinocchio/multibody/joint.hpp"
10
11#include <eigenpy/eigen-to-python.hpp>
12
13namespace pinocchio
14{
15 namespace python
16 {
17 namespace bp = boost::python;
18
19 // generic expose_joint_model : do nothing special
20 template<class T>
21 bp::class_<T> & expose_joint_model(bp::class_<T> & cl)
22 {
23 return cl;
24 }
25
26 // specialization for JointModelRevolute
27 template<>
28 bp::class_<context::JointModelRX> &
29 expose_joint_model<context::JointModelRX>(bp::class_<context::JointModelRX> & cl)
30 {
31 return cl
32 .def(
33 bp::init<>(
34 bp::args("self"), "Init JointModelRX with the X axis ([1, 0, 0]) as rotation axis."))
35 .def(
36 "getMotionAxis", &context::JointModelRX::getMotionAxis,
37 "Rotation axis of the JointModelRX.");
38 }
39
40 template<>
41 bp::class_<context::JointModelRY> &
42 expose_joint_model<context::JointModelRY>(bp::class_<context::JointModelRY> & cl)
43 {
44 return cl
45 .def(
46 bp::init<>(
47 bp::args("self"), "Init JointModelRY with the Y axis ([0, 1, 0]) as rotation axis."))
48 .def(
49 "getMotionAxis", &context::JointModelRY::getMotionAxis,
50 "Rotation axis of the JointModelRY.");
51 }
52
53 template<>
54 bp::class_<context::JointModelRZ> &
55 expose_joint_model<context::JointModelRZ>(bp::class_<context::JointModelRZ> & cl)
56 {
57 return cl
58 .def(
59 bp::init<>(
60 bp::args("self"), "Init JointModelRZ with the Z axis ([0, 0, 1]) as rotation axis"))
61 .def(
62 "getMotionAxis", &context::JointModelRZ::getMotionAxis,
63 "Rotation axis of the JointModelRZ.");
64 }
65
66 // specialization for JointModelRevoluteUnaligned
67 template<>
68 bp::class_<context::JointModelRevoluteUnaligned> &
69 expose_joint_model<context::JointModelRevoluteUnaligned>(
70 bp::class_<context::JointModelRevoluteUnaligned> & cl)
71 {
72 return cl
73 .def(
74 bp::init<context::Scalar, context::Scalar, context::Scalar>(
75 bp::args("self", "x", "y", "z"),
76 "Init JointModelRevoluteUnaligned from the components x, y, z of the axis"))
77 .def(
78 bp::init<const context::Vector3s &>(
79 bp::args("self", "axis"),
80 "Init JointModelRevoluteUnaligned from an axis with x-y-z components"))
81 .def_readwrite(
82 "axis", &context::JointModelRevoluteUnaligned::axis,
83 "Rotation axis of the JointModelRevoluteUnaligned.");
84 }
85
86 // specialization for JointModelRevoluteUnbounded
87 template<>
88 bp::class_<context::JointModelRUBX> &
89 expose_joint_model<context::JointModelRUBX>(bp::class_<context::JointModelRUBX> & cl)
90 {
91 return cl
92 .def(
93 bp::init<>(
94 bp::args("self"), "Init JointModelRUBX with the X axis ([1, 0, 0]) as rotation axis"))
95 .def(
96 "getMotionAxis", &context::JointModelRUBX::getMotionAxis,
97 "Rotation axis of the JointModelRUBX.");
98 }
99
100 template<>
101 bp::class_<context::JointModelRUBY> &
102 expose_joint_model<context::JointModelRUBY>(bp::class_<context::JointModelRUBY> & cl)
103 {
104 return cl
105 .def(
106 bp::init<>(
107 bp::args("self"), "Init JointModelRUBY with the Y axis ([0, 1, 0]) as rotation axis"))
108 .def(
109 "getMotionAxis", &context::JointModelRUBY::getMotionAxis,
110 "Rotation axis of the JointModelRUBY.");
111 }
112
113 template<>
114 bp::class_<context::JointModelRUBZ> &
115 expose_joint_model<context::JointModelRUBZ>(bp::class_<context::JointModelRUBZ> & cl)
116 {
117 return cl
118 .def(
119 bp::init<>(
120 bp::args("self"), "Init JointModelRUBZ with the Z axis ([0, 0, 1]) as rotation axis"))
121 .def(
122 "getMotionAxis", &context::JointModelRUBZ::getMotionAxis,
123 "Rotation axis of the JointModelRUBZ.");
124 }
125
126 // specialization for JointModelPrismatic
127 template<>
128 bp::class_<context::JointModelPX> &
129 expose_joint_model<context::JointModelPX>(bp::class_<context::JointModelPX> & cl)
130 {
131 return cl
132 .def(
133 bp::init<>(
134 bp::args("self"), "Init JointModelPX with the X axis ([1, 0, 0]) as rotation axis"))
135 .def(
136 "getMotionAxis", &context::JointModelPX::getMotionAxis,
137 "Rotation axis of the JointModelPX.");
138 }
139
140 template<>
141 bp::class_<context::JointModelPY> &
142 expose_joint_model<context::JointModelPY>(bp::class_<context::JointModelPY> & cl)
143 {
144 return cl
145 .def(
146 bp::init<>(
147 bp::args("self"), "Init JointModelPY with the Y axis ([0, 1, 0]) as rotation axis"))
148 .def(
149 "getMotionAxis", &context::JointModelPY::getMotionAxis,
150 "Rotation axis of the JointModelPY.");
151 }
152
153 template<>
154 bp::class_<context::JointModelPZ> &
155 expose_joint_model<context::JointModelPZ>(bp::class_<context::JointModelPZ> & cl)
156 {
157 return cl
158 .def(
159 bp::init<>(
160 bp::args("self"), "Init JointModelPZ with the Z axis ([0, 0, 1]) as rotation axis"))
161 .def(
162 "getMotionAxis", &context::JointModelPZ::getMotionAxis,
163 "Rotation axis of the JointModelPZ.");
164 }
165
166 // specialization for JointModelPrismaticUnaligned
167 template<>
168 bp::class_<context::JointModelPrismaticUnaligned> &
169 expose_joint_model<context::JointModelPrismaticUnaligned>(
170 bp::class_<context::JointModelPrismaticUnaligned> & cl)
171 {
172 return cl
173 .def(
174 bp::init<context::Scalar, context::Scalar, context::Scalar>(
175 bp::args("self", "x", "y", "z"),
176 "Init JointModelPrismaticUnaligned from the components x, y, z of the axis"))
177 .def(
178 bp::init<const context::Vector3s &>(
179 bp::args("self", "axis"),
180 "Init JointModelPrismaticUnaligned from an axis with x-y-z components"))
181 .def_readwrite(
182 "axis", &context::JointModelPrismaticUnaligned::axis,
183 "Translation axis of the JointModelPrismaticUnaligned.");
184 }
185
186 // specialization for JointModelHelicalUnaligned
187 template<>
188 bp::class_<context::JointModelHelicalUnaligned> &
189 expose_joint_model<context::JointModelHelicalUnaligned>(
190 bp::class_<context::JointModelHelicalUnaligned> & cl)
191 {
192 return cl
193 .def(
194 bp::init<context::Scalar, context::Scalar, context::Scalar, context::Scalar>(
195 bp::args("self", "x", "y", "z", "pitch"),
196 "Init JointModelHelicalUnaligned from the components x, y, z of the axis and the "
197 "pitch"))
198 .def(
199 bp::init<const context::Vector3s &, context::Scalar>(
200 bp::args("self", "axis", "pitch"),
201 "Init JointModelHelicalUnaligned from an axis with x-y-z components and the pitch"))
202 .def_readwrite(
203 "axis", &context::JointModelHelicalUnaligned::axis,
204 "Translation axis of the JointModelHelicalUnaligned.")
205 .def_readwrite(
206 "pitch", &context::JointModelHelicalUnaligned::m_pitch,
207 "Pitch h of the JointModelHelicalUnaligned.");
208 }
209
210 // specialization for JointModelHelical
211 template<>
212 bp::class_<context::JointModelHX> &
213 expose_joint_model<context::JointModelHX>(bp::class_<context::JointModelHX> & cl)
214 {
215 return cl
216 .def(
217 bp::init<context::Scalar>(
218 bp::args("self", "pitch"),
219 "Init JointModelHX with pitch value and the X axis ([1, 0, 0]) as a rotation axis."))
220 .def(
221 bp::init<>(
222 bp::args("self"),
223 "Init JointModelHX with pitch 0.0 and the X axis ([1, 0, 0]) as a rotation axis."))
224 .def(
225 "getMotionAxis", &context::JointModelHX::getMotionAxis,
226 "Rotation axis of the JointModelHX.")
227 .def_readwrite("pitch", &context::JointModelHX::m_pitch, "Pitch h of the JointModelHX.");
228 }
229
230 template<>
231 bp::class_<context::JointModelHY> &
232 expose_joint_model<context::JointModelHY>(bp::class_<context::JointModelHY> & cl)
233 {
234 return cl
235 .def(
236 bp::init<context::Scalar>(
237 bp::args("self", "pitch"),
238 "Init JointModelHY with pitch value and the Y axis ([0, 1, 0]) as a rotation axis."))
239 .def(
240 bp::init<>(
241 bp::args("self"),
242 "Init JointModelHY with pitch 0.0 and the Y axis ([0, 1, 0]) as a rotation axis."))
243 .def(
244 "getMotionAxis", &context::JointModelHY::getMotionAxis,
245 "Rotation axis of the JointModelHY.")
246 .def_readwrite("pitch", &context::JointModelHY::m_pitch, "Pitch h of the JointModelHY.");
247 }
248
249 template<>
250 bp::class_<context::JointModelHZ> &
251 expose_joint_model<context::JointModelHZ>(bp::class_<context::JointModelHZ> & cl)
252 {
253 return cl
254 .def(
255 bp::init<context::Scalar>(
256 bp::args("self", "pitch"),
257 "Init JointModelHZ with pitch value and the Z axis ([0, 0, 1]) as a rotation axis."))
258 .def(
259 bp::init<>(
260 bp::args("self"),
261 "Init JointModelHZ with pitch 0.0 and the Z axis ([0, 0, 1]) as a rotation axis."))
262 .def(
263 "getMotionAxis", &context::JointModelHZ::getMotionAxis,
264 "Rotation axis of the JointModelHZ.")
265 .def_readwrite("pitch", &context::JointModelHZ::m_pitch, "Pitch h of the JointModelHZ.");
266 }
267
268 // specialization for JointModelHelical
269 template<>
270 bp::class_<context::JointModelEllipsoid> &
271 expose_joint_model<context::JointModelEllipsoid>(bp::class_<context::JointModelEllipsoid> & cl)
272 {
273 return cl
274 .def(
275 bp::init<context::Scalar, context::Scalar, context::Scalar>(
276 bp::args("self", "radius_x", "radius_y", "radius_z"),
277 "Init JointModelEllipsoid with radii along x, y, z axes."))
278 .def(bp::init<>(bp::args("self"), "Init JointModelEllipsoid with default radii equal to 0"))
279 .def_readwrite(
280 "radius_x", &context::JointModelEllipsoid::radius_x,
281 "Radius of the JointModelEllipsoid along X axis.")
282 .def_readwrite(
283 "radius_y", &context::JointModelEllipsoid::radius_y,
284 "Radius of the JointModelEllipsoid along Y axis.")
285 .def_readwrite(
286 "radius_z", &context::JointModelEllipsoid::radius_z,
287 "Radius of the JointModelEllipsoid along Z axis.");
288 }
289
290 // specialization for JointModelUniversal
291 template<>
292 bp::class_<context::JointModelUniversal> &
293 expose_joint_model<context::JointModelUniversal>(bp::class_<context::JointModelUniversal> & cl)
294 {
295 return cl
296 .def(
297 bp::init<
298 context::Scalar, context::Scalar, context::Scalar, context::Scalar, context::Scalar,
299 context::Scalar>(
300 bp::args("self", "x1", "y1", "z1", "x2", "y2", "z2"),
301 "Init JointModelUniversal from the components x, y, z of the axes"))
302 .def(
303 bp::init<const context::Vector3s &, const context::Vector3s &>(
304 bp::args("self", "axis1", "axis2"),
305 "Init JointModelUniversal from two axes with x-y-z components"))
306 .def_readwrite(
307 "axis1", &context::JointModelUniversal::axis1,
308 "First rotation axis of the JointModelUniversal.")
309 .def_readwrite(
310 "axis2", &context::JointModelUniversal::axis2,
311 "Second rotation axis of the JointModelUniversal.");
312 }
313
314 // specialization for JointModelComposite
315
316 struct JointModelCompositeAddJointVisitor
317 : public boost::static_visitor<context::JointModelComposite &>
318 {
319 context::JointModelComposite & m_joint_composite;
320 const context::SE3 & m_joint_placement;
321 const std::string & m_name;
322
323 JointModelCompositeAddJointVisitor(
324 context::JointModelComposite & joint_composite,
325 const context::SE3 & joint_placement,
326 const std::string & name)
327 : m_joint_composite(joint_composite)
328 , m_joint_placement(joint_placement)
329 , m_name(name)
330 {
331 }
332
333 template<typename JointModelDerived>
334 context::JointModelComposite & operator()(JointModelDerived & jmodel) const
335 {
336 return m_joint_composite.addJoint(jmodel, m_joint_placement, m_name);
337 }
338 }; // struct JointModelCompositeAddJointVisitor
339
340 static context::JointModelComposite & addJoint_proxy(
341 context::JointModelComposite & joint_composite,
342 const context::JointModel & jmodel,
343 const context::SE3 & joint_placement = context::SE3::Identity(),
344 const std::string & name = "")
345 {
346 return boost::apply_visitor(
347 JointModelCompositeAddJointVisitor(joint_composite, joint_placement, name),
348 jmodel.toVariant());
349 }
350
351 struct JointModelCompositeConstructorVisitor
352 : public boost::static_visitor<context::JointModelComposite *>
353 {
354 const context::SE3 & m_joint_placement;
355 const std::string & m_name;
356
357 JointModelCompositeConstructorVisitor(
358 const context::SE3 & joint_placement, const std::string & name)
359 : m_joint_placement(joint_placement)
360 , m_name(name)
361 {
362 }
363
364 template<typename JointModelDerived>
365 context::JointModelComposite * operator()(JointModelDerived & jmodel) const
366 {
367 return new context::JointModelComposite(jmodel, m_joint_placement, m_name);
368 }
369 }; // struct JointModelCompositeConstructorVisitor
370
371 static context::JointModelComposite * init_proxy1(const context::JointModel & jmodel)
372 {
373 return boost::apply_visitor(
374 JointModelCompositeConstructorVisitor(context::SE3::Identity(), "joint_1"), jmodel);
375 }
376
377 static context::JointModelComposite *
378 init_proxy2(const context::JointModel & jmodel, const context::SE3 & joint_placement)
379 {
380 return boost::apply_visitor(
381 JointModelCompositeConstructorVisitor(joint_placement, "joint_1"), jmodel);
382 }
383
384 static context::JointModelComposite * init_proxy3(
385 const context::JointModel & jmodel,
386 const context::SE3 & joint_placement,
387 const std::string & name)
388 {
389 return boost::apply_visitor(
390 JointModelCompositeConstructorVisitor(joint_placement, name), jmodel);
391 }
392
393 template<>
394 bp::class_<context::JointModelComposite> &
395 expose_joint_model<context::JointModelComposite>(bp::class_<context::JointModelComposite> & cl)
396 {
397 return cl
398 .def(
399 bp::init<const size_t>(
400 bp::args("self", "size"), "Init JointModelComposite with a defined size"))
401 .def(
402 "__init__",
403 bp::make_constructor(init_proxy1, bp::default_call_policies(), bp::args("joint_model")),
404 "Init JointModelComposite from a joint")
405 .def(
406 "__init__",
407 bp::make_constructor(
408 init_proxy2, bp::default_call_policies(), bp::args("joint_model", "joint_placement")),
409 "Init JointModelComposite from a joint and a placement")
410 .def(
411 "__init__",
412 bp::make_constructor(
413 init_proxy3, bp::default_call_policies(),
414 bp::args("joint_model", "joint_placement", "name")),
415 "Init JointModelComposite from a joint, a placement and a name")
416 .add_property("joints", &context::JointModelComposite::joints)
417 .add_property("jointPlacements", &context::JointModelComposite::jointPlacements)
418 .add_property("njoints", &context::JointModelComposite::njoints)
419 .def(
420 "addJoint", &addJoint_proxy,
421 (bp::arg("self"), bp::arg("joint_model"),
422 bp::arg("joint_placement") = context::SE3::Identity(), bp::arg("name") = "joint_1"),
423 "Add a joint to the vector of joints.", bp::return_internal_reference<>())
424 .def(
425 "getJointId", &context::JointModelComposite::getJointId, bp::args("joint_name"),
426 "Find the index of a joint inside a joint composite based on its name.")
427
428#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
429 .def(bp::self == bp::self)
430 .def(bp::self != bp::self)
431#endif
432 ;
433 }
434
435 // Specialization for JointModelMimic
436 struct JointModelMimicConstructorVisitor
437 : public boost::static_visitor<context::JointModelMimic *>
438 {
439 const context::Scalar & m_scaling;
440 const context::Scalar & m_offset;
441
442 JointModelMimicConstructorVisitor(
443 const context::Scalar & scaling, const context::Scalar & offset)
444 : m_scaling(scaling)
445 , m_offset(offset)
446 {
447 }
448
449 template<typename JointModelDerived>
450 context::JointModelMimic * operator()(const JointModelDerived & jmodel) const
451 {
452
453 return new context::JointModelMimic(jmodel, m_scaling, m_offset);
454 }
455
456 }; // struct JointModelMimicConstructorVisitor
457
458 static context::JointModelMimic * init_proxy(
459 const context::JointModel & jmodel,
460 const context::Scalar & scaling,
461 const context::Scalar & offset)
462 {
463 return boost::apply_visitor(JointModelMimicConstructorVisitor(scaling, offset), jmodel);
464 }
465
466 static context::Scalar get_scaling(context::JointModelMimic & jmodel)
467 {
468 return jmodel.scaling();
469 }
470
471 static context::Scalar get_offset(context::JointModelMimic & jmodel)
472 {
473 return jmodel.offset();
474 }
475
476 template<>
477 bp::class_<context::JointModelMimic> &
478 expose_joint_model<context::JointModelMimic>(bp::class_<context::JointModelMimic> & cl)
479 {
480 return cl
481 .def(
482 "__init__",
483 bp::make_constructor(
484 init_proxy, bp::default_call_policies(), bp::args("joint_model", "scaling", "offset")),
485 "Init JointModelMimic from an existing joint with scaling and offset.")
486 .add_property("scaling", &get_scaling)
487 .add_property("offset", &get_offset);
488 }
489
490 } // namespace python
491} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11