WEBVTT

00:00.080 --> 00:02.510
We are now at the last step for this project.

00:02.540 --> 00:03.620
Step number six.

00:03.620 --> 00:07.070
And here we are not going to add any new functionality.

00:07.100 --> 00:12.830
We are just going to make the application more dynamic and scalable with parameters and launch files.

00:12.860 --> 00:13.160
Okay.

00:13.190 --> 00:16.790
So you can start the application with different values for different parameters.

00:16.790 --> 00:18.830
You don't need to change the code at all.

00:18.830 --> 00:22.370
And you can also start everything from just one file.

00:22.370 --> 00:24.290
And let's start with the parameters.

00:24.290 --> 00:31.340
So we are going to go to the code of Total controller and Total Spawner and see what could be a parameter.

00:31.370 --> 00:36.200
And well here for example you see that we have a catch closest total first.

00:36.200 --> 00:37.850
So that's something we can choose.

00:37.850 --> 00:40.940
But it's hard coded in the nodes.

00:40.940 --> 00:42.830
So we will need to modify the code.

00:42.830 --> 00:45.380
Instead of that we can add a parameter.

00:45.380 --> 00:50.810
So I'm going to do self dot declare parameter.

00:50.990 --> 00:59.810
And let's name it simply catch closest total first.

00:59.840 --> 01:03.240
And let's put a default value of true.

01:03.510 --> 01:04.050
Okay.

01:04.050 --> 01:09.060
So then we can just going to reverse the order here.

01:13.140 --> 01:26.430
So this one instead of true we can say self get parameter with the name and then dot value.

01:26.670 --> 01:28.860
And again no parentheses here.

01:28.890 --> 01:29.280
All right.

01:29.280 --> 01:31.320
So you can see it's very easy to create a parameter.

01:31.320 --> 01:34.740
You declare it and then you do get parameter dot value.

01:34.770 --> 01:36.900
Okay let's save that.

01:36.900 --> 01:39.480
And then we can go to turtle spawner.

01:39.480 --> 01:41.910
And here I'm going to add two parameters.

01:41.940 --> 01:42.240
Okay.

01:42.270 --> 01:47.190
We're going to be able to change the turtle prefix I have just used turtle for now.

01:47.190 --> 01:50.790
But let's say you want to use my turtle or any other name.

01:50.790 --> 01:53.160
You can choose it with the parameters.

01:53.160 --> 01:58.530
And also well, that's something I have actually changed in the code to make some different tests.

01:58.560 --> 02:03.220
The frequency at which we're gonna spawn turtles.

02:03.250 --> 02:06.340
Okay, that could be very useful as a parameter.

02:06.850 --> 02:08.920
So let's start here.

02:09.370 --> 02:11.800
Self declare parameter.

02:12.130 --> 02:14.620
So let's name this one turtle.

02:14.650 --> 02:16.150
Name prefix.

02:17.020 --> 02:18.130
The default value.

02:18.160 --> 02:21.250
We're going to use the same one as in the code turtle.

02:21.850 --> 02:25.750
And then self declare parameter with.

02:25.780 --> 02:29.410
So for example spawn frequency.

02:29.440 --> 02:33.400
Here I'm going to use frequency instead of period.

02:33.430 --> 02:33.610
Okay.

02:33.640 --> 02:35.080
It's just the opposite.

02:35.080 --> 02:43.450
To get the frequency you do one divided by the period.

02:43.990 --> 02:44.410
Okay.

02:44.410 --> 02:51.400
So to get the period you will need to do actually one divided by frequency.

02:51.430 --> 02:52.030
All right.

02:52.030 --> 02:54.460
So it's basically the same thing.

02:54.460 --> 02:57.610
We just need to modify something here in the code.

02:57.970 --> 03:01.880
And let's say the default frequency is going to be one hertz.

03:01.880 --> 03:11.660
So then I have my turtle name prefix which is going to be so self get parameter.

03:12.350 --> 03:13.640
The name is here.

03:15.830 --> 03:20.630
Dot value and then self dot.

03:20.690 --> 03:23.360
Here I'm going to create a spawn frequency.

03:24.560 --> 03:37.610
We don't have this variable yet is equal to self get parameter with spawn frequency and dot value.

03:38.150 --> 03:39.050
All right.

03:39.050 --> 03:45.410
So then turtle name prefix is correctly set the spawn frequency I don't use it.

03:45.410 --> 03:47.150
So I'm going to have to use it here.

03:47.150 --> 03:56.630
I'm going to simply do 1.0 divided by self dot spawn frequency.

03:56.630 --> 03:59.520
So if I give ten it means ten hertz.

03:59.550 --> 04:01.950
It means ten turtles per second.

04:01.950 --> 04:04.770
And this is going to be 0.1.

04:04.800 --> 04:05.190
Okay.

04:05.220 --> 04:06.720
That's how the frequency works.

04:06.750 --> 04:07.170
All right.

04:07.170 --> 04:09.570
And that's basically it.

04:09.570 --> 04:10.710
So I can save.

04:10.740 --> 04:12.300
Now you could already.

04:12.330 --> 04:17.790
Well if you want you can start the nodes already here and start with the parameters.

04:17.790 --> 04:22.230
I'm going to go directly to the next thing which is to create the launch file.

04:22.230 --> 04:24.330
And so where do we create launch files.

04:24.330 --> 04:27.390
Well you need a dedicated bringup package for that.

04:27.390 --> 04:32.520
So you can either create one new package for that and set it up and everything.

04:32.520 --> 04:35.970
But I already have my robot bring up in this workspace.

04:35.970 --> 04:37.320
So I'm going to use that.

04:37.320 --> 04:44.010
And in the launch folder I'm going to create a new file named turtle SIM.

04:44.280 --> 04:46.170
Catch them all.

04:46.170 --> 04:50.640
Well you can name it as you want dot launch dot XML.

04:51.180 --> 05:00.280
Let's open and close the launch tag And then what nodes do we need to start?

05:00.310 --> 05:04.000
Well, the first node is actually the turtle sim node.

05:04.000 --> 05:08.590
So if I come back here you see we do restaurant turtle sim.

05:08.620 --> 05:09.760
Turtle sim node.

05:10.210 --> 05:11.710
So node with pig.

05:12.580 --> 05:15.340
Turtle SIM exec.

05:16.540 --> 05:18.460
Turtle sim node.

05:19.300 --> 05:19.570
Okay.

05:19.600 --> 05:21.190
That's the first node we need.

05:21.550 --> 05:25.300
The second node where we could start both.

05:25.330 --> 05:29.950
It doesn't matter the order, but we're going to start the controller from turtle SIM.

05:29.950 --> 05:30.820
Catch them all.

05:30.850 --> 05:31.690
That's the package.

05:31.690 --> 05:34.060
And controller is the executable.

05:34.840 --> 05:42.490
So node, pig turtle sim catch them all.

05:43.510 --> 05:46.540
Exec controller.

05:47.260 --> 05:54.070
And the third node is also going to be from the same package here.

05:54.070 --> 06:01.550
And the executable you can see Ease if I come back is spawner.

06:06.290 --> 06:06.740
All right.

06:06.740 --> 06:12.620
So we've just that we can start what we started in those three terminals here.

06:12.740 --> 06:14.660
And now I'm going to add the parameters.

06:14.660 --> 06:23.090
So you could add the parameters as we saw previously here with param and then name and then value.

06:23.090 --> 06:28.850
But what I'm going to do instead is I'm going to create a YAML file that I will load directly for all

06:28.850 --> 06:29.690
the nodes.

06:29.690 --> 06:31.790
So how to create a YAML file.

06:31.790 --> 06:34.220
I'm going to go to my config folder here.

06:34.220 --> 06:44.240
And I don't know let's name this catch them all config dot YAML for example.

06:44.240 --> 06:47.450
And let's put the parameters for each nodes.

06:47.480 --> 06:50.120
Do we need parameters for the turtle sim node?

06:50.150 --> 06:50.810
No.

06:50.810 --> 06:54.680
You could actually add parameters if you wanted to change the background.

06:54.710 --> 06:54.890
Okay.

06:54.920 --> 06:58.210
You know that you have three colors red blue and green.

06:58.210 --> 07:02.470
You could change the background if you want to, but I'm not going to do that here.

07:02.530 --> 07:06.730
I'm going to add parameters for the controller and actually the node.

07:06.790 --> 07:11.050
So if you run the node I'm going to run that same node data.

07:11.080 --> 07:14.800
Same with the controller and the spawner.

07:15.070 --> 07:19.360
And if I do Ros two uh node list.

07:20.410 --> 07:23.800
You see that's the node here turtle controller and turtle spawner.

07:25.270 --> 07:25.510
Okay.

07:25.540 --> 07:26.980
So that's what we need.

07:28.150 --> 07:37.690
So slash turtle controller and then Ros underscore underscore parameters.

07:38.260 --> 07:40.120
And what parameters we have.

07:40.120 --> 07:42.040
Well we just take it from here.

07:42.070 --> 07:45.850
Catch closest turtle.

07:46.360 --> 07:48.400
And I'm just going to put it to true.

07:48.430 --> 07:48.730
Okay.

07:48.760 --> 07:51.160
Even if it's the default value I'm going to use.

07:51.160 --> 07:51.520
True.

07:51.520 --> 07:55.240
Because yes I want to catch the closest turtle first.

07:55.450 --> 07:56.960
Then I can do.

07:56.990 --> 07:58.850
So what was the name?

07:59.090 --> 08:00.440
Turtle spawner.

08:03.530 --> 08:06.980
And then Ross parameters.

08:08.150 --> 08:11.150
And here we have two parameters.

08:11.150 --> 08:13.790
So we have turtle name prefix.

08:16.310 --> 08:21.080
Let's name this one my turtle to change it.

08:21.080 --> 08:24.110
And we have the spawn frequency.

08:26.060 --> 08:26.450
Okay.

08:26.480 --> 08:28.490
The default is one hertz.

08:28.970 --> 08:31.220
Let's say 1.5Hz.

08:31.700 --> 08:32.900
So it's a bit faster.

08:32.900 --> 08:36.620
And that's all the parameters that I can provide.

08:36.920 --> 08:38.960
Let's save this file.

08:38.960 --> 08:45.680
And then in that one we are going to provide the parameters directly from that YAML file.

08:45.680 --> 08:50.960
So for that node here I'm going to open and close the node tag.

08:51.380 --> 08:53.300
And I'm going to put the param.

08:53.990 --> 08:57.310
And if you don't remember the syntax we had it here.

08:57.310 --> 09:01.120
So from and then find PG share.

09:01.150 --> 09:05.680
So from and then dollar sign parentheses.

09:05.710 --> 09:08.620
Find pg share.

09:08.620 --> 09:12.100
The name of the package is my robot.

09:12.880 --> 09:18.160
Bring up and then slash config slash.

09:18.190 --> 09:21.550
Catch them all.

09:22.240 --> 09:24.310
Config dot YAML.

09:25.960 --> 09:26.680
All right.

09:26.680 --> 09:30.670
And the good thing about that is we can just duplicate the code.

09:30.670 --> 09:34.240
So I also open and close that node like this.

09:34.270 --> 09:39.100
And I can just basically take the same right here.

09:39.130 --> 09:40.210
It's the same file.

09:40.240 --> 09:40.660
Okay.

09:40.690 --> 09:45.730
So you can see our launch file is now nine lines of code long.

09:45.730 --> 09:50.290
And we start three nodes including parameters for two nodes.

09:50.380 --> 09:50.800
All right.

09:50.830 --> 09:57.100
So the first node the second node so the controller node with the params and the spawner node with the

09:57.100 --> 10:00.040
params that are all in this YAML file.

10:00.070 --> 10:04.210
Now we can go back here and we will need to build this time.

10:05.050 --> 10:09.040
Call and build the packages.

10:09.250 --> 10:13.090
Select my robot.

10:13.300 --> 10:14.590
Bring up.

10:17.410 --> 10:20.590
So yeah actually I miss a space here.

10:21.040 --> 10:28.990
And actually before I build one thing we can do because we are going to use, you see, from that,

10:28.990 --> 10:35.380
uh, launch file, we are starting nodes from the turtle package and the turtle sim catch them all package.

10:35.380 --> 10:37.690
So let's go to package dot XML.

10:37.690 --> 10:49.390
And you see we have an exact deployment here that we can add exact depends with turtle sim exact depend.

10:49.390 --> 10:52.570
And then another exact depend.

10:53.650 --> 10:54.350
Turtle SIM him.

10:54.350 --> 10:55.250
Catch them all.

10:56.690 --> 10:58.760
Okay, so we make things a bit cleaner.

10:58.760 --> 11:05.150
So in case those packages were not installed, then we will get an error directly when we try to do

11:05.150 --> 11:06.170
a call on build.

11:06.770 --> 11:08.030
So let's do that.

11:08.990 --> 11:09.470
Okay.

11:09.500 --> 11:10.520
It was very quick.

11:10.550 --> 11:12.770
And then well actually we don't need to do much.

11:12.770 --> 11:18.050
We just source the environment and we do.

11:18.080 --> 11:20.330
Ros two launch.

11:21.140 --> 11:21.800
Turtle.

11:22.160 --> 11:25.370
No actually it's from my robot.

11:25.610 --> 11:30.380
Bring up and launch file is called turtle SIM.

11:30.380 --> 11:31.430
Catch them all.

11:31.460 --> 11:33.380
Dot launch dot XML.

11:33.410 --> 11:37.130
Let's see what happens if I run this and you see.

11:37.130 --> 11:39.590
Well the application is just working.

11:39.590 --> 11:41.870
We have I'm going to do Ctrl C here.

11:42.380 --> 11:46.100
And let's come back here to the beginning.

11:46.100 --> 11:48.230
You see we start three processes.

11:48.260 --> 11:48.530
Okay.

11:48.560 --> 11:51.110
The turtle SIM node the controller and the spawner.

11:51.380 --> 11:56.820
And we have all the logs here that are mixed together in this launch file.

11:57.060 --> 12:00.300
Okay, so let's start again.

12:03.060 --> 12:03.360
All right.

12:03.360 --> 12:06.450
You can see the turtle is chasing the other turtles.

12:06.450 --> 12:09.990
And even here you see it changed to go to the closest one.

12:10.440 --> 12:11.190
All right.

12:11.220 --> 12:13.800
And that's going to continue again and again.

12:13.800 --> 12:16.290
And you can see the turtle name.

12:16.380 --> 12:18.750
So you see my turtle here.

12:18.780 --> 12:21.360
The prefix is my turtle.

12:21.870 --> 12:22.050
Okay.

12:22.080 --> 12:26.730
So that's because we have provided the configuration here my turtle.

12:26.730 --> 12:32.610
And now the cool thing about that is let's say you want to start the application with different parameters.

12:32.850 --> 12:34.620
You just stop.

12:35.100 --> 12:37.710
And we don't even need to go to the code.

12:37.800 --> 12:40.080
So we don't need to go to turtle spawner.

12:40.080 --> 12:42.450
We don't need to go to turtle controller.

12:42.630 --> 12:45.210
We don't even need to go to the launch file.

12:45.750 --> 12:55.450
We just open the config file and we say okay, instead of my turtle I want test And instead of 1.5,

12:55.450 --> 12:59.110
I want let's say very high frequency 5.0.

12:59.140 --> 13:01.150
I'm going to keep this one to true here.

13:01.150 --> 13:04.090
But you see I just for example, changed those settings.

13:04.450 --> 13:14.020
I save then of course I need to build, I need to source and I can run again.

13:15.250 --> 13:17.530
And you see now what is going very fast.

13:17.530 --> 13:19.960
We have five turtles per second.

13:19.990 --> 13:20.830
Okay.

13:21.040 --> 13:26.980
But you see, it just takes a few seconds to change those values.

13:26.980 --> 13:28.030
Save.

13:28.630 --> 13:30.700
And here.

13:30.880 --> 13:33.310
Well, maybe we had too many things.

13:34.120 --> 13:34.660
Okay.

13:34.690 --> 13:41.770
Build and source and run.

13:42.640 --> 13:43.030
All right.

13:43.030 --> 13:47.590
And we start the same application with a complete different set of configs.

13:49.450 --> 13:49.840
And.

13:49.840 --> 13:50.800
Congratulations.

13:50.800 --> 13:53.110
The project is now finished.
