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

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.init_node('tester')
rospy.set_param('foo', 1)
rospy.spin()

I then run rosparam list, I get:

/foo
/rosdistro
/roslaunch/uris/host_knxps13_local__35409
/rosversion /run_id

Why don't I get:

 /tester/foo

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
1

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.


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

/tester/foo     
/rosdistro     
/roslaunch/uris/host_knxps13_local__35409     
/rosversion   
/run_id

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

import rospy

rospy.init_node('tester')
rospy.set_param('~foo', 1)
rospy.spin()

Additional info:
http://wiki.ros.org/rospy/Overview/Pa...
http://wiki.ros.org/rospy_tutorials/T...
http://wiki.ros.org/Names#Resolving

edit flag offensive delete link more

Comments

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

Question Tools

2 followers

Stats

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

Seen: 683 times

Last updated: Feb 16 '18