WEBVTT

00:00.050 --> 00:04.820
In this lesson, you will see how you can save all your parameters for a node or even several nodes

00:04.820 --> 00:09.500
inside only one file that you can load at runtime.

00:09.500 --> 00:11.510
And for this we will use YAML.

00:11.510 --> 00:14.870
So that's why we call the files YAML files.

00:14.870 --> 00:17.450
And first let's understand why you need those.

00:17.450 --> 00:20.600
Well here for example you see I have started my.

00:20.630 --> 00:24.170
So I start my number publisher node with two parameters.

00:24.170 --> 00:27.500
But two parameters is a very small amount of parameters for a node.

00:27.500 --> 00:31.490
You will see later on that you can have dozens of parameters for a node.

00:31.490 --> 00:37.490
So if you need to provide those every time with dash p for each parameter, that's going to be quite

00:37.490 --> 00:39.470
long to do that from the command line.

00:39.470 --> 00:44.030
And also what if you want several configurations for several different nodes, etc.?

00:44.030 --> 00:50.720
Well, it's going to be easier to save those values directly inside one file so that you can just load

00:50.720 --> 00:52.940
the file when you start the node.

00:52.970 --> 00:53.270
All right.

00:53.300 --> 00:59.210
So let's um create I'm going to create a folder here in my home directory.

00:59.240 --> 01:02.990
Let's call it YAML params.

01:02.990 --> 01:05.280
This doesn't really matter at all for now.

01:05.430 --> 01:08.580
It's just you create a folder and we're going to put the YAML files.

01:08.580 --> 01:15.540
And then in the next section on launch files we will see how to actually install those YAML files because

01:15.540 --> 01:17.880
we're going to install them inside your workspace.

01:17.910 --> 01:18.060
Okay.

01:18.090 --> 01:20.460
But for now you just put them anywhere.

01:20.460 --> 01:21.360
It doesn't matter.

01:21.360 --> 01:29.820
And let's create a file called let's say number params dot YAML.

01:29.820 --> 01:32.520
So you make sure you have the YAML extension.

01:32.520 --> 01:33.930
And then it could be number.

01:33.960 --> 01:40.380
So number is because it's the number app kind of and params are number config something like that.

01:40.380 --> 01:42.840
And then we're going to edit this file.

01:42.840 --> 01:44.640
So it's just one file I'm going to use Jedit.

01:44.670 --> 01:47.760
You could also open it with VSCode as you want.

01:49.290 --> 01:49.710
All right.

01:49.710 --> 01:52.770
So what do we write inside this file.

01:52.770 --> 01:57.570
Well first of all let's let's run this just in case.

01:57.570 --> 01:59.850
It's always useful to run the node and see what we have.

01:59.850 --> 02:01.890
So ros2 node list.

02:01.920 --> 02:04.920
You see the node is slash number publisher.

02:05.130 --> 02:13.370
So I'm going to come back to my file and I'm going to write the name of the node number publisher.

02:13.970 --> 02:14.120
Okay.

02:14.150 --> 02:17.060
So I start with this and then I put a colon.

02:17.060 --> 02:22.520
I go back to a new line and I'm going to add an indentation of two spaces.

02:22.520 --> 02:31.430
Then I'm going to write Ross underscore underscore parameters and then another column.

02:31.580 --> 02:33.230
So this is super important.

02:33.260 --> 02:36.230
You write the name of the node the complete name.

02:36.230 --> 02:39.200
And then with an indentation we're going to use two spaces.

02:39.230 --> 02:43.610
You write exactly Ross underscore underscore parameters.

02:43.610 --> 02:47.060
That's going to be the same for every node in your application.

02:47.060 --> 02:50.900
Then you go back to a new line and let's add another indentation of two spaces.

02:50.900 --> 02:54.860
So in total here I should have 1234 spaces.

02:54.860 --> 03:02.060
And then I just provide the values for each parameter one by one one in each line.

03:02.060 --> 03:03.080
So what do we have.

03:03.080 --> 03:06.920
You see we have the number parameter and the timer period.

03:06.950 --> 03:09.380
If I do Ross two parameter list.

03:10.370 --> 03:14.580
Basically those are all the parameters that I can give.

03:14.880 --> 03:19.410
So I could also change the use same time so that the simulation time, for example, if you're using

03:19.410 --> 03:24.990
gazebo or stuff like that for simulation, you could decide to start some nodes using the simulation

03:24.990 --> 03:27.270
time, but it's not really useful for now.

03:27.420 --> 03:29.220
And let's go here.

03:29.220 --> 03:34.440
So you see we can do number and timer period.

03:34.440 --> 03:38.610
So let's put number and then a value.

03:38.610 --> 03:44.670
So we make sure to provide a value that is compatible with the data type we have set in the node.

03:45.480 --> 03:51.660
And let's say timer period of 0.7.

03:51.690 --> 03:52.020
Right.

03:52.050 --> 03:56.010
And then you can just add as many parameters as you want okay.

03:56.040 --> 04:01.920
You will see later on it's not uncommon to see files like this which contains more than 100 lines.

04:01.950 --> 04:02.280
All right.

04:02.280 --> 04:03.690
So let's save that file.

04:03.720 --> 04:05.040
Make sure you save it.

04:05.040 --> 04:10.770
And then what we can do I'm going to stop the node and let's start it again.

04:10.770 --> 04:14.400
But this time I'm not going to provide the parameters value directly.

04:14.400 --> 04:19.620
So I will keep Ross ARGs because I'm going to add arguments, but I'm going to add this one.

04:19.620 --> 04:22.830
So let's put it a bit bigger here.

04:23.610 --> 04:28.830
I'm going to add dash dash and then params file.

04:28.830 --> 04:31.560
And I need to put the path to the file.

04:31.560 --> 04:37.200
So it's in my home directory and then YAML params folder.

04:37.200 --> 04:41.760
And that was number params YAML.

04:41.760 --> 04:43.950
You see I can use the autocompletion here.

04:43.950 --> 04:51.210
And if I run that well first it's working and then let's see what we have simply with the Ross two topic

04:51.600 --> 04:53.340
equal number.

04:55.440 --> 04:57.600
You see we publish five every.

04:57.600 --> 05:00.870
So that was I think 0.7 seconds.

05:01.350 --> 05:13.800
We can do Ross two topic h z with number is going to listen to the topic and you see the rate.

05:13.800 --> 05:18.960
So the rate is 1.4 because the period here is 0.7.

05:18.960 --> 05:24.240
That's exactly what we have specified here in the YAML file.

05:24.270 --> 05:24.750
All right.

05:24.750 --> 05:26.190
So you can see this is quite convenient.

05:26.190 --> 05:28.590
You can put as many values as you want here.

05:28.620 --> 05:32.910
You could even create different YAML files for different configurations that you want to load.

05:32.910 --> 05:35.400
And then the command is the same.

05:35.400 --> 05:40.350
You see if you have 1 or 100 parameters the command is going to be the same.

05:40.380 --> 05:46.770
Now this you can do even more with it because we have just the parameters for one node.

05:46.770 --> 05:49.470
But you can have the parameters for as many nodes as you want.

05:49.500 --> 05:56.940
So let's say we want to run two nodes and we're going to rename them number one and number two.

05:56.970 --> 06:00.630
And the two will have different values for the parameters.

06:00.780 --> 06:04.530
So let's rename that one with one.

06:04.530 --> 06:11.160
And then what I'm going to do is simply I'm just going to take this structure and write the same exact

06:11.160 --> 06:15.420
same structure here with a different name here.

06:15.420 --> 06:18.720
So you see you just add the nodes one by one.

06:18.720 --> 06:20.910
Just make sure that you respect the indentation.

06:20.910 --> 06:23.640
We still have the name of the node Ros parameters.

06:23.640 --> 06:26.400
And then let's change the value here.

06:26.550 --> 06:32.100
Let's put three and the time period is going to be 1.0.

06:32.190 --> 06:34.740
All right let's save that.

06:34.980 --> 06:37.830
And now this YAML file we can load it.

06:37.830 --> 06:40.830
And when we load it the node well the node is going to check.

06:40.860 --> 06:44.580
Do I have one line that corresponds to the node name.

06:44.580 --> 06:45.000
Yes.

06:45.000 --> 06:46.860
If yes I apply the parameters.

06:46.860 --> 06:50.100
So let's try this with an example here.

06:50.100 --> 06:52.080
Let's so clear.

06:52.320 --> 06:54.870
Let's run that node.

06:54.870 --> 06:58.740
But I'm going to also rename it because actually let's run it like this.

06:58.740 --> 07:00.480
And let's see what happens.

07:01.260 --> 07:04.500
You see that now we publish.

07:04.500 --> 07:07.380
So we are back to publishing two every one second.

07:07.380 --> 07:08.070
Why is that.

07:08.070 --> 07:12.540
Because we're going to load the YAML file with this node.

07:12.540 --> 07:15.540
But the node is named number publisher.

07:15.960 --> 07:19.560
We check do we have one node here that is named number publisher.

07:19.590 --> 07:20.100
No.

07:20.130 --> 07:21.690
They each have a different name.

07:21.690 --> 07:22.890
So it's not going to be applied.

07:22.890 --> 07:29.290
So the node name must be exactly one of the nodes that you have in the YAML file.

07:29.380 --> 07:35.770
So that's why I'm going to do here dash r and then node.

07:35.860 --> 07:42.490
And I'm going to name it uh number publisher one for example.

07:44.350 --> 07:46.150
So it's been renamed.

07:46.150 --> 07:53.140
And then you can see we have published five every 0.7 seconds.

07:53.170 --> 07:57.730
Because the number of publisher one node here will get all its parameters from that.

07:57.730 --> 08:03.040
And you can see we load a YAML file with two configurations for two nodes.

08:03.040 --> 08:08.230
But this node is only going to take the configuration for its name okay.

08:08.260 --> 08:10.270
It's going to ignore that one.

08:10.270 --> 08:11.950
So then I can start the second node here.

08:11.950 --> 08:18.460
For example to run my what we can start from the Python package or the C plus plus package.

08:18.490 --> 08:23.410
It doesn't matter number publisher and then ros args.

08:23.440 --> 08:31.060
Let's rename it to Number publisher two okay.

08:31.090 --> 08:39.670
Because we want also to have the parameters here and then params file.

08:40.090 --> 08:48.520
And let's provide the path YAML params and number params dot YAML.

08:48.550 --> 08:48.700
Okay.

08:48.730 --> 08:50.110
You can see the command is the same.

08:50.110 --> 08:53.230
We just changed the name of the node.

08:54.220 --> 08:55.690
Okay it is running.

08:55.690 --> 09:03.160
And now here if I do Ros two topic equal with number.

09:05.800 --> 09:09.160
You see we received three and five at different frequencies.

09:09.160 --> 09:17.200
So both nodes are publishing to the number topic with a different number and a different time period.

09:17.200 --> 09:23.500
So you can see you can put several configurations for several nodes inside one file that you load.

09:23.500 --> 09:29.260
And the file is going to check if the name corresponds to one of the nodes that you've provided here,

09:29.260 --> 09:32.680
and if yes, it's going to load the parameters for that node.
