Size: 7752
Comment:
|
Size: 7872
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 182: | Line 182: |
`rxgraph` creates a dynamic graph of what's going on. |
`rxgraph` creates a dynamic graph of what's going on. Before we can use rxgraph we have to make the rxtools package: {{{ $ rosmake rxtools }}} Now let's look at rxgraph: |
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 covers using the roscore, rosnode, rxgraph, and rosrun commandline tools.
Tutorial Level: BEGINNER
Next Tutorial: Understanding ROS topics, services, and params
Contents
Quick Overview of Graph Concepts
Messages: ROS data structures
Nodes: a process in ROS that communicates with other Node processes
Topics: Topics stream Messages. Nodes can publish Messages to a Topic as well as subscribe to Messages.
Services: A Node can provide a Service, which receives a request Message and returns a response Message.
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 'private' name, uses the Node's name as a new namespace. These Names are sometimes called 'private' as 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, lets 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 ROS nodes currently running. The rosnode list command lists the nodes currently running.
$ rosnode list
This showed us that there was only one node: rosout. This is always running as it collects debugging output of Nodes and logs it.
/rosout
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, lets see some more Nodes. For this, we're going to use rosrun to bring up another Node.
Using rosrun
rosrun allows you to directly run a node within a package using the package name rather than having to know the package path.
Usage:
$ rosrun package_name node_name
So now we can run the talker.py node in the rospy_tutorials package:
$ rosrun rospy_tutorials talker.py
In a new terminal:
$ rosnode list
You will see something similar to:
/rosout /talker-ninja.local-68301-1251270608865
The name for the 'talker' node is kind of ugly -- it's an anonymous Node. In ROS, Nodes have to have unique names. This is because, in robot systems, you rarely want two Nodes doing the same thing: for example, if you have two laser drivers attempting to get data from the same laser, that's going to cause problems. We use the anonymous feature for Nodes that are safe to run multiple copies of.
One of the powerful features of the ROS is that you can reassign Names from the command-line. The anonymous Name above is ugly to work with, so lets give it a different name.
Go back to the rosrun window and use ctrl-C to stop the Node. Now lets re-run it, but this time use a Remapping Argument to change the Node's name:
rosrun rospy_tutorials talker.py __name:=talker
Now, if we go back and use rosnode list:
$ rosnode list
You will see something similar to:
/rosout /talker
We see our new /talker Node. Lets use another rosnode command, ping, to test that it's up:
$ rosnode ping talker
rosnode: node is [/talker] pinging /talker with a timeout of 3.0s xmlrpc reply from http://ninja.local:54748/ time=4.828930ms
Before we finish, it's time to introduce one more tool, rxgraph:
Using rxgraph
rxgraph creates a dynamic graph of what's going on. Before we can use rxgraph we have to make the rxtools package:
$ rosmake rxtools
Now let's look at rxgraph:
$ rxgraph
You will see something similar to:
Here the nodes and topics are highlighted in different colors. Here we can see that the talker node is publishing to the chatter and rosout topics while the rosout node is subscribed to the rosout and time topics.
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.