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

Running multiple instances of same node

asked 2014-05-03 07:28:18 -0600

merosss gravatar image

updated 2022-02-04 01:49:35 -0600

Hi everybody. I'm slightly new to Ros so I'm sorry for any mistake in terminology or logic I will do while asking. My problem is that I've written a node that communicates with Vrep (a robot simulator) publishing some positions to a topic to which Vrep is subscribed (goal positions that the robot is following), it is also subscribed to a topic which is published by Vrep that publishes the current position of the robot.

What i want to do is to run multiple instances of this node with different topic names so to control multiple robots, but I can't figure out which is the best solution. The thing is that I also want to dynamically generate the needed number of nodes, and give as arguments to the nodes the name of the topics to which they have to subscribe/publish. Is this possible?

The only solutions I found out so far are:

  1. Create multiple .cpp files with the topic names hardcoded in them, one for every robot I want to control. (NOT Dynamic)
  2. Create multiple nodes inside a single main with appropriate callback functions defined for every robot. (Seems messy, still NOT Dynamic)

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-05-04 08:47:02 -0600

fergs gravatar image

You want to take a look at Remapping Arguments, any ROS name can be remapped at runtime. Thus, you can start multiple versions of a node which, in code, publishes "my_topic", and remap each one, so that the first remaps "my_topic" to "my_first_topic", and the second remaps to "my_second_topic".

Obviously typing in all these different configurations every time you start the nodes would be horrible. That's where launch files come in . The launchfile also makes it easy to make sure each of your nodes has a different name when creating a node ( ).

edit flag offensive delete link more



Thanks man! That's exactly what I was looking for! Disentangling the jungle of the ros wiki sometimes it's hard for a beginner like me, those links where perfect!

merosss gravatar image merosss  ( 2014-05-04 12:30:15 -0600 )edit

That's cool! I was not aware of that feature. I've been writing nodes that take a numerical command line argument and then adding that number to the topic name string in my code before publishing or subscribing, but remapping arguments sounds like the proper way to handle it.

Kurt Leucht gravatar image Kurt Leucht  ( 2014-05-05 16:48:45 -0600 )edit

This helped me a lot for the publishers of my node. But what if I want the different instances to be aware of which node they are. I have a tracking node that I want to start 2 times for 2 cameras. Is it possible to know which instance I am when I am in the node?is there a way to get the nodes name?

Marcus gravatar image Marcus  ( 2015-04-01 10:06:26 -0600 )edit

Question Tools



Asked: 2014-05-03 07:28:18 -0600

Seen: 9,162 times

Last updated: Feb 04 '22