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 <eigen_geometry_pybind.h>
35 #include <pybind11/eigen.h>
36 #include <pybind11/pybind11.h>
37 #include "Joint.hpp"
38 
39 namespace py = pybind11;
40 
41 namespace dart {
42 namespace python {
43 
RevoluteJoint(py::module & m)44 void RevoluteJoint(py::module& m)
45 {
46   ::py::class_<dart::dynamics::RevoluteJoint::UniqueProperties>(
47       m, "RevoluteJointUniqueProperties")
48       .def(::py::init<>())
49       .def(::py::init<const Eigen::Vector3d&>(), ::py::arg("axis"));
50 
51   ::py::class_<
52       dart::dynamics::RevoluteJoint::Properties,
53       dart::dynamics::GenericJoint<math::R1Space>::Properties,
54       dart::dynamics::RevoluteJoint::UniqueProperties>(
55       m, "RevoluteJointProperties")
56       .def(::py::init<>())
57       .def(
58           ::py::init<const dart::dynamics::GenericJoint<
59               dart::math::R1Space>::Properties&>(),
60           ::py::arg("genericJointProperties"))
61       .def(
62           ::py::init<
63               const dart::dynamics::GenericJoint<
64                   dart::math::R1Space>::Properties&,
65               const dart::dynamics::RevoluteJoint::UniqueProperties&>(),
66           ::py::arg("genericJointProperties"),
67           ::py::arg("uniqueProperties"))
68       .def_readwrite(
69           "mAxis",
70           &dart::dynamics::detail::RevoluteJointUniqueProperties::mAxis);
71 
72   DARTPY_DEFINE_JOINT_COMMON_BASE(RevoluteJoint, R1Space)
73 
74   ::py::class_<
75       dart::dynamics::RevoluteJoint,
76       dart::dynamics::detail::RevoluteJointBase,
77       std::shared_ptr<dart::dynamics::RevoluteJoint>>(m, "RevoluteJoint")
78       .def(
79           "hasRevoluteJointAspect",
80           +[](const dart::dynamics::RevoluteJoint* self) -> bool {
81             return self->hasRevoluteJointAspect();
82           })
83       .def(
84           "setRevoluteJointAspect",
85           +[](dart::dynamics::RevoluteJoint* self,
86               const dart::common::EmbedPropertiesOnTopOf<
87                   dart::dynamics::RevoluteJoint,
88                   dart::dynamics::detail::RevoluteJointUniqueProperties,
89                   dart::dynamics::GenericJoint<
90                       dart::math::RealVectorSpace<1>>>::Aspect* aspect) {
91             self->setRevoluteJointAspect(aspect);
92           },
93           ::py::arg("aspect"))
94       .def(
95           "removeRevoluteJointAspect",
96           +[](dart::dynamics::RevoluteJoint* self) {
97             self->removeRevoluteJointAspect();
98           })
99       .def(
100           "releaseRevoluteJointAspect",
101           +[](dart::dynamics::RevoluteJoint* self)
102               -> std::unique_ptr<dart::common::EmbedPropertiesOnTopOf<
103                   dart::dynamics::RevoluteJoint,
104                   dart::dynamics::detail::RevoluteJointUniqueProperties,
105                   dart::dynamics::GenericJoint<
106                       dart::math::RealVectorSpace<1>>>::Aspect> {
107             return self->releaseRevoluteJointAspect();
108           })
109       .def(
110           "setProperties",
111           +[](dart::dynamics::RevoluteJoint* self,
112               const dart::dynamics::RevoluteJoint::Properties& _properties) {
113             self->setProperties(_properties);
114           },
115           ::py::arg("properties"))
116       .def(
117           "setProperties",
118           +[](dart::dynamics::RevoluteJoint* self,
119               const dart::dynamics::RevoluteJoint::UniqueProperties&
120                   _properties) { self->setProperties(_properties); },
121           ::py::arg("properties"))
122       .def(
123           "setAspectProperties",
124           +[](dart::dynamics::RevoluteJoint* self,
125               const dart::common::EmbedPropertiesOnTopOf<
126                   dart::dynamics::RevoluteJoint,
127                   dart::dynamics::detail::RevoluteJointUniqueProperties,
128                   dart::dynamics::GenericJoint<
129                       dart::math::RealVectorSpace<1>>>::AspectProperties&
130                   properties) { self->setAspectProperties(properties); },
131           ::py::arg("properties"))
132       .def(
133           "getRevoluteJointProperties",
134           +[](const dart::dynamics::RevoluteJoint* self)
135               -> dart::dynamics::RevoluteJoint::Properties {
136             return self->getRevoluteJointProperties();
137           })
138       .def(
139           "copy",
140           +[](dart::dynamics::RevoluteJoint* self,
141               const dart::dynamics::RevoluteJoint* _otherJoint) {
142             self->copy(_otherJoint);
143           },
144           ::py::arg("otherJoint"))
145       .def(
146           "getType",
147           +[](const dart::dynamics::RevoluteJoint* self) -> const std::string& {
148             return self->getType();
149           },
150           ::py::return_value_policy::reference_internal)
151       .def(
152           "isCyclic",
153           +[](const dart::dynamics::RevoluteJoint* self,
154               std::size_t _index) -> bool { return self->isCyclic(_index); },
155           ::py::arg("index"))
156       .def(
157           "setAxis",
158           +[](dart::dynamics::RevoluteJoint* self,
159               const Eigen::Vector3d& _axis) { self->setAxis(_axis); },
160           ::py::arg("axis"))
161       .def(
162           "getAxis",
163           +[](const dart::dynamics::RevoluteJoint* self)
164               -> const Eigen::Vector3d& { return self->getAxis(); },
165           ::py::return_value_policy::reference_internal)
166       .def(
167           "getRelativeJacobianStatic",
168           +[](const dart::dynamics::RevoluteJoint* self,
169               const dart::dynamics::GenericJoint<
170                   dart::math::RealVectorSpace<1>>::Vector& positions)
171               -> dart::dynamics::GenericJoint<
172                   dart::math::RealVectorSpace<1>>::JacobianMatrix {
173             return self->getRelativeJacobianStatic(positions);
174           },
175           ::py::arg("positions"))
176       .def_static(
177           "getStaticType",
178           +[]() -> const std::string& {
179             return dart::dynamics::RevoluteJoint::getStaticType();
180           },
181           ::py::return_value_policy::reference_internal);
182 }
183 
184 } // namespace python
185 } // namespace dart
186