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

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

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

jwhendy gravatar image

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

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():

rospy.init_node('my_node_name')

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
2

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

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

Question Tools

2 followers

Stats

Asked: 2017-05-16 10:38:55 -0500

Seen: 5,663 times

Last updated: May 17 '17