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

Accessing node namespace in code assigned by roslaunch

asked 2022-09-07 09:26:33 -0500

JaFeKl gravatar image

updated 2023-06-18 10:05:39 -0500

lucasw gravatar image

Hello everyone,

I have the following problem. I am running a node from a launch file based on a group ns.

<launch>  
 <group ns = "transferunit_1">  
<node name="transferunit1_hardware", pkg="transferunit_hardware"/>  
</group>  
</launch>

This makes the node correctly be started in the namespace. /transferunit_1/transferunit_hardware

In the .cpp file of the node I'am currently doing the following:

ros::init(argc, argv, "transferunit_hardware");  
std::string ns = ros::thisnode::getNamespace();

However, ns is just empty "/" ....

How can I access the namespace that has been assigned during roslaunch?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-07 16:55:34 -0500

Mike Scheutzow gravatar image

I don't recognize the ros::thisnode syntax you used, there are 0 hits for it in google search, and it doesn't compile on my machine. This is the standard way to obtain the current namespace:

ros::init(argc, argv, "my_ros_node");
ros::NodeHandle nh;
std::string ns = nh.getNamespace();
edit flag offensive delete link more

Comments

This might be a typo.

ros::this_node does exist, and contains a class ThisNode which does have a method getNameSpace(). See the documentation. The same method exists as a free function in the ros::this_node namespace (see here).

gvdhoorn gravatar image gvdhoorn  ( 2022-09-08 02:34:09 -0500 )edit

ros::thisnode::getNamespace();

@gvdhoorn More like 3 typos! Thanks for the information, I haven't seen that class before.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-09-08 06:33:14 -0500 )edit

Question Tools

Stats

Asked: 2022-09-07 09:26:33 -0500

Seen: 46 times

Last updated: Sep 07 '22