Debian Codegraph @

python/dartpy/dynamics/DegreeOfFreedom.cpp

raw
1 /*
2 * Copyright (c) 2011-2022, 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
36 #include "eigen_geometry_pybind.h"
37 #include "eigen_pybind.h"
38
39 namespace py = pybind11;
40
41 namespace dart {
42 namespace python {
43
44 void DegreeOfFreedom(py::module& m)
45 {
46 ::py::class_<
47 dart::dynamics::DegreeOfFreedom,
48 dart::common::Subject,
49 std::shared_ptr<dart::dynamics::DegreeOfFreedom>>(m, "DegreeOfFreedom")
50 .def(
51 "setName",
52 +[](dart::dynamics::DegreeOfFreedom* self, const std::string& _name)
53 -> const std::string& { return self->setName(_name); },
54 ::py::return_value_policy::reference_internal,
55 ::py::arg("name"))
56 .def(
57 "setName",
58 +[](dart::dynamics::DegreeOfFreedom* self,
59 const std::string& _name,
60 bool _preserveName) -> const std::string& {
61 return self->setName(_name, _preserveName);
62 },
63 ::py::return_value_policy::reference_internal,
64 ::py::arg("name"),
65 ::py::arg("preserveName"))
66 .def(
67 "getName",
68 +[](const dart::dynamics::DegreeOfFreedom* self)
69 -> const std::string& { return self->getName(); },
70 ::py::return_value_policy::reference_internal)
71 .def(
72 "preserveName",
73 +[](dart::dynamics::DegreeOfFreedom* self, bool _preserve) {
74 self->preserveName(_preserve);
75 },
76 ::py::arg("preserve"))
77 .def(
78 "isNamePreserved",
79 +[](const dart::dynamics::DegreeOfFreedom* self) -> bool {
80 return self->isNamePreserved();
81 })
82 .def(
83 "getIndexInSkeleton",
84 +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
85 return self->getIndexInSkeleton();
86 })
87 .def(
88 "getIndexInTree",
89 +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
90 return self->getIndexInTree();
91 })
92 .def(
93 "getIndexInJoint",
94 +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
95 return self->getIndexInJoint();
96 })
97 .def(
98 "getTreeIndex",
99 +[](const dart::dynamics::DegreeOfFreedom* self) -> std::size_t {
100 return self->getTreeIndex();
101 })
102 .def(
103 "setCommand",
104 +[](dart::dynamics::DegreeOfFreedom* self, double _command) {
105 self->setCommand(_command);
106 },
107 ::py::arg("command"))
108 .def(
109 "getCommand",
110 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
111 return self->getCommand();
112 })
113 .def(
114 "resetCommand",
115 +[](dart::dynamics::DegreeOfFreedom* self) { self->resetCommand(); })
116 .def(
117 "setPosition",
118 +[](dart::dynamics::DegreeOfFreedom* self, double _position) {
119 self->setPosition(_position);
120 },
121 ::py::arg("position"))
122 .def(
123 "getPosition",
124 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
125 return self->getPosition();
126 })
127 .def(
128 "setPositionLimits",
129 +[](dart::dynamics::DegreeOfFreedom* self,
130 double _lowerLimit,
131 double _upperLimit) {
132 self->setPositionLimits(_lowerLimit, _upperLimit);
133 },
134 ::py::arg("lowerLimit"),
135 ::py::arg("upperLimit"))
136 .def(
137 "setPositionLimits",
138 +[](dart::dynamics::DegreeOfFreedom* self,
139 const std::pair<double, double>& _limits) {
140 self->setPositionLimits(_limits);
141 },
142 ::py::arg("limits"))
143 .def(
144 "getPositionLimits",
145 +[](const dart::dynamics::DegreeOfFreedom* self)
146 -> std::pair<double, double> {
147 return self->getPositionLimits();
148 })
149 .def(
150 "setPositionLowerLimit",
151 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
152 self->setPositionLowerLimit(_limit);
153 },
154 ::py::arg("limit"))
155 .def(
156 "getPositionLowerLimit",
157 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
158 return self->getPositionLowerLimit();
159 })
160 .def(
161 "setPositionUpperLimit",
162 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
163 self->setPositionUpperLimit(_limit);
164 },
165 ::py::arg("limit"))
166 .def(
167 "getPositionUpperLimit",
168 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
169 return self->getPositionUpperLimit();
170 })
171 .def(
172 "isCyclic",
173 +[](const dart::dynamics::DegreeOfFreedom* self) -> bool {
174 return self->isCyclic();
175 })
176 .def(
177 "hasPositionLimit",
178 +[](const dart::dynamics::DegreeOfFreedom* self) -> bool {
179 return self->hasPositionLimit();
180 })
181 .def(
182 "resetPosition",
183 +[](dart::dynamics::DegreeOfFreedom* self) { self->resetPosition(); })
184 .def(
185 "setInitialPosition",
186 +[](dart::dynamics::DegreeOfFreedom* self, double _initial) {
187 self->setInitialPosition(_initial);
188 },
189 ::py::arg("initial"))
190 .def(
191 "getInitialPosition",
192 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
193 return self->getInitialPosition();
194 })
195 .def(
196 "setVelocity",
197 +[](dart::dynamics::DegreeOfFreedom* self, double _velocity) {
198 self->setVelocity(_velocity);
199 },
200 ::py::arg("velocity"))
201 .def(
202 "getVelocity",
203 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
204 return self->getVelocity();
205 })
206 .def(
207 "setVelocityLimits",
208 +[](dart::dynamics::DegreeOfFreedom* self,
209 double _lowerLimit,
210 double _upperLimit) {
211 self->setVelocityLimits(_lowerLimit, _upperLimit);
212 },
213 ::py::arg("lowerLimit"),
214 ::py::arg("upperLimit"))
215 .def(
216 "setVelocityLimits",
217 +[](dart::dynamics::DegreeOfFreedom* self,
218 const std::pair<double, double>& _limits) {
219 self->setVelocityLimits(_limits);
220 },
221 ::py::arg("limits"))
222 .def(
223 "getVelocityLimits",
224 +[](const dart::dynamics::DegreeOfFreedom* self)
225 -> std::pair<double, double> {
226 return self->getVelocityLimits();
227 })
228 .def(
229 "setVelocityLowerLimit",
230 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
231 self->setVelocityLowerLimit(_limit);
232 },
233 ::py::arg("limit"))
234 .def(
235 "getVelocityLowerLimit",
236 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
237 return self->getVelocityLowerLimit();
238 })
239 .def(
240 "setVelocityUpperLimit",
241 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
242 self->setVelocityUpperLimit(_limit);
243 },
244 ::py::arg("limit"))
245 .def(
246 "getVelocityUpperLimit",
247 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
248 return self->getVelocityUpperLimit();
249 })
250 .def(
251 "resetVelocity",
252 +[](dart::dynamics::DegreeOfFreedom* self) { self->resetVelocity(); })
253 .def(
254 "setInitialVelocity",
255 +[](dart::dynamics::DegreeOfFreedom* self, double _initial) {
256 self->setInitialVelocity(_initial);
257 },
258 ::py::arg("initial"))
259 .def(
260 "getInitialVelocity",
261 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
262 return self->getInitialVelocity();
263 })
264 .def(
265 "setAcceleration",
266 +[](dart::dynamics::DegreeOfFreedom* self, double _acceleration) {
267 self->setAcceleration(_acceleration);
268 },
269 ::py::arg("acceleration"))
270 .def(
271 "getAcceleration",
272 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
273 return self->getAcceleration();
274 })
275 .def(
276 "resetAcceleration",
277 +[](dart::dynamics::DegreeOfFreedom* self) {
278 self->resetAcceleration();
279 })
280 .def(
281 "setAccelerationLimits",
282 +[](dart::dynamics::DegreeOfFreedom* self,
283 double _lowerLimit,
284 double _upperLimit) {
285 self->setAccelerationLimits(_lowerLimit, _upperLimit);
286 },
287 ::py::arg("lowerLimit"),
288 ::py::arg("upperLimit"))
289 .def(
290 "setAccelerationLimits",
291 +[](dart::dynamics::DegreeOfFreedom* self,
292 const std::pair<double, double>& _limits) {
293 self->setAccelerationLimits(_limits);
294 },
295 ::py::arg("limits"))
296 .def(
297 "getAccelerationLimits",
298 +[](const dart::dynamics::DegreeOfFreedom* self)
299 -> std::pair<double, double> {
300 return self->getAccelerationLimits();
301 })
302 .def(
303 "setAccelerationLowerLimit",
304 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
305 self->setAccelerationLowerLimit(_limit);
306 },
307 ::py::arg("limit"))
308 .def(
309 "getAccelerationLowerLimit",
310 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
311 return self->getAccelerationLowerLimit();
312 })
313 .def(
314 "setAccelerationUpperLimit",
315 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
316 self->setAccelerationUpperLimit(_limit);
317 },
318 ::py::arg("limit"))
319 .def(
320 "getAccelerationUpperLimit",
321 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
322 return self->getAccelerationUpperLimit();
323 })
324 .def(
325 "setForce",
326 +[](dart::dynamics::DegreeOfFreedom* self, double _force) {
327 self->setForce(_force);
328 },
329 ::py::arg("force"))
330 .def(
331 "getForce",
332 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
333 return self->getForce();
334 })
335 .def(
336 "resetForce",
337 +[](dart::dynamics::DegreeOfFreedom* self) { self->resetForce(); })
338 .def(
339 "setForceLimits",
340 +[](dart::dynamics::DegreeOfFreedom* self,
341 double _lowerLimit,
342 double _upperLimit) {
343 self->setForceLimits(_lowerLimit, _upperLimit);
344 },
345 ::py::arg("lowerLimit"),
346 ::py::arg("upperLimit"))
347 .def(
348 "setForceLimits",
349 +[](dart::dynamics::DegreeOfFreedom* self,
350 const std::pair<double, double>& _limits) {
351 self->setForceLimits(_limits);
352 },
353 ::py::arg("limits"))
354 .def(
355 "getForceLimits",
356 +[](const dart::dynamics::DegreeOfFreedom* self)
357 -> std::pair<double, double> { return self->getForceLimits(); })
358 .def(
359 "setForceLowerLimit",
360 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
361 self->setForceLowerLimit(_limit);
362 },
363 ::py::arg("limit"))
364 .def(
365 "getForceLowerLimit",
366 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
367 return self->getForceLowerLimit();
368 })
369 .def(
370 "setForceUpperLimit",
371 +[](dart::dynamics::DegreeOfFreedom* self, double _limit) {
372 self->setForceUpperLimit(_limit);
373 },
374 ::py::arg("limit"))
375 .def(
376 "getForceUpperLimit",
377 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
378 return self->getForceUpperLimit();
379 })
380 .def(
381 "setVelocityChange",
382 +[](dart::dynamics::DegreeOfFreedom* self, double _velocityChange) {
383 self->setVelocityChange(_velocityChange);
384 },
385 ::py::arg("velocityChange"))
386 .def(
387 "getVelocityChange",
388 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
389 return self->getVelocityChange();
390 })
391 .def(
392 "resetVelocityChange",
393 +[](dart::dynamics::DegreeOfFreedom* self) {
394 self->resetVelocityChange();
395 })
396 .def(
397 "setConstraintImpulse",
398 +[](dart::dynamics::DegreeOfFreedom* self, double _impulse) {
399 self->setConstraintImpulse(_impulse);
400 },
401 ::py::arg("impulse"))
402 .def(
403 "getConstraintImpulse",
404 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
405 return self->getConstraintImpulse();
406 })
407 .def(
408 "resetConstraintImpulse",
409 +[](dart::dynamics::DegreeOfFreedom* self) {
410 self->resetConstraintImpulse();
411 })
412 .def(
413 "setSpringStiffness",
414 +[](dart::dynamics::DegreeOfFreedom* self, double _k) {
415 self->setSpringStiffness(_k);
416 },
417 ::py::arg("k"))
418 .def(
419 "getSpringStiffness",
420 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
421 return self->getSpringStiffness();
422 })
423 .def(
424 "setRestPosition",
425 +[](dart::dynamics::DegreeOfFreedom* self, double _q0) {
426 self->setRestPosition(_q0);
427 },
428 ::py::arg("q0"))
429 .def(
430 "getRestPosition",
431 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
432 return self->getRestPosition();
433 })
434 .def(
435 "setDampingCoefficient",
436 +[](dart::dynamics::DegreeOfFreedom* self, double _coeff) {
437 self->setDampingCoefficient(_coeff);
438 },
439 ::py::arg("coeff"))
440 .def(
441 "getDampingCoefficient",
442 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
443 return self->getDampingCoefficient();
444 })
445 .def(
446 "setCoulombFriction",
447 +[](dart::dynamics::DegreeOfFreedom* self, double _friction) {
448 self->setCoulombFriction(_friction);
449 },
450 ::py::arg("friction"))
451 .def(
452 "getCoulombFriction",
453 +[](const dart::dynamics::DegreeOfFreedom* self) -> double {
454 return self->getCoulombFriction();
455 })
456 .def(
457 "getSkeleton",
458 +[](dart::dynamics::DegreeOfFreedom* self)
459 -> dart::dynamics::SkeletonPtr { return self->getSkeleton(); })
460 .def(
461 "getSkeleton",
462 +[](const dart::dynamics::DegreeOfFreedom* self)
463 -> dart::dynamics::ConstSkeletonPtr {
464 return self->getSkeleton();
465 });
466 }
467
468 } // namespace python
469 } // namespace dart