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

Namespaces of Nodes

asked 2019-02-02 09:32:16 -0600

gktg1514 gravatar image

updated 2019-02-02 09:34:10 -0600

At first I executed the command roscore to activate name service and XMLRPC mechanism for node communation. Then, I launched two turtlesim nodes for turtle simulation which are turtlesim_node and teleop_turtle.

Finally, I executed the command rosnode list to display running nodes in ROS system. The output is demonstrated below.

/rosout

/teleop_turtle

/turtlesim

In this point, a question came to my mind. I have read names and namespaces section of wikiros. I am a little bit familiar with namespace concept.

Can we say that all nodes are located directly under global namespace ?

I am asking this question because when I list running nodes, names of these nodes begin with forward slash ( / ), which means that their namespaces are global namespace itself. Can we make such a generalization ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2019-02-03 23:47:18 -0600

robustify gravatar image

You can definitely run nodes in namespaces, and it is quite easy in lauch files. To run a node in a namespace, simply add the ns attribute to a <node> tag. For example:

<node pkg="foo" type="bar" name="my_node" ns="my_namespace" />

would run the bar node with runtime name my_node in the my_namespace namespace. Therefore, if you ran rosnode list now, you would see /my_namespace/my_node.

Running a node in a namespace allows the following:

  • You can run multiple instances of a node with the same name, as long as they are in different namespaces
  • All topics and services the node advertises or subscribes to are also placed in the same namespace, as long as there is no leading slash in the topic or service name string

There are some fancy things you can do with namespaces in launch files, like running a bunch of things in a namespace using <group>, or including other launch files and putting everything in those launch files into a namespace. Check out the roslaunch XML syntax documentation for more http://wiki.ros.org/roslaunch/XML

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-02-02 09:32:16 -0600

Seen: 8,581 times

Last updated: Feb 03 '19