The launch file

The launch file is a useful feature in ROS for launching more than one node. In these sections, we have created nodes and we have been executing them in different shells. Imagine working with 20 nodes and the nightmare of executing each one in a shell!

With the launch file, we can do it in the same shell by launching a configuration file with the extension .launch.

To practise using this utility, we are going to create a new folder in our package as follows:

    $ roscd chapter2_tutorials/
    $ mkdir launch
    $ cd launch
    $ vim chapter2.launch  

Now put the following code inside the chapter2.launch file:

<?xml version="1.0"?> 
<launch> 
  <node name ="example1_a" pkg="chapter2_tutorials" 
type="example1_a"/> <node name ="example1_b" pkg="chapter2_tutorials"
type="example1_b"/> </launch>

This file is simple, although you can write a very complex file if you want, for example, to control a complete robot, such as PR2 or Robonaut. Both are real robots and they are simulated in ROS.

The file has a launch tag; inside this tag, you can see the node tag. The node tag is used to launch a node from a package, for example, the example1_a node from the chapter2_tutorials package.

This launch file will execute two nodes-the first two examples of this chapter. If you remember, the example1_a node sends a message to the example1_b node.
To launch the file, you can use the following command:

    $ roslaunch chapter2_tutorials chapter2.launch  

You will see something similar to the following screenshot on your screen:

The running nodes are listed in the screenshot. You can also see the running nodes using the following command:

    $ rosnode list  

You will see the three nodes listed as follows:

When you launch a launch file, it is not necessary to execute it before the roscore command; roslaunch does it for us.

Remember that the example1_b node prints on the screen the message received from the other node. If you take a look, you won't see anything. This is because example1_b prints the message using ROS_INFO, and when you run only a node in a shell, you can see it, but when you run a launch file, you can't.

Now, to see the message printed on the screen, you can use the rqt_console utility. You will learn more about this utility in the following chapters. Now run the following command:

    $ rqt_console  

You will see the message sent by example1_b, as shown in the following screenshot:

On the line, you can see the message, the node that has sent it, and the path of the source file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.48.218