Ask Your Question
1

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

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 imagedebonair ( 2018-10-19 08:47:31 -0600 )edit
1

@debonair: that is not how this works.

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

1 Answer

Sort by ยป oldest newest most voted
2

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:

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 imageMago 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

Stats

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

Seen: 512 times

Last updated: Oct 19 '18