Ask Your Question

getNamespace returns double slash

asked 2015-06-01 10:45:16 -0600

Mago Nick gravatar image

updated 2015-06-01 10:45:36 -0600

Hello everybody, I am experiencing a weird error. Considering a launch file where I launch a node in either of the two following ways

<node name="velocity_control" pkg="uav_velocity_control" type="ControlNode"  ns="vtol" output="screen"/>


  <group ns="vtol">
    <node name="velocity_control" pkg="uav_velocity_control" type="ControlNode"  output="screen"/>   

In my node I have the following line of code

ros::Subscriber sub = n.subscribe(ros::this_node::getNamespace() + "/attitude", queue_size, callbackAngularVelocities);

However if I print the obtained topic name

std::cout << ros::this_node::getNamespace() << "/attitude" << std::endl;

I obtain


I cannot understand this behaviour. I temporarily solved hardcoding the namespace in the node, but I believe you understand the importance of setting the namespaces in the launch file.

Thank you very much


edit retag flag offensive close merge delete


can you please answer :

debonair gravatar image debonair  ( 2018-10-19 08:47:31 -0600 )edit

@debonair: that is not how this works.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-19 08:54:58 -0600 )edit

The issue in OP, which is a duplicate slash, same as what is asking, seems to be a bug. I posted some info in the same link.

130s gravatar image 130s  ( 2021-06-11 11:48:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-01 11:14:40 -0600

tbh gravatar image

updated 2015-06-01 11:17:26 -0600

You should use a nodehandle with a relative namespace instead. The node's namespace includes the full path of the node, including the root. However, your nodehandle is probably the default, which is relative to the node. In this case, it's / . Creating a new nodehandle with the node's private namespace, ~ should fix your error.

Try this:

ros::NodeHandle private_n("~");
ros::Subscriber sub = private_n.subscribe("attitude", queue_size, callbackAngularVelocities);

EDIT for further reading:

edit flag offensive delete link more


That actually solved the issue. Thank you!!!

Mago Nick gravatar image Mago Nick  ( 2015-06-01 12:13:22 -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

1 follower


Asked: 2015-06-01 10:45:16 -0600

Seen: 814 times

Last updated: Oct 19 '18