Ask Your Question

rospy: node namespace is empty

asked 2018-02-16 08:49:29 -0600

knxa gravatar image

I got the impression that a node per default has a namespace matching the node name.

Mini example, I run this node:

import rospy

rospy.set_param('foo', 1)

I then run rosparam list, I get:

/rosversion /run_id

Why don't I get:


Why is the namespace of the node / and not /tester?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-02-16 09:07:02 -0600

updated 2018-02-16 10:48:50 -0600

Short answer. rospy nodes do not have a direct equivalent to roscpp ros::NodeHandle.

See (almost) duplicate question and answer - including way to resolve names relative to a rospy node's name - here.

Yes, for rospy, in order to have rosparam list generate this:


You will need to set the foo as a private parameter of the tester rospy node:

import rospy

rospy.set_param('~foo', 1)

Additional info:

edit flag offensive delete link more


Thanks for a quick reply! The resolve_name seems to work only for private parameters:

value = rospy.set_param('~bar', 'zzz')
rospy.loginfo('%s has value %s', rospy.resolve_name('~bar'), value)

... but does not work without the ~.

knxa gravatar image knxa  ( 2018-02-16 09:23:53 -0600 )edit

@knxa That is correct. When you call rospy.resolve_name('~bar'), you are telling ROS, "Give me the global name of relative name ~bar" - in this case /tester/bar. If you were to call rospy.set_param('foo', 1), then rospy.resolve_name('foo') would return /foo...

josephcoombe gravatar image josephcoombe  ( 2018-02-16 10:42:13 -0600 )edit

since / is the namespace in which the relative parameter name foo was declared. If you were to launch tester in another namespace ns1 (via roslaunch), then rospy.resolve_name('~bar') would return /ns1/tester/bar and rospy.resolve_name('food') would return /ns1/foo

josephcoombe gravatar image josephcoombe  ( 2018-02-16 10:43:10 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-02-16 08:49:29 -0600

Seen: 271 times

Last updated: Feb 16 '18