1#include "state_representation_bindings.hpp" 
    3#include <state_representation/parameters/ParameterType.hpp> 
    4#include <state_representation/parameters/Parameter.hpp> 
    5#include <state_representation/parameters/ParameterMap.hpp> 
    7#include <state_representation/space/cartesian/CartesianState.hpp> 
    8#include <state_representation/space/cartesian/CartesianPose.hpp> 
    9#include <state_representation/space/joint/JointState.hpp> 
   10#include <state_representation/space/joint/JointPositions.hpp> 
   11#include <state_representation/geometry/Ellipsoid.hpp> 
   13#include "parameter_container.hpp" 
   14#include "py_parameter_map.hpp" 
   16using namespace py_parameter;
 
   18void parameter_type(py::module_& m) {
 
   19  py::enum_<ParameterType>(m, 
"ParameterType")
 
   20      .value(
"INT", ParameterType::INT)
 
   21      .value(
"INT_ARRAY", ParameterType::INT_ARRAY)
 
   22      .value(
"DOUBLE", ParameterType::DOUBLE)
 
   23      .value(
"DOUBLE_ARRAY", ParameterType::DOUBLE_ARRAY)
 
   24      .value(
"BOOL", ParameterType::BOOL)
 
   25      .value(
"BOOL_ARRAY", ParameterType::BOOL_ARRAY)
 
   26      .value(
"STRING", ParameterType::STRING)
 
   27      .value(
"STRING_ARRAY", ParameterType::STRING_ARRAY)
 
   28      .value(
"STATE", ParameterType::STATE)
 
   29      .value(
"VECTOR", ParameterType::VECTOR)
 
   30      .value(
"MATRIX", ParameterType::MATRIX)
 
   34void parameter_interface(py::module_& m) {
 
   35  py::class_<ParameterInterface, std::shared_ptr<ParameterInterface>, 
State> c(m, 
"ParameterInterface");
 
   37  c.def(py::init<const std::string&, const ParameterType&, const StateType&>(), 
"Constructor of a ParameterInterface with name, parameter type and parameter state type", 
"name"_a, 
"type"_a, 
"parameter_state_type"_a=StateType::NONE);
 
   38  c.def(py::init<const ParameterInterface&>(), 
"Copy constructor from another ParameterInterface", 
"parameter"_a);
 
   44void parameter(py::module_& m) {
 
   45  py::class_<ParameterContainer, std::shared_ptr<ParameterContainer>, 
ParameterInterface> c(m, 
"Parameter");
 
   47  c.def(py::init<const std::string&, const ParameterType&, const StateType&>(), 
"Constructor of a parameter with name, parameter type and parameter state type", 
"name"_a, 
"type"_a, 
"parameter_state_type"_a=StateType::NONE);
 
   48  c.def(py::init<const std::string&, const py::object&, const ParameterType&, const StateType&>(), 
"Constructor of a parameter with name, value, parameter type and parameter state type", 
"name"_a, 
"value"_a, 
"type"_a, 
"parameter_state_type"_a=StateType::NONE);
 
   49  c.def(py::init<const ParameterContainer&>(), 
"Copy constructor from another Parameter", 
"parameter"_a);
 
   50  c.def(py::init([](
const std::shared_ptr<ParameterInterface>& parameter) { 
return interface_ptr_to_container(parameter); }), 
"Constructor from a parameter interface pointer", 
"parameter"_a);
 
   52  c.def(
"get_value", &ParameterContainer::get_value, 
"Getter of the value attribute.");
 
   53  c.def(
"set_value", &ParameterContainer::set_value, 
"Setter of the value attribute.", py::arg(
"value"));
 
   62    std::stringstream buffer;
 
   63    switch (parameter.get_parameter_type()) {
 
   64      case ParameterType::INT:
 
   65        buffer << container_to_parameter<int>(parameter);
 
   67      case ParameterType::INT_ARRAY:
 
   68        buffer << container_to_parameter<std::vector<int>>(parameter);
 
   70      case ParameterType::DOUBLE:
 
   71        buffer << container_to_parameter<double>(parameter);
 
   73      case ParameterType::DOUBLE_ARRAY:
 
   74        buffer << container_to_parameter<std::vector<double>>(parameter);
 
   76      case ParameterType::BOOL:
 
   77        buffer << container_to_parameter<bool>(parameter);
 
   79      case ParameterType::BOOL_ARRAY:
 
   80        buffer << container_to_parameter<std::vector<bool>>(parameter);
 
   82      case ParameterType::STRING:
 
   83        buffer << container_to_parameter<std::string>(parameter);
 
   85      case ParameterType::STRING_ARRAY:
 
   86        buffer << container_to_parameter<std::vector<std::string>>(parameter);
 
   88      case ParameterType::STATE: {
 
   90          switch (parameter.get_parameter_state_type()) {
 
   91            case StateType::CARTESIAN_STATE:
 
   92              buffer << container_to_parameter<CartesianState>(parameter);
 
   94            case StateType::CARTESIAN_POSE:
 
   95              buffer << container_to_parameter<CartesianPose>(parameter);
 
   97            case StateType::JOINT_STATE:
 
   98              buffer << container_to_parameter<JointState>(parameter);
 
  100            case StateType::JOINT_POSITIONS:
 
  101              buffer << container_to_parameter<JointPositions>(parameter);
 
  103            case StateType::GEOMETRY_ELLIPSOID:
 
  104              buffer << container_to_parameter<Ellipsoid>(parameter);
 
  107              buffer << 
"Parameter '" << parameter.get_name() << 
"' contains an unsupported state type" << std::endl;
 
  110        } 
catch (
const std::exception&) {
 
  111          buffer << 
"Parameter '" << parameter.get_name() << 
"' is invalid" << std::endl;
 
  116      case ParameterType::MATRIX:
 
  117        buffer << container_to_parameter<Eigen::MatrixXd>(parameter);
 
  119      case ParameterType::VECTOR:
 
  120        buffer << container_to_parameter<Eigen::VectorXd>(parameter);
 
  123        buffer << 
"Parameter '" << parameter.get_name() << 
"' has an invalid parameter type" << std::endl;
 
  130void parameter_map(py::module_& m) {
 
  131  py::class_<ParameterMap, std::shared_ptr<ParameterMap>, 
PyParameterMap> c(m, 
"ParameterMap");
 
  133  c.def(py::init(), 
"Empty constructor");
 
  135      py::init([](
const std::map<std::string, ParameterContainer>& parameters) {
 
  136        auto parameter_map = container_to_interface_ptr_map(parameters);
 
  138      }), 
"Construct the parameter map with an initial list of parameters", 
"parameters"_a
 
  141      py::init([](
const std::list<ParameterContainer>& parameters) {
 
  142        auto parameter_list = container_to_interface_ptr_list(parameters);
 
  144      }), 
"Construct the parameter map with an initial map of parameters", 
"parameters"_a);
 
  149       } , 
"Get a parameter by its name", 
"name"_a
 
  154      } , 
"Get a map of all the <name, parameter> pairs" 
  157      "get_parameter_value", [](
ParameterMap& self, 
const std::string& name) -> py::object {
 
  158        return interface_ptr_to_container(self.
get_parameter(name)).get_value();
 
  159      }, 
"Get a parameter value by its name", 
"name"_a
 
  164      } , 
"Get a list of all the parameters" 
  169  }, 
"Set a parameter", 
"parameter"_a);
 
  170  c.def(
"set_parameters", [](
ParameterMap& self, 
const std::list<ParameterContainer>& parameters) {
 
  172  }, 
"Set parameters from a list of parameters", 
"parameters"_a);
 
  173  c.def(
"set_parameters", [](
ParameterMap& self, 
const std::map<std::string, ParameterContainer>& parameters) {
 
  175  }, 
"Set parameters from a map with <name, parameter> pairs", 
"parameters"_a);
 
  177      "set_parameter_value", [](
ParameterMap& self, 
const std::string& name, 
const py::object& value, 
const ParameterType& type, 
const StateType& parameter_state_type) -> 
void {
 
  180      }, 
"Set a parameter value by its name", 
"name"_a, 
"value"_a, 
"type"_a, 
"parameter_state_type"_a=StateType::NONE
 
  182  c.def(
"remove_parameter", &ParameterMap::remove_parameter, 
"Remove a parameter from the parameter map.", 
"name"_a);
 
  185void bind_parameters(py::module_& m) {
 
  187  parameter_interface(m);
 
StateType get_parameter_state_type() const
Get the state type of the parameter.
 
ParameterType get_parameter_type() const
Get the parameter type.
 
A wrapper class to contain a map of Parameter pointers by name and provide robust access methods.
 
ParameterInterfaceMap get_parameters() const
Get a map of all the <name, parameter> pairs.
 
ParameterInterfaceList get_parameter_list() const
Get a list of all the parameters.
 
std::shared_ptr< ParameterInterface > get_parameter(const std::string &name) const
Get a parameter by its name.
 
void set_parameters(const ParameterInterfaceList ¶meters)
Set parameters from a list of parameters.
 
void set_parameter(const std::shared_ptr< ParameterInterface > ¶meter)
Set a parameter.
 
Abstract class to represent a state.
 
ParameterType
The parameter value types.
 
StateType
The class types inheriting from State.