1#include "state_representation_bindings.h"
3#include <state_representation/State.hpp>
4#include <state_representation/space/SpatialState.hpp>
5#include <state_representation/space/cartesian/CartesianState.hpp>
6#include <state_representation/space/cartesian/CartesianPose.hpp>
7#include <state_representation/space/cartesian/CartesianTwist.hpp>
8#include <state_representation/space/cartesian/CartesianAcceleration.hpp>
9#include <state_representation/space/cartesian/CartesianWrench.hpp>
12void spatial_state(py::module_& m) {
13 py::class_<SpatialState, std::shared_ptr<SpatialState>,
State> c(m,
"SpatialState");
15 c.def(py::init(),
"Empty constructor.");
16 c.def(py::init<const StateType&>(),
"Constructor only specifying the type.",
"type"_a);
17 c.def(py::init<const StateType&, const std::string&, const std::string&, const bool&>(),
"Constructor with name and reference frame specification.",
"type"_a,
"name"_a,
"reference_frame"_a=std::string(
"world"),
"empty"_a=
true);
18 c.def(py::init<const SpatialState&>(),
"Copy constructor from another SpatialState.",
"state"_a);
22 c.def(
"is_compatible", &
SpatialState::is_compatible,
"Check if the state is compatible for operations with the state given as argument.",
"state"_a);
27 c.def(
"__deepcopy__", [](
const SpatialState &state, py::dict) {
31 std::stringstream buffer;
37void cartesian_state_variable(py::module_& m) {
38 py::enum_<CartesianStateVariable>(m,
"CartesianStateVariable")
39 .value(
"POSITION", CartesianStateVariable::POSITION)
40 .value(
"ORIENTATION", CartesianStateVariable::ORIENTATION)
41 .value(
"POSE", CartesianStateVariable::POSE)
42 .value(
"LINEAR_VELOCITY", CartesianStateVariable::LINEAR_VELOCITY)
43 .value(
"ANGULAR_VELOCITY", CartesianStateVariable::ANGULAR_VELOCITY)
44 .value(
"TWIST", CartesianStateVariable::TWIST)
45 .value(
"LINEAR_ACCELERATION", CartesianStateVariable::LINEAR_ACCELERATION)
46 .value(
"ANGULAR_ACCELERATION", CartesianStateVariable::ANGULAR_ACCELERATION)
47 .value(
"ACCELERATION", CartesianStateVariable::ACCELERATION)
48 .value(
"FORCE", CartesianStateVariable::FORCE)
49 .value(
"TORQUE", CartesianStateVariable::TORQUE)
50 .value(
"WRENCH", CartesianStateVariable::WRENCH)
51 .value(
"ALL", CartesianStateVariable::ALL)
55void cartesian_state(py::module_& m) {
56 m.def(
"dist", py::overload_cast<const CartesianState&, const CartesianState&, const CartesianStateVariable&>(&
state_representation::dist),
"Compute the distance between two CartesianStates",
"s1"_a,
"s2"_a,
"state_variable_type"_a=CartesianStateVariable::ALL);
58 py::class_<CartesianState, std::shared_ptr<CartesianState>,
SpatialState> c(m,
"CartesianState");
59 c.def(py::init(),
"Empty constructor");
60 c.def(py::init<const std::string&, const std::string&>(),
"Constructor with name and reference frame provided",
"name"_a,
"reference_frame"_a=std::string(
"world"));
61 c.def(py::init<const CartesianState&>(),
"Copy constructor of a CartesianState",
"state"_a);
63 c.def_static(
"Identity", &
CartesianState::Identity,
"Constructor for the identity CartesianState (identity pose and 0 for the rest)",
"name"_a,
"reference_frame"_a=std::string(
"world"));
64 c.def_static(
"Random", &
CartesianState::Random,
"Constructor for a random state",
"name"_a,
"reference_frame"_a=std::string(
"world"));
67 c.def(
"get_orientation", [](
const CartesianState &state) -> py::object {
68 py::object PyQuaternion = py::module_::import(
"pyquaternion").attr(
"Quaternion");
69 return PyQuaternion(state.get_orientation_coefficients());;
70 },
"Getter of the orientation attribute as pyquaternion object");
72 c.def(
"get_pose", &
CartesianState::get_pose,
"Getter of a 7d pose vector from position and orientation coefficients");
88 c.def(
"set_position", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_position),
"Setter of the position from a list");
89 c.def(
"set_position", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_position),
"Setter of the position from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
90 c.def(
"set_orientation", [](
CartesianState &state,
const py::object& quaternion) {
91 py::object PyQuaternion = py::module_::import(
"pyquaternion").attr(
"Quaternion");
92 if (py::isinstance<py::list>(quaternion)) {
93 state.set_orientation(py::cast<std::vector<double>>(quaternion));
94 }
else if (py::isinstance<py::array>(quaternion)) {
95 state.set_orientation(py::cast<Eigen::Vector4d>(quaternion));
96 }
else if (py::isinstance(quaternion, PyQuaternion)) {
97 state.set_orientation(py::cast<Eigen::Vector4d>(quaternion.attr(
"elements")));
99 throw std::invalid_argument(
"Type of input argument quaternion is not supported. "
100 "Supported types are: pyquaternion.Quaternion, numpy.array, list");
102 },
"Setter of the orientation attribute from a pyquaternion.Quaternion, numpy.array(w, x, y, z), or list(w, x, y, z)");
103 c.def(
"set_pose", py::overload_cast<
const Eigen::Matrix<double, 7, 1>&>(&
CartesianState::set_pose),
"Setter of the pose from a 7d vector of position and orientation coefficients (x, y, z, qw, qx, qy, qz)");
104 c.def(
"set_pose", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_pose),
"Setter of the pose from a 7d list of position and orientation coefficients (x, y, z, qw, qx, qy, qz)");
108 c.def(
"set_linear_velocity", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_linear_velocity),
"Setter of the linear velocity from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
111 c.def(
"set_angular_velocity", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_angular_velocity),
"Setter of the angular velocity from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
112 c.def(
"set_twist", py::overload_cast<
const Eigen::Matrix<double, 6, 1>&>(&
CartesianState::set_twist),
"Setter of the linear and angular velocities from a 6d twist vector");
113 c.def(
"set_twist", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_twist),
"Setter of the linear and angular velocities from a list");
117 c.def(
"set_linear_acceleration", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_linear_acceleration),
"Setter of the linear acceleration from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
120 c.def(
"set_angular_acceleration", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_angular_acceleration),
"Setter of the angular acceleration from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
121 c.def(
"set_acceleration", py::overload_cast<
const Eigen::Matrix<double, 6, 1>&>(&
CartesianState::set_acceleration),
"Setter of the linear and angular accelerations from a 6d acceleration vector");
122 c.def(
"set_acceleration", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_acceleration),
"Setter of the linear and angular accelerations from a list");
124 c.def(
"set_force", py::overload_cast<const Eigen::Vector3d&>(&
CartesianState::set_force),
"Setter of the force attribute");
125 c.def(
"set_force", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_force),
"Setter of the force from a list");
126 c.def(
"set_force", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_force),
"Setter of the force from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
127 c.def(
"set_torque", py::overload_cast<const Eigen::Vector3d&>(&
CartesianState::set_torque),
"Setter of the torque attribute");
128 c.def(
"set_torque", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_torque),
"Setter of the torque from a list");
129 c.def(
"set_torque", py::overload_cast<const double&, const double&, const double&>(&
CartesianState::set_torque),
"Setter of the torque from three scalar coordinates",
"x"_a,
"y"_a,
"z"_a);
130 c.def(
"set_wrench", py::overload_cast<
const Eigen::Matrix<double, 6, 1>&>(&
CartesianState::set_wrench),
"Setter of the force and torque from a 6d wrench vector");
131 c.def(
"set_wrench", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_wrench),
"Setter of the force and torque velocities from a list");
134 c.def(
"clamp_state_variable", &
CartesianState::clamp_state_variable,
"Clamp inplace the magnitude of the a specific state variable (velocity, acceleration or force)",
"max_value"_a,
"state_variable_type"_a,
"noise_ratio"_a=
double(0));
136 c.def(
"data", &
CartesianState::data,
"Returns the data as the concatenation of all the state variables in a single vector");
138 c.def(
"set_data", py::overload_cast<const Eigen::VectorXd&>(&
CartesianState::set_data),
"Set the data of the state from all the state variables in a single vector",
"data"_a);
139 c.def(
"set_data", py::overload_cast<
const std::vector<double>&>(&
CartesianState::set_data),
"Set the data of the state from all the state variables in a single list",
"data"_a);
141 c.def(py::self *= py::self);
142 c.def(py::self * py::self);
143 c.def(py::self *=
double());
144 c.def(py::self *
double());
145 c.def(
double() * py::self);
146 c.def(py::self /=
double());
147 c.def(py::self /
double());
148 c.def(py::self += py::self);
149 c.def(py::self + py::self);
150 c.def(py::self -= py::self);
151 c.def(py::self - py::self);
154 c.def(
"dist", &
CartesianState::dist,
"Compute the distance to another state as the sum of distances between each features",
"state"_a,
"state_variable_type"_a=CartesianStateVariable::ALL);
155 c.def(
"norms", &
CartesianState::norms,
"Compute the norms of the state variable specified by the input type (default is full state)",
"state_variable_type"_a=CartesianStateVariable::ALL);
156 c.def(
"normalize", &
CartesianState::normalize,
"Normalize inplace the state at the state variable given in argument (default is full state)",
"state_variable_type"_a=CartesianStateVariable::ALL);
157 c.def(
"normalized", &
CartesianState::normalized,
"Compute the normalized state at the state variable given in argument (default is full state)",
"state_variable_type"_a=CartesianStateVariable::ALL);
168 std::stringstream buffer;
174void cartesian_pose(py::module_& m) {
175 py::class_<CartesianPose, std::shared_ptr<CartesianPose>,
CartesianState> c(m,
"CartesianPose");
177 c.def(py::init(),
"Empty constructor");
178 c.def(py::init<const std::string&, const std::string&>(),
"Constructor with name and reference frame provided",
"name"_a,
"reference_frame"_a=std::string(
"world"));
179 c.def(py::init<const CartesianPose&>(),
"Copy constructor of a CartesianPose",
"pose"_a);
180 c.def(py::init<const CartesianState&>(),
"Copy constructor from a CartesianState",
"state"_a);
181 c.def(py::init<const CartesianTwist&>(),
"Copy constructor from a CartesianTwist by considering that it is a displacement over 1 second",
"twist"_a);
183 c.def(py::init<const std::string&, const Eigen::Vector3d&, const std::string&>(),
"Constructor of a CartesianPose from a position given as a vector of coordinates",
"name"_a,
"position"_a,
"reference_frame"_a=std::string(
"world"));
184 c.def(py::init<const std::string&, double, double, double, const std::string&>(),
"Constructor of a CartesianPose from a position given as three scalar coordinates",
"name"_a,
"x"_a,
"y"_a,
"z"_a,
"reference_frame"_a=std::string(
"world"));
185 c.def(py::init([](
const std::string& name,
const Eigen::Vector4d& orientation,
const std::string& reference) {
186 Eigen::Quaterniond q(orientation(0), orientation(1), orientation(2), orientation(3));
188 }),
"Constructor of a CartesianPose from a quaternion",
"name"_a,
"orientation"_a,
"reference_frame"_a=std::string(
"world"));
189 c.def(py::init([](
const std::string& name,
const Eigen::Vector3d& position,
const Eigen::Vector4d& orientation,
const std::string& reference) {
190 Eigen::Quaterniond q(orientation(0), orientation(1), orientation(2), orientation(3));
192 }),
"Constructor of a CartesianPose from a position given as a vector of coordinates and a quaternion",
"name"_a,
"position"_a,
"orientation"_a,
"reference_frame"_a=std::string(
"world"));
194 c.def_static(
"Identity", &
CartesianPose::Identity,
"Constructor for the identity pose",
"name"_a,
"reference_frame"_a=std::string(
"world"));
195 c.def_static(
"Random", &
CartesianPose::Random,
"Constructor for a random pose",
"name"_a,
"reference_frame"_a=std::string(
"world"));
197 std::vector<std::string> deleted_attributes = {
201 "linear_acceleration",
202 "angular_acceleration",
209 for (
const std::string& attr : deleted_attributes) {
210 c.def(std::string(
"get_" + attr).c_str(), [](
const CartesianPose&) ->
void {},
"Deleted method from parent class.");
211 c.def(std::string(
"set_" + attr).c_str(), [](
const CartesianPose& pose) ->
CartesianPose {
return pose; },
"Deleted method from parent class.");
214 c.def(py::self *= py::self);
215 c.def(py::self * py::self);
219 c.def(py::self * Eigen::Vector3d());
220 c.def(py::self *=
double());
221 c.def(py::self *
double());
222 c.def(
double() * py::self);
223 c.def(py::self /=
double());
224 c.def(py::self /
double());
226 c.def(py::self += py::self);
227 c.def(py::self + py::self);
228 c.def(py::self -= py::self);
229 c.def(py::self - py::self);
231 c.def(py::self / std::chrono::nanoseconds());
235 c.def(
"set_data", py::overload_cast<const Eigen::VectorXd&>(&
CartesianPose::set_data),
"Set the pose data from a vector",
"data"_a);
236 c.def(
"set_data", py::overload_cast<
const std::vector<double>&>(&
CartesianPose::set_data),
"Set the pose data from a list",
"data"_a);
237 c.def(
"norms", &
CartesianPose::norms,
"Compute the norms of the state variable specified by the input type (default is full pose)",
"state_variable_type"_a=CartesianStateVariable::POSE);
238 c.def(
"normalized", &
CartesianPose::normalized,
"Compute the normalized pose at the state variable given in argument (default is full pose)",
"state_variable_type"_a=CartesianStateVariable::POSE);
243 c.def(
"__deepcopy__", [](
const CartesianPose &pose, py::dict) {
247 std::stringstream buffer;
253void cartesian_twist(py::module_& m) {
254 py::class_<CartesianTwist, std::shared_ptr<CartesianTwist>,
CartesianState> c(m,
"CartesianTwist");
256 c.def(py::init(),
"Empty constructor");
257 c.def(py::init<const std::string&, const std::string&>(),
"Constructor with name and reference frame provided",
"name"_a,
"reference_frame"_a=std::string(
"world"));
258 c.def(py::init<const CartesianTwist&>(),
"Copy constructor",
"twist"_a);
259 c.def(py::init<const CartesianState&>(),
"Copy constructor from a CartesianState",
"state"_a);
260 c.def(py::init<const CartesianPose&>(),
"Copy constructor from a CartesianPose by considering that it is equivalent to dividing the pose by 1 second",
"pose"_a);
262 c.def(py::init<const std::string&, const Eigen::Vector3d&, const std::string&>(),
"Construct a CartesianTwist from a linear velocity given as a vector.",
"name"_a,
"linear_velocity"_a,
"reference_frame"_a=std::string(
"world"));
263 c.def(py::init<const std::string&, const Eigen::Vector3d&, const Eigen::Vector3d&, const std::string&>(),
"Construct a CartesianTwist from a linear velocity and angular velocity given as vectors.",
"name"_a,
"linear_velocity"_a,
"angular_velocity"_a,
"reference_frame"_a=std::string(
"world"));
264 c.def(py::init<
const std::string&,
const Eigen::Matrix<double, 6, 1>&,
const std::string&>(),
"Construct a CartesianTwist from a single 6d twist vector",
"name"_a,
"twist"_a,
"reference_frame"_a=std::string(
"world"));
266 c.def_static(
"Zero", &
CartesianTwist::Zero,
"Constructor for the zero twist",
"name"_a,
"reference_frame"_a=std::string(
"world"));
267 c.def_static(
"Random", &
CartesianTwist::Random,
"Constructor for a random twist",
"name"_a,
"reference_frame"_a=std::string(
"world"));
269 std::vector<std::string> deleted_attributes = {
273 "linear_acceleration",
274 "angular_acceleration",
281 for (
const std::string& attr : deleted_attributes) {
282 c.def(std::string(
"get_" + attr).c_str(), [](
const CartesianTwist&) ->
void {},
"Deleted method from parent class.");
283 c.def(std::string(
"set_" + attr).c_str(), [](
const CartesianTwist& twist) ->
CartesianTwist {
return twist; },
"Deleted method from parent class.");
285 c.def(std::string(
"get_orientation_coefficients").c_str(), [](
const CartesianTwist&) ->
void {},
"Deleted method from parent class.");
287 c.def(py::self += py::self);
288 c.def(py::self + py::self);
289 c.def(py::self -= py::self);
290 c.def(py::self - py::self);
292 c.def(py::self *=
double());
293 c.def(py::self *
double());
294 c.def(py::self /=
double());
295 c.def(py::self /
double());
296 c.def(py::self *= Eigen::Matrix<double, 6, 6>());
297 c.def(py::self * std::chrono::nanoseconds());
298 c.def(py::self / std::chrono::nanoseconds());
300 c.def(
double() * py::self);
301 c.def(std::chrono::nanoseconds() * py::self);
302 c.def(Eigen::Matrix<double, 6, 6>() * py::self);
304 c.def(
"clamp", &
CartesianTwist::clamp,
"Clamp inplace the magnitude of the twist to the values in argument",
"max_linear"_a,
"max_angular"_a,
"linear_noise_ratio"_a=0,
"angular_noise_ratio"_a=0);
305 c.def(
"clamped", &
CartesianTwist::clamped,
"Return the clamped twist",
"max_linear"_a,
"max_angular"_a,
"linear_noise_ratio"_a=0,
"angular_noise_ratio"_a=0);
309 c.def(
"set_data", py::overload_cast<const Eigen::VectorXd&>(&
CartesianTwist::set_data),
"Set the twist data from a vector",
"data"_a);
310 c.def(
"set_data", py::overload_cast<
const std::vector<double>&>(&
CartesianTwist::set_data),
"Set the twist data from a list",
"data"_a);
311 c.def(
"norms", &
CartesianTwist::norms,
"Compute the norms of the state variable specified by the input type (default is full twist)",
"state_variable_type"_a=CartesianStateVariable::TWIST);
312 c.def(
"normalized", &
CartesianTwist::normalized,
"Compute the normalized twist at the state variable given in argument (default is full twist)",
"state_variable_type"_a=CartesianStateVariable::TWIST);
321 std::stringstream buffer;
327void cartesian_acceleration(py::module_& m) {
328 py::class_<CartesianAcceleration, std::shared_ptr<CartesianAcceleration>,
CartesianState> c(m,
"CartesianAcceleration");
330 c.def(py::init(),
"Empty constructor");
331 c.def(py::init<const std::string&, const std::string&>(),
"Constructor with name and reference frame provided",
"name"_a,
"reference_frame"_a=std::string(
"world"));
332 c.def(py::init<const CartesianAcceleration&>(),
"Copy constructor",
"acceleration"_a);
333 c.def(py::init<const CartesianState&>(),
"Copy constructor from a CartesianState",
"state"_a);
334 c.def(py::init<const CartesianTwist&>(),
"Copy constructor from a CartesianTwist by considering that it is equivalent to dividing the twist by 1 second",
"twist"_a);
336 c.def(py::init<const std::string&, const Eigen::Vector3d&, const std::string&>(),
"Construct a CartesianAcceleration from a linear acceleration given as a vector.",
"name"_a,
"linear_acceleration"_a,
"reference_frame"_a=std::string(
"world"));
337 c.def(py::init<const std::string&, const Eigen::Vector3d&, const Eigen::Vector3d&, const std::string&>(),
"Construct a CartesianAcceleration from a linear acceleration and angular acceleration given as vectors.",
"name"_a,
"linear_acceleration"_a,
"angular_acceleration"_a,
"reference_frame"_a=std::string(
"world"));
338 c.def(py::init<
const std::string&,
const Eigen::Matrix<double, 6, 1>&,
const std::string&>(),
"Construct a CartesianAcceleration from a single 6d acceleration vector",
"name"_a,
"acceleration"_a,
"reference_frame"_a=std::string(
"world"));
340 c.def_static(
"Zero", &
CartesianAcceleration::Zero,
"Constructor for the zero acceleration",
"name"_a,
"reference_frame"_a=std::string(
"world"));
341 c.def_static(
"Random", &
CartesianAcceleration::Random,
"Constructor for a random acceleration",
"name"_a,
"reference_frame"_a=std::string(
"world"));
343 std::vector<std::string> deleted_attributes = {
355 for (
const std::string& attr : deleted_attributes) {
356 c.def(std::string(
"get_" + attr).c_str(), [](
const CartesianAcceleration&) ->
void {},
"Deleted method from parent class.");
359 c.def(std::string(
"get_orientation_coefficients").c_str(), [](
const CartesianAcceleration&) ->
void {},
"Deleted method from parent class.");
361 c.def(py::self += py::self);
362 c.def(py::self + py::self);
363 c.def(py::self -= py::self);
364 c.def(py::self - py::self);
366 c.def(py::self *=
double());
367 c.def(py::self *
double());
368 c.def(py::self /=
double());
369 c.def(py::self /
double());
370 c.def(py::self *= Eigen::Matrix<double, 6, 6>());
371 c.def(py::self * std::chrono::nanoseconds());
373 c.def(
double() * py::self);
374 c.def(std::chrono::nanoseconds() * py::self);
375 c.def(Eigen::Matrix<double, 6, 6>() * py::self);
377 c.def(
"clamp", &
CartesianAcceleration::clamp,
"Clamp inplace the magnitude of the acceleration to the values in argument",
"max_linear"_a,
"max_angular"_a,
"linear_noise_ratio"_a=0,
"angular_noise_ratio"_a=0);
378 c.def(
"clamped", &
CartesianAcceleration::clamped,
"Return the clamped acceleration",
"max_linear"_a,
"max_angular"_a,
"linear_noise_ratio"_a=0,
"angular_noise_ratio"_a=0);
384 c.def(
"norms", &
CartesianAcceleration::norms,
"Compute the norms of the state variable specified by the input type (default is full acceleration)",
"state_variable_type"_a=CartesianStateVariable::ACCELERATION);
385 c.def(
"normalized", &
CartesianAcceleration::normalized,
"Compute the normalized acceleration at the state variable given in argument (default is full acceleration)",
"state_variable_type"_a=CartesianStateVariable::ACCELERATION);
394 std::stringstream buffer;
395 buffer << acceleration;
400void cartesian_wrench(py::module_& m) {
401 py::class_<CartesianWrench, std::shared_ptr<CartesianWrench>,
CartesianState> c(m,
"CartesianWrench");
403 c.def(py::init(),
"Empty constructor");
404 c.def(py::init<const std::string&, const std::string&>(),
"Constructor with name and reference frame provided",
"name"_a,
"reference_frame"_a=std::string(
"world"));
405 c.def(py::init<const CartesianWrench&>(),
"Copy constructor",
"twist"_a);
406 c.def(py::init<const CartesianState&>(),
"Copy constructor from a CartesianState",
"state"_a);
408 c.def(py::init<const std::string&, const Eigen::Vector3d&, const std::string&>(),
"Construct a CartesianWrench from a force given as a vector.",
"name"_a,
"force"_a,
"reference_frame"_a=std::string(
"world"));
409 c.def(py::init<const std::string&, const Eigen::Vector3d&, const Eigen::Vector3d&, const std::string&>(),
"Construct a CartesianWrench from a force and torque given as vectors.",
"name"_a,
"force"_a,
"torque"_a,
"reference_frame"_a=std::string(
"world"));
410 c.def(py::init<
const std::string&,
const Eigen::Matrix<double, 6, 1>&,
const std::string&>(),
"Construct a CartesianTwist from a single 6d wrench vector",
"name"_a,
"wrench"_a,
"reference_frame"_a=std::string(
"world"));
412 c.def_static(
"Zero", &
CartesianWrench::Zero,
"Constructor for the zero wrench",
"name"_a,
"reference_frame"_a=std::string(
"world"));
413 c.def_static(
"Random", &
CartesianWrench::Random,
"Constructor for a random wrench",
"name"_a,
"reference_frame"_a=std::string(
"world"));
415 std::vector<std::string> deleted_attributes = {
422 "linear_acceleration",
423 "angular_acceleration",
427 for (
const std::string& attr : deleted_attributes) {
428 c.def(std::string(
"get_" + attr).c_str(), [](
const CartesianWrench&) ->
void {},
"Deleted method from parent class.");
429 c.def(std::string(
"set_" + attr).c_str(), [](
const CartesianWrench& wrench) ->
CartesianWrench {
return wrench; },
"Deleted method from parent class.");
431 c.def(std::string(
"get_orientation_coefficients").c_str(), [](
const CartesianWrench&) ->
void {},
"Deleted method from parent class.");
433 c.def(py::self += py::self);
434 c.def(py::self + py::self);
435 c.def(py::self -= py::self);
436 c.def(py::self - py::self);
438 c.def(py::self *=
double());
439 c.def(py::self *
double());
440 c.def(
double() * py::self);
441 c.def(py::self /=
double());
442 c.def(py::self /
double());
444 c.def(
"clamp", &
CartesianWrench::clamp,
"Clamp inplace the magnitude of the wrench to the values in argument",
"max_force"_a,
"max_torque"_a,
"force_noise_ratio"_a=0,
"torque_noise_ratio"_a=0);
445 c.def(
"clamped", &
CartesianWrench::clamped,
"Return the clamped wrench",
"max_force"_a,
"max_torque"_a,
"force_noise_ratio"_a=0,
"torque_noise_ratio"_a=0);
449 c.def(
"set_data", py::overload_cast<const Eigen::VectorXd&>(&
CartesianWrench::set_data),
"Set the wrench data from a vector",
"data"_a);
450 c.def(
"set_data", py::overload_cast<
const std::vector<double>&>(&
CartesianWrench::set_data),
"Set the wrench data from a list",
"data"_a);
451 c.def(
"norms", &
CartesianWrench::norms,
"Compute the norms of the state variable specified by the input type (default is full wrench)",
"state_variable_type"_a=CartesianStateVariable::WRENCH);
452 c.def(
"normalized", &
CartesianWrench::normalized,
"Compute the normalized twist at the state variable given in argument (default is full wrench)",
"state_variable_type"_a=CartesianStateVariable::WRENCH);
461 std::stringstream buffer;
467void bind_cartesian_space(py::module_& m) {
469 cartesian_state_variable(m);
473 cartesian_acceleration(m);
Class to define acceleration in cartesian space as 3D linear and angular acceleration vectors.
void clamp(double max_linear, double max_angular, double linear_noise_ratio=0, double angular_noise_ratio=0)
Clamp inplace the magnitude of the acceleration to the values in argument.
CartesianAcceleration copy() const
Return a copy of the CartesianAcceleration.
CartesianAcceleration clamped(double max_linear, double max_angular, double noise_ratio=0, double angular_noise_ratio=0) const
Return the clamped twist.
Eigen::VectorXd data() const override
Returns the acceleration data as an Eigen vector.
static CartesianAcceleration Zero(const std::string &name, const std::string &reference="world")
Constructor for the zero acceleration.
static CartesianAcceleration Random(const std::string &name, const std::string &reference="world")
Constructor for a random acceleration.
std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ACCELERATION) const override
Compute the norms of the state variable specified by the input type (default is full twist)
void set_data(const Eigen::VectorXd &data) override
Set the acceleration data from an Eigen vector.
CartesianAcceleration normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ACCELERATION) const
Compute the normalized acceleration at the state variable given in argument (default is full accelera...
Class to define CartesianPose in cartesian space as 3D position and quaternion based orientation.
void set_data(const Eigen::VectorXd &data) override
Set the pose data from an Eigen vector.
std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::POSE) const override
Compute the norms of the state variable specified by the input type (default is full pose)
static CartesianPose Identity(const std::string &name, const std::string &reference="world")
Constructor for the identity pose.
Eigen::VectorXd data() const override
Returns the pose data as an Eigen vector.
CartesianPose normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::POSE) const
Compute the normalized pose at the state variable given in argument (default is full pose)
CartesianPose copy() const
Return a copy of the CartesianPose.
static CartesianPose Random(const std::string &name, const std::string &reference="world")
Constructor for a random pose.
Class to represent a state in Cartesian space.
void set_zero()
Set the State to a zero value.
const Eigen::Vector3d & get_force() const
Getter of the force attribute.
void set_acceleration(const Eigen::Matrix< double, 6, 1 > &acceleration)
Setter of the linear and angular acceleration from a 6d acceleration vector.
CartesianState inverse() const
Compute the inverse of the current CartesianState.
Eigen::ArrayXd array() const
Return the data vector as an Eigen Array.
const Eigen::Vector3d & get_torque() const
Getter of the torque attribute.
static CartesianState Random(const std::string &name, const std::string &reference="world")
Constructor for a random state.
const Eigen::Vector3d & get_linear_velocity() const
Getter of the linear velocity attribute.
void set_angular_acceleration(const Eigen::Vector3d &angular_acceleration)
Setter of the angular velocity attribute.
const Eigen::Vector3d & get_position() const
Getter of the position attribute.
void normalize(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL)
Normalize inplace the state at the state variable given in argument (default is full state)
virtual std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL) const
Compute the norms of the state variable specified by the input type (default is full state)
void set_force(const Eigen::Vector3d &force)
Setter of the force attribute.
Eigen::Matrix< double, 6, 1 > get_twist() const
Getter of the 6d twist from linear and angular velocity attributes.
CartesianState normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::ALL) const
Compute the normalized state at the state variable given in argument (default is full state)
friend double dist(const CartesianState &s1, const CartesianState &s2, const CartesianStateVariable &state_variable_type)
compute the distance between two CartesianStates
static CartesianState Identity(const std::string &name, const std::string &reference="world")
Constructor for the identity CartesianState (identity pose and 0 for the rest)
const Eigen::Vector3d & get_linear_acceleration() const
Getter of the linear acceleration attribute.
Eigen::Matrix4d get_transformation_matrix() const
Getter of a pose from position and orientation attributes.
void set_linear_acceleration(const Eigen::Vector3d &linear_acceleration)
Setter of the linear acceleration attribute.
void clamp_state_variable(double max_norm, const CartesianStateVariable &state_variable_type, double noise_ratio=0)
Clamp inplace the norm of the a specific state variable.
Eigen::Matrix< double, 7, 1 > get_pose() const
Getter of a pose from position and orientation attributes.
void set_position(const Eigen::Vector3d &position)
Setter of the position.
void set_wrench(const Eigen::Matrix< double, 6, 1 > &wrench)
Setter of the force and torque from a 6d wrench vector.
Eigen::Matrix< double, 6, 1 > get_wrench() const
Getter of the 6d wrench from force and torque attributes.
void set_twist(const Eigen::Matrix< double, 6, 1 > &twist)
Setter of the linear and angular velocities from a 6d twist vector.
virtual Eigen::VectorXd data() const
Return the data as the concatenation of all the state variables in a single vector.
const Eigen::Vector3d & get_angular_velocity() const
Getter of the angular velocity attribute.
void set_pose(const Eigen::Vector3d &position, const Eigen::Quaterniond &orientation)
Setter of the pose from both position and orientation.
CartesianState copy() const
Return a copy of the CartesianState.
void set_torque(const Eigen::Vector3d &torque)
Setter of the torque attribute.
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.
Eigen::Vector4d get_orientation_coefficients() const
Getter of the orientation attribute as Vector4d of coefficients Beware, quaternion coefficients are r...
const Eigen::Vector3d & get_angular_acceleration() const
Getter of the angular acceleration attribute.
std::vector< double > to_std_vector() const
Return the state as a std vector.
void set_linear_velocity(const Eigen::Vector3d &linear_velocity)
Setter of the linear velocity attribute.
void set_angular_velocity(const Eigen::Vector3d &angular_velocity)
Setter of the angular velocity attribute.
Eigen::Matrix< double, 6, 1 > get_acceleration() const
Getter of the 6d acceleration from linear and angular acceleration attributes.
Class to define twist in cartesian space as 3D linear and angular velocity vectors.
std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::TWIST) const override
Compute the norms of the state variable specified by the input type (default is full twist)
Eigen::VectorXd data() const override
Returns the twist data as an Eigen vector.
CartesianTwist clamped(double max_linear, double max_angular, double noise_ratio=0, double angular_noise_ratio=0) const
Return the clamped twist.
static CartesianTwist Random(const std::string &name, const std::string &reference="world")
Constructor for a random twist.
static CartesianTwist Zero(const std::string &name, const std::string &reference="world")
Constructor for the zero twist.
void set_data(const Eigen::VectorXd &data) override
Set the twist data from an Eigen vector.
void clamp(double max_linear, double max_angular, double linear_noise_ratio=0, double angular_noise_ratio=0)
Clamp inplace the magnitude of the twist to the values in argument.
CartesianTwist copy() const
Return a copy of the CartesianTwist.
CartesianTwist normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::TWIST) const
Compute the normalized twist at the state variable given in argument (default is full twist)
Class to define wrench in cartesian space as 3D force and torque vectors.
Eigen::VectorXd data() const override
Returns the wrench data as an Eigen vector.
CartesianWrench normalized(const CartesianStateVariable &state_variable_type=CartesianStateVariable::WRENCH) const
Compute the normalized wrench at the state variable given in argument (default is full wrench)
static CartesianWrench Zero(const std::string &name, const std::string &reference="world")
Constructor for the zero wrench.
void set_data(const Eigen::VectorXd &data) override
Set the wrench data from an Eigen vector.
CartesianWrench clamped(double max_force, double max_torque, double force_noise_ratio=0, double torque_noise_ratio=0) const
Return the clamped wrench.
std::vector< double > norms(const CartesianStateVariable &state_variable_type=CartesianStateVariable::WRENCH) const override
Compute the norms of the state variable specified by the input type (default is full wrench)
CartesianWrench copy() const
Return a copy of the CartesianWrench.
void clamp(double max_force, double max_torque, double force_noise_ratio=0, double torque_noise_ratio=0)
Clamp inplace the magnitude of the wrench to the values in argument.
static CartesianWrench Random(const std::string &name, const std::string &reference="world")
Constructor for a random wrench.
virtual void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
virtual bool is_compatible(const State &state) const override
Check if the state is compatible for operations with the state given as argument.
const std::string & get_reference_frame() const
Getter of the reference frame as const reference.
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