Control Libraries 7.4.0
Loading...
Searching...
No Matches
bind_joint_space.cpp
1#include "state_representation_bindings.hpp"
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 *= double());
78 c.def(py::self * double());
79 c.def(double() * py::self);
80 c.def("__mul__", [](const JointState& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *: 'state_representation.JointState' and 'np.ndarray'"); });
81 c.def("__imul__", [](const JointState& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *=: 'state_representation.JointState' and 'np.ndarray'"); });
82 c.def(Eigen::MatrixXd() * py::self);
83 c.def(py::self /= double());
84 c.def(py::self / double());
85 c.def("__truediv__", [](const JointState& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for /: 'state_representation.JointState' and 'np.ndarray'"); });
86
87 c.def(py::self += py::self);
88 c.def(py::self + py::self);
89 c.def("__neg__", [](const JointState& self) -> JointState { return -self; });
90 c.def(py::self -= py::self);
91 c.def(py::self - 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 *= double());
142 c.def(py::self * double());
143 c.def(double() * py::self);
144 c.def("__mul__", [](const JointPositions& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *: 'state_representation.JointPositions' and 'np.ndarray'"); });
145 c.def("__imul__", [](const JointPositions& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *=: 'state_representation.JointPositions' and 'np.ndarray'"); });
146 c.def(Eigen::MatrixXd() * py::self);
147 c.def(py::self /= double());
148 c.def(py::self / double());
149 c.def("__truediv__", [](const JointPositions& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for /: 'state_representation.JointPositions' and 'np.ndarray'"); });
150 c.def(py::self / std::chrono::nanoseconds());
151
152 c.def(py::self += py::self);
153 c.def("__iadd__", [](const JointPositions& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointPositions' and 'state_representation.JointVelocities'"); });
154 c.def("__iadd__", [](const JointPositions& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointPositions' and 'state_representation.JointAccelerations'"); });
155 c.def("__iadd__", [](const JointPositions& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointPositions' and 'state_representation.JointTorques'"); });
156 c.def(py::self += JointState());
157 c.def(py::self + py::self);
158 c.def("__add__", [](const JointPositions& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointPositions' and 'state_representation.JointVelocities'"); });
159 c.def("__add__", [](const JointPositions& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointPositions' and 'state_representation.JointAccelerations'"); });
160 c.def("__add__", [](const JointPositions& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointPositions' and 'state_representation.JointTorques'"); });
161 c.def(py::self + JointState());
162 c.def("__neg__", [](const JointPositions& self) -> JointPositions { return -self; });
163 c.def(py::self -= py::self);
164 c.def("__isub__", [](const JointPositions& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointPositions' and 'state_representation.JointVelocities'"); });
165 c.def("__isub__", [](const JointPositions& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointPositions' and 'state_representation.JointAccelerations'"); });
166 c.def("__isub__", [](const JointPositions& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointPositions' and 'state_representation.JointTorques'"); });
167 c.def(py::self -= JointState());
168 c.def(py::self - py::self);
169 c.def("__sub__", [](const JointPositions& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointPositions' and 'state_representation.JointVelocities'"); });
170 c.def("__sub__", [](const JointPositions& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointPositions' and 'state_representation.JointAccelerations'"); });
171 c.def("__sub__", [](const JointPositions& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointPositions' and 'state_representation.JointTorques'"); });
172 c.def(py::self - JointState());
173
174 c.def("copy", &JointPositions::copy, "Return a copy of the JointPositions");
175 c.def("data", &JointPositions::data, "Returns the positions data as a vector");
176 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointPositions::set_data), "Set the positions data from a vector", "data"_a);
177 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointPositions::set_data), "Set the positions data from a list", "data"_a);
178
179 c.def("__copy__", [](const JointPositions &positions) {
180 return JointPositions(positions);
181 });
182 c.def("__deepcopy__", [](const JointPositions &positions, py::dict) {
183 return JointPositions(positions);
184 }, "memo"_a);
185 c.def("__repr__", [](const JointPositions& positions) {
186 std::stringstream buffer;
187 buffer << positions;
188 return buffer.str();
189 });
190}
191
192void joint_velocities(py::module_& m) {
193 py::class_<JointVelocities, std::shared_ptr<JointVelocities>, JointState> c(m, "JointVelocities");
194
195 c.def(py::init(), "Empty constructor");
196 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
197 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);
198 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and velocity values provided", "robot_name"_a, "velocities"_a);
199 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);
200 c.def(py::init<const JointVelocities&>(), "Copy constructor", "velocities"_a);
201 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
202 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);
203 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);
204
205 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);
206 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);
207 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);
208 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);
209
210 std::vector<std::string> deleted_attributes = {
211 "positions",
212 "position",
213 "accelerations",
214 "acceleration",
215 "torques",
216 "torque",
217 };
218
219 for (const std::string& attr : deleted_attributes) {
220 c.def(std::string("get_" + attr).c_str(), [](const JointVelocities&) -> void {}, "Deleted method from parent class.");
221 c.def(std::string("set_" + attr).c_str(), [](const JointVelocities& velocities) -> JointVelocities { return velocities; }, "Deleted method from parent class.");
222 }
223
224 c.def(py::self *= double());
225 c.def(py::self * double());
226 c.def(double() * py::self);
227 c.def("__mul__", [](const JointVelocities& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *: 'state_representation.JointVelocities' and 'np.ndarray'"); });
228 c.def("__imul__", [](const JointVelocities& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *=: 'state_representation.JointVelocities' and 'np.ndarray'"); });
229 c.def(Eigen::MatrixXd() * py::self);
230 c.def(py::self * std::chrono::nanoseconds());
231 c.def(std::chrono::nanoseconds() * py::self);
232 c.def(py::self /= double());
233 c.def(py::self / double());
234 c.def("__truediv__", [](const JointVelocities& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for /: 'state_representation.JointVelocities' and 'np.ndarray'"); });
235 c.def(py::self / std::chrono::nanoseconds());
236
237 c.def(py::self += py::self);
238 c.def("__iadd__", [](const JointVelocities& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointVelocities' and 'state_representation.JointPositions'"); });
239 c.def("__iadd__", [](const JointVelocities& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointVelocities' and 'state_representation.JointAccelerations'"); });
240 c.def("__iadd__", [](const JointVelocities& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointVelocities' and 'state_representation.JointTorques'"); });
241 c.def(py::self += JointState());
242 c.def(py::self + py::self);
243 c.def("__add__", [](const JointVelocities& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointVelocities' and 'state_representation.JointPositions'"); });
244 c.def("__add__", [](const JointVelocities& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointVelocities' and 'state_representation.JointAccelerations'"); });
245 c.def("__add__", [](const JointVelocities& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointVelocities' and 'state_representation.JointTorques'"); });
246 c.def(py::self + JointState());
247 c.def("__neg__", [](const JointVelocities& self) -> JointVelocities { return -self; });
248 c.def(py::self -= py::self);
249 c.def("__isub__", [](const JointVelocities& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointVelocities' and 'state_representation.JointPositions'"); });
250 c.def("__isub__", [](const JointVelocities& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointVelocities' and 'state_representation.JointAccelerations'"); });
251 c.def("__isub__", [](const JointVelocities& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointVelocities' and 'state_representation.JointTorques'"); });
252 c.def(py::self -= JointState());
253 c.def(py::self - py::self);
254 c.def("__sub__", [](const JointVelocities& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointVelocities' and 'state_representation.JointPositions'"); });
255 c.def("__sub__", [](const JointVelocities& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointVelocities' and 'state_representation.JointAccelerations'"); });
256 c.def("__sub__", [](const JointVelocities& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointVelocities' and 'state_representation.JointTorques'"); });
257 c.def(py::self - JointState());
258
259 c.def("copy", &JointVelocities::copy, "Return a copy of the JointVelocities");
260 c.def("data", &JointVelocities::data, "Returns the velocities data as a vector");
261 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointVelocities::set_data), "Set the velocities data from a vector", "data"_a);
262 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointVelocities::set_data), "Set the velocities data from a list", "data"_a);
263
264 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);
265 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);
266 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);
267 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);
268
269 c.def("__copy__", [](const JointVelocities &velocities) {
270 return JointVelocities(velocities);
271 });
272 c.def("__deepcopy__", [](const JointVelocities &velocities, py::dict) {
273 return JointVelocities(velocities);
274 }, "memo"_a);
275 c.def("__repr__", [](const JointVelocities& velocities) {
276 std::stringstream buffer;
277 buffer << velocities;
278 return buffer.str();
279 });
280}
281
282void joint_accelerations(py::module_& m) {
283 py::class_<JointAccelerations, std::shared_ptr<JointAccelerations>, JointState> c(m, "JointAccelerations");
284
285 c.def(py::init(), "Empty constructor");
286 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
287 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);
288 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and acceleration values provided", "robot_name"_a, "accelerations"_a);
289 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);
290 c.def(py::init<const JointAccelerations&>(), "Copy constructor", "accelerations"_a);
291 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
292 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);
293
294 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);
295 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);
296 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);
297 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);
298
299 std::vector<std::string> deleted_attributes = {
300 "positions",
301 "position",
302 "velocities",
303 "velocity",
304 "torques",
305 "torque",
306 };
307
308 for (const std::string& attr : deleted_attributes) {
309 c.def(std::string("get_" + attr).c_str(), [](const JointAccelerations&) -> void {}, "Deleted method from parent class.");
310 c.def(std::string("set_" + attr).c_str(), [](const JointAccelerations& accelerations) -> JointAccelerations { return accelerations; }, "Deleted method from parent class.");
311 }
312
313 c.def(py::self *= double());
314 c.def(py::self * double());
315 c.def(double() * py::self);
316 c.def("__mul__", [](const JointAccelerations& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *: 'state_representation.JointAccelerations' and 'np.ndarray'"); });
317 c.def("__imul__", [](const JointAccelerations& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *=: 'state_representation.JointAccelerations' and 'np.ndarray'"); });
318 c.def(Eigen::MatrixXd() * py::self);
319 c.def(py::self * std::chrono::nanoseconds());
320 c.def(std::chrono::nanoseconds() * py::self);
321 c.def(py::self /= double());
322 c.def(py::self / double());
323 c.def("__truediv__", [](const JointAccelerations& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for /: 'state_representation.JointAccelerations' and 'np.ndarray'"); });
324
325 c.def(py::self += py::self);
326 c.def("__iadd__", [](const JointAccelerations& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointAccelerations' and 'state_representation.JointPositions'"); });
327 c.def("__iadd__", [](const JointAccelerations& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointAccelerations' and 'state_representation.JointVelocities'"); });
328 c.def("__iadd__", [](const JointAccelerations& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointAccelerations' and 'state_representation.JointTorques'"); });
329 c.def(py::self += JointState());
330 c.def(py::self + py::self);
331 c.def("__add__", [](const JointAccelerations& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointAccelerations' and 'state_representation.JointPositions'"); });
332 c.def("__add__", [](const JointAccelerations& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointAccelerations' and 'state_representation.JointVelocities'"); });
333 c.def("__add__", [](const JointAccelerations& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointAccelerations' and 'state_representation.JointTorques'"); });
334 c.def(py::self + JointState());
335 c.def("__neg__", [](const JointAccelerations& self) -> JointAccelerations { return -self; });
336 c.def(py::self -= py::self);
337 c.def("__isub__", [](const JointAccelerations& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointAccelerations' and 'state_representation.JointPositions'"); });
338 c.def("__isub__", [](const JointAccelerations& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointAccelerations' and 'state_representation.JointVelocities'"); });
339 c.def("__isub__", [](const JointAccelerations& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointAccelerations' and 'state_representation.JointTorques'"); });
340 c.def(py::self -= JointState());
341 c.def(py::self - py::self);
342 c.def("__sub__", [](const JointAccelerations& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointAccelerations' and 'state_representation.JointPositions'"); });
343 c.def("__sub__", [](const JointAccelerations& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointAccelerations' and 'state_representation.JointVelocities'"); });
344 c.def("__sub__", [](const JointAccelerations& self, const JointTorques& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointAccelerations' and 'state_representation.JointTorques'"); });
345 c.def(py::self - JointState());
346
347 c.def("copy", &JointAccelerations::copy, "Return a copy of the JointAccelerations");
348 c.def("data", &JointAccelerations::data, "Returns the accelerations data as a vector");
349 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointAccelerations::set_data), "Set the accelerations data from a vector", "data"_a);
350 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointAccelerations::set_data), "Set the accelerations data from a list", "data"_a);
351
352 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);
353 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);
354 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);
355 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);
356
357 c.def("__copy__", [](const JointAccelerations &accelerations) {
358 return JointAccelerations(accelerations);
359 });
360 c.def("__deepcopy__", [](const JointAccelerations &accelerations, py::dict) {
361 return JointAccelerations(accelerations);
362 }, "memo"_a);
363 c.def("__repr__", [](const JointAccelerations& accelerations) {
364 std::stringstream buffer;
365 buffer << accelerations;
366 return buffer.str();
367 });
368}
369
370void joint_torques(py::module_& m) {
371 py::class_<JointTorques, std::shared_ptr<JointTorques>, JointState> c(m, "JointTorques");
372
373 c.def(py::init(), "Empty constructor");
374 c.def(py::init<const std::string&, unsigned int>(), "Constructor with name and number of joints provided", "robot_name"_a, "nb_joints"_a=0);
375 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);
376 c.def(py::init<const std::string&, const Eigen::VectorXd&>(), "Constructor with name and torque values provided", "robot_name"_a, "velocities"_a);
377 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);
378 c.def(py::init<const JointTorques&>(), "Copy constructor", "torques"_a);
379 c.def(py::init<const JointState&>(), "Copy constructor from a JointState", "state"_a);
380
381 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);
382 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);
383 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);
384 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);
385
386 std::vector<std::string> deleted_attributes = {
387 "positions",
388 "position",
389 "velocities",
390 "velocity",
391 "accelerations",
392 "acceleration",
393 };
394
395 for (const std::string& attr : deleted_attributes) {
396 c.def(std::string("get_" + attr).c_str(), [](const JointTorques&) -> void {}, "Deleted method from parent class.");
397 c.def(std::string("set_" + attr).c_str(), [](const JointTorques& torques) -> JointTorques { return torques; }, "Deleted method from parent class.");
398 }
399
400 c.def(py::self *= double());
401 c.def(py::self * double());
402 c.def(double() * py::self);
403 c.def("__mul__", [](const JointTorques& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *: 'state_representation.JointTorques' and 'np.ndarray'"); });
404 c.def("__imul__", [](const JointTorques& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for *=: 'state_representation.JointTorques' and 'np.ndarray'"); });
405 c.def(Eigen::MatrixXd() * py::self);
406 c.def(py::self /= double());
407 c.def(py::self / double());
408 c.def("__truediv__", [](const JointTorques& self, const Eigen::MatrixXd& other) -> void { throw py::type_error("unsupported operand type(s) for /: 'state_representation.JointTorques' and 'np.ndarray'"); });
409
410 c.def(py::self += py::self);
411 c.def("__iadd__", [](const JointTorques& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointTorques' and 'state_representation.JointPositions'"); });
412 c.def("__iadd__", [](const JointTorques& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointTorques' and 'state_representation.JointVelocities'"); });
413 c.def("__iadd__", [](const JointTorques& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for +=: 'state_representation.JointTorques' and 'state_representation.JointAccelerations'"); });
414 c.def(py::self += JointState());
415 c.def(py::self + py::self);
416 c.def("__add__", [](const JointTorques& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointTorques' and 'state_representation.JointPositions'"); });
417 c.def("__add__", [](const JointTorques& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointTorques' and 'state_representation.JointVelocities'"); });
418 c.def("__add__", [](const JointTorques& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for +: 'state_representation.JointTorques' and 'state_representation.JointAccelerations'"); });
419 c.def(py::self + JointState());
420 c.def("__neg__", [](const JointTorques& self) -> JointTorques { return -self; });
421 c.def(py::self -= py::self);
422 c.def("__isub__", [](const JointTorques& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointTorques' and 'state_representation.JointPositions'"); });
423 c.def("__isub__", [](const JointTorques& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointTorques' and 'state_representation.JointVelocities'"); });
424 c.def("__isub__", [](const JointTorques& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for -=: 'state_representation.JointTorques' and 'state_representation.JointAccelerations'"); });
425 c.def(py::self -= JointState());
426 c.def(py::self - py::self);
427 c.def("__sub__", [](const JointTorques& self, const JointPositions& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointTorques' and 'state_representation.JointPositions'"); });
428 c.def("__sub__", [](const JointTorques& self, const JointVelocities& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointTorques' and 'state_representation.JointVelocities'"); });
429 c.def("__sub__", [](const JointTorques& self, const JointAccelerations& other) -> void { throw py::type_error("unsupported operand type(s) for -: 'state_representation.JointTorques' and 'state_representation.JointAccelerations'"); });
430 c.def(py::self - JointState());
431
432 c.def("copy", &JointTorques::copy, "Return a copy of the JointTorques");
433 c.def("data", &JointTorques::data, "Returns the torques data as a vector");
434 c.def("set_data", py::overload_cast<const Eigen::VectorXd&>(&JointTorques::set_data), "Set the torques data from a vector", "data"_a);
435 c.def("set_data", py::overload_cast<const std::vector<double>&>(&JointTorques::set_data), "Set the torques data from a list", "data"_a);
436
437 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);
438 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);
439 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);
440 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);
441
442 c.def("__copy__", [](const JointTorques &torques) {
443 return JointTorques(torques);
444 });
445 c.def("__deepcopy__", [](const JointTorques &torques, py::dict) {
446 return JointTorques(torques);
447 }, "memo"_a);
448 c.def("__repr__", [](const JointTorques& torques) {
449 std::stringstream buffer;
450 buffer << torques;
451 return buffer.str();
452 });
453}
454
455void bind_joint_space(py::module_& m) {
456 joint_state_variable(m);
457 joint_state(m);
458 joint_positions(m);
459 joint_velocities(m);
460 joint_accelerations(m);
461 joint_torques(m);
462}
Class to define accelerations of the joints.
JointAccelerations copy() const
Return a copy of the joint accelerations.
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 zero joint accelerations.
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 random joint accelerations.
Class to define positions of the joints.
static JointPositions Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for zero joint positions.
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 random joint positions.
JointPositions copy() const
Return a copy of the joint positions.
Class to define a state in joint space.
const Eigen::VectorXd & get_torques() const
Getter of the torques attribute.
void set_accelerations(const Eigen::VectorXd &accelerations)
Setter of the accelerations attribute.
void set_positions(const Eigen::VectorXd &positions)
Setter of the positions attribute.
static JointState Random(const std::string &robot_name, unsigned int nb_joints)
Constructor for a random joint state.
void set_names(unsigned int nb_joints)
Setter of the names attribute from the number of joints.
void set_zero()
Set the joint state to a zero value.
const Eigen::VectorXd & get_velocities() const
Getter of the velocities attribute.
unsigned int get_size() const
Getter of the size from the attributes.
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.
void set_acceleration(double acceleration, const std::string &joint_name)
Set the acceleration of a joint by its name.
std::vector< double > to_std_vector() const
Return the joint state as a std vector.
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero joint state.
Eigen::ArrayXd array() const
Returns the data vector as an Eigen array.
unsigned int get_joint_index(const std::string &joint_name) const
Get joint index by the name of the joint, if it exists.
JointState copy() const
Return a copy of the joint state.
void set_torques(const Eigen::VectorXd &torques)
Setter of the torques attribute.
void set_position(double position, const std::string &joint_name)
Set the position of a joint by its name.
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.
void set_torque(double torque, const std::string &joint_name)
Set the torque of a joint by its name.
friend double dist(const JointState &s1, const JointState &s2, const JointStateVariable &state_variable_type)
Compute the distance between two joint states.
const Eigen::VectorXd & get_accelerations() const
Getter of the accelerations attribute.
const std::vector< std::string > & get_names() const
Getter of the names attribute.
void set_velocity(double velocity, const std::string &joint_name)
Set the velocity of a joint by its name.
const Eigen::VectorXd & get_positions() const
Getter of the positions attribute.
void set_velocities(const Eigen::VectorXd &velocities)
Setter of the velocities attribute.
virtual Eigen::VectorXd data() const
Returns the data as the concatenation of all the state variables in a single vector.
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 joint torques.
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 random joint torques.
static JointTorques Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for zero joint torques.
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 random joint velocities.
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 zero joint velocities.
JointVelocities copy() const
Return a copy of the joint velocities.
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 Cartesian states.