ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Multiple classes that inherit from rclcpp::Node in one executable

asked 2021-07-26 05:47:50 -0500

max11gen gravatar image

I would like to implement a ROS Node that manages multiple objects which each have their own subscriptions. Now for an object to have its own subscriptions the class needs to inherit from rclcpp::Node. So is it possible to have to compile two different classes that both inherit from rclcpp::Node in one executable or does this break ROS 2 design rules?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2021-07-27 14:45:57 -0500

jdlangs gravatar image

If you make two different classes that derive from rclcpp::Node and create instances of both of them then you will have two different nodes. That is sometimes a valid pattern but it sounds like you probably don't want to do that from your first sentence.

Now for an object to have its own subscriptions the class needs to inherit from rclcpp::Node

This is not accurate, it only needs to have access to a Node object when creating the subscriptions. You could easily create the node object and then pass it to the constructor of these other subscription-holding objects, which would then manage the subscriptions as needed.

edit flag offensive delete link more
1

answered 2021-07-26 15:24:47 -0500

carlossvg gravatar image

So is it possible to have to compile two different classes that both inherit from rclcpp::Node in one executable or does this break ROS 2 design rules?

You could create each node in separate files and use them in one executable using node composition. Please take a look at this example https://github.com/ros2/demos/blob/ma....

You can read more about composition here: - https://docs.ros.org/en/rolling/Conce... - https://docs.ros.org/en/rolling/Tutor... - https://roscon.ros.org/2019/talks/ros...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-07-26 05:47:50 -0500

Seen: 456 times

Last updated: Jul 27 '21