Skip to content

Commit

Permalink
feat: add python bindings for existing and new utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
bpapaspyros committed Oct 17, 2024
1 parent ba568bf commit 5b91f1d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions python/source/state_representation/bind_cartesian_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void cartesian_state_variable(py::module_& m) {
.value("WRENCH", CartesianStateVariable::WRENCH)
.value("ALL", CartesianStateVariable::ALL)
.export_values();

m.def("string_to_cartesian_state_variable", &state_representation::string_to_cartesian_state_variable, "Convert a string to a CartesianStateVariable enum (case insensitive)", "variable"_a);
m.def("cartesian_state_variable_to_string", &state_representation::cartesian_state_variable_to_string, "Convert CartesianStateVariable to a string", "variable"_a);
}

void cartesian_state(py::module_& m) {
Expand Down Expand Up @@ -173,6 +176,10 @@ void cartesian_state(py::module_& m) {
buffer << state;
return buffer.str();
});

c.def("get_state_variable", &CartesianState::get_state_variable, "Getter of the variable value corresponding to the input", "state_variable_type"_a);
c.def("set_state_variable", py::overload_cast<const Eigen::VectorXd&, const CartesianStateVariable&>(&CartesianState::set_state_variable), "Setter of the variable value corresponding to the input", "new_value"_a, "state_variable_type"_a);
// c.def("set_state_variable", py::overload_cast<const std::vector<double>&, const CartesianStateVariable&>(&CartesianState::set_state_variable), "Setter of the variable value corresponding to the input", "new_value"_a, "state_variable_type"_a);
}

void cartesian_pose(py::module_& m) {
Expand Down
2 changes: 2 additions & 0 deletions python/source/state_representation/bind_exceptions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "state_representation_bindings.hpp"

#include <state_representation/exceptions/EmptyStateException.hpp>
#include <state_representation/exceptions/InvalidStateVariableException.hpp>
#include <state_representation/exceptions/IncompatibleReferenceFramesException.hpp>
#include <state_representation/exceptions/IncompatibleSizeException.hpp>
#include <state_representation/exceptions/IncompatibleStatesException.hpp>
Expand All @@ -11,6 +12,7 @@

void bind_exceptions(py::module_& m) {
py::register_exception<exceptions::EmptyStateException>(m, "EmptyStateError", PyExc_RuntimeError);
py::register_exception<exceptions::EmptyStateException>(m, "InvalidStateVariableException", PyExc_RuntimeError);
py::register_exception<exceptions::IncompatibleReferenceFramesException>(m, "IncompatibleReferenceFramesError", PyExc_RuntimeError);
py::register_exception<exceptions::IncompatibleSizeException>(m, "IncompatibleSizeError", PyExc_RuntimeError);
py::register_exception<exceptions::IncompatibleStatesException>(m, "IncompatibleStatesError", PyExc_RuntimeError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,14 @@ class CartesianState : public SpatialState {
*/
void set_state_variable(const Eigen::VectorXd& new_value, const CartesianStateVariable& state_variable_type);

protected:
/**
* @brief Setter of the variable value corresponding to the input
* @param new_value The new value of the variable as std vector
* @param state_variable_type The type of variable to set
*/
void set_state_variable(const std::vector<double>& new_value, const CartesianStateVariable& state_variable_type);

protected:
/**
* @copydoc SpatialState::to_string
*/
Expand Down Expand Up @@ -650,7 +650,7 @@ inline state_representation::CartesianStateVariable string_to_cartesian_state_va
* @param variable The CartesianStateVariable enum to convert
* @return A string corresponding to the CartesianStateVariable enum
*/
inline std::string cartesian_state_variable_to_string(const CartesianStateVariable variable) {
inline std::string cartesian_state_variable_to_string(const CartesianStateVariable& variable) {
switch (variable) {
case CartesianStateVariable::POSITION:
return "position";
Expand Down

0 comments on commit 5b91f1d

Please sign in to comment.