Accessing node namespace in code assigned by roslaunch
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. /transferunit1/transferunithardware
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?
Asked by JaFeKl on 2022-09-07 09:26:33 UTC
Answers
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();
Asked by Mike Scheutzow on 2022-09-07 16:55:34 UTC
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).
Asked by gvdhoorn on 2022-09-08 02:34:09 UTC
ros::thisnode::getNamespace();
@gvdhoorn More like 3 typos! Thanks for the information, I haven't seen that class before.
Asked by Mike Scheutzow on 2022-09-08 06:33:14 UTC
Comments