You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Iron.

Hardware Components

Hardware components represent abstraction of physical hardware in ros2_control framework. There are three types of hardware Actuator, Sensor and System. For details on each type check Hardware Components description.

Guidelines and Best Practices

Handling of errors that happen during read() and write() calls

If hardware_interface::return_type::ERROR is returned from read() or write() methods of a hardware_interface class, on_error(previous_state) method will be called to handle any error that happened.

Error handling follows the node lifecycle. If successful CallbackReturn::SUCCESS is returned and hardware is again in UNCONFIGURED state, if any ERROR or FAILURE happens the hardware ends in FINALIZED state and can not be recovered. The only option is to reload the complete plugin, but there is currently no service for this in the Controller Manager.

Migration from Foxy to newer versions

Between Foxy and Galactic we made substantial changes to the interface of hardware components to enable management of their lifecycle. The following list shows a set of quick changes to port existing hardware components to Galactic:

  1. Rename configure to on_init and change return type to CallbackReturn

  2. If using BaseInterface as base class then you should remove it. Specifically, change:

hardware_interface::BaseInterface<hardware_interface::[Actuator|Sensor|System]Interface>

to

hardware_interface::[Actuator|Sensor|System]Interface
  1. Remove include of headers base_interface.hpp and hardware_interface_status_values.hpp

  2. Add include of header rclcpp_lifecycle/state.hpp although this may not be strictly necessary

  3. replace first three lines in on_init to

if (hardware_interface::[Actuator|Sensor|System]Interface::on_init(info) != CallbackReturn::SUCCESS)
{
  return CallbackReturn::ERROR;
}
  1. Change last return of on_init to return CallbackReturn::SUCCESS;

  2. Remove all lines with status_ = ... or status::...

  3. Rename start() to on_activate(const rclcpp_lifecycle::State & previous_state) and stop() to on_deactivate(const rclcpp_lifecycle::State & previous_state)

  4. Change return type of on_activate and on_deactivate to CallbackReturn

  5. Change last return of on_activate and on_deactivate to return CallbackReturn::SUCCESS;

  6. If you have any return_type::ERROR in on_init, on_activate, or in_deactivate change to CallbackReturn::ERROR

  7. If you get link errors with undefined refernences to symbols in rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface, then add rclcpp_lifecyle package dependency to CMakeLists.txt and package.xml