Note: This tutorial assumes that you have completed the previous tutorials: Understanding ROS services and parameters.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Using rxconsole and roslaunch

Description: This tutorial introduces ROS using rxconsole and rxloggerlevel for debugging and roslaunch for starting many nodes at once.

Tutorial Level: BEGINNER

Next Tutorial: Using rosed

/!\ This tutorial page is obsolete starting from ROS groovy. Please see ROS/Tutorials/UsingRqtconsoleRoslaunch and come back if necessary.

Prerequisites rxtools and turtlesim package

The tutorial uses both the rxtools and turtlesim packages. To do this tutorial, please install both packages, if you have not yet.

$ sudo apt-get install ros-<distro>-rx ros-<distro>-turtlesim 

Replace <distro> with the name of your ROS distribution (e.g. electric, fuerte, groovy).

NOTE: you may have already built rxtools and turtlesim for one of the previous tutorials. If you are not sure, installing them again will not hurt anything.

Using rxconsole and rxloggerlevel

rxconsole attaches to ROS's logging framework to display output from nodes. rxloggerlevel allows us to change the verbosity level (DEBUG, WARN, INFO, and ERROR) of nodes as they run.

Now let's look at the turtlesim output in rxconsole and switch logger levels in rxloggerlevel as we use turtlesim. Before we start the turtlesim, in two new terminals start rxconsole and rxloggerlevel:

$ rxconsole

$ rxloggerlevel

You will see two windows popup:

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/rxconsole(start).png

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/rxloggerlevel.png

Now let's start turtlesim in a new terminal:

$ rosrun turtlesim turtlesim_node

Since the default logger level is INFO you will see any info that the turtlesim publishes when it starts up, which should look like:

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/rxconsole(turtlesimstart).png

Now let's change the logger level to Warn by refreshing the nodes in the rxloggerlevel window and selecting Warn as shown below:

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/rxloggerlevel(error).png

Now let's run our turtle into the wall and see what is displayed in our rxconsole:

rostopic pub /turtle1/command_velocity turtlesim/Velocity -r 1 -- 2.0  0.0

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/rxconsole(turtlesimerror).png

Quick Note about logger levels

Logging levels are prioritized in the following order:

Fatal
Error
Warn
Info
Debug

Fatal has the highest priority and Debug has the lowest. By setting the logger level, you will get all messages of that priority level or higher. For example, by setting the level to Warn, you will get all Warn, Error, and Fatal logging messages.

Let's Ctrl-C our turtlesim and let's use roslaunch to bring up multiple turtlesim nodes and a mimicking node to cause one turtlesim to mimic another:

Using roslaunch

roslaunch starts nodes as defined in a launch file.

Usage:

$ roslaunch [package] [filename.launch]

First we must make a launch file. In your beginner_tutorials package let's make a launch directory and create a launch file:

$ roscd beginner_tutorials 
$ mkdir launch
$ cd launch

If roscd fails, remember to set the ROS_PACKAGE_PATH variable in your terminal. Then the commands will look like this:

$ export ROS_PACKAGE_PATH=~/fuerte_workspace/sandbox:$ROS_PACKAGE_PATH
$ roscd beginner_tutorials 
$ mkdir launch
$ cd launch

If you still cannot find the beginner_tutorials then go back and follow the instructions on creating a package in the second lesson

[http://www.ros.org/wiki/ROS/Tutorials/CreatingPackage]

The Launch File

Now let's create a launch file called turtlemimic.launch and paste the following:

   1 <launch>
   2 
   3   <group ns="turtlesim1">
   4     <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
   5   </group>
   6 
   7   <group ns="turtlesim2">
   8     <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
   9   </group>
  10         
  11   <node pkg="turtlesim" name="mimic" type="mimic">
  12     <remap from="input" to="turtlesim1/turtle1"/>
  13     <remap from="output" to="turtlesim2/turtle1"/>
  14   </node>
  15 
  16 </launch>

The Launch File Explained

Now, let's break the launch xml down.

   1 <launch>

Here we start the launch file with the launch tag, so that the file is identified as a launch file.

   3   <group ns="turtlesim1">
   4     <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
   5   </group>
   6 
   7   <group ns="turtlesim2">
   8     <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
   9   </group>

Here we start two groups with a namespace tag of turtlesim1 and turtlesim2 with a turtlesim node with a name of sim. This allows us to start two simulators without having name conflicts.

  11   <node pkg="turtlesim" name="mimic" type="mimic">
  12     <remap from="input" to="turtlesim1/turtle1"/>
  13     <remap from="output" to="turtlesim2/turtle1"/>
  14   </node>

Here we start the mimic node with the topics input and output renamed to turtlesim1 and turtlesim2. This renaming will cause turtlesim2 to mimic turtlesim1.

  16 </launch>

This closes the xml tag for the launch file.

roslaunching

Now let's roslaunch the launch file:

$ roslaunch beginner_tutorials turtlemimic.launch

Two turtlesims will start and in a new terminal send the rostopic command:

$ rostopic pub /turtlesim1/turtle1/command_velocity turtlesim/Velocity -r 1 -- 2.0  -1.8

You will see the two turtlesims start moving even though the publish command is only being sent to turtlesim1.

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/mimic.png

We can also use rxgraph to better understand what our launch file did:

$ rxgraph

http://ros.org/images/wiki/UsingRxconsoleRoslaunch/mimiclaunch.png

Now that you have successfully used rxconsole and roslaunch, let's learn about editor options for ROS. You can Crtl-C all your turtlesims, as you will not need them for the next tutorials.

Wiki: th/ROS/Tutorials/UsingRxconsoleRoslaunch (last edited 2014-11-19 04:54:45 by AkkharaphongEKSIRI)