And this is the second part for the activity five for the second challenge.
In this challenge we are focusing on the LED panel node.
So let's go back to the code and we can leave this here and go to LED panel.
As you can see we have.
So we are setting three LEDs with default state to zero which means turning off the LED.
And what we want to be able to do is to provide a different configuration for this array.
When we start the node.
So we can add a parameter for that self declare parameter and let's name it led state.
Okay.
Could be led initial states.
I'm just going to leave it like this.
And the default value.
Well as I told you you could use basic data types like strings integer doubles.
But you can also use lists of those data types.
So the default value can be a list of integers.
All right.
So I just put the same value I used before.
So what I'm saying here is that I'm creating an led state state's parameter of data type list of integer
and it contains three zeros.
And then what I can do is LD states is equal to self dot get parameter.
The name of the parameter is led states and then dot value.
So that's it for the parameter.
Then let's check that everything is correct.
So where do we use that.
You see we publish this on a topic.
So all good.
And then in the callback set LED we also check that the LED number is not outside of the list.
And because we use this syntax we just check the length.
So it's quite dynamic, meaning that if the list contains three elements it's going to work.
But if the list contains five elements, it's also going to work.
So we check that the code is still working correctly.
And yes, I'm going to save that.
Let's go back to the terminal.
And I have used Simulink installed previously.
So I can just run the node.
So Python package LED panel.
Let's just run it like this and let's do a Ros two.
So Ros two param list to see that we have the parameter okay.
And then Ros two param get LED panel and LED states.
So you see integer values which means a list of integer zero zero and zero.
So that's the initial state.
That's the configuration for our LED panel we say that basically we have three LEDs powered off.
And I also have a topic eco LED states or something like that LED panel state.
And that's going to be every five second.
You see we have the LED states here.
Now let's provide something different.
Let's say that you want to start this LED panel node, but you have five LEDs.
So let's do Ros args dash p LED states.
And then let's provide a list like that.
Zero.
Size three.
That's four.
And that's five.
Okay.
And you can see we have an error.
Because you cannot pass an array like that.
You need to also put some quotes.
Okay.
Because you have some spaces as well.
So you need to put some quotes and then it should work.
So what do we have on the topic.
Let's see.
Let's wait a bit.
And we have you see now on the topic we have five entities.
And the parameter also has five values.
So you see it's quite powerful.
You could have an LED panel node with as many LEDs as you want.
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,
and then you start the node with how many LEDs you want to start.
And one thing to pay attention here is let's say I start this again and I provide the value seven here.
And it's still working.
Okay.
Because I didn't check anything in the code, so I'm going to get the value seven.
Even though I have stated in the code that I only want values that are 0 or 1.
Okay.
As you can see, when I get a request here from the service, I check if the value is 0 or 1.
So what you can do when you have parameters is you can also decide to check if the value is correct,
so you can decide to trust or not.
What you get from the command line or from the YAML files okay.
So usually in well in most applications usually you know that you give values that are correct, okay.
Because you are the one writing the code and you are also the one writing the parameters when you start
the node.
Okay.
So here you would not do that.
You would provide a 0 or 1.
But if you want you could also validate the data before you actually use it in the code.
All right.
So that's it for this parameter.
But then we also want to add this inside a YAML file.
So let's go back here and I'm going to go inside my YAML params folder.
Again you can put it anywhere you want.
We're going to install it in the next section.
But for now it doesn't matter at all as long as you know where it is.
And I'm going to create a LED config for example dot YAML.
So the name doesn't matter.
Just make something that has some sense and YAML extension.
And let's do a git led config.
So let's start with the name of the node.
The name of the node we see is going to be led panel.
I'm not going to rename it.
So slash LED panel new line two spaces rows underscore underscore parameters and then two more spaces.
What do we have.
We have led state.
And let's say 0000.
I'm going to put four LEDs here.
All right.
And I just have one parameter.
So that's it.
All right.
So we have three lines.
The first one is for the name of the node.
Then the parameters for every node and then the list of parameters one in each line.
Let's save the file.
And now what we can do I can start my LED panel node again.
But instead of providing the parameters like that I can do so ros args and then params file.
And let's go to the.
So let's put the path YAML params and led config.yaml.
All right it is started and we can just verify that very quickly.
You see we have four values.
So that was correctly working.
And if I echo the topic we will have here you see we have four values which means that the value from
the YAML file was taken and is now active in the code.