1#include "state_representation_bindings.h"
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>
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)
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);
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);
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);
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);
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);
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);
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);
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);
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);
72 c.def(
"data", &
JointState::data,
"Returns the data as the concatenation of all the state variables in a single vector.");
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);
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);
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);
97 c.def(
"__copy__", [](
const JointState &state) {
100 c.def(
"__deepcopy__", [](
const JointState &state, py::dict) {
103 c.def(
"__repr__", [](
const JointState& state) {
104 std::stringstream buffer;
110void joint_positions(py::module_& m) {
111 py::class_<JointPositions, std::shared_ptr<JointPositions>,
JointState> c(m,
"JointPositions");
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);
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);
127 std::vector<std::string> deleted_attributes = {
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.");
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);
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);
166 c.def(
"__deepcopy__", [](
const JointPositions &positions, py::dict) {
170 std::stringstream buffer;
176void joint_velocities(py::module_& m) {
177 py::class_<JointVelocities, std::shared_ptr<JointVelocities>,
JointState> c(m,
"JointVelocities");
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);
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);
194 std::vector<std::string> deleted_attributes = {
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.");
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());
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);
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);
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);
241 c.def(
"__deepcopy__", [](
const JointVelocities &velocities, py::dict) {
245 std::stringstream buffer;
246 buffer << velocities;
251void joint_accelerations(py::module_& m) {
252 py::class_<JointAccelerations, std::shared_ptr<JointAccelerations>,
JointState> c(m,
"JointAccelerations");
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);
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);
268 std::vector<std::string> deleted_attributes = {
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.");
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());
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);
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);
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);
318 std::stringstream buffer;
319 buffer << accelerations;
324void joint_torques(py::module_& m) {
325 py::class_<JointTorques, std::shared_ptr<JointTorques>,
JointState> c(m,
"JointTorques");
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);
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);
340 std::vector<std::string> deleted_attributes = {
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.");
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);
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);
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);
383 c.def(
"__deepcopy__", [](
const JointTorques &torques, py::dict) {
387 std::stringstream buffer;
393void bind_joint_space(py::module_& m) {
394 joint_state_variable(m);
398 joint_accelerations(m);
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.
const Eigen::VectorXd & get_torques() const
Getter of the torques attribute.
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.
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 JointState.
void set_names(unsigned int nb_joints)
Setter of the names attribute from the number of joints.
void set_zero()
Set the JointState 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 of floats.
static JointState Zero(const std::string &robot_name, unsigned int nb_joints)
Constructor for a zero JointState.
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 JointState.
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.
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 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.
double dist(const CartesianState &s1, const CartesianState &s2, const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL)
compute the distance between two CartesianStates