Control Libraries 7.4.0
Loading...
Searching...
No Matches
bind_state.cpp
1#include "state_representation_bindings.hpp"
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 .value("DIGITAL_IO_STATE", StateType::DIGITAL_IO_STATE)
27 .value("ANALOG_IO_STATE", StateType::ANALOG_IO_STATE)
28 .export_values();
29}
30
31void state(py::module_& m) {
32 py::class_<State, std::shared_ptr<State>> c(m, "State");
33 c.def_property_readonly_static("__array_priority__", [](py::object) { return 10000; });
34
35 c.def(py::init(), "Empty constructor");
36 c.def(py::init<const std::string&>(), "Constructor with name specification", "name"_a);
37 c.def(py::init<const State&>(), "Copy constructor from another State", "state"_a);
38
39 c.def("get_type", &State::get_type, "Getter of the type attribute");
40 c.def("is_empty", &State::is_empty, "Getter of the empty attribute");
41 c.def("get_age", &State::get_age, "Get the age of the state, i.e. the time since last modification");
42 c.def("get_timestamp", &State::get_timestamp, "Getter of the timestamp attribute");
43 c.def("reset_timestamp", &State::reset_timestamp, "Reset the timestamp attribute to the current time");
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_incompatible", &State::is_incompatible, "Check if the state is compatible for operations with the state given as argument", "state"_a);
50 c.def("reset", &State::reset, "Reset the state to be empty with no data");
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:61
const std::string & get_name() const
Getter of the name attribute.
Definition State.cpp:29
virtual void set_name(const std::string &name)
Setter of the name attribute.
Definition State.cpp:45
const StateType & get_type() const
Getter of the type attribute.
Definition State.cpp:25
const std::chrono::time_point< std::chrono::steady_clock > & get_timestamp() const
Getter of the timestamp attribute.
Definition State.cpp:37
virtual void reset()
Reset the object to a post-construction state.
Definition State.cpp:77
virtual bool is_incompatible(const State &state) const
Check if the state is incompatible for operations with the state given as argument.
Definition State.cpp:91
double get_age() const
Get the age of the state, i.e. the time since the last modification.
Definition State.cpp:81
bool is_empty() const
Getter of the empty attribute.
Definition State.cpp:33