ROS2: How to make objects to share one node? (C++)

asked 2022-08-27 22:57:56 -0500

Sagal gravatar image

In tf-listener tutorial, the class has been implemented to two perform two functions-they are looking up for transform and manipulating a turtle.

I think it violates SRP rule so want to divide into multiple classes. Here is a problem. Assume that there are two objects of tf searcher and turtle manipulator. In ros2, most of objects interact with ROS should be a node itself so the classes inherit "rclcpp::Node". In ros1, the objects did not need to be node itself but just require node handle object so it is simply implemented with transferring shared pointer of the node handle.

Is there no way to divide a node into objects of single responsibility? Available solutions: 1. I have found a solution using composition, but it makes problem more complex so I want to solve with a simple solution. 2. I think it may be solved using inheritance. But it limits re-usability of the code.

edit retag flag offensive close merge delete