WEBVTT

00:00.140 --> 00:07.100
In this laboratory lesson, we will add support for the Ros2 control library to our robot so that we

00:07.100 --> 00:12.770
can start the robot's joint control system when we launch the gazebo simulation.

00:13.190 --> 00:21.200
To do this, we will need to slightly modify the Urdf model of our robot and add some tags and plugins

00:21.200 --> 00:28.370
that are required by the Ros2 control library for the simulation in gazebo and for the proper functioning.

00:28.370 --> 00:30.620
So back to Visual Studio Code.

00:30.620 --> 00:37.640
Let's open the Arduino board description package and here within the Urdf folder, let's continue modifying

00:37.640 --> 00:38.630
this file here.

00:38.630 --> 00:44.750
So the Arduino bot dot Urdf dot acro here at the beginning of this file.

00:44.750 --> 00:46.310
So we can do it here.

00:46.310 --> 00:53.840
Let's declare a new macro argument with the tag macro argument.

00:53.960 --> 00:59.060
And let's close it here within the same line and accept the argument.

00:59.090 --> 01:03.240
Basically works like a variable for other programming languages.

01:03.240 --> 01:10.770
In fact, we are going to use this argument, this variable, in order to load the proper version of

01:10.770 --> 01:13.380
the Ros2 control plugin for gazebo.

01:13.380 --> 01:19.770
In fact, you will need to load a different Ros2 control plugin for gazebo depending on which Ros2 version

01:19.770 --> 01:20.820
you are using.

01:20.850 --> 01:23.430
So let's call this variable.

01:24.300 --> 01:29.490
Is ignition perfect and by default.

01:31.860 --> 01:35.070
Let's set it to true.

01:35.100 --> 01:36.030
Perfect.

01:36.030 --> 01:37.950
And that's it for this file.

01:37.950 --> 01:43.380
So for this file we just need actually to declare this argument here that now we are going to use in

01:43.380 --> 01:47.040
order to decide which Ros2 control plugin to load.

01:47.160 --> 01:54.030
Now instead of configuring the gazebo plugins and the Ros2 control library in this same file.

01:54.030 --> 01:57.300
So in the Arduino board Erfc Sacro.

01:57.300 --> 02:02.610
And so this will create a huge and hard to read CSV file.

02:02.610 --> 02:07.770
So this is already pretty huge and only contains the links and the joints of the robot.

02:07.800 --> 02:14.010
Now, instead of adding to this file, also the configuration for the gazebo and for the Ros2 control

02:14.010 --> 02:16.740
library, we can do it in a different file.

02:16.740 --> 02:23.850
So we can use another interesting feature of the exact format that is to include a Docker file from

02:23.850 --> 02:25.470
another profile.

02:25.470 --> 02:28.410
So basically we can create a new file.

02:28.410 --> 02:35.370
And for example let's call it Arduino robot gazebo dot Sacro.

02:35.370 --> 02:37.560
So for the moment this is an empty file.

02:37.560 --> 02:40.560
But the cool thing is that we can include.

02:40.560 --> 02:47.910
So here with the Sacro include like this.

02:47.910 --> 02:52.560
We can include the file name that we have just created.

02:52.560 --> 02:58.830
So let's find within the Arduino bot.

03:00.180 --> 03:01.530
description package.

03:01.530 --> 03:04.470
And from this package here we want to load.

03:04.470 --> 03:16.230
So from the Urdf folder we want to load the Arduino bot gazebo dot profile.

03:16.230 --> 03:17.130
Perfect.

03:17.130 --> 03:26.100
And so this instruction here basically so these include instruction is equivalent to copy all the content

03:26.100 --> 03:30.300
of this file here that now we are going to create just copy pasting it here.

03:30.300 --> 03:33.270
So this instruction is exactly equivalent.

03:33.270 --> 03:39.210
And the advantage of course is that we have separated all the links and the joints that are declared

03:39.210 --> 03:44.700
here in this Sacro file from the gazebo configuration that we are going to insert here.

03:44.700 --> 03:47.610
And so this is now easier to maintain.

03:47.610 --> 03:53.820
So if we want to load a new gazebo plugin, or if we want to change the configuration for our gazebo

03:53.820 --> 03:55.590
simulation, we just need to touch.

03:55.590 --> 04:01.390
So to modify this file here and instead this one will just contain the links and the joints of the robot,

04:01.390 --> 04:03.550
and so it will not change.

04:03.580 --> 04:04.480
Perfect.

04:04.480 --> 04:06.910
So let's start also this file here.

04:06.910 --> 04:08.800
So the Arduino board the gazebo file.

04:08.800 --> 04:12.970
And actually we can copy the first line from this one here.

04:12.970 --> 04:15.580
So from the Arduino bot Urdf dot sacro.

04:15.580 --> 04:18.040
So let's copy and let's paste it.

04:18.040 --> 04:21.220
In fact this is still an XML file.

04:21.220 --> 04:24.550
And then we have opened the robot tag.

04:24.550 --> 04:27.370
And here our robot is called Arduino bot.

04:27.400 --> 04:32.230
Also in this case let's insert the closing tag for the robot tag.

04:32.260 --> 04:33.010
Perfect.

04:33.010 --> 04:40.030
And now we can actually start configuring gazebo so we can actually start loading the gazebo plugins.

04:40.030 --> 04:44.470
To do so we can use the tag gazebo.

04:44.470 --> 04:51.640
And now in this tag we need to load a different Ros2 control plugin for the gazebo depending on the

04:51.640 --> 04:53.590
Ros2 version that you are using.

04:53.680 --> 04:57.700
So to do so, we can use the exact argument that we have created here.

04:57.710 --> 05:00.260
So this exact argument here.

05:00.260 --> 05:06.860
And so we can check its value with the exact row if perfect.

05:07.040 --> 05:13.400
And now let's check the value of the is ignition argument.

05:14.210 --> 05:19.370
So if the argument is ignition perfect.

05:19.370 --> 05:23.300
So we are checking the value of this one.

05:23.300 --> 05:29.300
And if this one is set to true in this case it means that you are using ros2 humble.

05:29.300 --> 05:35.300
And so if you are using Ros2 humble you need to load the plugin that is called.

05:35.300 --> 05:49.340
So here the file name is called ignition Ros2 Control system and the name of the class that we want

05:49.340 --> 05:51.320
to load from this plugin here.

05:52.370 --> 05:57.890
So the name is the from the package ignition Ross two.

05:59.750 --> 06:03.920
Control is the ignition.

06:04.610 --> 06:09.200
Ross two control plugin.

06:09.260 --> 06:10.310
Perfect.

06:10.430 --> 06:17.630
Eventually we can also configure this plugin here with some parameters with the tag parameters.

06:17.630 --> 06:22.850
And for the moment we can leave this tag here empty as we are going to configure it.

06:22.850 --> 06:24.620
So we are going to modify it.

06:24.650 --> 06:27.560
We are going to assign some parameters to this plugin.

06:27.560 --> 06:32.210
When in the following lessons we will learn about YAML files.

06:32.510 --> 06:33.350
Perfect.

06:33.350 --> 06:38.060
And so this is if you are using the humble version of Ross two.

06:38.090 --> 06:39.050
Otherwise.

06:39.050 --> 06:44.060
So let's use the exact pro and less perfect.

06:44.060 --> 06:58.700
And if the value of the argument is ignition is set to false, it means that you are using a newer version

06:58.700 --> 07:01.670
of Ros2, and so you need to load a different plugin.

07:03.440 --> 07:03.980
Perfect.

07:03.980 --> 07:05.690
And the file name.

07:05.840 --> 07:20.540
So here the file name that you need to load is called gazebo underscore Ros2 control system.

07:20.660 --> 07:29.960
And the name of the class that we want to load from this plugin is from the gazebo Ros2 control package.

07:30.170 --> 07:40.340
And then the class is called gazebo SIM Ros2 control plugin.

07:40.340 --> 07:41.120
Perfect.

07:41.150 --> 07:45.140
Also in this case we can configure this plugin here with some parameters.

07:45.140 --> 07:47.660
So we can copy the parameters tag.

07:47.660 --> 07:53.480
And also in this case actually we can leave this one empty as we will come back to modify this file

07:53.480 --> 07:57.210
in the future when we will learn about YAML files.

07:58.350 --> 08:04.470
For the moment, we have done with this file so we can save it, and we can move on to the creation

08:04.470 --> 08:06.510
of another exact file.

08:06.510 --> 08:15.030
So still here, still in the Urdf folder, let's create a new file and let's call it Arduino bot Ros2

08:16.350 --> 08:19.230
control dot sacrum.

08:19.230 --> 08:25.530
And as the name of this file suggests, basically here in this new file we are just going to insert

08:25.530 --> 08:28.890
the Ros2 control configuration for our robot.

08:28.890 --> 08:34.890
And actually this one will contain both the Ros2 control configuration for the simulated robot.

08:34.890 --> 08:40.560
And also in the following sections of this course, it will contain the Ros2 control configuration for

08:40.560 --> 08:42.570
the real robot as well.

08:42.630 --> 08:45.960
Now remember that we have declared a new macro file.

08:45.960 --> 08:50.310
And so actually we can include it here in the main urdf file.

08:50.310 --> 08:55.200
So this one here will be the one that we will load with the robot state publisher.

08:55.210 --> 09:02.740
So we can copy this include statement and we can paste it in order to include also the file that we

09:02.770 --> 09:03.970
have just created.

09:03.970 --> 09:11.500
And that is called Arduino bot Ros2 control dot Sacro.

09:11.500 --> 09:17.350
And so remember that this instruction here is equivalent to copying all the content of this file here

09:17.350 --> 09:20.830
that we are going to create right now and pasting here.

09:20.830 --> 09:26.110
And the advantage is of course, that we have smaller files that we can maintain easily.

09:26.230 --> 09:33.280
So again let's copy the first two instructions of this file and let's paste them here within the Arduino

09:33.280 --> 09:34.480
bot to control.

09:34.480 --> 09:37.690
Let's also close the robot tag.

09:37.720 --> 09:38.410
Perfect.

09:38.410 --> 09:40.480
And now within this tag here.

09:40.480 --> 09:46.030
So within the robot tag we can start configuring the Ros2 control library for our robot.

09:46.030 --> 09:52.330
We can do so using the Ros2 control tag.

09:52.360 --> 09:56.230
Perfect and now here let's set the type.

09:57.970 --> 10:01.210
And the type that we want to represent is a complete system.

10:01.210 --> 10:04.720
So a complete robot composed of several joints.

10:04.720 --> 10:08.170
So let's set the type to system.

10:08.170 --> 10:15.730
And also we can set the name to robot system perfect.

10:15.760 --> 10:19.390
Also in this case so also in the Ros2 control tag.

10:19.420 --> 10:25.420
Depending on the Ros2 version that you are using, you need to load a different Ros2 control plugin

10:25.420 --> 10:27.610
for the hardware interface.

10:27.610 --> 10:32.500
So for interacting with the simulated hardware on gazebo for this reason.

10:32.500 --> 10:35.920
Also in this case we can use the is ignition variable.

10:36.070 --> 10:41.260
So let's check whether the variable.

10:42.880 --> 10:52.270
So the value of the argument is ignition is set to true.

10:52.300 --> 10:54.490
Again if this one is set to true.

10:54.520 --> 11:00.550
It means that you are working with Ros2 humble, and in this case, you need to load the hardware interface.

11:01.600 --> 11:03.610
So let's call it hardware.

11:03.610 --> 11:12.190
And this is implemented in the plugin that is from the ignition Ros2 control library.

11:12.190 --> 11:17.260
And that is called ignition system.

11:17.260 --> 11:17.890
Perfect.

11:17.890 --> 11:24.460
And so this is the hardware interface for the simulated robot that you need to load if you are working

11:24.460 --> 11:26.320
with Ros2 Campbell.

11:26.350 --> 11:27.550
Otherwise.

11:28.120 --> 11:41.680
So sacral unless if the value of the argument is ignition is set to false.

11:41.680 --> 11:43.450
So it means that we are here.

11:43.450 --> 11:50.230
And so it means that on your PC you have installed a newer version of Ros2, like for example Ros2 Jessie.

11:50.290 --> 11:58.610
In this case the Hardware interface that you need to load is defined in the plugin that is from the

11:58.610 --> 12:09.200
gazebo Ros2 control library, and that is called gazebo SIM system.

12:09.200 --> 12:09.950
Perfect.

12:09.950 --> 12:15.710
And so with this one here, we have loaded the Arduino interface for the simulated robot.

12:15.710 --> 12:21.110
Whether you are using Ros2 humble or whether you are using any newer version.

12:21.140 --> 12:27.500
Now in the last section of this course, actually, we will come back to modify this file here.

12:27.500 --> 12:34.520
So the Arduino Ros2 control file in order to add another hardware interface, this time not with gazebo,

12:34.520 --> 12:36.680
but for the real robot.

12:36.680 --> 12:42.950
So the Arduino interface that will actually communicate with the real motors, that will drive the real

12:42.950 --> 12:44.060
robot arm.

12:44.750 --> 12:49.610
For the moment, let's just conclude the configuration of the Ros2 control plugin.

12:49.640 --> 12:57.150
Also, by adding some joint tag in order to define the interface that each movable joint of the robot

12:57.180 --> 13:01.470
has to use in order to interact with the Ros2 control library.

13:01.500 --> 13:06.060
Namely, each joint will specify how it will be controlled.

13:06.360 --> 13:13.980
So let's start with the first joint that is called joint one.

13:13.980 --> 13:20.520
And now, as you may recall from the theoretical lessons to connect the Ros2 control library to an hardware

13:20.520 --> 13:21.240
interface.

13:21.240 --> 13:28.440
So to an hardware resource, we need to define the two interfaces for communicating with the resource.

13:28.440 --> 13:32.640
And the first interface is called command.

13:34.680 --> 13:35.850
Interface.

13:35.850 --> 13:36.750
And this one.

13:36.750 --> 13:41.910
So the command interface is the one that we use in order to send commands to the hardware.

13:41.910 --> 13:44.670
So to send commands to the motors.

13:44.670 --> 13:49.410
And then there is also another interface that instead is called state

13:51.390 --> 13:54.990
Interface, we can close it in the same line.

13:54.990 --> 13:55.620
Perfect.

13:55.620 --> 13:57.270
And the second interface.

13:57.270 --> 14:05.370
So the state interface instead is used for reading the feedback from the hardware, namely to read the

14:05.370 --> 14:11.430
current state of the motor and for example, to read the current position or the current velocity of

14:11.430 --> 14:13.560
the motors in both cases.

14:13.590 --> 14:19.290
So for the command interface we want to use a position interface.

14:19.470 --> 14:25.590
So let's set the name to be position for the command interface.

14:25.590 --> 14:30.510
And also we can copy this one and we can set it here for the state interface.

14:30.510 --> 14:37.170
So we want to use a position interface both for sending commands to the hardware and also for receiving

14:37.170 --> 14:37.770
its feedback.

14:37.770 --> 14:40.530
So we want to know the position of the motors.

14:40.530 --> 14:45.060
And also we want to send the commands expressed in the position of the robot.

14:45.060 --> 14:51.300
And here in the command interface, we can also limit the maximum and the minimum command that we want

14:51.300 --> 14:52.170
to set.

14:52.410 --> 14:55.710
So let's set the parameters.

14:56.700 --> 15:00.450
So the name is called min.

15:00.510 --> 15:06.930
And also let's set another parameter for the command interface that is called max.

15:06.960 --> 15:12.570
And so this one is in order to limit the rotation of the first joint.

15:12.570 --> 15:19.860
And for the first joint we want to limit it from -90 degrees to 90 degrees.

15:19.860 --> 15:23.400
So actually this has to be expressed in radians.

15:23.400 --> 15:31.080
So if we go back here in the Arduino urdf we can copy the declaration of this variable here.

15:31.080 --> 15:33.570
And we can use it here as well.

15:34.050 --> 15:35.880
So let's paste it.

15:35.880 --> 15:36.630
Perfect.

15:36.630 --> 15:41.400
And now we can use this variable in order to define the minimum that is minus.

15:43.050 --> 15:48.660
And then the variable pi divided by two.

15:48.690 --> 15:49.440
Perfect.

15:49.440 --> 15:50.760
And the maximum.

15:50.800 --> 15:52.390
so we can copy this one.

15:52.390 --> 15:55.390
It's simply pi divided by two.

15:55.420 --> 15:58.150
So as we said 90 degrees.

15:58.240 --> 15:59.020
Perfect.

15:59.020 --> 16:01.900
And with this one we have completed the joint one.

16:01.900 --> 16:04.810
Now we are missing all the other joints of the robot.

16:04.840 --> 16:10.780
However, since all the movable joints of the robot will use the same command interface and will also

16:10.780 --> 16:19.030
provide the same state interface, we can simply copy paste this same instruction and we can use it

16:19.030 --> 16:20.770
for the joint two.

16:21.640 --> 16:24.670
Then we can paste it also for the joint three.

16:24.670 --> 16:28.060
And with this we have completed the joints of the arm.

16:28.090 --> 16:33.280
And then let's also set it for the joints of the gripper that are the joint four.

16:33.730 --> 16:37.210
And also we have the joint five.

16:37.240 --> 16:38.050
Perfect.

16:38.050 --> 16:45.220
Now we need to do some few changes, especially for these last two joints which control the fingers

16:45.220 --> 16:46.480
of the gripper.

16:46.480 --> 16:48.730
And actually these two joints here.

16:48.730 --> 16:53.960
So the joint four and the joint five are not independent, but they will move together.

16:53.960 --> 16:56.780
In fact, they are connected with a gearbox.

16:56.780 --> 17:04.100
And so, for example, when the joint four opens, also the joint five will open as they are moved together

17:04.100 --> 17:05.840
by the same motor.

17:05.930 --> 17:08.240
For this reason we need to set.

17:08.270 --> 17:12.230
So here for the joint four we need a different limit.

17:12.230 --> 17:15.710
And so the minimum is still -90 degree.

17:15.710 --> 17:22.220
But then when it closes it reaches the maximum position of 0.0.

17:22.220 --> 17:22.910
Perfect.

17:22.910 --> 17:26.720
And this is for the joint four instead for the joint five.

17:26.720 --> 17:32.030
So here this one will actually not have its own command interface.

17:32.030 --> 17:33.710
So we can remove it.

17:33.710 --> 17:37.550
And it will not have its state interface.

17:37.550 --> 17:39.320
So we can remove also this one.

17:39.320 --> 17:43.370
And this is because the joint five is not, as I said, the independent.

17:43.370 --> 17:48.050
But the joint five will simply mimic the behavior of the joint four.

17:48.080 --> 17:54.530
And now in order to indicate also to the Ros2 control library that this joint here will replicate.

17:54.530 --> 17:57.440
So we'll mimic the behavior of the joint for.

17:57.440 --> 18:00.080
We need to set here a parameter.

18:01.970 --> 18:08.210
So let's set the parameter that is called mimic.

18:11.120 --> 18:17.750
And here let's set the name of the joint that this joint here so that the joint five will mimic.

18:17.750 --> 18:21.200
And this is the joint four.

18:21.200 --> 18:26.660
And so with this parameter we are simply saying to the Ros2 control library that the joint five will

18:26.660 --> 18:28.760
move as the joint four.

18:28.760 --> 18:32.090
And then let's also set another parameter.

18:32.480 --> 18:36.170
And this one is called multiplier.

18:37.460 --> 18:40.070
And let's set it to minus one.

18:40.070 --> 18:48.170
And this simply indicates that the joint five will move as the joint four but in the different direction.

18:48.170 --> 18:56.120
So for example if the joint four will move 45 degrees, the joint five will move -45 degrees.

18:56.120 --> 19:00.110
And so this is because we have set the multiplier to minus one.

19:00.110 --> 19:05.270
So the intensity of the two movements will be the same but in the opposite direction.

19:05.660 --> 19:06.530
Perfect.

19:06.530 --> 19:08.300
So we can save this file.

19:08.300 --> 19:11.990
And with this we have completed the Urdf model of our robot.

19:12.020 --> 19:17.900
To support also the usage of the Ros2 control library in the gazebo simulation.

19:17.900 --> 19:23.570
And so here we have added we have loaded the proper Ros2 control plugin for gazebo.

19:23.570 --> 19:25.760
And here we have configured it.

19:25.760 --> 19:31.880
So we have configured all the joints of our robot in order to be actuated in the gazebo simulation.

19:31.910 --> 19:37.400
Now as we have added, as you can see here, the dependencies from these two libraries.

19:37.400 --> 19:46.400
So from the ignition cross to control if you are on Ros2 or from gazebo Ros2 control if you are on Ros2.

19:46.430 --> 19:50.130
Jazzy, we need to declare these dependencies also here.

19:50.130 --> 19:52.290
So in the package dot XML.

19:52.290 --> 20:00.180
So here let's add an execution dependency from the gazebo Ros2 control.

20:00.210 --> 20:06.300
However, as I said you're going to need this package here only if you are on newer version of Ros2.

20:06.300 --> 20:08.640
So for example, only if you are on Ros2.

20:08.670 --> 20:09.240
Jessie.

20:09.420 --> 20:12.270
So let's add a conditional dependency.

20:13.230 --> 20:18.690
So we want to add this dependency only if this condition is satisfied.

20:18.690 --> 20:22.050
And the condition that we want to verify is that the variable.

20:22.050 --> 20:26.820
So the environmental variable that is called Ros distro.

20:26.820 --> 20:31.320
So this variable here is bigger than or equal to iron.

20:31.320 --> 20:36.120
So if you are working with a ros2 version that is newer than iron.

20:36.120 --> 20:40.470
And for example if you are working with Jessie you need this package here.

20:40.530 --> 20:47.010
Otherwise let's add another execution dependency, this time from the ignition Ros2.

20:48.220 --> 20:49.480
Control package.

20:49.480 --> 20:51.700
And you need this package here only.

20:51.700 --> 20:57.460
If so, the condition is that you have the Ros distro.

20:59.890 --> 21:04.960
So the Ros version that you are using is equal to humble perfect.

21:04.960 --> 21:10.930
So if you are on Ros two humble you are going to need this package here.

21:10.930 --> 21:16.270
Otherwise if you are on any newer version you are going to need this other package here.

21:16.330 --> 21:19.270
So let's save also this file and that's it.

21:19.390 --> 21:24.400
Later in the course we will return to modify especially this file here.

21:24.400 --> 21:31.960
So the Arduino Ros to control file in order to add the support not only to the simulated hardware interfaces.

21:32.080 --> 21:37.120
So these other interfaces that will communicate with the simulated motors in gazebo.

21:37.120 --> 21:40.990
But also we will add the support to the real hardware interface.

21:40.990 --> 21:46.930
So to the hardware interface that will interact with the real motors and with the real robot.
