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

Namespace and Remapping

asked 2011-10-28 05:46:07 -0600

Constantin S gravatar image

updated 2011-10-29 12:23:46 -0600

Hello all, I have been reading the documentation and running test examples on namespaces and remaps but I still cannot achieve what I am trying to do. My attempts have also spawned new questions which I could not find answers to.

First Problem: My node publishes topics in the following manner:


I would like to remap the sim/* commands to other commands:

/mynode/[robot_name]/sim/twist            -> /[robot_name]/cmd_vel
/mynode/[robot_name]/sim/odom             -> /[robot_name]/odom
/mynode/[robot_name]/sim/base_scan        -> /[robot_name]/base_scan

Note, that [robot_name] is dynamic, based on an input file. (Just like stage's robot_0, robot_1, robot_2, etc).

Removing the node name was simple, but the sim/* -> new_name did not work. In the launch file:

  <remap from="/mynode" to ="/" /> --- This works
  <remap from="sim/twist" to ="cmd_vel" /> --- These don't
  <remap from="sim/odom" to ="odom" /> --- These don't
  <remap from="sim/base_scan" to ="base_scan" /> --- These don't

Could anyone offer any suggestions on a fix?

Second Problem: When I remap "/mynode" to "/", parameters I pass into my node aren't found anymore. NodeHandle.searchParam does not find them, but they still exist. For example:

 namespace of node = "/"     (this is because of the remap above)
 parameters = "/mynode/PARAM1" , "/mynode/PARAM2"  (parameters are not remapped!!)

As stated, searchParams does not find them, but getParam("/mynode/Param1") works (and of course getParam("Param1") fails since the node's namespace changed. Does anyone have any thoughts? Thank you for your time!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2011-10-28 06:55:27 -0600

dornhege gravatar image

updated 2013-05-13 06:44:24 -0600

Claudio gravatar image

I think your problem arises from the difference between a NodeHandle (constructed as NodeHandle nh;) and a private NodeHandle (Nodehandle nh("~");) that you probably use.

I suspect you only use the second, which will put everything in the node's namespace (mynode). This is what you want for parameters, but not necessarily for topics, etc.

So: Use the private NodeHandle for getting parameters and a "normal" NodeHandle for creating topics/services. That should clean up a lot of your problems.

edit flag offensive delete link more


This, sir, is beautifully elegant. Thank you.
Constantin S gravatar image Constantin S  ( 2011-10-29 12:13:25 -0600 )edit

answered 2011-10-28 10:28:45 -0600

bhaskara gravatar image

updated 2016-08-10 18:32:15 -0600

130s gravatar image

As described on remapping happens on full names, and after the names are resolved. So for your second remap,

  1. Resolving 'sim/twist' would result in either '/mynode/sim/twist' or '/sim/twist' depending on whether you put the remap inside or outside the <node> tag for mynode.
  2. '/mynode/myrobot/sim/twist' does not equal '/mynode/sim/twist' so would be unaffected by the remap.

I'm not sure how to do what you want in roslaunch — you'd need for the robot name to be known at the point that the node is launched, and passed in somehow.

See also .

edit flag offensive delete link more


Thank you for your reponse, I am still confused. Those wiki pages state I can remap parts of names. More specifically sim/twist:=cmd_vel should match /bla/sim/twist, as described on those websites, and remap it to /bla/cm_vel. Am I incorrect?
Constantin S gravatar image Constantin S  ( 2011-10-29 12:19:26 -0600 )edit
I think you're incorrect. From the remapping page: We resolve the arguments before doing the match. The effect of this is that you are remapping a full name, whereas before the remappings only applied to a specific string. For example, where foo:=bar previously only matched the exact string foo, it
bhaskara gravatar image bhaskara  ( 2011-10-29 17:07:22 -0600 )edit
will also match /<node_namespace>/foo. After resolution, a direct string match is used, so you cannot use it to remap parts of Names, i.e. foo:=bar will match foo or /<node_namespace>/foo, but will not match foo/baz.
bhaskara gravatar image bhaskara  ( 2011-10-29 17:08:14 -0600 )edit
/bla = <node_namespace> and foo = sim/twist, hence I match /<node_namespace>/foo .... It seems to me that their example is incorrect. Also, not to be rude, but I have read those pages religiously, linking what they state does not help. My understanding of what they state must be incorrect.
Constantin S gravatar image Constantin S  ( 2011-10-31 01:47:58 -0600 )edit
When the remapping you mentioned is processed, two steps happen: 1. Resolve. This means replacing the names by fully qualified names. In this case, 'sim/twist' gets remapped to '/sim/twist' (assuming your remap was outside the node tag), and 'cmd_vel' to '/cmd_vel'.
bhaskara gravatar image bhaskara  ( 2011-10-31 04:20:34 -0600 )edit
2. Add this entry to the remapping table: "'/sim/twist' => '/cmd_vel'". In your code, when the name '/bla/sim/twist' is encountered, again two steps happen: 1. Resolve. In this case '/bla/sim/twist' is already fully qualified, so remains unchanged.
bhaskara gravatar image bhaskara  ( 2011-10-31 04:20:54 -0600 )edit
2. Remap. Look up this string in the remapping table. It doesn't exist, so nothing happens. Are there specific parts of the wiki documentation that contradict the above? If so, it should be updated.
bhaskara gravatar image bhaskara  ( 2011-10-31 04:21:00 -0600 )edit
Bhaskara, thank you that clarified much from the wiki. I have one last question for you. My remap is specified inside <node> tags, and the /my_node:= / from earlier is not given. Furthermore, using the advice from the other poster, I am publishing using a global nh, to /[robot_name/sim/twist
Constantin S gravatar image Constantin S  ( 2011-10-31 04:33:55 -0600 )edit

Question Tools



Asked: 2011-10-28 05:46:07 -0600

Seen: 12,247 times

Last updated: Aug 10 '16