From 40975cf94321a68b658fe5f06e74b8f6b1aa5159 Mon Sep 17 00:00:00 2001 From: Manuel M Date: Wed, 22 May 2024 18:05:45 +0200 Subject: [PATCH] rename export_state/command_interface_2 to export_state/commad_interface_descriptions --- .../doc/writing_new_hardware_component.rst | 8 ++++---- .../hardware_interface/actuator_interface.hpp | 10 ++++++---- .../hardware_interface/sensor_interface.hpp | 5 +++-- .../hardware_interface/system_interface.hpp | 10 ++++++---- .../test_component_interfaces_custom_export.cpp | 15 ++++++++++----- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/hardware_interface/doc/writing_new_hardware_component.rst b/hardware_interface/doc/writing_new_hardware_component.rst index 21c55cb311..ad3728c21a 100644 --- a/hardware_interface/doc/writing_new_hardware_component.rst +++ b/hardware_interface/doc/writing_new_hardware_component.rst @@ -55,14 +55,14 @@ The following is a step-by-step guide to create source files, basic tests, and c #. Implement ``on_cleanup`` method, which does the opposite of ``on_configure``. #. ``Command-/StateInterfaces`` are now created and exported automatically by the framework via the ``on_export_command_interfaces()`` or ``on_export_state_interfaces()`` methods based on the interfaces defined in the ``ros2_control`` XML-tag, which gets parsed and the ``InterfaceDescription`` is created accordingly (check the `hardware_info.hpp `__). - * To access the automatically created ``Command-/StateInterfaces`` we provide the ``std::unordered_map``, where the string is the fully qualified name of the interface and the ``InterfaceDescription`` is the configuration of the interface. The ``std::unordered_map<>`` are divided into ``type_state_interfaces_`` and ``type_command_interfaces_`` where type can be: ``joint``, ``sensor``, ``gpio`` and ``unlisted``. E.g. the ``CommandInterfaces`` for all joints can be found in the ``joint_command_interfaces_`` map. The ``unlisted`` includes all interfaces not listed in the ``ros2_control`` XML-tag but were created by overriding the ``export_command_interfaces_2()`` or ``export_state_interfaces_2()`` function by creating some custom ``Command-/StateInterfaces``. + * To access the automatically created ``Command-/StateInterfaces`` we provide the ``std::unordered_map``, where the string is the fully qualified name of the interface and the ``InterfaceDescription`` is the configuration of the interface. The ``std::unordered_map<>`` are divided into ``type_state_interfaces_`` and ``type_command_interfaces_`` where type can be: ``joint``, ``sensor``, ``gpio`` and ``unlisted``. E.g. the ``CommandInterfaces`` for all joints can be found in the ``joint_command_interfaces_`` map. The ``unlisted`` includes all interfaces not listed in the ``ros2_control`` XML-tag but were created by overriding the ``export_command_interface_descriptions()`` or ``export_state_interface_descriptions()`` function by creating some custom ``Command-/StateInterfaces``. * For the ``Sensor``-type hardware interface there is no ``export_command_interfaces`` method. * As a reminder, the full interface names have structure ``/``. #. (optional) If you want some unlisted ``Command-/StateInterfaces`` not included in the ``ros2_control`` XML-tag you can follow those steps: - #. Override the ``virtual std::vector export_command_interfaces_2()`` or ``virtual std::vector export_state_interfaces_2()`` - #. Create the InterfaceDescription for each of the interfaces you want to create in the override ``export_command_interfaces_2()`` or ``export_state_interfaces_2()`` function, add it to a vector and return the vector: + #. Override the ``virtual std::vector export_command_interface_descriptions()`` or ``virtual std::vector export_state_interface_descriptions()`` + #. Create the InterfaceDescription for each of the interfaces you want to create in the override ``export_command_interface_descriptions()`` or ``export_state_interface_descriptions()`` function, add it to a vector and return the vector: .. code-block:: c++ @@ -81,7 +81,7 @@ The following is a step-by-step guide to create source files, basic tests, and c #. (optional) In case the default implementation (``on_export_command_interfaces()`` or ``on_export_state_interfaces()`` ) for exporting the ``Command-/StateInterfaces`` is not enough you can override them. You should however consider the following things: - * If you want to have unlisted interfaces available you need to call the ``export_command_interfaces_2()`` or ``export_state_interfaces_2()`` and add them to the ``unlisted_command_interfaces_`` or ``unlisted_state_interfaces_``. + * If you want to have unlisted interfaces available you need to call the ``export_command_interface_descriptions()`` or ``export_state_interface_descriptions()`` and add them to the ``unlisted_command_interfaces_`` or ``unlisted_state_interfaces_``. * Don't forget to store the created ``Command-/StateInterfaces`` internally as you only return shared_ptrs and the resource manager will not provide access to the created ``Command-/StateInterfaces`` for the hardware. So you must take care of storing them yourself. * Names must be unique! diff --git a/hardware_interface/include/hardware_interface/actuator_interface.hpp b/hardware_interface/include/hardware_interface/actuator_interface.hpp index cc32adce3e..3080c33c62 100644 --- a/hardware_interface/include/hardware_interface/actuator_interface.hpp +++ b/hardware_interface/include/hardware_interface/actuator_interface.hpp @@ -189,7 +189,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod * * \return vector of descriptions to the unlisted StateInterfaces */ - virtual std::vector export_state_interfaces_2() + virtual std::vector + export_state_interface_descriptions() { // return empty vector by default. return {}; @@ -206,7 +207,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod { // import the unlisted interfaces std::vector unlisted_interface_descriptions = - export_state_interfaces_2(); + export_state_interface_descriptions(); std::vector> state_interfaces; state_interfaces.reserve( @@ -265,7 +266,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod * * \return vector of descriptions to the unlisted CommandInterfaces */ - virtual std::vector export_command_interfaces_2() + virtual std::vector + export_command_interface_descriptions() { // return empty vector by default. return {}; @@ -282,7 +284,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod { // import the unlisted interfaces std::vector unlisted_interface_descriptions = - export_command_interfaces_2(); + export_command_interface_descriptions(); std::vector> command_interfaces; command_interfaces.reserve( diff --git a/hardware_interface/include/hardware_interface/sensor_interface.hpp b/hardware_interface/include/hardware_interface/sensor_interface.hpp index fbe6e1ac94..0726fd90ce 100644 --- a/hardware_interface/include/hardware_interface/sensor_interface.hpp +++ b/hardware_interface/include/hardware_interface/sensor_interface.hpp @@ -173,7 +173,8 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI * * \return vector of descriptions to the unlisted StateInterfaces */ - virtual std::vector export_state_interfaces_2() + virtual std::vector + export_state_interface_descriptions() { // return empty vector by default. return {}; @@ -190,7 +191,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI { // import the unlisted interfaces std::vector unlisted_interface_descriptions = - export_state_interfaces_2(); + export_state_interface_descriptions(); std::vector> state_interfaces; state_interfaces.reserve( diff --git a/hardware_interface/include/hardware_interface/system_interface.hpp b/hardware_interface/include/hardware_interface/system_interface.hpp index 8f5fa99ce3..d41af76e9f 100644 --- a/hardware_interface/include/hardware_interface/system_interface.hpp +++ b/hardware_interface/include/hardware_interface/system_interface.hpp @@ -208,7 +208,8 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI * * \return vector of descriptions to the unlisted StateInterfaces */ - virtual std::vector export_state_interfaces_2() + virtual std::vector + export_state_interface_descriptions() { // return empty vector by default. return {}; @@ -225,7 +226,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI { // import the unlisted interfaces std::vector unlisted_interface_descriptions = - export_state_interfaces_2(); + export_state_interface_descriptions(); std::vector> state_interfaces; state_interfaces.reserve( @@ -297,7 +298,8 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI * * \return vector of descriptions to the unlisted CommandInterfaces */ - virtual std::vector export_command_interfaces_2() + virtual std::vector + export_command_interface_descriptions() { // return empty vector by default. return {}; @@ -314,7 +316,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI { // import the unlisted interfaces std::vector unlisted_interface_descriptions = - export_command_interfaces_2(); + export_command_interface_descriptions(); std::vector> command_interfaces; command_interfaces.reserve( diff --git a/hardware_interface/test/test_component_interfaces_custom_export.cpp b/hardware_interface/test/test_component_interfaces_custom_export.cpp index 7a5011892b..38794a8b91 100644 --- a/hardware_interface/test/test_component_interfaces_custom_export.cpp +++ b/hardware_interface/test/test_component_interfaces_custom_export.cpp @@ -57,7 +57,8 @@ class DummyActuatorDefault : public hardware_interface::ActuatorInterface { std::string get_name() const override { return "DummyActuatorDefault"; } - std::vector export_state_interfaces_2() override + std::vector export_state_interface_descriptions() + override { std::vector interfaces; hardware_interface::InterfaceInfo info; @@ -68,7 +69,8 @@ class DummyActuatorDefault : public hardware_interface::ActuatorInterface return interfaces; } - std::vector export_command_interfaces_2() override + std::vector export_command_interface_descriptions() + override { std::vector interfaces; hardware_interface::InterfaceInfo info; @@ -96,7 +98,8 @@ class DummySensorDefault : public hardware_interface::SensorInterface { std::string get_name() const override { return "DummySensorDefault"; } - std::vector export_state_interfaces_2() override + std::vector export_state_interface_descriptions() + override { std::vector interfaces; hardware_interface::InterfaceInfo info; @@ -118,7 +121,8 @@ class DummySystemDefault : public hardware_interface::SystemInterface { std::string get_name() const override { return "DummySystemDefault"; } - std::vector export_state_interfaces_2() override + std::vector export_state_interface_descriptions() + override { std::vector interfaces; hardware_interface::InterfaceInfo info; @@ -129,7 +133,8 @@ class DummySystemDefault : public hardware_interface::SystemInterface return interfaces; } - std::vector export_command_interfaces_2() override + std::vector export_command_interface_descriptions() + override { std::vector interfaces; hardware_interface::InterfaceInfo info;