Ask Your Question

rospy equivalent to ros::NodeHandle nh("namespace")

asked 2017-05-16 10:38:55 -0600

jwhendy gravatar image

updated 2017-05-16 10:40:15 -0600

I'm very new to ROS and am [slightly] more versed in python than C++, so that's the route I'm currently pursuing in my learning. One option that is shown in the C++ tutorials is how one would set a custom namespace or parent namespace :

You can also specify a parent NodeHandle and a namespace to append:

### adding the initialization call from above
ros::init(argc, argv, "my_node_name");

ros::NodeHandle nh1("ns1");
ros::NodeHandle nh2(nh1, "ns2");

In the python information, I've only ever seen this used, which I take as equivalent to ros::init():


How would one put node my_node_name into a custom or parent namespace using rospy?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-05-17 21:20:04 -0600

ahendrix gravatar image

rospy doesn't have a direct analog to the ros::NodeHandle in C++. If you do need to resolve names relative to the node name (or another name) in Python, you can use rospy.resolve_name(name, caller_id=None), but instead of a dedicated object this just return a string.

There's some documentation about this on the rospy Names and Node Information wiki.

edit flag offensive delete link more

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: 2017-05-16 10:38:55 -0600

Seen: 4,325 times

Last updated: May 17 '17