Accessing rclcpp.Node functionality from within a custom hardware_interface::SystemInterface implementation

asked 2022-04-20 14:35:36 -0600

updated 2022-04-20 20:44:39 -0600

I am implementing a custom hardware_interface::SystemInterface class, and need its write() method to issue ROS service calls to MCUs (MicroROS) via the ROS service client API. The signatures of SystemInterface, and its parent class LifecycleNodeInterface, do not expose any way to retrieve an underlying Node instance from which to create such a service client:

class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface

The on_init() and on_configure() methods don't offer any such option via their input parameters either.

Note that I want to rely on the automatic instantiation of my custom class by the ControllerManager, as plugged-in via the <ros2_control> tag. For example:

<ros2_control name="pole" type="system">
    <hardware>
      <plugin>my_hardware/MyCustomHardwareSystem</plugin>
      <param name="blah">some_value</param>
    </hardware>
    ...
</ros2_contol>

What would be the best design pattern to access such a Node instance from within my custom SystemInterface implementation?

  • Multiple inheritance from SystemInterface and Node, so the class is automatically a node itself?
  • Creation of a new Node instance within constructor(), on_init() or on_configure()?
  • Some other way to retrieve a Node instance (such as that of the containing ControllerManager node)?

Thanks in advance.

edit retag flag offensive close merge delete