[Ros2] Creating Multiple nodes using class inheritance
Hi,
I was wondering if you had an example on how to create multiple Nodes using the class inheritance.
In ros, I created multiple nodes using ros::NodeHandle;
.
I read in one of the ros2 answers that I could use the following instead:
auto node = std::make_shared<rclcpp::Node>("...", ...);
node->create_publisher<...>("~/chatter", ...);
but in the publisher not_composable.cpp example which uses this method, it is written that:
We do not recommend this style anymore, because composition of multiple nodes in the same executable is not possible. Please see one of the subclass
So, I guessed there was a better way to create multiple nodes using the inheritance class.
My current problem is that the Node is being created on the constructor of the inheritance class:
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
but, in my code I am not sure which publishers will be needed so, I want to be able to control when a Node is made.
Update to my question:
Basically, my question was brought out by a lack of understanding of how ros worked. Trying to migrate to ros2 without fully understand ros first, was really dumb of me.
Thanks to the following post and its references I was able to learn more about ros and ros2: link text
I initially thought that a publisher and a subscriber needed their own nodes which is entirely wrong. What I meant by "I want to be able to control when a Node is made. " was basically me thinking that when a new publisher is created, a node needed to be initialized as well. I will keep on studying and before I make my next question I will do more thorough research.