WEBVTT

00:00.080 --> 00:05.960
Now that you have seen renaming and remappings in this lesson, you will learn how to set parameters

00:05.960 --> 00:09.080
values to your nodes inside a launch file.

00:09.080 --> 00:15.590
We will first set the parameters one by one, and then load them directly from a YAML file that we will

00:15.590 --> 00:19.220
also install inside the Myrobot bringup package.

00:19.220 --> 00:20.390
Let's get started.

00:20.390 --> 00:28.070
So if you remember from the command line so I can stop all that from the command line when we start

00:28.070 --> 00:31.040
a node with Ros to run, we have also Ros args.

00:31.040 --> 00:34.730
And then we can do dash p param name.

00:34.790 --> 00:37.310
And that's going to be value okay.

00:37.340 --> 00:40.580
So how do we add this inside a launch file.

00:40.580 --> 00:44.750
Well let's go back and well where do we have parameters.

00:44.750 --> 00:48.290
Actually we don't have any parameter in my number counter.

00:48.290 --> 00:52.670
So I'm going to well we have the default ones but we haven't added ones in the code.

00:52.700 --> 00:54.740
I'm going to leave this one like that.

00:54.740 --> 00:58.100
But in number publisher we have two parameters okay.

00:58.130 --> 01:01.910
So if I come back to the code number publisher?

01:02.690 --> 01:06.650
You see, we have the number parameter and the timer period.

01:07.610 --> 01:09.200
So let's add those parameters.

01:09.200 --> 01:10.880
Let's add values for those.

01:10.880 --> 01:11.780
Where do we do this.

01:11.810 --> 01:14.060
Well you do this inside the node tag.

01:14.060 --> 01:18.560
So you need to open and close the node tag if it hasn't been done yet.

01:18.560 --> 01:22.970
And then we can add a param tag.

01:23.000 --> 01:23.270
Okay.

01:23.300 --> 01:26.330
So we have the remappings and then we have the param tags.

01:26.330 --> 01:32.780
And for each param tag you have name and value arguments.

01:33.440 --> 01:37.100
So quite easy here name is going to be number.

01:37.100 --> 01:40.580
And the value let's say six.

01:40.580 --> 01:44.450
And that's going to set the parameter number with the value six.

01:44.450 --> 01:47.570
When you start the node with the launch file okay.

01:47.690 --> 01:52.940
And if you want to add more params you add another param tag name.

01:52.940 --> 01:56.690
That one is timer period.

01:56.690 --> 01:59.100
Make sure it's the correct name value.

01:59.220 --> 02:05.130
Let's say 1.5 seconds and make sure you provide the correct data type as well.

02:05.160 --> 02:05.610
All right.

02:05.610 --> 02:07.500
And that's it for the parameters here.

02:07.500 --> 02:11.430
Let's save and then let's build again.

02:11.700 --> 02:17.640
So let's do a click on build let's source.

02:18.960 --> 02:24.630
And let's start the number app launch dot XML.

02:24.630 --> 02:28.260
So you see to start and to test launch files is quite easy.

02:28.260 --> 02:34.830
It's quite convenient to have one terminal here where you just build source and launch in that order.

02:36.780 --> 02:40.230
So okay it's working.

02:40.230 --> 02:44.730
And now we can just check actually what we have on the number topic.

02:44.730 --> 02:48.810
Ross two topic equal number.

02:50.700 --> 02:52.800
Actually it's not a number.

02:52.800 --> 03:00.630
It's it's my number because if you remember, we have remapped the topic.

03:01.470 --> 03:05.160
So what do we have on my number?

03:05.460 --> 03:08.850
We have six published every word.

03:08.880 --> 03:12.720
You can check the frequency but it's going to be every 1.5 second.

03:12.990 --> 03:13.800
Great.

03:13.800 --> 03:26.460
And we can also do rows to param list and see that we have plus two param get with my number publisher

03:27.510 --> 03:29.100
and number.

03:30.720 --> 03:32.040
We have six.

03:32.700 --> 03:42.060
And for the time period we have 1.5 which is exactly what we have set in the launch file.

03:42.090 --> 03:43.980
Okay so it's quite easy now.

03:44.010 --> 03:47.250
Well that's good if you have only a few parameters.

03:47.250 --> 03:48.990
But let's say you have many parameters.

03:48.990 --> 03:53.760
And let's say you've already created a YAML file or you want to create a new one.

03:53.760 --> 03:56.200
Where are you going to put your YAML files?

03:56.200 --> 04:04.420
Because for now, if you remember, we have just added I have a YAML params folder here in my home directory,

04:04.420 --> 04:10.240
and we have the two YAML files that we have created here number params and led config.

04:10.270 --> 04:16.780
Well, now that we have this bringup package here, we're not just going to create the YAML files anywhere

04:16.780 --> 04:21.610
in our computer, we're going to add them inside the package.

04:21.910 --> 04:24.970
And for that I'm going to go back to.

04:25.000 --> 04:29.560
So let's go to our My Robot Bringup package.

04:29.680 --> 04:32.110
And we have a launch folder.

04:32.110 --> 04:38.050
I'm going to create a new one that will usually we name it config.

04:38.080 --> 04:39.610
It could be params.

04:39.640 --> 04:40.990
It could be whatever you want.

04:41.260 --> 04:43.840
But usually config is a quite common name.

04:44.050 --> 04:46.870
And now you have a launch and a config folder.

04:47.230 --> 04:48.430
Okay it's here.

04:48.430 --> 04:52.090
And in this config folder you are going to add your YAML files.

04:52.120 --> 04:55.360
And there's one thing we need to do to set up this config folder.

04:55.360 --> 05:03.370
We go back to the cmakelists.txt and you see here we say to install the launch folder inside this directory.

05:03.400 --> 05:07.540
After launch you're going to put a space and then config.

05:07.540 --> 05:11.440
So now we say to install the launch folder and the config folder.

05:11.440 --> 05:17.620
So any new folder that you add in the Myrobot bringup that you want to install, you just add a space

05:17.620 --> 05:19.510
and then you put the name of the folder.

05:19.510 --> 05:22.630
So make sure you add the config folder here.

05:22.660 --> 05:23.680
Very important.

05:23.950 --> 05:27.400
And then let's add a new YAML file.

05:27.400 --> 05:32.560
So let's call it number app dot YAML for example.

05:32.560 --> 05:34.480
And now let's provide the parameters.

05:34.480 --> 05:41.920
So we want to add the number parameter and the timer parameter for the my number publisher okay.

05:41.950 --> 05:44.320
You see the name must match.

05:45.100 --> 05:49.810
So I'm going to write my number publisher.

05:51.190 --> 06:01.330
And then two spaces Ross underscore underscore parameters and then more spaces here number.

06:02.050 --> 06:10.630
Well let's use the same values and timer period 1.5 okay I'm going to save that file.

06:10.630 --> 06:14.110
So this is what we've seen on the previous section on parameters.

06:14.110 --> 06:18.400
If you have some doubt you can come back to the to the lesson on YAML files.

06:18.400 --> 06:25.420
And now that we have this YAML file here inside the config folder, we can load it directly here inside

06:25.420 --> 06:26.320
this launch file.

06:26.320 --> 06:27.790
And how do we do this.

06:27.790 --> 06:31.480
Well first I'm going to actually comment those lines.

06:31.480 --> 06:34.720
So here I use control shift and slash.

06:34.750 --> 06:39.490
I'm going to comment those lines so that I don't write the parameters manually.

06:39.490 --> 06:42.010
But I still leave the code so that you can see it.

06:42.040 --> 06:47.410
How to say that we want to load those parameters from this launch file.

06:47.620 --> 06:55.310
Well you are going to add a param tag as well, but instead of name and value you are going to write

06:55.310 --> 06:59.450
from, and that's going to be the path to the YAML file.

06:59.450 --> 07:00.590
And how do we find this?

07:00.620 --> 07:02.120
Well, we're going to use the function.

07:02.120 --> 07:09.650
We have used the same function in the in this XML file to include another launch file we are going to

07:09.680 --> 07:10.340
use.

07:10.340 --> 07:20.060
So dollar sign parentheses bind pkg share and the name of the package my robot bring up.

07:20.060 --> 07:21.440
So it could be from this package.

07:21.440 --> 07:23.210
It could be from another package.

07:23.210 --> 07:26.030
And then slash where is the file.

07:26.090 --> 07:33.320
Well in config slash number app dot YAML okay.

07:33.320 --> 07:35.090
And then we finish.

07:35.090 --> 07:36.290
We close the tag.

07:36.290 --> 07:42.320
So once again find pkg share with the package name in parentheses with a dollar sign.

07:42.410 --> 07:44.720
And then slash the path.

07:44.720 --> 07:48.350
So the relative path here to the YAML file.

07:48.410 --> 07:50.870
And that's going to load the YAML file.

07:50.870 --> 07:58.610
And in this YAML file we have you see parameters for my number publisher which is going to work with

07:58.610 --> 07:58.940
this.

07:58.940 --> 08:04.100
And so you see if you have 200 parameters then you add your 200 parameters here.

08:04.490 --> 08:07.550
And your launch file is still super small.

08:07.580 --> 08:08.750
Let's save that.

08:08.750 --> 08:13.490
And let's uh, let's just test it.

08:14.300 --> 08:24.920
So we build again, we source again and we run again and it's working I guess.

08:24.920 --> 08:26.120
No surprise.

08:27.410 --> 08:31.040
Time period and number, you see still the same.

08:31.040 --> 08:34.580
But this time we load them from the YAML file.

08:35.510 --> 08:42.830
And here is what you have to do in case you have to add parameters inside the Python launch file you

08:42.830 --> 08:43.910
see inside the node.

08:43.910 --> 08:51.870
Here we have another parameters argument, which is a list, but this time we use curly brackets.

08:51.900 --> 08:55.680
Okay, so make sure that you don't make the confusion here.

08:55.680 --> 09:00.420
So this is like a dictionary but this is a tuple for remappings.

09:00.450 --> 09:00.630
Okay.

09:00.630 --> 09:01.710
So not the same thing.

09:01.710 --> 09:05.550
And then you can just put one parameter on each line just like that.

09:05.580 --> 09:07.290
So not too complicated.

09:07.500 --> 09:08.970
And that's the code.

09:08.970 --> 09:12.990
If you want to load a YAML file inside a Python launch file.

09:12.990 --> 09:15.060
So we are still using the same YAML file.

09:15.090 --> 09:16.500
Okay from this package.

09:16.530 --> 09:24.870
But you can see you need to import get package shared directory from element index python packages and

09:24.870 --> 09:25.920
then import OS.

09:25.920 --> 09:30.570
You can have the path here for the parameter config.

09:30.570 --> 09:33.270
And then you can add the parameter here just like that.

09:33.270 --> 09:36.300
So just in case that's how you do it in Python.

09:36.300 --> 09:39.750
But of course I recommend you do that in XML.

09:39.750 --> 09:43.890
You just have to remember find pkg share and that's it.
