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