0
$\begingroup$

Rosanswers logo

In a launch file I want to remap parameters of my node to other, already existing parameters. It is working for global parameters but not for private ones.

This is a simple example node "param.py":

#!/usr/bin/env python
"""Just testing parameter mapping."""
import rospy

rospy.init_node("param")
print(rospy.get_param("foo"))
print(rospy.get_param("bar"))
print(rospy.get_param("~baz"))

The node is launched by this launch file "param.launch":

<launch>
    <node name="param" pkg="mypkg" type="param.py" output="screen">
        <remap from="/bar" to="/foo" />
        <remap from="baz" to="foo" />
    </node>
</launch>

In a terminal I run:

rosparam set foo 42
roslaunch mypkg param.launch

The output is:

42
42
KeyError: '~baz'

How can I make it work?


Originally posted by Felix Widmaier on ROS Answers with karma: 382 on 2018-02-21

Post score: 0


Original comments

Comment by 130s on 2018-09-20:
I'm afraid rosparam would fail without Parameter server running. Maybe add roscore command a line above?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Private parameter names have to be prefixed with ~ even when the <remap> is defined inside the <node> tag:

<launch>
    <node name="param" pkg="mypkg" type="param.py" output="screen">
        <remap from="/bar" to="/foo" />
        <remap from="~baz" to="foo" />
    </node>
</launch>

Output:

42
42
42

Originally posted by Felix Widmaier with karma: 382 on 2018-02-21

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by 130s on 2018-09-20:
Nice dig! Added to remap page.

Comment by meyerj on 2020-02-24:
Could it be that this approach does not work for roscpp nodes? The remapping is not applied for NodeHandles created as

ros::NodeHandle private_nh("~");
assert(private_nh.resolveName("baz") == "/param/foo");

with the launch file snippet from this answer.

Or is this not what to expect?

Comment by meyerj on 2020-02-24:
Furthermore I think what is meant by "assignment for private node parameters" in the original content of the wiki page is not remapping. Both, rospy and roscpp, support assigning parameters via "special" remappings _key:=value, but that is not the same as remapping parameter name ~key to ~value.

Comment by meyerj on 2020-02-24:
Found the problem with the snippet in my first post: The target of the remapping is not private, so private_nh.resolveName("baz") == "/foo", not "/param/foo".

$\endgroup$

Your Answer

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