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

Revision history [back]

Let's say node A has created it's publisher using something like

ros::Publisher pub = node.advertise<std_msgs::Twist>("turtle1/cmd_vel", 100);

and node B has subscribed using something like

ros::Subscriber sub = node.subscribe("cmd_vel", 100, datacb);

I believe that is the situation you are describing. Then the question is how to get the subscriber in B to successfully subscribe to the topic published by A. This is fundamentally a question of how ROS Names are resolved. Below are a few possible solutions. The correct solution depends on your specific application:

  • Remapping You could use "ROS Remapping" to either remap the publisher or the subscriber to be the correct topic. This can be done with rosrun via Remapping Arguments, or in roslaunch via the remap tag.
  • Namespaces You could modify the namespace that node B is in so that it runs in the turtle1/ namespace. Then its subscriber would automatically resolve to turtle1/cmd_vel. This could be done using the ns attribute of either the node tag or the group tag. You could also modify the namespace of a node at the command line with the ROS_NAMESPACE environment variable.