WEBVTT

00:00.080 --> 00:05.300
Now that you understand the purpose of launch files, let's see how to actually create one for your

00:05.300 --> 00:06.590
Ros2 application.

00:06.590 --> 00:11.570
And the first question is where do we create our launch files.

00:11.570 --> 00:16.310
So if I go to my workspace in the source folder you see I have three packages.

00:16.310 --> 00:18.080
So where do I create the launch file.

00:18.080 --> 00:22.400
Well technically you could add a launch file in any package.

00:22.400 --> 00:29.270
But as we did for our interfaces, we are going to create a dedicated package for the launch files.

00:29.270 --> 00:34.520
We will add all the launch files for our application and also configuration files for example the YAML

00:34.520 --> 00:35.120
files.

00:35.120 --> 00:40.340
This will make it much easier for you to handle dependencies in your application, and also later on

00:40.340 --> 00:42.020
if you check some other projects.

00:42.020 --> 00:48.290
If you find other robots for which the code is open source and on GitHub, you will find this organization

00:48.290 --> 00:49.490
all the time.

00:49.490 --> 00:51.500
So we're going to create a new package.

00:51.500 --> 01:00.170
And well let's just first you go to the source folder of your workspace and let's do Ros2 pkg Create.

01:00.170 --> 01:03.170
And I'm going to start with my robot.

01:03.200 --> 01:03.380
Okay.

01:03.410 --> 01:07.880
So if your robot is named ABC, you're going to write ABC.

01:07.880 --> 01:11.120
Just use the name of your robot or your application.

01:11.120 --> 01:14.180
And then I'm going to add the bring up suffix.

01:14.210 --> 01:14.480
Okay.

01:14.510 --> 01:19.340
So for interfaces we have interfaces for launch file we have bring up.

01:19.340 --> 01:21.140
This is really common okay.

01:21.170 --> 01:27.800
You will find this kind of bring up package in a lot of different GitHub projects if you browse online

01:27.800 --> 01:29.450
for different robots okay.

01:29.450 --> 01:31.610
So it's always the same thing.

01:31.610 --> 01:34.580
And I recommend that you use also the name bring up.

01:34.580 --> 01:38.270
Then what build type do we need to provide?

01:38.270 --> 01:45.860
Well we can provide payment CMake if we want, but we can also skip it which is going to create anyway,

01:46.010 --> 01:47.510
even CMake by default.

01:47.510 --> 01:50.660
And for the dependencies I'm not going to provide any dependency.

01:50.690 --> 01:54.770
Now we're going to add them as we add more stuff in our launch files.

01:54.770 --> 01:57.480
So basically just Ros2 pkg PG.

01:57.480 --> 01:58.800
Create my robot.

01:58.800 --> 01:59.580
Bring up.

02:00.270 --> 02:01.980
We have a new package.

02:02.010 --> 02:02.970
You see some logs?

02:02.970 --> 02:04.710
The warning for the license.

02:05.190 --> 02:05.520
Okay.

02:05.550 --> 02:06.900
And let's go inside.

02:06.900 --> 02:09.330
So RLS, we have the new package here.

02:09.330 --> 02:13.800
Let's go inside my robot bring up.

02:13.800 --> 02:15.030
And what do we have.

02:15.030 --> 02:21.060
Well, classic stuff with Cmakelists.txt that we will keep package dot XML.

02:21.090 --> 02:22.050
Very important.

02:22.050 --> 02:24.150
And then we have include and source.

02:24.150 --> 02:27.150
We don't need those folders so let's remove them.

02:27.330 --> 02:30.330
Let's remove include and let's remove source.

02:30.360 --> 02:35.730
Now I'm going to create a new folder right now called launch okay.

02:35.730 --> 02:40.800
So now in my package I have this launch folder and those two files.

02:40.800 --> 02:45.570
And in this launch folder I will write all the launch files for my application.

02:45.570 --> 02:46.050
Great.

02:46.050 --> 02:55.800
So now we can open uh let's just open the workspace with VSCode here from the source folder.

02:57.570 --> 03:02.460
And we can go to our bring up package.

03:02.460 --> 03:07.770
And what I'm going to do is I'm going to set up the package for installing the launch files.

03:07.800 --> 03:07.980
Okay?

03:08.010 --> 03:12.240
Just like when we created the interfaces package, we had a bit of setup here.

03:12.240 --> 03:16.560
We also have a bit of setup specific for launch files is going to be much quicker.

03:16.560 --> 03:21.330
First of all, we don't have to do anything in the package dot XML, so you can just keep it like this.

03:21.330 --> 03:23.820
You see we have build type A1, CMake.

03:23.850 --> 03:25.200
That's what we want.

03:25.200 --> 03:28.470
And then we're going to go to the Cmakelists.txt.

03:28.890 --> 03:32.520
And in that one I'm going to simplify the code here as well.

03:32.520 --> 03:34.560
I'm going to remove the build testing.

03:34.560 --> 03:36.270
We don't need that for now.

03:36.270 --> 03:38.130
And I'm going to remove those comments.

03:38.130 --> 03:44.400
And now basically the only instruction that we are going to provide here is to say that we want to install

03:44.400 --> 03:46.740
the launch folder, okay.

03:46.770 --> 03:49.230
And everything that's inside the launch folder.

03:49.230 --> 03:54.840
So I'm going to write install and then uppercase Directory.

03:55.590 --> 03:56.040
Okay.

03:56.070 --> 03:57.810
Let's go to New Line.

03:58.800 --> 03:59.910
I'm going to put launch.

03:59.940 --> 04:08.190
Launch is because that folder is named launch and then destination all uppercase.

04:08.280 --> 04:10.140
Make sure you don't make any typo.

04:10.140 --> 04:12.330
And then we are going to write share.

04:12.360 --> 04:12.840
Okay.

04:12.840 --> 04:16.740
So we are going to install this inside a share folder.

04:16.770 --> 04:16.950
Okay.

04:16.980 --> 04:20.220
That's going to be inside the install folder of your workspace.

04:20.220 --> 04:23.550
And it's important that you write share here slash.

04:23.550 --> 04:26.460
And then we're going to put the project name.

04:26.460 --> 04:31.890
So basically the package name with dollar sign and curly brackets.

04:31.920 --> 04:34.350
Make sure you don't put parentheses so often.

04:34.350 --> 04:35.610
This is a common mistake.

04:35.640 --> 04:40.890
But parentheses now it's curly brackets and project name.

04:40.890 --> 04:44.430
And you can add a slash here if you want.

04:44.460 --> 04:47.820
So okay make sure you write exactly this.

04:48.150 --> 04:48.390
Okay.

04:48.420 --> 04:54.840
So between find package and payment package you add this install instruction and that's basically it.

04:54.870 --> 05:00.030
Everything that we will write inside the launch folder here is going to be installed.

05:00.030 --> 05:01.920
So we only need to write this once.

05:01.920 --> 05:02.790
That's it.

05:02.820 --> 05:05.130
Let's make sure we save.

05:05.130 --> 05:07.650
And while the package is correctly configured.

05:07.650 --> 05:08.730
So that's basically it.

05:08.730 --> 05:11.190
You create a Myrobot package.

05:11.190 --> 05:14.880
Then you create a launch folder and you install this launch folder.

05:14.910 --> 05:17.700
Now let's create our first launch file.

05:17.700 --> 05:21.330
For this we are going to add it inside the launch folder.

05:21.330 --> 05:23.190
So you could go to the terminal.

05:23.190 --> 05:34.530
I can also just create it here and let's name it number app dot launch dot XML okay so what I'm going

05:34.560 --> 05:37.110
to start the number of application from this launch file.

05:37.110 --> 05:38.820
What I want to do is start different nodes.

05:38.820 --> 05:43.980
So for this example I'm going to start the number publisher and the number counter that we have created

05:43.980 --> 05:45.240
previously in this course.

05:45.240 --> 05:48.750
So I'm just going to name this application number app.

05:48.780 --> 05:55.210
Then you have dot launch and then dot XML because we write an XML file.

05:55.330 --> 05:55.780
Okay.

05:55.810 --> 06:00.730
And you can see this is inside the launch folder inside the package.

06:00.730 --> 06:04.930
So you can do that from the terminal, from VSCode from anywhere you want.

06:04.960 --> 06:08.260
And then we are going to initialize our launch file.

06:08.260 --> 06:09.310
And for that it's very easy.

06:09.310 --> 06:11.290
So we're going to write XML code.

06:11.290 --> 06:14.170
And we need a launch tag.

06:14.170 --> 06:20.950
So you open a launch tag like this and you close the launch tag and that's it.

06:20.980 --> 06:22.780
Your launch file is initialized.

06:22.780 --> 06:28.420
So for every launch file you create in rust with XML, you need to add those launch tags.

06:28.420 --> 06:31.810
And everything you write is going to be inside this.

06:31.810 --> 06:38.080
Then you don't need to provide any indentation okay, it's XML, but still I'm going to add an indentation

06:38.080 --> 06:39.220
for readability.

06:39.220 --> 06:45.550
And in this launch file let's say we want to start two nodes I want to start the number publisher node

06:45.550 --> 06:47.410
and the number counter node.

06:47.440 --> 06:51.610
To start a node you can provide the node tag just like that.

06:51.610 --> 06:58.960
So you open it and inside the node tag you have a pkg argument that's going to be the package where

06:58.960 --> 06:59.650
the node.

06:59.800 --> 07:02.380
So actually where the executable is.

07:02.410 --> 07:06.520
And for example let's start the one from my pi pkg.

07:06.940 --> 07:09.970
And then we have exec okay.

07:10.000 --> 07:15.430
So we have pkg and exec exec is the executable.

07:15.430 --> 07:19.870
So number publisher actually you could just check that.

07:19.870 --> 07:25.270
So here I can do Ros to run package name okay.

07:25.300 --> 07:26.560
Executable name.

07:27.130 --> 07:33.010
So to construct a so number publisher to construct a launch file you can just run the commands here

07:33.010 --> 07:36.010
one by one all the nodes inside terminals.

07:36.010 --> 07:41.080
And then you can just take the names that you have written here just to make sure that this is correct.

07:41.080 --> 07:42.490
You see my pi pkg.

07:42.850 --> 07:45.100
That's the package and number publisher.

07:45.100 --> 07:46.480
That's the executable.

07:46.600 --> 07:48.280
And I'm going to close.

07:48.310 --> 07:49.810
It's just going to be one line for now.

07:49.810 --> 07:51.550
So I'm going to close like this.

07:51.670 --> 07:51.970
Okay.

07:52.000 --> 07:54.790
With a forward slash and a bracket.

07:54.820 --> 07:59.320
And so what will happen if I launch if I start this launch file.

07:59.320 --> 08:02.410
Well it's going to start that executable.

08:02.410 --> 08:05.830
Just like if you would run that node in the terminal.

08:05.860 --> 08:06.880
Same thing.

08:06.910 --> 08:10.570
Now let's say that I want to start the number counter.

08:10.570 --> 08:11.890
And this time let's change.

08:11.890 --> 08:17.020
Let's use the C plus plus package number counter.

08:17.020 --> 08:20.770
So you see package executable name.

08:20.770 --> 08:24.940
So I'm adding another node tag pkg.

08:25.330 --> 08:33.400
My cp pkg and exec is going to be number counter.

08:33.670 --> 08:33.910
Okay.

08:33.910 --> 08:36.790
Just like if you would run that on the terminal.

08:36.820 --> 08:37.120
Okay.

08:37.150 --> 08:39.610
And with this simple launch file we have four lines.

08:39.610 --> 08:41.950
Then we have started two nodes.

08:41.980 --> 08:42.220
Okay.

08:42.250 --> 08:43.930
No configuration nothing.

08:43.930 --> 08:46.120
We're going to add that in the following lessons.

08:46.120 --> 08:48.320
But you see with just this we start two nodes.

08:48.320 --> 08:49.700
I'm going to save this.

08:49.700 --> 08:56.420
And also because you see that from my robot bring up, we are going to execute stuff from two other

08:56.420 --> 08:57.230
packages.

08:57.230 --> 09:03.230
So because of that I'm going to go inside my package dot XML of the My Robot Bringer package.

09:03.230 --> 09:06.470
And after here I'm going to add dependencies.

09:06.530 --> 09:06.950
Okay.

09:06.980 --> 09:10.700
So usually I have written the depend tag.

09:11.210 --> 09:20.030
But for large files you could also use the exec depend tag because well, exec depend is a bit less

09:20.030 --> 09:21.590
strict than depend.

09:21.590 --> 09:25.520
And it just means that you need the dependencies for execution.

09:25.550 --> 09:25.910
Okay.

09:25.940 --> 09:30.530
Not for compiling, not for building anything, just for execution.

09:30.560 --> 09:30.950
All right.

09:30.980 --> 09:33.080
We're not going to compile any code here.

09:33.080 --> 09:36.950
We just say that we need this package when we execute the launch file.

09:36.950 --> 09:39.140
So we can use exec depend.

09:39.140 --> 09:41.780
And my pi pkg okay.

09:41.810 --> 09:53.600
Here execute depend and then exec depend with my cp pkg exec depend.

09:53.600 --> 10:00.260
So as a best practice, whenever you see you start to use a new package inside a launch file in this

10:00.260 --> 10:08.000
package here, then you add the package with exec, depend in the package dot XML file and let's save

10:08.000 --> 10:08.570
everything.

10:08.570 --> 10:10.280
Now we can go back to the terminal.

10:10.280 --> 10:14.000
Let's let's go back to our workspace.

10:14.000 --> 10:16.190
And let's build on build.

10:16.880 --> 10:22.190
Let's use packages select to just build my robot.

10:22.220 --> 10:27.680
Bring up and use the Autocompletion once again okay.

10:27.680 --> 10:30.260
So this one is always going to be quite quick.

10:30.290 --> 10:31.910
There is nothing really to compile.

10:31.910 --> 10:35.960
It's just going to install the the file somewhere in the install folder.

10:35.960 --> 10:37.070
And now to start it.

10:37.100 --> 10:38.930
Well to start it is very easy.

10:38.930 --> 10:40.580
I'm just going to keep this terminal here.

10:40.580 --> 10:48.200
I'm going to make sure that I source My workspace here with the setup that bash.

10:48.230 --> 10:54.650
And then well, let's do this to have more space then we can do Ros2 launch.

10:54.680 --> 10:55.130
Okay.

10:55.130 --> 10:57.680
So for node you do Ros to run.

10:57.680 --> 11:00.530
If you want to start a launch file, you do Ros to launch.

11:00.530 --> 11:04.790
And then you need to provide what the package where the launch file is.

11:04.790 --> 11:06.200
So that's my robot.

11:06.230 --> 11:08.960
Bring up my robot.

11:09.020 --> 11:11.150
Bring up using Autocompletion.

11:11.150 --> 11:13.490
And if I press tab twice here.

11:14.030 --> 11:16.760
Well you see I have some options and stuff.

11:16.760 --> 11:20.900
But you see I have my number app dot launch dot XML.

11:20.900 --> 11:27.080
So if I just start number app you see I can find it with Autocompletion.

11:27.200 --> 11:31.490
So Ros2 launch package name and then launch file name.

11:31.490 --> 11:36.440
Let's start it and you can see what do we have here.

11:36.440 --> 11:37.490
We have a few logs.

11:37.490 --> 11:42.260
So stuff where you can find logs here logging verbosity.

11:42.260 --> 11:49.640
And then you see that for each executable that we start in the launch file, we have a log saying that

11:49.640 --> 11:51.050
we have started the process.

11:51.080 --> 11:52.730
It even gives you the PID.

11:52.730 --> 11:54.230
So the process ID here.

11:54.230 --> 11:59.180
And you see now we have started an executable named number publisher one.

11:59.180 --> 12:00.620
Number counter two.

12:00.650 --> 12:00.890
Okay.

12:00.920 --> 12:03.320
So that's the executable that has been started.

12:03.320 --> 12:04.760
And then you see the logs.

12:04.790 --> 12:07.940
Those are the logs that we directly print from the nodes.

12:07.940 --> 12:12.230
So we have the number counter node and we have the number publisher node.

12:12.260 --> 12:15.770
Now well actually I'm going to start some terminals here.

12:17.210 --> 12:24.230
If I do ros2 node list you see I have my two nodes okay.

12:24.260 --> 12:27.020
I didn't need to start them from two terminals.

12:27.020 --> 12:29.480
I just started them from the same launch file.

12:29.510 --> 12:30.230
Okay.

12:30.530 --> 12:37.730
If I do ros2 topic list, you see I have my number topic and my number count topic.

12:37.730 --> 12:44.610
If I do ros2 topic equal number counts just to check that it works.

12:45.780 --> 12:53.640
And you see I have my data here so it's correctly working I can do RCT graph.

12:56.250 --> 12:58.110
And well you might refresh.

12:58.110 --> 13:00.120
You put nodes topics all.

13:00.150 --> 13:06.300
You also uncheck those boxes here and you will have also that view okay.

13:06.330 --> 13:07.920
So everything is correctly working.

13:07.920 --> 13:09.690
Our application has been launched.

13:09.690 --> 13:16.260
We've just you see this command line and that's how you create an XML launch file.

13:16.260 --> 13:22.620
So if you want to create a new one you just add a new file here in the launch folder you start with

13:22.650 --> 13:27.390
a launch tag, and then you add one node tag for each node that you want to start.

13:27.390 --> 13:28.650
And then that's it.

13:28.650 --> 13:34.230
You just make sure that you build the package again and that you source the environment.

13:34.230 --> 13:39.570
And then you can just do Ros2 launch package and launch file name.
