WEBVTT

00:00.050 --> 00:03.050
This is the solution for the activity on launch files.

00:03.050 --> 00:06.800
And in this activity, the challenge is to start a bunch of nodes.

00:06.800 --> 00:10.700
So you have the image provided in the description of the activity.

00:10.700 --> 00:14.060
And we are going to try to get the same thing on Actigraph.

00:14.060 --> 00:20.180
So what you could do first before writing the launch file is to start all the nodes one by one.

00:20.210 --> 00:20.420
Okay.

00:20.450 --> 00:22.280
For example, you could do Ros to run.

00:22.280 --> 00:29.750
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.

00:29.750 --> 00:30.800
It doesn't matter.

00:31.790 --> 00:34.160
Robot news station.

00:34.160 --> 00:37.160
So that's the package name executable name.

00:37.160 --> 00:40.490
And then we actually need to rename it.

00:40.490 --> 00:45.950
So ros args dash r node.

00:46.250 --> 00:53.150
This one is going to be robot News Station discard.

00:53.180 --> 00:54.290
That's the first one.

00:54.290 --> 00:57.950
And we also want to use the uh parameter.

00:57.950 --> 01:02.080
So we had if you don't remember you just start the node like this.

01:02.770 --> 01:03.460
Okay.

01:03.490 --> 01:03.760
You do.

01:03.790 --> 01:05.380
Rows two node list.

01:06.400 --> 01:06.880
Okay.

01:06.880 --> 01:11.890
We have the correct node, then rows two topic list.

01:12.190 --> 01:14.710
So we have the robot news topic.

01:14.710 --> 01:16.480
That's the topic we want.

01:16.840 --> 01:17.710
No problem.

01:17.740 --> 01:20.110
Rows two param list.

01:21.580 --> 01:24.430
And you see we have a robot name parameter.

01:24.430 --> 01:26.890
So I can start again.

01:28.510 --> 01:40.390
So I do my node renaming and then dash p robot name is equal to discard.

01:41.770 --> 01:42.520
All right.

01:43.240 --> 01:45.250
And we have an error.

01:45.700 --> 01:48.040
Yes I forgot the semicolon here.

01:50.170 --> 01:50.560
Okay.

01:50.590 --> 01:51.910
It is started.

01:51.910 --> 01:57.160
And then if I do rows two topic equal with robot news.

01:59.140 --> 02:04.350
You see how this is discard from the robot news station.

02:04.440 --> 02:10.650
All right, so first I did this because well, if you are not sure what to write inside a launch file,

02:10.710 --> 02:13.200
you can just do the Ros two run command first.

02:13.200 --> 02:15.090
And then you have all the information here.

02:15.120 --> 02:18.480
You just need to add the different information here inside the launch file.

02:18.510 --> 02:23.730
And second, you can see that I could have checked the code actually because I've written the code.

02:23.730 --> 02:26.940
But we can find all the information from the terminal.

02:26.940 --> 02:32.490
Even if you don't know the parameter name the topic name, you just start the node and then you discover

02:32.490 --> 02:34.680
them again and you can easily modify them.

02:34.710 --> 02:35.130
All right.

02:35.130 --> 02:39.750
So I'm not going to start the five nodes for the publisher here.

02:39.960 --> 02:45.690
I'm going to directly start a launch file and basically duplicate that with the information for each

02:45.690 --> 02:46.440
node.

02:46.440 --> 02:51.450
So let's go to my robot bring up in the launch I'm going to start.

02:51.450 --> 03:01.200
So I'm going to create a new file named well let's name it radio dot launch dot XML for example.

03:01.230 --> 03:03.810
Just make sure you have that launch XML.

03:03.980 --> 03:08.930
Then we initialize the launch file with launch tag.

03:08.930 --> 03:10.370
And that's it.

03:10.400 --> 03:13.040
Let's start one node.

03:13.880 --> 03:17.270
So pkg is going to be my.

03:17.690 --> 03:19.370
Let's use the Python one.

03:21.080 --> 03:28.460
And exec is going to be if you don't remember you go back here robot news station.

03:29.780 --> 03:33.230
Robot news station.

03:33.710 --> 03:34.550
Great.

03:34.580 --> 03:36.230
Do we need to rename the node.

03:36.230 --> 03:36.950
Yes.

03:36.980 --> 03:39.860
Name and the name?

03:39.890 --> 03:46.490
Well I have just written it here, so I'm going to put it there.

03:46.490 --> 03:50.120
Robot news station discard.

03:50.150 --> 03:51.800
Do I need to add a namespace?

03:51.800 --> 03:54.050
Well, I didn't give you this in the challenge.

03:54.050 --> 03:57.110
You can if you want but I'm going to keep it like this.

03:57.380 --> 04:01.940
I'm going to then close this like that.

04:01.940 --> 04:06.660
I'm going to close the node tag like this because I need to provide a parameter.

04:06.660 --> 04:11.280
So param name value.

04:13.020 --> 04:16.290
What is the name of the parameter you see?

04:16.320 --> 04:19.260
Robot name and the value is that one.

04:19.260 --> 04:21.180
So robot name.

04:24.150 --> 04:26.490
And just just got.

04:27.120 --> 04:34.200
So if I save that if I try to run it I should have the same thing as this roster run command.

04:34.230 --> 04:35.760
Let's try that first.

04:36.510 --> 04:43.350
Let's go to roster Workspace and let's do a call on build packages.

04:43.350 --> 04:47.490
Select with my robot bring up.

04:49.140 --> 04:51.180
Okay let's source.

04:52.260 --> 04:55.260
And let's do a roster launch.

04:55.440 --> 04:56.610
And the name is.

04:56.610 --> 05:00.780
So first the package my robot bring up.

05:00.780 --> 05:05.160
And the name is radio dot launch dot XML.

05:07.910 --> 05:08.750
Okay.

05:08.750 --> 05:12.410
Looks like it is working, I can.

05:12.500 --> 05:15.110
Well, let's do the Rostopic echo.

05:15.140 --> 05:22.670
It correctly works ros2 Ros two node list.

05:23.210 --> 05:24.590
Okay, that's what we want.

05:24.620 --> 05:26.720
So if I do arc graph.

05:29.000 --> 05:35.480
Also you see that we have the first part already correct.

05:36.170 --> 05:38.390
And now for the other publishers.

05:38.390 --> 05:40.880
So the other node is going to be very easy.

05:40.880 --> 05:45.200
I'm going to just take that node here and we need it five times.

05:45.200 --> 05:51.380
So 234 and five I could change the package and use the cplusplus if I want.

05:51.410 --> 05:52.790
I'm just going to use the same.

05:52.820 --> 05:57.890
The executable name is going to be the same every time, but then the node name of course we need to

05:57.890 --> 05:58.940
change it.

05:59.090 --> 06:02.900
So I'm going to put Vb8 here.

06:02.900 --> 06:05.690
I'm going to put the needle.

06:05.690 --> 06:09.460
And here I'm going to put gender.

06:09.460 --> 06:13.570
And here finally C-3po.

06:13.990 --> 06:15.220
Oh okay.

06:15.250 --> 06:17.440
Note that I put everything in lowercase here.

06:17.440 --> 06:20.230
And then let's also change the parameter name.

06:20.890 --> 06:22.360
Uh, maybe eight.

06:25.000 --> 06:28.990
To nil and here gender.

06:28.990 --> 06:32.860
And here C-3po.

06:33.700 --> 06:34.570
All right.

06:34.570 --> 06:37.480
And you see with this I'm going to start five nodes.

06:37.510 --> 06:48.880
Let's save let's build let's source and let's start.

06:49.840 --> 06:52.240
You see we have five processes here.

06:52.240 --> 06:57.580
So the executable names are robot new station 123.

06:57.610 --> 06:58.900
That's the executable name.

06:58.930 --> 06:59.500
Okay.

06:59.680 --> 07:03.700
And then we have the different node names that we can find with acute graph.

07:04.540 --> 07:05.140
Okay.

07:05.170 --> 07:05.860
All good.

07:05.860 --> 07:06.850
That's what we want.

07:06.880 --> 07:13.050
And we can check also that if I do rows two topic equal robot news.

07:13.410 --> 07:20.850
You see, we should receive all of the different, uh, messages from all the publishers with all the

07:20.850 --> 07:21.810
different names.

07:21.840 --> 07:25.710
Okay, because of the parameter that we have set here.

07:25.740 --> 07:28.650
Now finally I'm going to add another node.

07:28.650 --> 07:32.250
This one is so from package.

07:32.880 --> 07:34.740
Let's also use the Python one.

07:34.740 --> 07:38.070
So my pi pg.

07:38.430 --> 07:48.840
If you don't remember you can do for example rows to run my pi PG and it's going to be smartphone.

07:49.260 --> 07:50.700
I'm just going to use it like that.

07:50.700 --> 07:58.020
So exec smartphone and I don't need to provide any renaming.

07:58.020 --> 07:59.910
I don't need to remap anything.

07:59.910 --> 08:02.520
There is no namespace is no parameter.

08:02.520 --> 08:05.040
So just one line.

08:06.000 --> 08:09.710
And now well let's remove that.

08:10.220 --> 08:11.720
Let's stop.

08:11.720 --> 08:14.840
And we're going to build again.

08:15.890 --> 08:20.420
We're going to source again and run again.

08:20.450 --> 08:21.590
Actually launch again.

08:21.590 --> 08:28.580
You see now we have also smartphone and we have the logs because this node is going to receive all the

08:28.580 --> 08:34.490
information from the topic and print the log if I do arc graph.

08:37.550 --> 08:38.090
All right.

08:38.090 --> 08:43.370
And that's exactly the image that you could see on the challenge for this activity.

08:43.370 --> 08:46.250
So maybe the order of the nodes here is not exactly the same.

08:46.250 --> 08:49.100
But this you cannot really control it on a graph.

08:49.100 --> 08:50.900
But well that's the same thing.

08:51.080 --> 08:54.110
Now I'm going to stop that.

08:54.110 --> 09:01.610
And as an extra step of this activity, I also told you you could load the parameters from a YAML file.

09:01.610 --> 09:07.970
So here it's not really going to reduce the amount of lines in the code, because we just have one parameter

09:07.970 --> 09:09.050
for each node.

09:09.050 --> 09:13.690
But still to practice, let's create a YAML file in the config.

09:14.200 --> 09:17.380
We can create a new file and the name is going to be.

09:17.410 --> 09:23.170
Well, let's name it radio Config.yaml for example.

09:24.850 --> 09:32.080
And then we are going to add for example for the first one we have the name here Robot News Station

09:32.080 --> 09:32.920
discard.

09:32.920 --> 09:39.580
And I'm going to add a slash because here those are the parameters that are going to be loaded for that

09:39.580 --> 09:41.380
name for that node.

09:41.380 --> 09:47.620
And when we run the node well if you remember we had a slash in front okay.

09:47.650 --> 09:51.910
So even if you don't provide it in the code there's going to be one that will be added.

09:51.910 --> 09:54.490
So we need to add it here for the parameters as well.

09:54.910 --> 10:00.790
And then we have Ross double underscore parameters.

10:00.910 --> 10:09.160
And we have one parameter named robot name which is a string.

10:09.190 --> 10:10.630
So we put a string.

10:10.660 --> 10:11.270
All right.

10:11.270 --> 10:13.640
And that's for one node.

10:13.670 --> 10:15.800
Now we need to do the same for all the nodes.

10:15.800 --> 10:20.240
So I'm going to just copy this and paste it five times.

10:20.240 --> 10:24.290
So actually three four and five.

10:24.290 --> 10:27.740
And I'm going to make sure that I use the correct name.

10:29.060 --> 10:29.780
Okay.

10:30.110 --> 10:36.380
So in this case better to just copy directly the names.

10:39.830 --> 10:41.510
So that one.

10:41.540 --> 10:44.420
And then that's going to be it.

10:44.990 --> 10:50.540
And then I'm also going to use the value for the parameters here.

10:51.740 --> 10:52.850
That one.

10:55.310 --> 10:56.960
That one also.

10:58.280 --> 10:59.900
And the last one.

11:02.630 --> 11:03.290
Okay.

11:03.290 --> 11:05.990
Just have a quick look that is working.

11:05.990 --> 11:11.300
And you can see from one YAML file we have all the parameters for five nodes.

11:11.300 --> 11:16.570
And so now if you had, let's say, ten parameters for each node, you see, you could add all the parameters

11:16.570 --> 11:17.050
here.

11:17.050 --> 11:20.620
And then you would just need to load the param once.

11:20.620 --> 11:26.500
So let's save that file is going to be installed automatically because we already have the line in the

11:26.860 --> 11:27.610
List.txt.

11:27.640 --> 11:30.430
You see we already installed the config folder.

11:30.730 --> 11:33.910
Let's go back to our launch file.

11:33.910 --> 11:36.640
And I'm going to use the param tag.

11:36.640 --> 11:41.200
But instead of name and value I'm going to use from okay.

11:41.230 --> 11:44.560
So we use the same thing we did for this.

11:44.560 --> 11:46.750
So from and then find.

11:47.830 --> 12:06.910
So dollar sign parentheses find pkg share my robot bring up slash config slash radio config dot YAML

12:06.940 --> 12:08.320
okay you see that's the package.

12:08.320 --> 12:09.610
Name this one.

12:09.610 --> 12:11.050
And then the config folder.

12:11.050 --> 12:14.100
And then the file name radio Config.yaml.

12:14.700 --> 12:17.790
And the good thing is the param file.

12:17.790 --> 12:23.130
So the YAML file is the same for all the nodes because it contains the information for all of them.

12:23.130 --> 12:27.090
So I can just add it to all of the nodes.

12:27.120 --> 12:28.410
It's going to be the same.

12:28.980 --> 12:29.520
All right.

12:29.520 --> 12:34.980
So now you can see the only difference between this and that for example is the name of the node.

12:35.580 --> 12:38.190
I'm going to save it.

12:38.730 --> 12:41.580
And well let's just build and run.

12:41.580 --> 12:43.050
It's going to do the same thing.

12:43.080 --> 12:48.660
But let's just check source and launch.

12:49.800 --> 12:50.520
Okay.

12:51.150 --> 12:57.750
So well you see we receive from the smartphone node, we receive all of the correct, uh, topic data.

12:57.750 --> 13:02.910
So this is working which means that the parameters are working.

13:03.060 --> 13:06.240
And let's just do a quick graph here.

13:07.530 --> 13:08.820
And it's still the same.

13:08.820 --> 13:12.000
So everything is working correctly.

13:12.000 --> 13:14.490
And well that's the end of this activity.
