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

Running multiple instances of same node

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

merosss gravatar image

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

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
8

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

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 http://wiki.ros.org/roslaunch/XML/remap . The launchfile also makes it easy to make sure each of your nodes has a different name when creating a node ( http://wiki.ros.org/roslaunch/XML/node ).

edit flag offensive delete link more

Comments

1

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 -0500 )edit
1

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 -0500 )edit
1

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 -0500 )edit

Question Tools

3 followers

Stats

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

Seen: 9,375 times

Last updated: Feb 04 '22