Control Libraries 6.3.4
Loading...
Searching...
No Matches
bind_joint_space.cpp
1#include "state_representation_bindings.h"
2
3#include <state_representation/State.hpp>
4#include <state_representation/space/joint/JointState.hpp>
5#include <state_representation/space/joint/JointPositions.hpp>
6#include <state_representation/space/joint/JointVelocities.hpp>
7#include <state_representation/space/joint/JointTorques.hpp>
8
9void joint_state_variable(py::module_& m) {
10 py::enum_<JointStateVariable>(m, "JointStateVariable")
11 .value("POSITIONS", JointStateVariable::POSITIONS)
12 .value("VELOCITIES", JointStateVariable::VELOCITIES)
13 .value("ACCELERATIONS", JointStateVariable::ACCELERATIONS)
14 .value("TORQUES", JointStateVariable::TORQUES)
15 .value("ALL", JointStateVariable::ALL)
16 .export_values();
17}
18
19void joint_state(py::module_& m) {
20 m.def("dist", py::overload_cast<const JointState&, const JointState&, const JointStateVariable&>(&state_representation::dist), "Compute the distance between two JointState.", "s1"_a, "s2"_a, "state_variable_type"_a=JointStateVariable::ALL);
21
22 py::class_<JointState, std::shared_ptr<JointState>, State> c(m, "JointState");
23 c.def(py::init(), "Empty constructor for a JointState.");
24 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided.", "robot_name"_a, "nb_joints"_a=0);
25 c.def(py::init<const std::string&, const std::vector<std::string>&>(), "Constructor with name and list of joint names provided.", "robot_name"_a, "joint_names"_a);
26 c.def(py::init<const JointState&>(), "Copy constructor of a JointState.", "state"_a);
27
28 c.def_static("Zero", py::overload_cast<const std::string&, unsigned int>(&JointState::Zero), "Constructor for a zero JointState.", "robot_name"_a, "nb_joints"_a);
29 c.def_static("Zero", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointState::Zero), "Constructor for a zero JointState.", "robot_name"_a, "joint_names"_a);
30 c.def_static("Random", py::overload_cast<const std::string&, unsigned int>(&JointState::Random), "Constructor for a random JointState.", "robot_name"_a, "nb_joints"_a);
31 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointState::Random), "Constructor for a random JointState.", "robot_name"_a, "joint_names"_a);
32
33 c.def("get_size", &JointState::get_size, "Getter of the size from the attributes.");
34 c.def("get_names", &JointState::get_names, "Getter of the names attribute.");
35 c.def("get_joint_index", &JointState::get_joint_index, "Get joint index by the name of the joint, if it exists.", "joint_name"_a);
36 c.def("get_positions", &JointState::get_positions, "Getter of the positions attribute.");
37 c.def("get_position", [](const JointState& joint_state, const std::string& joint_name) { return joint_state.get_position(joint_name); }, "Get the position of a joint by its name, if it exists.", "joint_name"_a);
38 c.def("get_position", [](const JointState& joint_state, unsigned int joint_index) { return joint_state.get_position(joint_index); }, "Get the position of a joint by its name, if it exists.", "joint_index"_a);
39 c.def("get_velocities", &JointState::get_velocities, "Getter of the velocities attribute");
40 c.def("get_velocity", [](const JointState& joint_state, const std::string& joint_name) { return joint_state.get_velocity(joint_name); }, "Get the velocity of a joint by its name, if it exists.", "joint_name"_a);
41 c.def("get_velocity", [](const JointState& joint_state, unsigned int joint_index) { return joint_state.get_velocity(joint_index); }, "Get the velocity of a joint by its name, if it exists.", "joint_index"_a);
42 c.def("get_accelerations", &JointState::get_accelerations, "Getter of the accelerations attribute");
43 c.def("get_acceleration", [](const JointState& joint_state, const std::string& joint_name) { return joint_state.get_acceleration(joint_name); }, "Get the acceleration of a joint by its name, if it exists.", "joint_name"_a);
44 c.def("get_acceleration", [](const JointState& joint_state, unsigned int joint_index) { return joint_state.get_acceleration(joint_index); }, "Get the acceleration of a joint by its name, if it exists.", "joint_index"_a);
45 c.def("get_torques", &JointState::get_torques, "Getter of the torques attribute");
46 c.def("get_torque", [](const JointState& joint_state, const std::string& joint_name) { return joint_state.get_torque(joint_name); }, "Get the torque of a joint by its name, if it exists.", "joint_name"_a);
47 c.def("get_torque", [](const JointState& joint_state, unsigned int joint_index) { return joint_state.get_torque(joint_index); }, "Get the torque of a joint by its name, if it exists.", "joint_index"_a);
48
49 c.def("set_names", py::overload_cast<unsigned int>(&JointState::set_names), "Setter of the names attribute from the number of joints.", "nb_joints"_a);
50 c.def("set_names", py::overload_cast<const std::vector<std::string>&>(&JointState::set_names), "Setter of the names attribute.", "names"_a);
51 c.def("set_positions", py::overload_cast<const Eigen::VectorXd&>(&JointState::set_positions), "Setter of the positions attribute from a vector.", "positions"_a);
52 c.def("set_positions", py::overload_cast<const std::vector<double>&>(&JointState::set_positions), "Setter of the positions attribute from a list.", "positions"_a);
53 c.def("set_position", py::overload_cast<double, const std::string&>(&JointState::set_position), "Set the position of a joint by its name.", "position"_a, "joint_name"_a);
54 c.def("set_position", py::overload_cast<double, unsigned int>(&JointState::set_position), "Set the position of a joint by its index.", "position"_a, "joint_index"_a);
55 c.def("set_velocities", py::overload_cast<const Eigen::VectorXd&>(&JointState::set_velocities), "Setter of the velocities attribute from a vector.", "velocities"_a);
56 c.def("set_velocities", py::overload_cast<const std::vector<double>&>(&JointState::set_velocities), "Setter of the velocities attribute from a list.", "velocities"_a);
57 c.def("set_velocity", py::overload_cast<double, const std::string&>(&JointState::set_velocity), "Set the velocity of a joint by its name.", "velocity"_a, "joint_name"_a);
58 c.def("set_velocity", py::overload_cast<double, unsigned int>(&JointState::set_velocity), "Set the velocity of a joint by its index.", "velocity"_a, "joint_index"_a);
59 c.def("set_accelerations", py::overload_cast<const Eigen::VectorXd&>(&JointState::set_accelerations), "Setter of the accelerations attribute from a vector.", "accelerations"_a);
60 c.def("set_accelerations", py::overload_cast<const std::vector<double>&>(&JointState::set_accelerations), "Setter of the accelerations attribute from a list.", "accelerations"_a);
61 c.def("set_acceleration", py::overload_cast<double, const std::string&>(&JointState::set_acceleration), "Set the acceleration of a joint by its name.", "acceleration"_a, "joint_name"_a);
62 c.def("set_acceleration", py::overload_cast<double, unsigned int>(&JointState::set_acceleration), "Set the acceleration of a joint by its index.", "acceleration"_a, "joint_index"_a);
63 c.def("set_torques", py::overload_cast<const Eigen::VectorXd&>(&JointState::set_torques), "Setter of the torques attribute from a vector.", "torques"_a);
64 c.def("set_torques", py::overload_cast<const std::vector<double>&>(&JointState::set_torques), "Setter of the torques attribute from a list.", "torques"_a);
65 c.def("set_torque", py::overload_cast<double, const std::string&>(&JointState::set_torque), "Set the torque of a joint by its name.", "torque"_a, "joint_name"_a);
66 c.def("set_torque", py::overload_cast<double, unsigned int>(&JointState::set_torque), "Set the torque of a joint by its index.", "torque"_a, "joint_index"_a);
67
68 c.def("set_zero", &JointState::set_zero, "Set the JointState to a zero value.");
69 c.def("clamp_state_variable", py::overload_cast<double, const JointStateVariable&, double>(&JointState::clamp_state_variable), "Clamp inplace the magnitude of the a specific state variable.", "value"_a, "state_variable_type"_a, "noise_ratio"_a=double(0));
70 c.def("clamp_state_variable", py::overload_cast<const Eigen::ArrayXd&, const JointStateVariable&, const Eigen::ArrayXd&>(&JointState::clamp_state_variable), "Clamp inplace the magnitude of the a specific state variable.", "max_absolute_value_array"_a, "state_variable_type"_a, "noise_ratio_array"_a);
71 c.def("copy", &JointState::copy, "Return a copy of the JointState.");
72 c.def("data", &JointState::data, "Returns the data as the concatenation of all the state variables in a single vector.");
73 c.def("array", &JointState::array, "Returns the data vector as an array.");
74 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointState::set_data), "Set the data of the state from all the state variables in a single vector.", "data"_a);
75 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointState::set_data), "Set the data of the state from all the state variables in a single list.", "data"_a);
76
77 c.def(py::self += py::self);
78 c.def(py::self + py::self);
79 c.def(py::self -= py::self);
80 c.def(py::self - py::self);
81 c.def(py::self *= double());
82 c.def(py::self * double());
83 c.def(py::self *= Eigen::ArrayXd());
84 c.def(py::self * Eigen::ArrayXd());
85 c.def(py::self *= Eigen::MatrixXd());
86 c.def(py::self * Eigen::MatrixXd());
87 c.def(py::self /= double());
88 c.def(py::self / double());
89 c.def(double() * py::self);
90 c.def(Eigen::ArrayXd() * py::self);
91 c.def(Eigen::MatrixXd() * py::self);
92
93 c.def("dist", &JointState::dist, "Compute the distance to another state as the sum of distances between each attribute.", "state"_a, "state_variable_type"_a=JointStateVariable::ALL);
94
95 c.def("to_list", &JointState::to_std_vector, "Return the state as a list.");
96
97 c.def("__copy__", [](const JointState &state) {
98 return JointState(state);
99 });
100 c.def("__deepcopy__", [](const JointState &state, py::dict) {
101 return JointState(state);
102 }, "memo"_a);
103 c.def("__repr__", [](const JointState& state) {
104 std::stringstream buffer;
105 buffer << state;
106 return buffer.str();
107 });
108}
109
110void joint_positions(py::module_& m) {
111 py::class_<JointPositions, std::shared_ptr<JointPositions>, JointState> c(m, "JointPositions");
112
113 c.def(py::init(), "Empty constructor");
114 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
115 c.def(py::init<const std::string&, const std::vector<std::string>&>(), "Constructor with name and list of joint names provided", "robot_name"_a, "joint_names"_a);
116 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and position values provided", "robot_name"_a, "positions"_a);
117 c.def(py::init<const std::string&, const std::vector<std::string>&, const Eigen::VectorXd&>(), "Constructor with name, a list of joint names and position values provided", "robot_name"_a, "joint_names"_a, "positions"_a);
118 c.def(py::init<const JointPositions&>(), "Copy constructor", "positions"_a);
119 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
120 c.def(py::init<const JointVelocities&>(), "Integration constructor from a JointVelocities by considering that it is equivalent to multiplying the velocities by 1 second", "velocities"_a);
121
122 c.def_static("Zero", py::overload_cast<const std::string&, unsigned int>(&JointPositions::Zero), "Constructor for the zero JointPositions", "robot_name"_a, "nb_joints"_a);
123 c.def_static("Zero", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointPositions::Zero), "Constructor for the zero JointPositions", "robot_name"_a, "joint_names"_a);
124 c.def_static("Random", py::overload_cast<const std::string&, unsigned int>(&JointPositions::Random), "Constructor for the random JointPositions", "robot_name"_a, "nb_joints"_a);
125 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointPositions::Random), "Constructor for the random JointPositions", "robot_name"_a, "joint_names"_a);
126
127 std::vector<std::string> deleted_attributes = {
128 "velocities",
129 "velocity",
130 "accelerations",
131 "acceleration",
132 "torques",
133 "torque",
134 };
135
136 for (const std::string& attr : deleted_attributes) {
137 c.def(std::string("get_" + attr).c_str(), [](const JointPositions&) -> void {}, "Deleted method from parent class.");
138 c.def(std::string("set_" + attr).c_str(), [](const JointPositions& positions) -> JointPositions { return positions; }, "Deleted method from parent class.");
139 }
140
141 c.def(py::self += py::self);
142 c.def(py::self + py::self);
143 c.def(py::self -= py::self);
144 c.def(py::self - py::self);
145 c.def(py::self *= double());
146 c.def(py::self * double());
147 c.def(py::self *= Eigen::ArrayXd());
148 c.def(py::self * Eigen::ArrayXd());
149 c.def(py::self *= Eigen::MatrixXd());
150 c.def(py::self * Eigen::MatrixXd());
151 c.def(py::self /= double());
152 c.def(py::self / double());
153 c.def(py::self / std::chrono::nanoseconds());
154 c.def(double() * py::self);
155 c.def(Eigen::ArrayXd() * py::self);
156 c.def(Eigen::MatrixXd() * py::self);
157
158 c.def("copy", &JointPositions::copy, "Return a copy of the JointPositions");
159 c.def("data", &JointPositions::data, "Returns the positions data as a vector");
160 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointPositions::set_data), "Set the positions data from a vector", "data"_a);
161 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointPositions::set_data), "Set the positions data from a list", "data"_a);
162
163 c.def("__copy__", [](const JointPositions &positions) {
164 return JointPositions(positions);
165 });
166 c.def("__deepcopy__", [](const JointPositions &positions, py::dict) {
167 return JointPositions(positions);
168 }, "memo"_a);
169 c.def("__repr__", [](const JointPositions& positions) {
170 std::stringstream buffer;
171 buffer << positions;
172 return buffer.str();
173 });
174}
175
176void joint_velocities(py::module_& m) {
177 py::class_<JointVelocities, std::shared_ptr<JointVelocities>, JointState> c(m, "JointVelocities");
178
179 c.def(py::init(), "Empty constructor");
180 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
181 c.def(py::init<const std::string&, const std::vector<std::string>&>(), "Constructor with name and list of joint names provided", "robot_name"_a, "joint_names"_a);
182 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and velocity values provided", "robot_name"_a, "velocities"_a);
183 c.def(py::init<const std::string&, const std::vector<std::string>&, const Eigen::VectorXd&>(), "Constructor with name, a list of joint names and velocity values provided", "robot_name"_a, "joint_names"_a, "velocities"_a);
184 c.def(py::init<const JointVelocities&>(), "Copy constructor", "velocities"_a);
185 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
186 c.def(py::init<const JointPositions&>(), "Differentiation constructor from a JointPositions by considering that it is equivalent to dividing the positions by 1 second", "positions"_a);
187 c.def(py::init<const JointAccelerations&>(), "Integration constructor from a JointAccelerations by considering that it is equivalent to multiplying the accelerations by 1 second", "accelerations"_a);
188
189 c.def_static("Zero", py::overload_cast<const std::string&, unsigned int>(&JointVelocities::Zero), "Constructor for the zero JointVelocities", "robot_name"_a, "nb_joints"_a);
190 c.def_static("Zero", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointVelocities::Zero), "Constructor for the zero JointVelocities", "robot_name"_a, "joint_names"_a);
191 c.def_static("Random", py::overload_cast<const std::string&, unsigned int>(&JointVelocities::Random), "Constructor for the random JointVelocities", "robot_name"_a, "nb_joints"_a);
192 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointVelocities::Random), "Constructor for the random JointVelocities", "robot_name"_a, "joint_names"_a);
193
194 std::vector<std::string> deleted_attributes = {
195 "positions",
196 "position",
197 "accelerations",
198 "acceleration",
199 "torques",
200 "torque",
201 };
202
203 for (const std::string& attr : deleted_attributes) {
204 c.def(std::string("get_" + attr).c_str(), [](const JointVelocities&) -> void {}, "Deleted method from parent class.");
205 c.def(std::string("set_" + attr).c_str(), [](const JointVelocities& velocities) -> JointVelocities { return velocities; }, "Deleted method from parent class.");
206 }
207
208 c.def(py::self += py::self);
209 c.def(py::self + py::self);
210 c.def(py::self -= py::self);
211 c.def(py::self - py::self);
212 c.def(py::self *= double());
213 c.def(py::self * double());
214 c.def(py::self *= Eigen::ArrayXd());
215 c.def(py::self * Eigen::ArrayXd());
216 c.def(py::self *= Eigen::MatrixXd());
217 c.def(py::self * Eigen::MatrixXd());
218 c.def(py::self /= double());
219 c.def(py::self / double());
220 c.def(py::self / std::chrono::nanoseconds());
221 c.def(py::self * std::chrono::nanoseconds());
222
223 c.def(double() * py::self);
224 c.def(std::chrono::nanoseconds() * py::self);
225 c.def(Eigen::ArrayXd() * py::self);
226 c.def(Eigen::MatrixXd() * py::self);
227
228 c.def("copy", &JointVelocities::copy, "Return a copy of the JointVelocities");
229 c.def("data", &JointVelocities::data, "Returns the velocities data as a vector");
230 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointVelocities::set_data), "Set the velocities data from a vector", "data"_a);
231 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointVelocities::set_data), "Set the velocities data from a list", "data"_a);
232
233 c.def("clamp", py::overload_cast<double, double>(&JointVelocities::clamp), "Clamp inplace the magnitude of the velocity to the values in argument", "max_absolute_value"_a, "noise_ratio"_a=0.0);
234 c.def("clamped", py::overload_cast<double, double>(&JointVelocities::clamp), "Return the velocity clamped to the values in argument", "max_absolute_value"_a, "noise_ratio"_a=0.0);
235 c.def("clamp", py::overload_cast<const Eigen::ArrayXd&, const Eigen::ArrayXd&>(&JointVelocities::clamp), "Clamp inplace the magnitude of the velocity to the values in argument", "max_absolute_value_array"_a, "noise_ratio_array"_a);
236 c.def("clamped", py::overload_cast<const Eigen::ArrayXd&, const Eigen::ArrayXd&>(&JointVelocities::clamp), "Return the velocity clamped to the values in argument", "max_absolute_value_array"_a, "noise_ratio_array"_a);
237
238 c.def("__copy__", [](const JointVelocities &velocities) {
239 return JointVelocities(velocities);
240 });
241 c.def("__deepcopy__", [](const JointVelocities &velocities, py::dict) {
242 return JointVelocities(velocities);
243 }, "memo"_a);
244 c.def("__repr__", [](const JointVelocities& velocities) {
245 std::stringstream buffer;
246 buffer << velocities;
247 return buffer.str();
248 });
249}
250
251void joint_accelerations(py::module_& m) {
252 py::class_<JointAccelerations, std::shared_ptr<JointAccelerations>, JointState> c(m, "JointAccelerations");
253
254 c.def(py::init(), "Empty constructor");
255 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
256 c.def(py::init<const std::string&, const std::vector<std::string>&>(), "Constructor with name and list of joint names provided", "robot_name"_a, "joint_names"_a);
257 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and acceleration values provided", "robot_name"_a, "accelerations"_a);
258 c.def(py::init<const std::string&, const std::vector<std::string>&, const Eigen::VectorXd&>(), "Constructor with name, a list of joint names and acceleration values provided", "robot_name"_a, "joint_names"_a, "accelerations"_a);
259 c.def(py::init<const JointAccelerations&>(), "Copy constructor", "accelerations"_a);
260 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
261 c.def(py::init<const JointVelocities&>(), "Differentiation constructor from a JointVelocities by considering that it is equivalent to dividing the velocities by 1 second", "velocities"_a);
262
263 c.def_static("Zero", py::overload_cast<const std::string&, unsigned int>(&JointAccelerations::Zero), "Constructor for the zero JointAccelerations", "robot_name"_a, "nb_joints"_a);
264 c.def_static("Zero", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointAccelerations::Zero), "Constructor for the zero JointAccelerations", "robot_name"_a, "joint_names"_a);
265 c.def_static("Random", py::overload_cast<const std::string&, unsigned int>(&JointAccelerations::Random), "Constructor for the random JointAccelerations", "robot_name"_a, "nb_joints"_a);
266 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointAccelerations::Random), "Constructor for the random JointAccelerations", "robot_name"_a, "joint_names"_a);
267
268 std::vector<std::string> deleted_attributes = {
269 "positions",
270 "position",
271 "velocities",
272 "velocity",
273 "torques",
274 "torque",
275 };
276
277 for (const std::string& attr : deleted_attributes) {
278 c.def(std::string("get_" + attr).c_str(), [](const JointAccelerations&) -> void {}, "Deleted method from parent class.");
279 c.def(std::string("set_" + attr).c_str(), [](const JointAccelerations& accelerations) -> JointAccelerations { return accelerations; }, "Deleted method from parent class.");
280 }
281
282 c.def(py::self += py::self);
283 c.def(py::self + py::self);
284 c.def(py::self -= py::self);
285 c.def(py::self - py::self);
286 c.def(py::self *= double());
287 c.def(py::self * double());
288 c.def(py::self *= Eigen::ArrayXd());
289 c.def(py::self * Eigen::ArrayXd());
290 c.def(py::self *= Eigen::MatrixXd());
291 c.def(py::self * Eigen::MatrixXd());
292 c.def(py::self /= double());
293 c.def(py::self / double());
294 c.def(py::self * std::chrono::nanoseconds());
295
296 c.def(double() * py::self);
297 c.def(std::chrono::nanoseconds() * py::self);
298 c.def(Eigen::ArrayXd() * py::self);
299 c.def(Eigen::MatrixXd() * py::self);
300
301 c.def("copy", &JointAccelerations::copy, "Return a copy of the JointAccelerations");
302 c.def("data", &JointAccelerations::data, "Returns the accelerations data as a vector");
303 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointAccelerations::set_data), "Set the accelerations data from a vector", "data"_a);
304 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointAccelerations::set_data), "Set the accelerations data from a list", "data"_a);
305
306 c.def("clamp", py::overload_cast<double, double>(&JointAccelerations::clamp), "Clamp inplace the magnitude of the accelerations to the values in argument", "max_absolute_value"_a, "noise_ratio"_a=0.0);
307 c.def("clamped", py::overload_cast<double, double>(&JointAccelerations::clamp), "Return the accelerations clamped to the values in argument", "max_absolute_value"_a, "noise_ratio"_a=0.0);
308 c.def("clamp", py::overload_cast<const Eigen::ArrayXd&, const Eigen::ArrayXd&>(&JointAccelerations::clamp), "Clamp inplace the magnitude of the accelerations to the values in argument", "max_absolute_value_array"_a, "noise_ratio_array"_a);
309 c.def("clamped", py::overload_cast<const Eigen::ArrayXd&, const Eigen::ArrayXd&>(&JointAccelerations::clamp), "Return the accelerations clamped to the values in argument", "max_absolute_value_array"_a, "noise_ratio_array"_a);
310
311 c.def("__copy__", [](const JointAccelerations &accelerations) {
312 return JointAccelerations(accelerations);
313 });
314 c.def("__deepcopy__", [](const JointAccelerations &accelerations, py::dict) {
315 return JointAccelerations(accelerations);
316 }, "memo"_a);
317 c.def("__repr__", [](const JointAccelerations& accelerations) {
318 std::stringstream buffer;
319 buffer << accelerations;
320 return buffer.str();
321 });
322}
323
324void joint_torques(py::module_& m) {
325 py::class_<JointTorques, std::shared_ptr<JointTorques>, JointState> c(m, "JointTorques");
326
327 c.def(py::init(), "Empty constructor");
328 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
329 c.def(py::init<const std::string&, const std::vector<std::string>&>(), "Constructor with name and list of joint names provided", "robot_name"_a, "joint_names"_a);
330 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and torque values provided", "robot_name"_a, "velocities"_a);
331 c.def(py::init<const std::string&, const std::vector<std::string>&, const Eigen::VectorXd&>(), "Constructor with name, a list of joint names and torque values provided", "robot_name"_a, "joint_names"_a, "velocities"_a);
332 c.def(py::init<const JointTorques&>(), "Copy constructor", "torques"_a);
333 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
334
335 c.def_static("Zero", py::overload_cast<const std::string&, unsigned int>(&JointTorques::Zero), "Constructor for the zero JointTorques", "robot_name"_a, "nb_joints"_a);
336 c.def_static("Zero", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointTorques::Zero), "Constructor for the zero JointTorques", "robot_name"_a, "joint_names"_a);
337 c.def_static("Random", py::overload_cast<const std::string&, unsigned int>(&JointTorques::Random), "Constructor for the random JointTorques", "robot_name"_a, "nb_joints"_a);
338 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&>(&JointTorques::Random), "Constructor for the random JointTorques", "robot_name"_a, "joint_names"_a);
339
340 std::vector<std::string> deleted_attributes = {
341 "positions",
342 "position",
343 "velocities",
344 "velocity",
345 "accelerations",
346 "acceleration",
347 };
348
349 for (const std::string& attr : deleted_attributes) {
350 c.def(std::string("get_" + attr).c_str(), [](const JointTorques&) -> void {}, "Deleted method from parent class.");
351 c.def(std::string("set_" + attr).c_str(), [](const JointTorques& torques) -> JointTorques { return torques; }, "Deleted method from parent class.");
352 }
353
354 c.def(py::self += py::self);
355 c.def(py::self + py::self);
356 c.def(py::self -= py::self);
357 c.def(py::self - py::self);
358 c.def(py::self *= double());
359 c.def(py::self * double());
360 c.def(py::self *= Eigen::ArrayXd());
361 c.def(py::self * Eigen::ArrayXd());
362 c.def(py::self *= Eigen::MatrixXd());
363 c.def(py::self * Eigen::MatrixXd());
364 c.def(py::self /= double());
365 c.def(py::self / double());
366 c.def(double() * py::self);
367 c.def(Eigen::ArrayXd() * py::self);
368 c.def(Eigen::MatrixXd() * py::self);
369
370 c.def("copy", &JointTorques::copy, "Return a copy of the JointTorques");
371 c.def("data", &JointTorques::data, "Returns the torques data as a vector");
372 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointTorques::set_data), "Set the torques data from a vector", "data"_a);
373 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointTorques::set_data), "Set the torques data from a list", "data"_a);
374
375 c.def("clamp", py::overload_cast<double, double>(&JointTorques::clamp), "Clamp inplace the magnitude of the torque to the values in argument", "max_absolute_value"_a, "noise_ratio"_a=0.0);
376 c.def("clamped", py::overload_cast<double, double>(&JointTorques::clamp), "Return the torque clamped to the values in argument", "max_absolute_value"_a, "noise_ratio"_a=0.0);
377 c.def("clamp", py::overload_cast<const Eigen::ArrayXd&, const Eigen::ArrayXd&>(&JointTorques::clamp), "Clamp inplace the magnitude of the torque to the values in argument", "max_absolute_value_array"_a, "noise_ratio_array"_a);
378 c.def("clamped", py::overload_cast<const Eigen::ArrayXd&, const Eigen::ArrayXd&>(&JointTorques::clamp), "Return the torque clamped to the values in argument", "max_absolute_value_array"_a, "noise_ratio_array"_a);
379
380 c.def("__copy__", [](const JointTorques &torques) {
381 return JointTorques(torques);
382 });
383 c.def("__deepcopy__", [](const JointTorques &torques, py::dict) {
384 return JointTorques(torques);
385 }, "memo"_a);
386 c.def("__repr__", [](const JointTorques& torques) {
387 std::stringstream buffer;
388 buffer << torques;
389 return buffer.str();
390 });
391}
392
393void bind_joint_space(py::module_& m) {
394 joint_state_variable(m);
395 joint_state(m);
396 joint_positions(m);
397 joint_velocities(m);
398 joint_accelerations(m);
399 joint_torques(m);
400}
Class to define accelerations of the joints.
JointAccelerations copy() const
Return a copy of the JointAccelerations.
Eigen::VectorXd data() const override
Returns the accelerations data as an Eigen vector.
virtual void set_data(const Eigen::VectorXd &data) override
Set the accelerations data from an Eigen vector.
static JointAccelerations Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for the zero JointAccelerations.
void clamp(double max_absolute_value, double noise_ratio=0.)
Clamp inplace the magnitude of the acceleration to the values in argument.
static JointAccelerations Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for the random JointAccelerations.
Class to define a positions of the joints.
static JointPositions Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for the zero JointPositions.
Eigen::VectorXd data() const override
Returns the positions data as an Eigen vector.
virtual void set_data(const Eigen::VectorXd &data) override
Set the positions data from an Eigen vector.
static JointPositions Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for the random JointPositions.
JointPositions copy() const
Return a copy of the JointPositions.
Class to define a state in joint space.
Definition: JointState.hpp:36
const Eigen::VectorXd & get_torques() const
Getter of the torques attribute.
Definition: JointState.cpp:182
double dist(const JointState &state, const JointStateVariable &state_variable_type=JointStateVariable::ALL) const
Compute the distance to another state as the sum of distances between each attribute.
Definition: JointState.cpp:389
void set_accelerations(const Eigen::VectorXd &accelerations)
Setter of the accelerations attribute.
Definition: JointState.cpp:163
void set_positions(const Eigen::VectorXd &positions)
Setter of the positions attribute.
Definition: JointState.cpp:99
static JointState Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for a random JointState.
Definition: JointState.cpp:64
void set_names(unsigned int nb_joints)
Setter of the names attribute from the number of joints.
Definition: JointState.hpp:664
void set_zero()
Set the JointState to a zero value.
Definition: JointState.cpp:43
const Eigen::VectorXd & get_velocities() const
Getter of the velocities attribute.
Definition: JointState.cpp:118
unsigned int get_size() const
Getter of the size from the attributes.
Definition: JointState.hpp:656
void clamp_state_variable(double max_absolute_value, const JointStateVariable &state_variable_type, double noise_ratio=0)
Clamp inplace the magnitude of the a specific joint state variable.
Definition: JointState.cpp:379
void set_acceleration(double acceleration, const std::string &joint_name)
Set the acceleration of a joint by its name.
Definition: JointState.cpp:171
std::vector< double > to_std_vector() const
Return the joint state as a std vector of floats.
Definition: JointState.hpp:732
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero JointState.
Definition: JointState.cpp:50
Eigen::ArrayXd array() const
Returns the data vector as an Eigen Array.
Definition: JointState.cpp:346
unsigned int get_joint_index(const std::string &joint_name) const
Get joint index by the name of the joint, if it exists.
Definition: JointState.cpp:78
JointState copy() const
Return a copy of the JointState.
Definition: JointState.cpp:329
void set_torques(const Eigen::VectorXd &torques)
Setter of the torques attribute.
Definition: JointState.cpp:195
void set_position(double position, const std::string &joint_name)
Set the position of a joint by its name.
Definition: JointState.cpp:107
virtual void set_data(const Eigen::VectorXd &data) override
Set the data of the state from all the state variables in a single Eigen vector.
Definition: JointState.cpp:338
void set_torque(double torque, const std::string &joint_name)
Set the torque of a joint by its name.
Definition: JointState.cpp:203
const Eigen::VectorXd & get_accelerations() const
Getter of the accelerations attribute.
Definition: JointState.cpp:150
const std::vector< std::string > & get_names() const
Getter of the names attribute.
Definition: JointState.hpp:660
void set_velocity(double velocity, const std::string &joint_name)
Set the velocity of a joint by its name.
Definition: JointState.cpp:139
const Eigen::VectorXd & get_positions() const
Getter of the positions attribute.
Definition: JointState.cpp:86
void set_velocities(const Eigen::VectorXd &velocities)
Setter of the velocities attribute.
Definition: JointState.cpp:131
virtual Eigen::VectorXd data() const
Returns the data as the concatenation of all the state variables in a single vector.
Definition: JointState.cpp:334
Class to define torques of the joints.
void clamp(double max_absolute_value, double noise_ratio=0.)
Clamp inplace the magnitude of the torque to the values in argument.
JointTorques copy() const
Return a copy of the JointTorques.
virtual void set_data(const Eigen::VectorXd &data) override
Set the torques data from an Eigen vector.
static JointTorques Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for the random JointTorques.
static JointTorques Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for the zero JointTorques.
Eigen::VectorXd data() const override
Returns the torques data as an Eigen vector.
Class to define velocities of the joints.
static JointVelocities Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for the random JointVelocities.
Eigen::VectorXd data() const override
Returns the velocities data as an Eigen vector.
static JointVelocities Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for the zero JointVelocities.
JointVelocities copy() const
Return a copy of the JointVelocities.
void clamp(double max_absolute_value, double noise_ratio=0.)
Clamp inplace the magnitude of the velocity to the values in argument.
virtual void set_data(const Eigen::VectorXd &data) override
Set the velocities data from an Eigen vector.
Abstract class to represent a state.
Definition: State.hpp:25
double dist(const CartesianState &s1, const CartesianState &s2, const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL)
compute the distance between two CartesianStates