1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  *   https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  *   Redistribution and use in source and binary forms, with or
10  *   without modification, are permitted provided that the following
11  *   conditions are met:
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *   * Redistributions in binary form must reproduce the above
15  *     copyright notice, this list of conditions and the following
16  *     disclaimer in the documentation and/or other materials provided
17  *     with the distribution.
18  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  *   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  *   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  *   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  *   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  *   AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  *   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  *   POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <dart/dart.hpp>
34 #include <pybind11/pybind11.h>
35 #include "eigen_geometry_pybind.h"
36 #include "eigen_pybind.h"
37 
38 namespace py = pybind11;
39 
40 namespace dart {
41 namespace python {
42 
DegreeOfFreedom(py::module & m)43 void DegreeOfFreedom(py::module& m)
44 {
45   ::py::class_<
46       dart::dynamics::DegreeOfFreedom,
47       dart::common::Subject,
48       std::shared_ptr<dart::dynamics::DegreeOfFreedom>>(m, "DegreeOfFreedom")
49       .def(
50           "setName",
51           +[](dart::dynamics::DegreeOfFreedom* self, const std::string& _name)
52               -> const std::string& { return self->setName(_name); },
53           ::py::return_value_policy::reference_internal,
54           ::py::arg("name"))
55       .def(
56           "setName",
57           +[](dart::dynamics::DegreeOfFreedom* self,
58               const std::string& _name,
59               bool _preserveName) -> const std::string& {
60             return self->setName(_name, _preserveName);
61           },
62           ::py::return_value_policy::reference_internal,
63           ::py::arg("name"),
64           ::py::arg("preserveName"))
65       .def(
66           "getName",
67           +[](const dart::dynamics::DegreeOfFreedom* self)
68               -> const std::string& { return self->getName(); },
69           ::py::return_value_policy::reference_internal)
70       .def(
71           "preserveName",
72           +[](dart::dynamics::DegreeOfFreedom* self, bool _preserve) {
73             self->preserveName(_preserve);
74           },
75           ::py::arg("preserve"))
76       .def(
77           "isNamePreserved",
78           +[](const dart::dynamics::DegreeOfFreedom* self) -> bool {
79             return self->isNamePreserved();
80           })
81       .def(
82           "getIndexInSkeleton",
83           +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
84             return self->getIndexInSkeleton();
85           })
86       .def(
87           "getIndexInTree",
88           +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
89             return self->getIndexInTree();
90           })
91       .def(
92           "getIndexInJoint",
93           +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
94             return self->getIndexInJoint();
95           })
96       .def(
97           "getTreeIndex",
98           +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
99             return self->getTreeIndex();
100           })
101       .def(
102           "setCommand",
103           +[](dart::dynamics::DegreeOfFreedom* self, double _command) {
104             self->setCommand(_command);
105           },
106           ::py::arg("command"))
107       .def(
108           "getCommand",
109           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
110             return self->getCommand();
111           })
112       .def(
113           "resetCommand",
114           +[](dart::dynamics::DegreeOfFreedom* self) { self->resetCommand(); })
115       .def(
116           "setPosition",
117           +[](dart::dynamics::DegreeOfFreedom* self, double _position) {
118             self->setPosition(_position);
119           },
120           ::py::arg("position"))
121       .def(
122           "getPosition",
123           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
124             return self->getPosition();
125           })
126       .def(
127           "setPositionLimits",
128           +[](dart::dynamics::DegreeOfFreedom* self,
129               double _lowerLimit,
130               double _upperLimit) {
131             self->setPositionLimits(_lowerLimit, _upperLimit);
132           },
133           ::py::arg("lowerLimit"),
134           ::py::arg("upperLimit"))
135       .def(
136           "setPositionLimits",
137           +[](dart::dynamics::DegreeOfFreedom* self,
138               const std::pair<double, double>& _limits) {
139             self->setPositionLimits(_limits);
140           },
141           ::py::arg("limits"))
142       .def(
143           "getPositionLimits",
144           +[](const dart::dynamics::DegreeOfFreedom* self)
145               -> std::pair<double, double> {
146             return self->getPositionLimits();
147           })
148       .def(
149           "setPositionLowerLimit",
150           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
151             self->setPositionLowerLimit(_limit);
152           },
153           ::py::arg("limit"))
154       .def(
155           "getPositionLowerLimit",
156           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
157             return self->getPositionLowerLimit();
158           })
159       .def(
160           "setPositionUpperLimit",
161           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
162             self->setPositionUpperLimit(_limit);
163           },
164           ::py::arg("limit"))
165       .def(
166           "getPositionUpperLimit",
167           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
168             return self->getPositionUpperLimit();
169           })
170       .def(
171           "isCyclic",
172           +[](const dart::dynamics::DegreeOfFreedom* self) -> bool {
173             return self->isCyclic();
174           })
175       .def(
176           "hasPositionLimit",
177           +[](const dart::dynamics::DegreeOfFreedom* self) -> bool {
178             return self->hasPositionLimit();
179           })
180       .def(
181           "resetPosition",
182           +[](dart::dynamics::DegreeOfFreedom* self) { self->resetPosition(); })
183       .def(
184           "setInitialPosition",
185           +[](dart::dynamics::DegreeOfFreedom* self, double _initial) {
186             self->setInitialPosition(_initial);
187           },
188           ::py::arg("initial"))
189       .def(
190           "getInitialPosition",
191           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
192             return self->getInitialPosition();
193           })
194       .def(
195           "setVelocity",
196           +[](dart::dynamics::DegreeOfFreedom* self, double _velocity) {
197             self->setVelocity(_velocity);
198           },
199           ::py::arg("velocity"))
200       .def(
201           "getVelocity",
202           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
203             return self->getVelocity();
204           })
205       .def(
206           "setVelocityLimits",
207           +[](dart::dynamics::DegreeOfFreedom* self,
208               double _lowerLimit,
209               double _upperLimit) {
210             self->setVelocityLimits(_lowerLimit, _upperLimit);
211           },
212           ::py::arg("lowerLimit"),
213           ::py::arg("upperLimit"))
214       .def(
215           "setVelocityLimits",
216           +[](dart::dynamics::DegreeOfFreedom* self,
217               const std::pair<double, double>& _limits) {
218             self->setVelocityLimits(_limits);
219           },
220           ::py::arg("limits"))
221       .def(
222           "getVelocityLimits",
223           +[](const dart::dynamics::DegreeOfFreedom* self)
224               -> std::pair<double, double> {
225             return self->getVelocityLimits();
226           })
227       .def(
228           "setVelocityLowerLimit",
229           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
230             self->setVelocityLowerLimit(_limit);
231           },
232           ::py::arg("limit"))
233       .def(
234           "getVelocityLowerLimit",
235           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
236             return self->getVelocityLowerLimit();
237           })
238       .def(
239           "setVelocityUpperLimit",
240           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
241             self->setVelocityUpperLimit(_limit);
242           },
243           ::py::arg("limit"))
244       .def(
245           "getVelocityUpperLimit",
246           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
247             return self->getVelocityUpperLimit();
248           })
249       .def(
250           "resetVelocity",
251           +[](dart::dynamics::DegreeOfFreedom* self) { self->resetVelocity(); })
252       .def(
253           "setInitialVelocity",
254           +[](dart::dynamics::DegreeOfFreedom* self, double _initial) {
255             self->setInitialVelocity(_initial);
256           },
257           ::py::arg("initial"))
258       .def(
259           "getInitialVelocity",
260           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
261             return self->getInitialVelocity();
262           })
263       .def(
264           "setAcceleration",
265           +[](dart::dynamics::DegreeOfFreedom* self, double _acceleration) {
266             self->setAcceleration(_acceleration);
267           },
268           ::py::arg("acceleration"))
269       .def(
270           "getAcceleration",
271           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
272             return self->getAcceleration();
273           })
274       .def(
275           "resetAcceleration",
276           +[](dart::dynamics::DegreeOfFreedom* self) {
277             self->resetAcceleration();
278           })
279       .def(
280           "setAccelerationLimits",
281           +[](dart::dynamics::DegreeOfFreedom* self,
282               double _lowerLimit,
283               double _upperLimit) {
284             self->setAccelerationLimits(_lowerLimit, _upperLimit);
285           },
286           ::py::arg("lowerLimit"),
287           ::py::arg("upperLimit"))
288       .def(
289           "setAccelerationLimits",
290           +[](dart::dynamics::DegreeOfFreedom* self,
291               const std::pair<double, double>& _limits) {
292             self->setAccelerationLimits(_limits);
293           },
294           ::py::arg("limits"))
295       .def(
296           "getAccelerationLimits",
297           +[](const dart::dynamics::DegreeOfFreedom* self)
298               -> std::pair<double, double> {
299             return self->getAccelerationLimits();
300           })
301       .def(
302           "setAccelerationLowerLimit",
303           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
304             self->setAccelerationLowerLimit(_limit);
305           },
306           ::py::arg("limit"))
307       .def(
308           "getAccelerationLowerLimit",
309           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
310             return self->getAccelerationLowerLimit();
311           })
312       .def(
313           "setAccelerationUpperLimit",
314           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
315             self->setAccelerationUpperLimit(_limit);
316           },
317           ::py::arg("limit"))
318       .def(
319           "getAccelerationUpperLimit",
320           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
321             return self->getAccelerationUpperLimit();
322           })
323       .def(
324           "setForce",
325           +[](dart::dynamics::DegreeOfFreedom* self, double _force) {
326             self->setForce(_force);
327           },
328           ::py::arg("force"))
329       .def(
330           "getForce",
331           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
332             return self->getForce();
333           })
334       .def(
335           "resetForce",
336           +[](dart::dynamics::DegreeOfFreedom* self) { self->resetForce(); })
337       .def(
338           "setForceLimits",
339           +[](dart::dynamics::DegreeOfFreedom* self,
340               double _lowerLimit,
341               double _upperLimit) {
342             self->setForceLimits(_lowerLimit, _upperLimit);
343           },
344           ::py::arg("lowerLimit"),
345           ::py::arg("upperLimit"))
346       .def(
347           "setForceLimits",
348           +[](dart::dynamics::DegreeOfFreedom* self,
349               const std::pair<double, double>& _limits) {
350             self->setForceLimits(_limits);
351           },
352           ::py::arg("limits"))
353       .def(
354           "getForceLimits",
355           +[](const dart::dynamics::DegreeOfFreedom* self)
356               -> std::pair<double, double> { return self->getForceLimits(); })
357       .def(
358           "setForceLowerLimit",
359           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
360             self->setForceLowerLimit(_limit);
361           },
362           ::py::arg("limit"))
363       .def(
364           "getForceLowerLimit",
365           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
366             return self->getForceLowerLimit();
367           })
368       .def(
369           "setForceUpperLimit",
370           +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
371             self->setForceUpperLimit(_limit);
372           },
373           ::py::arg("limit"))
374       .def(
375           "getForceUpperLimit",
376           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
377             return self->getForceUpperLimit();
378           })
379       .def(
380           "setVelocityChange",
381           +[](dart::dynamics::DegreeOfFreedom* self, double _velocityChange) {
382             self->setVelocityChange(_velocityChange);
383           },
384           ::py::arg("velocityChange"))
385       .def(
386           "getVelocityChange",
387           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
388             return self->getVelocityChange();
389           })
390       .def(
391           "resetVelocityChange",
392           +[](dart::dynamics::DegreeOfFreedom* self) {
393             self->resetVelocityChange();
394           })
395       .def(
396           "setConstraintImpulse",
397           +[](dart::dynamics::DegreeOfFreedom* self, double _impulse) {
398             self->setConstraintImpulse(_impulse);
399           },
400           ::py::arg("impulse"))
401       .def(
402           "getConstraintImpulse",
403           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
404             return self->getConstraintImpulse();
405           })
406       .def(
407           "resetConstraintImpulse",
408           +[](dart::dynamics::DegreeOfFreedom* self) {
409             self->resetConstraintImpulse();
410           })
411       .def(
412           "setSpringStiffness",
413           +[](dart::dynamics::DegreeOfFreedom* self, double _k) {
414             self->setSpringStiffness(_k);
415           },
416           ::py::arg("k"))
417       .def(
418           "getSpringStiffness",
419           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
420             return self->getSpringStiffness();
421           })
422       .def(
423           "setRestPosition",
424           +[](dart::dynamics::DegreeOfFreedom* self, double _q0) {
425             self->setRestPosition(_q0);
426           },
427           ::py::arg("q0"))
428       .def(
429           "getRestPosition",
430           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
431             return self->getRestPosition();
432           })
433       .def(
434           "setDampingCoefficient",
435           +[](dart::dynamics::DegreeOfFreedom* self, double _coeff) {
436             self->setDampingCoefficient(_coeff);
437           },
438           ::py::arg("coeff"))
439       .def(
440           "getDampingCoefficient",
441           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
442             return self->getDampingCoefficient();
443           })
444       .def(
445           "setCoulombFriction",
446           +[](dart::dynamics::DegreeOfFreedom* self, double _friction) {
447             self->setCoulombFriction(_friction);
448           },
449           ::py::arg("friction"))
450       .def(
451           "getCoulombFriction",
452           +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
453             return self->getCoulombFriction();
454           })
455       .def(
456           "getSkeleton",
457           +[](dart::dynamics::DegreeOfFreedom* self)
458               -> dart::dynamics::SkeletonPtr { return self->getSkeleton(); })
459       .def(
460           "getSkeleton",
461           +[](const dart::dynamics::DegreeOfFreedom* self)
462               -> dart::dynamics::ConstSkeletonPtr {
463             return self->getSkeleton();
464           });
465 }
466 
467 } // namespace python
468 } // namespace dart
469