Control Libraries 6.3.4
Loading...
Searching...
No Matches
bind_state.cpp
1#include "state_representation_bindings.h"
2
3#include <state_representation/State.hpp>
4
5
6void state_type(py::module_& m) {
7 py::enum_<StateType>(m, "StateType")
8 .value("NONE", StateType::NONE)
9 .value("STATE", StateType::STATE)
10 .value("SPATIAL_STATE", StateType::SPATIAL_STATE)
11 .value("CARTESIAN_STATE", StateType::CARTESIAN_STATE)
12 .value("CARTESIAN_POSE", StateType::CARTESIAN_POSE)
13 .value("CARTESIAN_TWIST", StateType::CARTESIAN_TWIST)
14 .value("CARTESIAN_ACCELERATION", StateType::CARTESIAN_ACCELERATION)
15 .value("CARTESIAN_WRENCH", StateType::CARTESIAN_WRENCH)
16 .value("JOINT_STATE", StateType::JOINT_STATE)
17 .value("JOINT_POSITIONS", StateType::JOINT_POSITIONS)
18 .value("JOINT_VELOCITIES", StateType::JOINT_VELOCITIES)
19 .value("JOINT_ACCELERATIONS", StateType::JOINT_ACCELERATIONS)
20 .value("JOINT_TORQUES", StateType::JOINT_TORQUES)
21 .value("JACOBIAN", StateType::JACOBIAN)
22 .value("PARAMETER", StateType::PARAMETER)
23 .value("GEOMETRY_SHAPE", StateType::GEOMETRY_SHAPE)
24 .value("GEOMETRY_ELLIPSOID", StateType::GEOMETRY_ELLIPSOID)
25 .value("TRAJECTORY", StateType::TRAJECTORY)
26 .export_values();
27}
28
29void state(py::module_& m) {
30 py::class_<State, std::shared_ptr<State>> c(m, "State");
31
32 c.def(py::init(), "Empty constructor");
33 c.def(py::init<const StateType&>(), "Constructor only specifying the type of the state from the StateType enumeration", "type"_a);
34 c.def(py::init<const StateType&, const std::string&, const bool&>(), "Constructor with name specification", "type"_a, "name"_a, "empty"_a=true);
35 c.def(py::init<const State&>(), "Copy constructor from another State", "state"_a);
36
37 c.def("get_type", &State::get_type, "Getter of the type attribute");
38 c.def("is_empty", &State::is_empty, "Getter of the empty attribute");
39 c.def("set_empty", &State::set_empty, "Setter of the empty attribute", "empty"_a=true);
40 c.def("set_filled", &State::set_filled, "Setter of the empty attribute to false and also reset the timestamp");
41 c.def("get_timestamp", &State::get_timestamp, "Getter of the timestamp attribute");
42 c.def("set_timestamp", &State::set_timestamp, "Setter of the timestamp attribute");
43 c.def("reset_timestamp", &State::reset_timestamp, "Reset the timestamp attribute to now");
44 c.def("get_name", &State::get_name, "Getter of the name");
45 c.def("set_name", &State::set_name, "Setter of the name");
46
47 c.def("is_deprecated", &State::is_deprecated<std::micro>, "Check if the state is deprecated given a certain time delay with microsecond precision");
48
49 c.def("is_compatible", &State::is_compatible, "Check if the state is compatible for operations with the state given as argument", "state"_a);
50 c.def("initialize", &State::initialize, "Initialize the State to a zero value");
51
52 c.def("__copy__", [](const State &state) {
53 return State(state);
54 });
55 c.def("__deepcopy__", [](const State &state, py::dict) {
56 return State(state);
57 }, "memo"_a);
58 c.def("__repr__", [](const State& state) {
59 std::stringstream buffer;
60 buffer << state;
61 return buffer.str();
62 });
63 c.def("__bool__", [](const State& state) {
64 return bool(state);
65 }, py::is_operator());
66}
67
68void bind_state(py::module_& m) {
69 state_type(m);
70 state(m);
71}
Abstract class to represent a state.
Definition: State.hpp:25
void reset_timestamp()
Reset the timestamp attribute to now.
Definition: State.cpp:44
virtual void initialize()
Initialize the State to a zero value.
Definition: State.cpp:61
const std::string & get_name() const
Getter of the name as const reference.
Definition: State.cpp:48
virtual void set_name(const std::string &name)
Setter of the name.
Definition: State.cpp:52
void set_timestamp(const std::chrono::time_point< std::chrono::steady_clock > &timepoint)
Setter of the timestamp attribute.
Definition: State.cpp:40
const StateType & get_type() const
Getter of the type attribute.
Definition: State.cpp:19
void set_filled()
Setter of the empty attribute to false and also reset the timestamp.
Definition: State.cpp:31
virtual bool is_compatible(const State &state) const
Check if the state is compatible for operations with the state given as argument.
Definition: State.cpp:56
const std::chrono::time_point< std::chrono::steady_clock > & get_timestamp() const
Getter of the timestamp attribute.
Definition: State.cpp:36
bool is_empty() const
Getter of the empty attribute.
Definition: State.cpp:23
void set_empty(bool empty=true)
Setter of the empty attribute.
Definition: State.cpp:27