WEBVTT

00:00.110 --> 00:04.730
And this is the second part for the activity five for the second challenge.

00:04.730 --> 00:09.110
In this challenge we are focusing on the LED panel node.

00:09.110 --> 00:14.780
So let's go back to the code and we can leave this here and go to LED panel.

00:14.780 --> 00:16.790
As you can see we have.

00:16.790 --> 00:22.490
So we are setting three LEDs with default state to zero which means turning off the LED.

00:22.490 --> 00:27.290
And what we want to be able to do is to provide a different configuration for this array.

00:27.290 --> 00:28.460
When we start the node.

00:28.460 --> 00:38.300
So we can add a parameter for that self declare parameter and let's name it led state.

00:38.420 --> 00:39.200
Okay.

00:39.290 --> 00:42.170
Could be led initial states.

00:42.200 --> 00:43.580
I'm just going to leave it like this.

00:43.580 --> 00:45.170
And the default value.

00:45.200 --> 00:50.330
Well as I told you you could use basic data types like strings integer doubles.

00:50.330 --> 00:53.690
But you can also use lists of those data types.

00:53.690 --> 00:57.770
So the default value can be a list of integers.

00:58.010 --> 00:58.250
All right.

00:58.250 --> 01:01.250
So I just put the same value I used before.

01:01.850 --> 01:09.630
So what I'm saying here is that I'm creating an led state state's parameter of data type list of integer

01:09.630 --> 01:12.570
and it contains three zeros.

01:12.570 --> 01:19.710
And then what I can do is LD states is equal to self dot get parameter.

01:20.160 --> 01:25.590
The name of the parameter is led states and then dot value.

01:25.620 --> 01:27.030
So that's it for the parameter.

01:27.060 --> 01:28.890
Then let's check that everything is correct.

01:28.890 --> 01:30.750
So where do we use that.

01:30.780 --> 01:33.270
You see we publish this on a topic.

01:33.270 --> 01:34.530
So all good.

01:34.830 --> 01:44.070
And then in the callback set LED we also check that the LED number is not outside of the list.

01:44.070 --> 01:47.640
And because we use this syntax we just check the length.

01:47.640 --> 01:52.530
So it's quite dynamic, meaning that if the list contains three elements it's going to work.

01:52.530 --> 01:56.280
But if the list contains five elements, it's also going to work.

01:56.280 --> 01:59.400
So we check that the code is still working correctly.

01:59.400 --> 02:02.550
And yes, I'm going to save that.

02:02.550 --> 02:04.050
Let's go back to the terminal.

02:04.050 --> 02:06.240
And I have used Simulink installed previously.

02:06.240 --> 02:07.980
So I can just run the node.

02:09.210 --> 02:13.070
So Python package LED panel.

02:13.070 --> 02:17.000
Let's just run it like this and let's do a Ros two.

02:17.420 --> 02:22.910
So Ros two param list to see that we have the parameter okay.

02:22.910 --> 02:31.070
And then Ros two param get LED panel and LED states.

02:32.720 --> 02:38.420
So you see integer values which means a list of integer zero zero and zero.

02:38.420 --> 02:39.620
So that's the initial state.

02:39.620 --> 02:45.740
That's the configuration for our LED panel we say that basically we have three LEDs powered off.

02:45.740 --> 02:52.190
And I also have a topic eco LED states or something like that LED panel state.

02:52.190 --> 02:54.860
And that's going to be every five second.

02:55.010 --> 02:57.440
You see we have the LED states here.

02:57.470 --> 02:59.540
Now let's provide something different.

02:59.540 --> 03:04.610
Let's say that you want to start this LED panel node, but you have five LEDs.

03:04.610 --> 03:12.440
So let's do Ros args dash p LED states.

03:13.070 --> 03:17.310
And then let's provide a list like that.

03:17.850 --> 03:18.840
Zero.

03:18.960 --> 03:19.890
Zero.

03:19.920 --> 03:20.730
Zero.

03:20.760 --> 03:21.390
Size three.

03:21.420 --> 03:21.930
That's four.

03:21.930 --> 03:23.190
And that's five.

03:24.780 --> 03:25.050
Okay.

03:25.080 --> 03:26.670
And you can see we have an error.

03:26.670 --> 03:29.340
Because you cannot pass an array like that.

03:29.340 --> 03:31.710
You need to also put some quotes.

03:34.110 --> 03:34.620
Okay.

03:34.650 --> 03:36.270
Because you have some spaces as well.

03:36.270 --> 03:40.800
So you need to put some quotes and then it should work.

03:40.800 --> 03:42.810
So what do we have on the topic.

03:44.220 --> 03:45.450
Let's see.

03:45.480 --> 03:46.530
Let's wait a bit.

03:46.530 --> 03:53.280
And we have you see now on the topic we have five entities.

03:53.400 --> 03:56.910
And the parameter also has five values.

03:56.910 --> 03:58.740
So you see it's quite powerful.

03:58.770 --> 04:03.000
You could have an LED panel node with as many LEDs as you want.

04:03.030 --> 04:07.440
So you could first set up the LEDs I don't know, let's say you have between 1 and 10 LEDs on your panel,

04:07.440 --> 04:10.530
and then you start the node with how many LEDs you want to start.

04:10.530 --> 04:16.710
And one thing to pay attention here is let's say I start this again and I provide the value seven here.

04:18.150 --> 04:19.990
And it's still working.

04:20.020 --> 04:20.200
Okay.

04:20.230 --> 04:24.250
Because I didn't check anything in the code, so I'm going to get the value seven.

04:24.280 --> 04:31.060
Even though I have stated in the code that I only want values that are 0 or 1.

04:31.090 --> 04:31.270
Okay.

04:31.300 --> 04:36.400
As you can see, when I get a request here from the service, I check if the value is 0 or 1.

04:36.400 --> 04:43.930
So what you can do when you have parameters is you can also decide to check if the value is correct,

04:43.930 --> 04:45.940
so you can decide to trust or not.

04:45.970 --> 04:50.230
What you get from the command line or from the YAML files okay.

04:50.590 --> 04:58.480
So usually in well in most applications usually you know that you give values that are correct, okay.

04:58.510 --> 05:05.530
Because you are the one writing the code and you are also the one writing the parameters when you start

05:05.530 --> 05:06.190
the node.

05:06.250 --> 05:06.520
Okay.

05:06.550 --> 05:08.530
So here you would not do that.

05:08.530 --> 05:11.470
You would provide a 0 or 1.

05:11.470 --> 05:16.960
But if you want you could also validate the data before you actually use it in the code.

05:16.990 --> 05:17.380
All right.

05:17.380 --> 05:19.630
So that's it for this parameter.

05:19.630 --> 05:23.590
But then we also want to add this inside a YAML file.

05:23.590 --> 05:30.410
So let's go back here and I'm going to go inside my YAML params folder.

05:30.530 --> 05:32.780
Again you can put it anywhere you want.

05:32.810 --> 05:35.120
We're going to install it in the next section.

05:35.120 --> 05:38.060
But for now it doesn't matter at all as long as you know where it is.

05:38.630 --> 05:44.270
And I'm going to create a LED config for example dot YAML.

05:44.300 --> 05:45.770
So the name doesn't matter.

05:45.770 --> 05:50.780
Just make something that has some sense and YAML extension.

05:51.440 --> 05:55.130
And let's do a git led config.

05:55.130 --> 05:58.400
So let's start with the name of the node.

05:58.400 --> 06:01.670
The name of the node we see is going to be led panel.

06:01.670 --> 06:02.960
I'm not going to rename it.

06:02.960 --> 06:16.310
So slash LED panel new line two spaces rows underscore underscore parameters and then two more spaces.

06:16.340 --> 06:17.300
What do we have.

06:17.330 --> 06:19.460
We have led state.

06:19.790 --> 06:23.690
And let's say 0000.

06:23.720 --> 06:25.370
I'm going to put four LEDs here.

06:25.400 --> 06:25.790
All right.

06:25.790 --> 06:27.770
And I just have one parameter.

06:27.770 --> 06:29.650
So that's it.

06:29.680 --> 06:29.950
All right.

06:29.980 --> 06:30.760
So we have three lines.

06:30.760 --> 06:33.220
The first one is for the name of the node.

06:33.310 --> 06:38.980
Then the parameters for every node and then the list of parameters one in each line.

06:38.980 --> 06:40.420
Let's save the file.

06:40.690 --> 06:47.740
And now what we can do I can start my LED panel node again.

06:47.740 --> 06:56.170
But instead of providing the parameters like that I can do so ros args and then params file.

06:56.230 --> 06:59.470
And let's go to the.

06:59.590 --> 07:06.730
So let's put the path YAML params and led config.yaml.

07:08.140 --> 07:12.670
All right it is started and we can just verify that very quickly.

07:13.630 --> 07:15.640
You see we have four values.

07:15.640 --> 07:17.440
So that was correctly working.

07:17.440 --> 07:29.440
And if I echo the topic we will have here you see we have four values which means that the value from

07:29.440 --> 07:34.510
the YAML file was taken and is now active in the code.
