Skip to content

Commit

Permalink
rename export_state/command_interface_2 to export_state/commad_interf…
Browse files Browse the repository at this point in the history
…ace_descriptions
  • Loading branch information
mamueluth committed Jul 24, 2024
1 parent b3faa8d commit 40975cf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
8 changes: 4 additions & 4 deletions hardware_interface/doc/writing_new_hardware_component.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/ros-controls/ros2_control/tree/{REPOS_FILE_BRANCH}/hardware_interface/include/hardware_interface/hardware_info.hpp>`__).

* To access the automatically created ``Command-/StateInterfaces`` we provide the ``std::unordered_map<std::string, InterfaceDescription>``, 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<std::string, InterfaceDescription>``, 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 ``<joint_name>/<interface_type>``.

#. (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<hardware_interface::InterfaceDescription> export_command_interfaces_2()`` or ``virtual std::vector<hardware_interface::InterfaceDescription> 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<hardware_interface::InterfaceDescription> export_command_interface_descriptions()`` or ``virtual std::vector<hardware_interface::InterfaceDescription> 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++

Expand All @@ -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!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
*
* \return vector of descriptions to the unlisted StateInterfaces
*/
virtual std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2()
virtual std::vector<hardware_interface::InterfaceDescription>
export_state_interface_descriptions()
{
// return empty vector by default.
return {};
Expand All @@ -206,7 +207,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
{
// import the unlisted interfaces
std::vector<hardware_interface::InterfaceDescription> unlisted_interface_descriptions =
export_state_interfaces_2();
export_state_interface_descriptions();

std::vector<std::shared_ptr<StateInterface>> state_interfaces;
state_interfaces.reserve(
Expand Down Expand Up @@ -265,7 +266,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
*
* \return vector of descriptions to the unlisted CommandInterfaces
*/
virtual std::vector<hardware_interface::InterfaceDescription> export_command_interfaces_2()
virtual std::vector<hardware_interface::InterfaceDescription>
export_command_interface_descriptions()
{
// return empty vector by default.
return {};
Expand All @@ -282,7 +284,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
{
// import the unlisted interfaces
std::vector<hardware_interface::InterfaceDescription> unlisted_interface_descriptions =
export_command_interfaces_2();
export_command_interface_descriptions();

std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
command_interfaces.reserve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*
* \return vector of descriptions to the unlisted StateInterfaces
*/
virtual std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2()
virtual std::vector<hardware_interface::InterfaceDescription>
export_state_interface_descriptions()
{
// return empty vector by default.
return {};
Expand All @@ -190,7 +191,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
{
// import the unlisted interfaces
std::vector<hardware_interface::InterfaceDescription> unlisted_interface_descriptions =
export_state_interfaces_2();
export_state_interface_descriptions();

std::vector<std::shared_ptr<StateInterface>> state_interfaces;
state_interfaces.reserve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*
* \return vector of descriptions to the unlisted StateInterfaces
*/
virtual std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2()
virtual std::vector<hardware_interface::InterfaceDescription>
export_state_interface_descriptions()
{
// return empty vector by default.
return {};
Expand All @@ -225,7 +226,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
{
// import the unlisted interfaces
std::vector<hardware_interface::InterfaceDescription> unlisted_interface_descriptions =
export_state_interfaces_2();
export_state_interface_descriptions();

std::vector<std::shared_ptr<StateInterface>> state_interfaces;
state_interfaces.reserve(
Expand Down Expand Up @@ -297,7 +298,8 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*
* \return vector of descriptions to the unlisted CommandInterfaces
*/
virtual std::vector<hardware_interface::InterfaceDescription> export_command_interfaces_2()
virtual std::vector<hardware_interface::InterfaceDescription>
export_command_interface_descriptions()
{
// return empty vector by default.
return {};
Expand All @@ -314,7 +316,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
{
// import the unlisted interfaces
std::vector<hardware_interface::InterfaceDescription> unlisted_interface_descriptions =
export_command_interfaces_2();
export_command_interface_descriptions();

std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
command_interfaces.reserve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class DummyActuatorDefault : public hardware_interface::ActuatorInterface
{
std::string get_name() const override { return "DummyActuatorDefault"; }

std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2() override
std::vector<hardware_interface::InterfaceDescription> export_state_interface_descriptions()
override
{
std::vector<hardware_interface::InterfaceDescription> interfaces;
hardware_interface::InterfaceInfo info;
Expand All @@ -68,7 +69,8 @@ class DummyActuatorDefault : public hardware_interface::ActuatorInterface
return interfaces;
}

std::vector<hardware_interface::InterfaceDescription> export_command_interfaces_2() override
std::vector<hardware_interface::InterfaceDescription> export_command_interface_descriptions()
override
{
std::vector<hardware_interface::InterfaceDescription> interfaces;
hardware_interface::InterfaceInfo info;
Expand Down Expand Up @@ -96,7 +98,8 @@ class DummySensorDefault : public hardware_interface::SensorInterface
{
std::string get_name() const override { return "DummySensorDefault"; }

std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2() override
std::vector<hardware_interface::InterfaceDescription> export_state_interface_descriptions()
override
{
std::vector<hardware_interface::InterfaceDescription> interfaces;
hardware_interface::InterfaceInfo info;
Expand All @@ -118,7 +121,8 @@ class DummySystemDefault : public hardware_interface::SystemInterface
{
std::string get_name() const override { return "DummySystemDefault"; }

std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2() override
std::vector<hardware_interface::InterfaceDescription> export_state_interface_descriptions()
override
{
std::vector<hardware_interface::InterfaceDescription> interfaces;
hardware_interface::InterfaceInfo info;
Expand All @@ -129,7 +133,8 @@ class DummySystemDefault : public hardware_interface::SystemInterface
return interfaces;
}

std::vector<hardware_interface::InterfaceDescription> export_command_interfaces_2() override
std::vector<hardware_interface::InterfaceDescription> export_command_interface_descriptions()
override
{
std::vector<hardware_interface::InterfaceDescription> interfaces;
hardware_interface::InterfaceInfo info;
Expand Down

0 comments on commit 40975cf

Please sign in to comment.