Revision 41 as of 2009-09-03 22:04:33

Clear message

Note: This tutorial assumes that you have completed the previous tutorial, creating a ROS msg and srv.

Understanding ROS Nodes

Description: This tutorial introduces ROS graph concepts and discusses the use of roscore, rosnode, rxgraph, and rosrun commandline tools.

Tutorial Level: BEGINNER

Next Tutorial: Understanding ROS topics, services, and params

Quick Overview of Graph Concepts

  • Messages: ROS data structures

  • Nodes: A Node really isn't much more than an executable file within a ROS Package, except that it also uses a ROS client library to communicate with other Nodes.

  • Topics: Topics stream Messages. Nodes can publish Messages to a Topic as well as subscribe to Messages.

  • Services: Services receive a request Message and return a response Message. A Node can provide a Service.

  • Master: Name service for ROS (i.e. helps Nodes find each other)

  • Parameter Server: centralized dictionary of key/value pairs

  • rosout: ROS equivalent of stdout/stderr

  • roscore: Master + Parameter Server + rosout

Quick Overview of Names

Parameters, Nodes, Topics, and Services all have Names. Names in ROS are hierarchical, with slashes ("/") used to denote a namespace.

There are three ways in which you will see Names written:

  • /global/name: this is the full, canonical representation of the Name

  • relative/name: a relative name is resolved relative to the Node's namespace.

  • ~local/name: a local name, sometimes call a 'private' name, uses the Node's name as a new namespace. These Names are sometimes called 'private' because resources with these names are not easily seen by other Nodes.

To give a concrete example, inside of a Node named /wg/robot1/mynode:

  • /foo/bar resolves to /foo/bar

  • foo/bar resolves to /wg/robot1/foo/bar

  • ~foo/bar resolves to /wg/robot1/mynode/foo/bar

ROS allows Names to be remapped at the command-line when Nodes are started. The tutorials on this page will show you how to do this, and why this is powerful.

Quick Environment Variable Setup

  • ROS_MASTER_URI: this points to the location of the ROS Master. By default, this is usually http://localhost:11311. If you are using ROS to communicate between machines, you will have to point to the correct machine and port.

  • ROS_IP/ROS_HOSTNAME: (optional) if you are using multiple machines, you may have to set this correctly. In particular, many machines default to a name like "foo.local", which isn't visible to other machines. Choosing the value for this variable is easy: set it to whatever you would use in a 'ping' command to ping your machine.

Nodes

A Node really isn't much more than an executable file within a ROS Package, except that it also uses a ROS client library to communicate with other Nodes. In order to get familiar with Nodes, let's startup the roscore:

$ roscore

You will see something similar to:

  • ... logging to ~/ros/ros/log/3a5749c2-965f-11de-8875-001b21201aa8/roslaunch-aqy-3581.log
    ... loading XML file [~/ros/ros/tools/roslaunch/roscore.xml]
    Added core node of type [rosout/rosout] in namespace [/]
    started roslaunch server http://aqy:56911/
    
    SUMMARY
    ========
    
    NODES
    
    starting new master (master configured for auto start)
    process[master]: started with pid [3613]
    ROS_MASTER_URI=http://aqy:11311/
    setting /run_id to 3a5749c2-965f-11de-8875-001b21201aa8
    +PARAM [/run_id] by /roslaunch
    +PARAM [/roslaunch/uris/aqy:56911] by /roslaunch
    process[rosout-1]: started with pid [3628]
    started core service [/rosout]
    +SERVICE [/rosout/get_loggers] /rosout http://aqy:53163/
    +SERVICE [/rosout/set_logger_level] /rosout http://aqy:53163/
    +SUB [/time] /rosout http://aqy:53163/
    +PUB [/rosout_agg] /rosout http://aqy:53163/
    +SUB [/rosout] /rosout http://aqy:53163/

In a new terminal, let's investigate what typing roscore did:

Using rosnode

rosnode displays information about the ROS nodes that are currently running. The rosnode list command lists these active nodes:

$ rosnode list
  • You will see:
  • /rosout

This showed us that there is only one node running: rosout. This is always running as it collects and logs Nodes' debugging output.

The rosnode info command returns information about a specific node.

$ rosnode info /rosout

This gave us some more information about rosout, such as the fact that it publishes /rosout_agg.

  • --------------------------------------------------------------------------------
    Node [/rosout]
    
    Publications:
     * /rosout_agg [roslib/Log]
    
    Subscriptions:
     * /time [unknown type]
     * /rosout [unknown type]
    
    Services:
     * /rosout/set_logger_level
     * /rosout/get_loggers
    
    contacting node http://foo.local:54614/ ...
    Pid: 5092

Now, let's see some more Nodes. For this, we're going to use rosrun to bring up another Node.

Using rosrun

rosrun allows you to use the package name to directly run a Node within a package (without having to know the package path).

Usage:

$ rosrun [package_name] [node_name]

So now we can run the turtlesim node in the turtlesim package, in a new terminal:

$ rosrun turtlesim turtlesim

You will see the tutrlesim window:

In a new terminal:

$ rosnode list

You will see something similar to:

  • /rosout
    /turtlesim

One powerful feature of ROS is that you can reassign Names from the command-line.

Go back to the rosrun window and use ctrl-C to stop the Node. Now let's re-run it, but this time use a Remapping Argument to change the Node's name:

rosrun turtlesim turtlesim __name:=my_tutrle

Now, if we go back and use rosnode list:

$ rosnode list
  • You will see something similar to:
  • /rosout
    /my_turtle

We see our new /my_turtle Node. Let's use another rosnode command, ping, to test that it's up:

$ rosnode ping my_turtle
  • rosnode: node is [/my_turtle]
    pinging /my_turtle with a timeout of 3.0s
    xmlrpc reply from http://aqy:42235/     time=1.152992ms
    xmlrpc reply from http://aqy:42235/     time=1.120090ms
    xmlrpc reply from http://aqy:42235/     time=1.700878ms
    xmlrpc reply from http://aqy:42235/     time=1.127958ms

Before we finish, it's time to introduce one more tool, rxgraph:

Using rxgraph

rxgraph creates a dynamic graph of what's going on in the system. Before we can use rxgraph, we have to make the rxtools package. In a new terminal:

$ rosmake rxtools

Now let's look at rxgraph:

$ rxgraph

You will see something similar to:

rxgraph(node_tutorial)0.png

Here the nodes and topics are highlighted in different colors. Here we can see that the my_turtle node is publishing to the turtle_pose and rosout topics and subscribed to the command_velocity topic. While the rosout node is subscribed to the rosout and time topics and publishing to rosout_agg topic.

rxgraph(node_tutorial).png

Now that you understand how ROS nodes work, let's look at how ROS topics, services, and params work. Also, feel free to press Ctrl-C to stop rosrun and rxgraph.