This is the solution for the activity on launch files.
And in this activity, the challenge is to start a bunch of nodes.
So you have the image provided in the description of the activity.
And we are going to try to get the same thing on Actigraph.
So what you could do first before writing the launch file is to start all the nodes one by one.
Okay.
For example, you could do Ros to run.
Let's do an example for the first node Ros to run my we can use the Python one or the C plus plus one.
It doesn't matter.
Robot news station.
So that's the package name executable name.
And then we actually need to rename it.
So ros args dash r node.
This one is going to be robot News Station discard.
That's the first one.
And we also want to use the uh parameter.
So we had if you don't remember you just start the node like this.
Okay.
You do.
Rows two node list.
Okay.
We have the correct node, then rows two topic list.
So we have the robot news topic.
That's the topic we want.
No problem.
Rows two param list.
And you see we have a robot name parameter.
So I can start again.
So I do my node renaming and then dash p robot name is equal to discard.
All right.
And we have an error.
Yes I forgot the semicolon here.
Okay.
It is started.
And then if I do rows two topic equal with robot news.
You see how this is discard from the robot news station.
All right, so first I did this because well, if you are not sure what to write inside a launch file,
you can just do the Ros two run command first.
And then you have all the information here.
You just need to add the different information here inside the launch file.
And second, you can see that I could have checked the code actually because I've written the code.
But we can find all the information from the terminal.
Even if you don't know the parameter name the topic name, you just start the node and then you discover
them again and you can easily modify them.
All right.
So I'm not going to start the five nodes for the publisher here.
I'm going to directly start a launch file and basically duplicate that with the information for each
node.
So let's go to my robot bring up in the launch I'm going to start.
So I'm going to create a new file named well let's name it radio dot launch dot XML for example.
Just make sure you have that launch XML.
Then we initialize the launch file with launch tag.
And that's it.
Let's start one node.
So pkg is going to be my.
Let's use the Python one.
And exec is going to be if you don't remember you go back here robot news station.
Robot news station.
Great.
Do we need to rename the node.
Yes.
Name and the name?
Well I have just written it here, so I'm going to put it there.
Robot news station discard.
Do I need to add a namespace?
Well, I didn't give you this in the challenge.
You can if you want but I'm going to keep it like this.
I'm going to then close this like that.
I'm going to close the node tag like this because I need to provide a parameter.
So param name value.
What is the name of the parameter you see?
Robot name and the value is that one.
So robot name.
And just just got.
So if I save that if I try to run it I should have the same thing as this roster run command.
Let's try that first.
Let's go to roster Workspace and let's do a call on build packages.
Select with my robot bring up.
Okay let's source.
And let's do a roster launch.
And the name is.
So first the package my robot bring up.
And the name is radio dot launch dot XML.
Okay.
Looks like it is working, I can.
Well, let's do the Rostopic echo.
It correctly works ros2 Ros two node list.
Okay, that's what we want.
So if I do arc graph.
Also you see that we have the first part already correct.
And now for the other publishers.
So the other node is going to be very easy.
I'm going to just take that node here and we need it five times.
So 234 and five I could change the package and use the cplusplus if I want.
I'm just going to use the same.
The executable name is going to be the same every time, but then the node name of course we need to
change it.
So I'm going to put Vb8 here.
I'm going to put the needle.
And here I'm going to put gender.
And here finally C-3po.
Oh okay.
Note that I put everything in lowercase here.
And then let's also change the parameter name.
Uh, maybe eight.
To nil and here gender.
And here C-3po.
All right.
And you see with this I'm going to start five nodes.
Let's save let's build let's source and let's start.
You see we have five processes here.
So the executable names are robot new station 123.
That's the executable name.
Okay.
And then we have the different node names that we can find with acute graph.
Okay.
All good.
That's what we want.
And we can check also that if I do rows two topic equal robot news.
You see, we should receive all of the different, uh, messages from all the publishers with all the
different names.
Okay, because of the parameter that we have set here.
Now finally I'm going to add another node.
This one is so from package.
Let's also use the Python one.
So my pi pg.
If you don't remember you can do for example rows to run my pi PG and it's going to be smartphone.
I'm just going to use it like that.
So exec smartphone and I don't need to provide any renaming.
I don't need to remap anything.
There is no namespace is no parameter.
So just one line.
And now well let's remove that.
Let's stop.
And we're going to build again.
We're going to source again and run again.
Actually launch again.
You see now we have also smartphone and we have the logs because this node is going to receive all the
information from the topic and print the log if I do arc graph.
All right.
And that's exactly the image that you could see on the challenge for this activity.
So maybe the order of the nodes here is not exactly the same.
But this you cannot really control it on a graph.
But well that's the same thing.
Now I'm going to stop that.
And as an extra step of this activity, I also told you you could load the parameters from a YAML file.
So here it's not really going to reduce the amount of lines in the code, because we just have one parameter
for each node.
But still to practice, let's create a YAML file in the config.
We can create a new file and the name is going to be.
Well, let's name it radio Config.yaml for example.
And then we are going to add for example for the first one we have the name here Robot News Station
discard.
And I'm going to add a slash because here those are the parameters that are going to be loaded for that
name for that node.
And when we run the node well if you remember we had a slash in front okay.
So even if you don't provide it in the code there's going to be one that will be added.
So we need to add it here for the parameters as well.
And then we have Ross double underscore parameters.
And we have one parameter named robot name which is a string.
So we put a string.
All right.
And that's for one node.
Now we need to do the same for all the nodes.
So I'm going to just copy this and paste it five times.
So actually three four and five.
And I'm going to make sure that I use the correct name.
Okay.
So in this case better to just copy directly the names.
So that one.
And then that's going to be it.
And then I'm also going to use the value for the parameters here.
That one.
That one also.
And the last one.
Okay.
Just have a quick look that is working.
And you can see from one YAML file we have all the parameters for five nodes.
And so now if you had, let's say, ten parameters for each node, you see, you could add all the parameters
here.
And then you would just need to load the param once.
So let's save that file is going to be installed automatically because we already have the line in the
List.txt.
You see we already installed the config folder.
Let's go back to our launch file.
And I'm going to use the param tag.
But instead of name and value I'm going to use from okay.
So we use the same thing we did for this.
So from and then find.
So dollar sign parentheses find pkg share my robot bring up slash config slash radio config dot YAML
okay you see that's the package.
Name this one.
And then the config folder.
And then the file name radio Config.yaml.
And the good thing is the param file.
So the YAML file is the same for all the nodes because it contains the information for all of them.
So I can just add it to all of the nodes.
It's going to be the same.
All right.
So now you can see the only difference between this and that for example is the name of the node.
I'm going to save it.
And well let's just build and run.
It's going to do the same thing.
But let's just check source and launch.
Okay.
So well you see we receive from the smartphone node, we receive all of the correct, uh, topic data.
So this is working which means that the parameters are working.
And let's just do a quick graph here.
And it's still the same.
So everything is working correctly.
And well that's the end of this activity.