1
$\begingroup$

Rosanswers logo

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.


Originally posted by merosss on ROS Answers with karma: 723 on 2014-05-03

Post score: 4

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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).


Originally posted by fergs with karma: 13902 on 2014-05-04

This answer was ACCEPTED on the original site

Post score: 8


Original comments

Comment by merosss on 2014-05-04:
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!

Comment by Kurt Leucht on 2014-05-05:
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.

Comment by Marcus on 2015-04-01:
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?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.