WEBVTT

00:00.200 --> 00:06.280
Finally, everything is ready to start the control system of our simulated robot in gazebo.

00:06.920 --> 00:14.920
The Urdf model is configured to load the gazebo Ros2 control plugin and the interface the simulated

00:14.920 --> 00:18.920
robot arm during gazebo with the Ros2 control library.

00:19.440 --> 00:25.840
We have defined the input and the output interfaces of each joint of the robot, and also we have configured

00:25.840 --> 00:32.840
the controller manager to interact with the robot's hardware and also with the other two applications.

00:33.480 --> 00:39.560
In this lesson, we will create a new launch file that starts all of this logic and functionalities.

00:40.120 --> 00:47.920
So let's open the Visual Studio Code and in the Arduino board controller let's create the new folder

00:47.920 --> 00:50.160
called launch.

00:50.440 --> 00:58.280
And here within this folder let's add a new file called controller dot launch dot pi.

00:58.600 --> 01:00.190
Since this is our a rush to launch.

01:00.230 --> 01:00.630
File.

01:00.990 --> 01:08.230
It is composed of a launch description object that we import from the launch library.

01:08.230 --> 01:11.350
So the launch description.

01:11.350 --> 01:18.390
And then we need to define the function generate launch.

01:20.870 --> 01:23.070
Description that returns.

01:25.230 --> 01:31.670
An object of type launch description which takes as input the list of all the functionalities that we

01:31.670 --> 01:33.550
want to start with this launch file.

01:34.030 --> 01:40.870
So let's start by launching the Robot State publisher node, which reads the Urdf model and publish

01:40.870 --> 01:43.310
its information into our Ros2 topic.

01:44.110 --> 01:50.430
We have already done this inside the Arduino bot description package inside the display dot launch,

01:50.430 --> 01:52.110
so let's copy this one.

01:52.150 --> 01:59.170
The node that is in charge of launching the robot state publisher and let's paste it here.

01:59.530 --> 02:02.850
Also let's remember to import the class node.

02:03.730 --> 02:08.170
So this one this instruction here to import the node.

02:08.610 --> 02:14.170
And now instead of using the model argument in the launch file as we did here.

02:14.570 --> 02:21.170
So where we enable the possibility to use a different model here in the controller launch, let's directly

02:21.170 --> 02:26.010
indicate the directory where the Urdf model of our robot is located.

02:26.370 --> 02:30.530
So let's import the OS library.

02:30.930 --> 02:40.490
And also let's import from the launch rose from the parameter description.

02:41.050 --> 02:48.410
Let's import the parameter value class and also from launch substitutions.

02:48.410 --> 02:57.190
So from launch substitutions let's import the class command.

02:58.510 --> 03:02.590
Now we need to assign a value to the robot.

03:05.390 --> 03:06.430
Description variable.

03:06.430 --> 03:09.030
So before it is used let's assign a value.

03:09.790 --> 03:15.550
And so here we need to indicate the directory where the Urdf model of the robot is located.

03:16.230 --> 03:19.070
So let's use a parameter value.

03:19.070 --> 03:21.590
So let's create a new object of this type.

03:21.910 --> 03:27.950
Within this one let's run a new command and the command that we want to run.

03:28.310 --> 03:30.630
Let's insert this one within a list.

03:31.190 --> 03:38.310
And so we want to run the command zero to convert first the model into a plain urdf model.

03:38.550 --> 03:44.910
And then we need to pass the full path of the Urdf model so we can use the function join.

03:47.030 --> 03:47.510
Okay.

03:47.830 --> 03:52.710
And here let's also remember to import the get package share directory.

03:52.710 --> 03:54.870
So from amend.

03:54.870 --> 03:57.660
Int index Python.

03:58.500 --> 04:08.060
From the packages module, let's import the get package share directory and we can use it here within

04:08.060 --> 04:09.180
the join function.

04:12.380 --> 04:16.700
To get access to the Arduino bot.

04:18.980 --> 04:20.020
Description.

04:23.460 --> 04:26.980
Package in which we have created the Urdf model.

04:27.540 --> 04:35.540
Then once we are in the Arduino bot description package, let's access to the Urdf folder and then within

04:35.540 --> 04:42.940
this folder let's access to our file that we called Arduino bot dot u.

04:44.980 --> 04:45.260
Dot.

04:46.540 --> 04:48.660
And also we want this command.

04:48.700 --> 04:56.210
So here we want this to be loaded with a value type Value type of a string.

04:56.210 --> 04:57.770
So str.

04:58.690 --> 05:02.010
Now the robot state publisher is completed.

05:02.450 --> 05:09.210
Before spawning the controllers that we defined in the Arduino bot controllers YAML configuration file.

05:09.650 --> 05:13.890
So actually before loading all the controllers that we defined here.

05:13.890 --> 05:20.530
So the arm controller and the gripper controller we first need to start another node that is available

05:20.530 --> 05:23.010
in the controller manager package.

05:23.010 --> 05:27.570
And that actually manages and supervises all of these controllers.

05:28.010 --> 05:29.450
So let's start a new node.

05:30.210 --> 05:33.690
So let's create a new instance called controller Manager.

05:34.090 --> 05:36.850
And this is an instance of the node class.

05:37.130 --> 05:37.810
Perfect.

05:37.810 --> 05:45.970
And we can use this one in order to start from the package that is the controller manager package.

05:46.130 --> 05:54.270
So from this one here we can start the executable that is the Ros2 Control node executable.

05:54.710 --> 05:57.430
And for this one here we can set some parameters.

05:57.870 --> 06:02.190
So we can set a list of parameters in order to configure this node here.

06:02.190 --> 06:05.510
So the Ros2 control node starting from the parameter.

06:05.870 --> 06:07.910
So here let's create a dictionary.

06:08.190 --> 06:14.310
And let's define the parameter that is called the robot description parameter.

06:14.470 --> 06:18.790
And this one will contain the urdf description of the robot.

06:19.070 --> 06:21.750
And so we can actually use this variable here.

06:21.750 --> 06:25.310
So we already loaded the urdf of our robot.

06:25.310 --> 06:26.270
So this one here.

06:26.270 --> 06:28.910
And we have already stored it in this variable.

06:28.910 --> 06:30.670
So in the robot description variable.

06:30.910 --> 06:35.550
And now we can use it in order to set a value for this parameter here.

06:35.550 --> 06:41.150
So we can simply set this variable so the robot description variable equal to the robot description

06:41.150 --> 06:41.750
parameter.

06:41.750 --> 06:44.670
So equal to this variable here then also.

06:44.710 --> 06:48.230
So finally after this variable here we can also set.

06:48.230 --> 06:52.700
So we can also provide the full directory to this configuration file here.

06:52.700 --> 06:53.900
So to the Arduino board.

06:53.940 --> 07:00.580
Controllers YAML so that the controller manager can be configured using these parameters here.

07:00.580 --> 07:05.740
So using these parameters here that we have defined in this configuration file.

07:06.540 --> 07:16.020
So here in order to provide the full directory to this file here we can use the OS path join function.

07:16.220 --> 07:22.980
And now here we can use the get package share directory in order to access the directory of the Arduino

07:22.980 --> 07:24.260
bot controller package.

07:27.660 --> 07:33.700
And then from this package so we can go to the config folder and from the config folder.

07:33.940 --> 07:36.340
So here we want to load this file here.

07:36.620 --> 07:43.860
So the Arduino bot controllers dot YAML file.

07:44.300 --> 07:44.980
Perfect.

07:45.140 --> 07:51.360
And now here with this one here we have correctly started and configured the controller manager.

07:51.680 --> 07:57.520
And now finally, for each of the controllers that we created and that we configured here.

07:57.720 --> 08:03.280
So for the ARM controller, for the gripper controller and also for this one here.

08:03.280 --> 08:08.960
So for the joint state broadcaster we can create a new node that actually starts.

08:08.960 --> 08:13.240
So that spawns each controller in the controller manager.

08:13.800 --> 08:19.320
So back here let's create a new instance that is called joint state.

08:23.240 --> 08:23.920
Spawner.

08:24.440 --> 08:26.440
So this is an instance of the node class.

08:26.880 --> 08:31.920
And we can use this node in order to start again from the package.

08:34.360 --> 08:35.920
That is the controller manager.

08:36.040 --> 08:43.480
So from this package here we can start the executable that is called the spawner executable.

08:43.800 --> 08:47.560
And so now we want to use this first instance of this node.

08:47.560 --> 08:51.020
So this instance of the spawner node in order to spawn.

08:51.020 --> 08:53.380
So in order to start this one here.

08:53.380 --> 08:56.260
So the joint state broadcaster controller.

08:56.820 --> 08:58.980
So here we can set some arguments.

09:00.820 --> 09:02.420
And this is a list of arguments.

09:02.660 --> 09:05.140
And so here let's start.

09:05.140 --> 09:12.420
So let's set the name of the controller that we want to start using this node which is the joint state.

09:14.700 --> 09:15.620
Broadcaster.

09:15.740 --> 09:19.860
And so actually this name here should match this one here.

09:19.860 --> 09:24.380
So the one that we have defined in the controller manager and also that we have configured.

09:24.420 --> 09:28.220
And so that we have specified which is the controller that it should load.

09:28.820 --> 09:39.060
Also here are the arguments that we need to set so we can set the flag controller manager perfect.

09:39.340 --> 09:47.170
And also we can set the namespace which is again controller Manager.

09:47.210 --> 09:48.970
And so this is just to set.

09:49.010 --> 09:51.530
So in order to link this one here.

09:51.530 --> 09:52.650
So this is pointer.

09:52.650 --> 09:57.570
So we are saying that we want to spawn this controller here into the controller manager.

09:57.970 --> 10:01.090
Now actually we need to use the same instruction.

10:01.090 --> 10:04.770
So we need to use the same node in order to start.

10:04.770 --> 10:07.810
So in order to spawn the remaining two controllers.

10:08.010 --> 10:11.170
So the arm controller and the gripper controller as well.

10:11.650 --> 10:15.850
So we can copy this instruction and we can paste it twice.

10:16.250 --> 10:17.330
So here we go.

10:17.370 --> 10:20.690
We have paste it twice and let's call the first one.

10:21.530 --> 10:25.770
Let's call it our controller spawner.

10:26.010 --> 10:29.810
And here we want to use this one in order to spawn the controller.

10:29.810 --> 10:31.930
So this one here the ARM controller.

10:32.050 --> 10:33.130
So we can copy it.

10:33.410 --> 10:36.370
And we can paste it here in the list of the arguments.

10:36.570 --> 10:40.130
And also in this case we want to spawn it into the controller manager.

10:40.570 --> 10:42.610
Now for the last node here.

10:42.610 --> 10:49.440
So let's call it instead Gripper controller spawner.

10:49.680 --> 10:52.040
And with this note here we want to start instead.

10:52.040 --> 10:54.240
So we want to spawn this one here.

10:54.240 --> 10:55.800
So the gripper controller.

10:55.800 --> 10:58.840
So let's copy it and let's paste it here.

10:58.840 --> 11:03.520
So in order to spawn the gripper controller into the controller manager.

11:04.120 --> 11:07.080
Now with this we have declared all the instructions.

11:07.080 --> 11:12.080
So all the nodes that we need in order to start the control system for our robot.

11:12.440 --> 11:19.240
So now in order to actually start using all of these classes so all of these objects, we need to declare

11:19.240 --> 11:20.000
them here.

11:20.240 --> 11:23.840
So in the list of the launch description class constructor.

11:24.320 --> 11:27.640
So let's start with the robot state publisher node.

11:27.640 --> 11:29.360
So let's first start this node.

11:29.840 --> 11:31.160
Then we can start.

11:31.200 --> 11:33.640
So as you can see here the controller manager.

11:35.520 --> 11:43.040
Then after the controller manager we can spawn the three controllers namely the joint state broadcaster

11:43.460 --> 11:49.020
Then the ARM controller and finally also the gripper controller spawner.

11:49.460 --> 11:50.140
Perfect.

11:50.500 --> 11:54.940
So with this we have completed our controller launch.py file.

11:54.940 --> 11:59.980
So this one here that in the order starts the controller manager.

12:00.260 --> 12:04.540
And then it spawns the three controller that we have configured.

12:04.540 --> 12:10.540
So the ARM controller, the gripper controller and the joint state broadcaster that simply will publish.

12:10.540 --> 12:13.580
So will provide the current state for each joint.

12:13.940 --> 12:17.220
So we can save this file and we can install it.

12:17.220 --> 12:23.220
So as we have created a new folder namely the launch folder in which we have created this file, we

12:23.260 --> 12:27.020
also need to install it so we can open the file cmake list.

12:27.300 --> 12:33.420
And here along with the config folder we also want to install the launch folder.

12:33.420 --> 12:39.460
So apart from installing the Arduino bot controllers let's also install here the controller launch dot

12:39.460 --> 12:45.410
Pi so that we can use the Ros2 launch command in order to start this file here.

12:45.810 --> 12:53.210
Then also as here in this launch file here, we have used some dependencies from the robot estate publisher

12:53.210 --> 12:55.250
and from the controller manager package.

12:55.410 --> 12:57.290
We need to declare them here.

12:57.530 --> 13:00.650
So we need to go in the package dot XML.

13:01.090 --> 13:09.210
And so we need to add a execution dependency from the Ros2 launch package.

13:09.610 --> 13:17.090
Then also we need another execution dependency from the robot estate publisher node.

13:17.330 --> 13:18.050
Perfect.

13:18.090 --> 13:19.330
We also need another one.

13:19.330 --> 13:26.610
So another execution dependency from the package which we have used in order to convert the exact model

13:26.610 --> 13:29.290
of our robot into a plain Urdf model.

13:29.690 --> 13:32.490
And finally, let's add another execution dependency.

13:34.850 --> 13:36.770
From the Controller manager node.

13:37.050 --> 13:37.730
Perfect.

13:37.730 --> 13:40.850
So with this also this file is completed and we can save it.
