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

getNamespace returns double slash

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

Mago Nick gravatar image

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

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"/>

or

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

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

//vtol/attitude

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

Andrea

edit retag flag offensive close merge delete

Comments

can you please answer :https://answers.ros.org/question/306197/getnamespace-returns-incorrect-namespace/

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

@debonair: that is not how this works.

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

The issue in OP, which is a duplicate slash, same as what https://answers.ros.org/question/3061... 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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

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

thebyohazard gravatar image

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

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:

http://wiki.ros.org/roscpp/Overview/N...

http://wiki.ros.org/Names

edit flag offensive delete link more

Comments

That actually solved the issue. Thank you!!!

Mago Nick gravatar image Mago Nick  ( 2015-06-01 12:13:22 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 990 times

Last updated: Oct 19 '18