WEBVTT

00:00.260 --> 00:07.220
In this lesson, we will create our first launch file to start visualizing the RDF model of the robot

00:07.220 --> 00:08.120
in RVs.

00:08.630 --> 00:14.900
The output will be very similar to the previous laboratory lesson, but this time we will be using just

00:14.900 --> 00:18.920
one terminal and just one command to start the launch file.

00:19.710 --> 00:20.910
To create a launch file.

00:20.910 --> 00:22.890
Let's open Visual Studio code.

00:22.890 --> 00:29.250
And so in the Arduino board description folder, where we have already created the Urdf model for our

00:29.250 --> 00:34.470
robot, let's create a new folder called Launch.

00:34.710 --> 00:37.950
And here let's create a new file called

00:38.610 --> 00:43.680
display.launch.py.

00:44.370 --> 00:51.690
As I mentioned in the theoretical lessons launch file in Ros two is a python file in which we can define

00:51.690 --> 00:54.270
a list of instructions to be executed.

00:54.570 --> 00:57.750
This list is called launch description.

00:57.750 --> 01:00.180
So let's start importing this class.

01:00.180 --> 01:11.100
So from the launch library, let's import the launch description class and then we need to define a

01:11.100 --> 01:11.910
new function.

01:11.910 --> 01:17.730
So let's call this one generate launch

01:19.620 --> 01:20.790
description.

01:21.300 --> 01:24.780
And this is executed when we launch the launch file.

01:24.780 --> 01:31.830
So when we start this file and here we need to define all the components that needs to be started and

01:31.830 --> 01:36.510
it will return a launch description object with all these components.

01:36.510 --> 01:46.040
So let's return a launch description object that contains a list of all the applications.

01:46.040 --> 01:52.260
So of all the nodes that we want to start over the action in general that we want to start with this

01:52.260 --> 01:53.070
launch file.

01:54.060 --> 01:56.520
As we did in the previous laboratory lesson.

01:56.520 --> 01:59.740
Let's start by executing the first node.

01:59.760 --> 02:06.420
So the robot estate publisher node, which is the one that reads the RDF model of the robot and publish

02:06.420 --> 02:10.170
it within our Ros2 topic to start a node.

02:10.200 --> 02:23.720
Let's import from the launch Ros library and from the actions module, let's import the node class and

02:23.730 --> 02:26.590
now we can use it to create a new instance of this node.

02:26.610 --> 02:31.380
So a new variable called Robot State.

02:34.380 --> 02:39.120
Publisher, for instance, that is an object of the node class.

02:39.150 --> 02:44.820
And here in the constructor of the Node class, we need to specify the package that contains the node

02:44.820 --> 02:46.240
that we want to start.

02:46.260 --> 02:58.200
So the package is the robot state publisher and the next we also need to specify the name of the node

02:58.230 --> 02:59.760
that we want to start.

03:00.060 --> 03:09.150
So let's start the X code table that has the same name of the package.

03:09.150 --> 03:15.510
So also this one is called Robot State Publisher.

03:15.510 --> 03:19.680
And the next we also need to configure this node with some parameters.

03:19.680 --> 03:25.260
So specifically, we need to indicate where the Urdf model of our robot is located.

03:25.350 --> 03:37.470
So let's set the parameters and let's set specifically the robot description parameter.

03:37.470 --> 03:43.710
And to this one we need to assign the directory where in our PC is the robot description?

03:43.710 --> 03:52.770
For the moment, let's store this one in a variable that we are going to call robot Description.

03:52.770 --> 03:56.760
So now we need to assign a value to this variable here.

03:56.880 --> 04:03.360
And to create this variable we need to declare an argument for this launch file which can be changed

04:03.360 --> 04:05.070
when the launch file is started.

04:05.070 --> 04:11.370
So for example, you can use in the future this same launch file to visualize also other urdf model

04:11.370 --> 04:14.610
of other robot that you might create in the future.

04:15.350 --> 04:17.990
To declare an argument for a launch file.

04:17.990 --> 04:30.170
Let's import from the launch library and from the actions module, the declare launch argument class.

04:30.170 --> 04:33.550
And now let's use this one to declare a launch argument.

04:33.560 --> 04:42.140
Let's call, for example, this one model arc as an instance of the declare launch argument, and this

04:42.140 --> 04:48.200
one will contain the name and the directory of the Urdf model that we want to visualize in our case.

04:48.680 --> 04:53.120
So the name let's call this one model.

04:53.120 --> 04:55.250
So this is the name of the argument.

04:55.250 --> 04:56.510
And by default.

04:56.510 --> 05:03.200
So if this argument is not set by the user who started this launch file, we want to visualize the urdf

05:03.200 --> 05:04.730
model of our robot.

05:04.730 --> 05:07.130
So the Arduino but Urdf sacrum.

05:07.430 --> 05:10.160
And so here let's set a default value.

05:11.970 --> 05:15.270
And as we want to indicate, a path to our directory.

05:15.270 --> 05:24.300
So to the directory where the Urdf model is stored, let's import the OS library from Pi for Python

05:24.540 --> 05:29.370
and let's use the OS path.

05:31.210 --> 05:35.530
Join function and also let's import.

05:36.730 --> 05:43.330
So here from the amend index python.

05:43.480 --> 05:53.440
So from the packages module, let's import the function, get package share directory and so we can

05:53.440 --> 05:57.520
use this function here for example within the join function.

05:57.520 --> 05:58.660
So let's use it.

05:58.660 --> 06:08.260
Get package share directory to obtain the full path, the full directory to the Arduino bot description

06:08.260 --> 06:13.510
package so that we don't have to rewrite all the path to this directory.

06:13.630 --> 06:17.620
So let's format this a little bit better.

06:22.260 --> 06:25.920
Okay so that it is easier to read for this package.

06:25.920 --> 06:27.330
So within the Arduino.

06:27.540 --> 06:32.820
Description package, we want them to open the Urdf folder.

06:32.820 --> 06:42.330
And then within this folder we want to open the Arduino bot dot Urdf dot acro file.

06:43.230 --> 06:45.330
Let's also add a description.

06:45.330 --> 06:49.920
So after the default value here, let's add a.

06:50.880 --> 07:04.560
Description and is just says absolute path to the robot urdf file so that every person that uses this

07:04.560 --> 07:08.760
launch file knows what the model argument does.

07:09.960 --> 07:14.070
Now we can finally create the robot description variable.

07:14.070 --> 07:18.370
So the one that we needed within the robot state publisher node.

07:18.390 --> 07:22.200
So let's instantiate this variable before using it.

07:23.300 --> 07:27.500
And this will contain the configuration parameter for the node.

07:27.830 --> 07:32.390
Also, to declare a variable of this type, we need to import another class.

07:32.420 --> 07:35.520
This time still from the Ros launch.

07:35.540 --> 07:40.040
So from launch Ros.

07:40.160 --> 07:43.520
This time from the parameter description.

07:43.730 --> 07:47.900
Let's import the parameter value.

07:48.290 --> 07:54.020
And now we can create the robot description as an instance of the parameter value class.

07:54.760 --> 08:01.540
Anyway, this parameter cannot simply contain the path to the robot's urdf model because we didn't use

08:01.570 --> 08:04.350
pure Urdf convention for its creation.

08:04.360 --> 08:06.100
Instead we used.

08:06.640 --> 08:08.430
So we use the exact format.

08:08.440 --> 08:15.220
So before using it, before taking this parameter and loading with the robot state publisher, we first

08:15.220 --> 08:22.720
need to convert our model into plain urdf format and we can do this by running a command.

08:22.750 --> 08:28.830
So in order to run a command from a launch file, we need to import another class.

08:28.840 --> 08:40.660
So from launch dot substitutions, let's import the command class and now let's use this one within

08:40.660 --> 08:44.740
the parameter to execute a certain command.

08:44.980 --> 08:48.430
And this command says Sacrow.

08:50.170 --> 08:55.120
And so it is responsible for converting the model to the Urdf.

08:55.120 --> 08:58.840
And also we need to pass the path to our model.

08:58.840 --> 09:01.990
So the path which we defined in the model argument.

09:01.990 --> 09:03.070
So here.

09:04.280 --> 09:11.210
Since the launch file arguments can be set while the file is started, we use another class from the

09:11.210 --> 09:13.280
launch substitutions modules.

09:13.280 --> 09:21.410
So from this one that is called launch configuration and we use this one to read the content of the

09:21.410 --> 09:24.950
modal argument when the launch file is started.

09:25.160 --> 09:27.860
So here sakoura.

09:29.580 --> 09:30.870
And then comma.

09:31.530 --> 09:40.470
And then we read the content of the modal argument that basically contains the full directory to the

09:40.530 --> 09:42.310
urdf modal of our robot.

09:42.330 --> 09:50.460
Basically what we are saying here is that the robot description will be the full plain urdf modal.

09:50.670 --> 09:56.190
And here we are going to take this full urdf model by converting.

09:56.190 --> 10:03.030
So using the command acro, by converting what we encounter at the modal path.

10:03.030 --> 10:05.760
So that by default was this one.

10:05.760 --> 10:08.280
So was the exact model of our robot.

10:08.900 --> 10:12.020
Now let's move on by launching another node.

10:12.020 --> 10:19.910
So if we remember, we also needed to launch the joint state publisher node that offered those sliders

10:19.910 --> 10:22.040
that allowed us to move the robot.

10:22.310 --> 10:25.670
So let's create a new variable joint.

10:27.770 --> 10:32.480
State publisher going.

10:32.780 --> 10:36.170
And this is a new instance of the Node class.

10:36.170 --> 10:49.640
And this time we want to start the node from the package joint state publisher and the executable.

10:52.470 --> 10:56.790
That we want to start is also called Joint State Publisher.

10:57.270 --> 10:59.820
This is Joint state publisher.

11:00.000 --> 11:04.570
We also denote is called Joint State Publisher.

11:05.550 --> 11:08.250
And then we just need to start one last note.

11:08.280 --> 11:09.870
That is Rvhs.

11:10.050 --> 11:15.600
So let's call this one Arv's node.

11:16.050 --> 11:17.790
And so this is our node.

11:18.210 --> 11:19.980
And from the package.

11:22.210 --> 11:25.150
That is called RV two.

11:25.570 --> 11:28.360
Let's start the executable.

11:28.900 --> 11:32.170
That is also called RV two.

11:33.680 --> 11:35.060
And let's name it.

11:35.540 --> 11:39.170
So let's assign a name that is RV to.

11:39.800 --> 11:44.090
We also want to see the output of this node in the terminal.

11:44.090 --> 11:48.320
So with any log message that this node may run.

11:48.530 --> 11:50.900
And so we set the output.

11:53.060 --> 11:59.510
Here, a comma and then output to the screen.

12:00.500 --> 12:08.330
If you remember by default when we start this, it shows the default graphical interface every time

12:08.330 --> 12:10.850
without any visualization or plugins.

12:11.330 --> 12:17.330
Anyway, we can make it load at different configuration at startup and for example, we can load the

12:17.330 --> 12:23.870
one that we have created and we have stored in the RV's folder and that already contains, for example,

12:23.870 --> 12:28.490
the visualization of the Urdf model of the robot and with its meshes.

12:28.910 --> 12:38.810
To do so, we need to pass some arguments, so arguments and let's pass a vector and here let's use

12:38.810 --> 12:46.130
the flag minus D to pass the directory of the RVs configuration that we want to visualize.

12:46.340 --> 12:57.290
And in order to take the directory, we can use again the path join function from the library of Python.

12:57.290 --> 13:04.500
And here again we can use the get package shared directory to get access to the full directory of the

13:05.130 --> 13:09.990
Arduino bot description package.

13:09.990 --> 13:22.590
And then within this one let's access to the Arviz folder and then we want to use the display dot RV.

13:22.610 --> 13:26.640
So we want to load this one by default when we start arviz.

13:27.520 --> 13:34.150
With this, we have created a variable, an object for each instruction that we want to start.

13:34.150 --> 13:36.580
So here we have declared an argument.

13:36.610 --> 13:39.250
Here we have started three nodes.

13:40.200 --> 13:46.470
Now we can pass these variables so these instructions to the launch description file, so to this one

13:46.470 --> 13:51.420
so that they can effectively be started when we execute the launch file.

13:51.900 --> 13:57.210
Let's start with the instruction that defines the argument of the launch file.

13:57.210 --> 13:58.920
So the model argument.

13:59.040 --> 14:07.470
Then let's launch the robot state publisher, then the joint state publisher, and then let's execute

14:07.470 --> 14:08.060
args.

14:09.230 --> 14:12.680
With these, we have finished and now we can save.

14:12.680 --> 14:20.010
And we only need to install the launch folder which we created in this lesson inside the Cmakelists.txt

14:20.060 --> 14:20.370
file.

14:20.390 --> 14:22.410
So let's open this file.

14:22.430 --> 14:29.930
Here we have already installed the meshes and the urdf folder, so let's install also the launch folder

14:30.080 --> 14:36.980
and the RV's folder which contains the configuration that RVs has to display by default.

14:37.550 --> 14:43.670
Furthermore, to ensure that the launch file that we just created is started without any issue and that

14:43.670 --> 14:48.140
all the packages that are needed to start the launch file are available.

14:48.140 --> 14:56.600
We need to declare some dependencies in the package dot XML and so we need to declare an execution dependency

14:56.600 --> 15:07.550
from the robot state publisher package which we used in our launch file and also another one from the

15:07.550 --> 15:13.320
joint state publisher Gooey package.

15:13.340 --> 15:22.520
Then also another one from our vs Chu and finally another one.

15:22.520 --> 15:28.700
So another execution dependency from the Ros two launch library.

15:29.710 --> 15:31.270
With this, we have finished.

15:31.270 --> 15:33.970
And now we can finally execute this launch file.

15:34.510 --> 15:41.170
So let's open a new terminal and let's go to the workspace and let's build it.

15:41.530 --> 15:48.430
In order to install the new file and the new folders, when this is done, we can finally open a new

15:48.430 --> 15:49.670
window of the terminal.

15:49.690 --> 15:52.240
As always, let's source the workspace.

15:54.670 --> 16:02.380
And now we can start the launch file with the command Ros to launch, followed by the name of the package

16:02.380 --> 16:08.680
which contains the launch file that we want to start, which is the Arduino bot description, followed

16:08.680 --> 16:10.960
by the name of the launch file itself.

16:10.960 --> 16:17.230
So if we press tab twice, we can see that we have the display dot launch available.

16:17.440 --> 16:19.330
So let's start this file.

16:19.960 --> 16:26.320
As we press enter, we can see that there is an error, an error in the directory.

16:26.350 --> 16:31.480
Since here there is no space between the command and the directory.

16:31.720 --> 16:33.970
So let's go back in Visual Studio code.

16:34.670 --> 16:37.460
And here we need to add a space.

16:37.700 --> 16:39.410
So let's save again.

16:40.250 --> 16:42.350
Let's build again the workspace.

16:44.280 --> 16:46.710
And now we can launch the file again.

16:47.610 --> 16:51.060
As we do so, we can see that just with one command.

16:51.060 --> 16:58.710
So just with the command Ros to launch, basically we have reproduced and we have the same result as

16:58.710 --> 16:59.970
the previous lesson.

16:59.970 --> 17:07.980
And so now we have again the Urdf model of our robot that is perfectly displayed and perfectly moving

17:07.980 --> 17:09.150
in the terminal.

17:11.030 --> 17:16.880
Now we are going to use this additional tool, the launch files, in the subsequent lesson of the course

17:16.880 --> 17:21.950
to start more complex application with more features with extremely ease.
