Ask Your Question
0

Node not able to get its namespace parameters

asked 2017-06-05 09:13:02 -0600

gnurf gravatar image

My code looks like:

rospy.init_node('images_feeder', anonymous=True)
params = rospy.get_param('~')

I'm pretty sure it used to work "before", but now it gives:

KeyError: '~'

The parameters server seems to be running because I can for example successfully:

print rospy.get_param('/rosdistro')

(which is indigo by the way). Between "before" and now, I performed several ros (system) packages updates, and maybe changed the way I run things (currently "roscore" in one terminal, "rosrun x y" in another).

Could this be a regression, or is there something more to do, so that the node can "get its namespace" ? Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-06-05 09:41:20 -0600

updated 2017-06-05 09:51:11 -0600

Are you sure that code worked previously? I'm not aware of any recent changes to rospy that would have changed this behavior, but I suppose I could have missed something. Also note that the KeyError being thrown is exactly what should happen if the parameter you are trying to get ("~") doesn't exist and you don't provide a default value (documentation here).

Regardless, there are a variety of functions specifically for getting names from the ROS graph in the rospy.names module. You could instead be using rospy.get_namespace() or perhaps rospy.get_name() (depending on what you are trying to do). Additionally rospy is slightly different from C++ in that you don't need a "private node handle" to be able to access private parameters. In other words, depending on what you are doing, you might not even need to get the namespace directly. You might be able to use something like rospy.get_param("~private_param1").

edit flag offensive delete link more

Comments

Actually, despite the wording of the question, I am not trying to get the namespace, but to later do:

x = params['x']
y = params['y']

My problem was, I was not longer providing these parameters (via command line or launch file). If I provide them, everything is fine.

gnurf gravatar imagegnurf ( 2017-06-05 13:27:40 -0600 )edit

So the confusing thing is: if the node does not have any parameter, it will fail on get_param('~'). I guess it's an implementation quirk.

gnurf gravatar imagegnurf ( 2017-06-05 13:28:35 -0600 )edit

Perhaps you'd actually want rospy.get_param_names?

jarvisschultz gravatar imagejarvisschultz ( 2017-06-05 16:02:33 -0600 )edit

That would have helped me debug the problem, but I really want it the way I wrote it, it's just the error that is confusing.

gnurf gravatar imagegnurf ( 2017-06-06 00:52:09 -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

2 followers

Stats

Asked: 2017-06-05 09:13:02 -0600

Seen: 518 times

Last updated: Jun 05 '17