0
$\begingroup$

Rosanswers logo

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:

/mynode/[robot_name]/sim/twist
/mynode/[robot_name]/sim/odom
/mynode/[robot_name]/sim/base_scan

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!


Originally posted by Constantin S on ROS Answers with karma: 296 on 2011-10-28

Post score: 6

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2011-10-28

This answer was ACCEPTED on the original site

Post score: 13


Original comments

Comment by Constantin S on 2011-10-29:
This, sir, is beautifully elegant. Thank you.

$\endgroup$
0
$\begingroup$

Rosanswers logo

As described on http://www.ros.org/wiki/Remapping%20Arguments 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 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 http://www.ros.org/wiki/Names.


Originally posted by bhaskara with karma: 1479 on 2011-10-28

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by Constantin S on 2011-11-01:
Bhaskara, thank you so much, I think I understand remappings much better now.

Comment by bhaskara on 2011-10-31:
Also, btw, my earlier comment wasn't quite right: the remap tag has the same effect whether it occurs within the node tag or outside. The difference is just that in the latter case, it affects all subsequent node tags in the launch file.

Comment by bhaskara on 2011-10-31:
Yeah, so sim/twist gets resolved to /sim/twist, and cmd_vel to /cmd_vel. So if you publish to my_robot/sim/twist, that gets resolved to /my_robot/sim/twist, which does not get remapped.

Comment by Constantin S on 2011-10-31:
How does the remap work now? We see sim/twist => cmd_vel , inside the tags. What gets added to the remap table? I guess if sim/twist gets resolved to /sim/twist in the remapping table it would not match my goal? Am I on the right track? Thank you so much for your patience and explanation

Comment by Constantin S on 2011-10-31:
Bhaskara, thank you that clarified much from the wiki. I have one last question for you. My remap is specified inside 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

Comment by bhaskara on 2011-10-31:
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.

Comment by bhaskara on 2011-10-31:
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.

Comment by bhaskara on 2011-10-31:
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'.

Comment by Constantin S on 2011-10-31:
/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.

Comment by bhaskara on 2011-10-29:
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.

Comment by bhaskara on 2011-10-29:
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

Comment by Constantin S on 2011-10-29:
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?

$\endgroup$

Your Answer

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