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
ScrewJoint(py::module & m)44 void ScrewJoint(py::module& m)
45 {
46 ::py::class_<dart::dynamics::ScrewJoint::UniqueProperties>(
47 m, "ScrewJointUniqueProperties")
48 .def(::py::init<>())
49 .def(::py::init<const Eigen::Vector3d&>(), ::py::arg("axis"))
50 .def(
51 ::py::init<const Eigen::Vector3d&, double>(),
52 ::py::arg("axis"),
53 ::py::arg("pitch"));
54
55 ::py::class_<
56 dart::dynamics::ScrewJoint::Properties,
57 dart::dynamics::GenericJoint<math::R1Space>::Properties,
58 dart::dynamics::ScrewJoint::UniqueProperties>(m, "ScrewJointProperties")
59 .def(::py::init<>())
60 .def(
61 ::py::init<const dart::dynamics::GenericJoint<
62 dart::math::R1Space>::Properties&>(),
63 ::py::arg("genericJointProperties"))
64 .def(
65 ::py::init<
66 const dart::dynamics::GenericJoint<
67 dart::math::R1Space>::Properties&,
68 const dart::dynamics::ScrewJoint::UniqueProperties&>(),
69 ::py::arg("genericJointProperties"),
70 ::py::arg("revoluteProperties"))
71 .def_readwrite(
72 "mAxis", &dart::dynamics::detail::ScrewJointUniqueProperties::mAxis)
73 .def_readwrite(
74 "mPitch",
75 &dart::dynamics::detail::ScrewJointUniqueProperties::mPitch);
76
77 DARTPY_DEFINE_JOINT_COMMON_BASE(ScrewJoint, R1Space)
78
79 ::py::class_<
80 dart::dynamics::ScrewJoint,
81 dart::common::EmbedPropertiesOnTopOf<
82 dart::dynamics::ScrewJoint,
83 dart::dynamics::detail::ScrewJointUniqueProperties,
84 dart::dynamics::GenericJoint<dart::math::RealVectorSpace<1>>>,
85 std::shared_ptr<dart::dynamics::ScrewJoint>>(m, "ScrewJoint")
86 .def(
87 "hasScrewJointAspect",
88 +[](const dart::dynamics::ScrewJoint* self) -> bool {
89 return self->hasScrewJointAspect();
90 })
91 .def(
92 "setScrewJointAspect",
93 +[](dart::dynamics::ScrewJoint* self,
94 const dart::common::EmbedPropertiesOnTopOf<
95 dart::dynamics::ScrewJoint,
96 dart::dynamics::detail::ScrewJointUniqueProperties,
97 dart::dynamics::GenericJoint<
98 dart::math::RealVectorSpace<1>>>::Aspect* aspect) {
99 self->setScrewJointAspect(aspect);
100 },
101 ::py::arg("aspect"))
102 .def(
103 "removeScrewJointAspect",
104 +[](dart::dynamics::ScrewJoint* self) {
105 self->removeScrewJointAspect();
106 })
107 .def(
108 "releaseScrewJointAspect",
109 +[](dart::dynamics::ScrewJoint* self)
110 -> std::unique_ptr<dart::common::EmbedPropertiesOnTopOf<
111 dart::dynamics::ScrewJoint,
112 dart::dynamics::detail::ScrewJointUniqueProperties,
113 dart::dynamics::GenericJoint<
114 dart::math::RealVectorSpace<1>>>::Aspect> {
115 return self->releaseScrewJointAspect();
116 })
117 .def(
118 "setProperties",
119 +[](dart::dynamics::ScrewJoint* self,
120 const dart::dynamics::ScrewJoint::Properties& _properties) {
121 self->setProperties(_properties);
122 },
123 ::py::arg("properties"))
124 .def(
125 "setProperties",
126 +[](dart::dynamics::ScrewJoint* self,
127 const dart::dynamics::ScrewJoint::UniqueProperties& _properties) {
128 self->setProperties(_properties);
129 },
130 ::py::arg("properties"))
131 .def(
132 "setAspectProperties",
133 +[](dart::dynamics::ScrewJoint* self,
134 const dart::common::EmbedPropertiesOnTopOf<
135 dart::dynamics::ScrewJoint,
136 dart::dynamics::detail::ScrewJointUniqueProperties,
137 dart::dynamics::GenericJoint<
138 dart::math::RealVectorSpace<1>>>::AspectProperties&
139 properties) { self->setAspectProperties(properties); },
140 ::py::arg("properties"))
141 .def(
142 "getScrewJointProperties",
143 +[](const dart::dynamics::ScrewJoint* self)
144 -> dart::dynamics::ScrewJoint::Properties {
145 return self->getScrewJointProperties();
146 })
147 .def(
148 "copy",
149 +[](dart::dynamics::ScrewJoint* self,
150 const dart::dynamics::ScrewJoint* _otherJoint) {
151 self->copy(_otherJoint);
152 },
153 ::py::arg("otherJoint"))
154 .def(
155 "getType",
156 +[](const dart::dynamics::ScrewJoint* self) -> const std::string& {
157 return self->getType();
158 },
159 ::py::return_value_policy::reference_internal)
160 .def(
161 "isCyclic",
162 +[](const dart::dynamics::ScrewJoint* self,
163 std::size_t _index) -> bool { return self->isCyclic(_index); },
164 ::py::arg("index"))
165 .def(
166 "setAxis",
167 +[](dart::dynamics::ScrewJoint* self, const Eigen::Vector3d& _axis) {
168 self->setAxis(_axis);
169 },
170 ::py::arg("axis"))
171 .def(
172 "getAxis",
173 +[](const dart::dynamics::ScrewJoint* self)
174 -> const Eigen::Vector3d& { return self->getAxis(); },
175 ::py::return_value_policy::reference_internal)
176 .def(
177 "setPitch",
178 +[](dart::dynamics::ScrewJoint* self, double _pitch) {
179 self->setPitch(_pitch);
180 },
181 ::py::arg("pitch"))
182 .def(
183 "getPitch",
184 +[](const dart::dynamics::ScrewJoint* self) -> double {
185 return self->getPitch();
186 })
187 .def(
188 "getRelativeJacobianStatic",
189 +[](const dart::dynamics::ScrewJoint* self,
190 const dart::dynamics::GenericJoint<
191 dart::math::RealVectorSpace<1>>::Vector& positions)
192 -> dart::dynamics::GenericJoint<
193 dart::math::RealVectorSpace<1>>::JacobianMatrix {
194 return self->getRelativeJacobianStatic(positions);
195 },
196 ::py::arg("positions"))
197 .def_static(
198 "getStaticType",
199 +[]() -> const std::
200 string& {
201 return dart::dynamics::ScrewJoint::getStaticType();
202 },
203 ::py::return_value_policy::reference_internal);
204 }
205
206 } // namespace python
207 } // namespace dart
208