WEBVTT

00:00.230 --> 00:01.910
To simulate our robot in gazebo.

00:02.210 --> 00:05.450
We only need the Urdf model and a launch file.

00:05.570 --> 00:07.250
To start the simulation.

00:07.670 --> 00:14.510
However, the Urdf model we have developed so far is not enough for the simulation as it doesn't contain

00:14.510 --> 00:20.690
all the information needed for Gazebo to simulate the physics and the forces that are acting on the

00:20.690 --> 00:21.380
robot.

00:21.560 --> 00:26.090
So let's add the missing tags inside the Urdf model of our robot.

00:26.180 --> 00:31.940
So in Visual Studio Code, let's go back to the Arduino board description, to the folder, and let's

00:31.940 --> 00:36.020
continue modifying the Arduino Urdf acro model.

00:36.810 --> 00:44.010
First of all, let's notice that each link only has a visual component associated with it that is represented

00:44.010 --> 00:45.360
by the robot mesh.

00:45.360 --> 00:48.930
So here we set for each link a certain robot mesh.

00:49.350 --> 00:55.800
However, while this is enough for RVs to display the robot model, it is not enough for Gazebo to simulate

00:55.800 --> 00:56.220
it.

00:56.520 --> 01:02.970
To achieve this, gazebo needs to know the volume occupied in the space by the link, not just its visualization.

01:03.180 --> 01:09.060
This is indicated with another tag that is called Collision.

01:09.060 --> 01:12.930
And so inside this tag we have the freedom to define the volume.

01:12.930 --> 01:15.720
So the space occupied by a certain link.

01:15.840 --> 01:22.790
For example, we can set that the base link occupy the exact same space as defined in the mesh.

01:22.800 --> 01:29.940
So basically we can copy the content of the visual tag and we can paste it within the collision tag.

01:30.150 --> 01:35.880
In this case, we have decided to use the same mesh both for the visualization and also for the simulation

01:35.880 --> 01:37.030
of the base link.

01:37.240 --> 01:39.400
However, this is not always the case.

01:39.760 --> 01:47.500
A mesh is in general a complex geometry consisting of many surfaces and edges, and it can be computationally

01:47.500 --> 01:53.860
very easy to simulate such geometries, especially when they interact with each other or with other

01:53.860 --> 01:54.820
surfaces.

01:55.420 --> 02:00.880
However, since our robot is very simple and there are very few links and so very few meshes, we can

02:00.880 --> 02:02.890
afford to use the entire mesh.

02:02.890 --> 02:09.100
So the complete mesh also for simulating the robot and so for defining the volume it occupies.

02:09.490 --> 02:15.160
So now let's continue adding the collision tag also to the other links.

02:17.780 --> 02:18.740
And within it.

02:18.740 --> 02:23.720
Let's paste still for all the links, the content of the visual tag.

02:23.720 --> 02:29.960
So for all the links, we are going to use the same mesh that we visualize in our vs also for simulating

02:29.960 --> 02:30.740
the volume.

02:31.550 --> 02:36.470
So let's continue with the forward drive arm.

02:40.260 --> 02:42.060
And then with the horizontal arm.

02:50.180 --> 02:51.830
Then with the closer port.

02:54.320 --> 02:56.180
So let's copy the content.

02:58.100 --> 02:59.240
And then with the gripper.

02:59.240 --> 02:59.840
Right?

03:11.960 --> 03:14.450
And finally the gripper left.

03:16.780 --> 03:18.940
In which you copy its content.

03:20.620 --> 03:25.920
Now let's add another essential piece of information for the simulation of each link.

03:25.920 --> 03:27.540
And this is the inertia.

03:28.260 --> 03:34.560
The inertia of a body, or in this case of a link, is a measure of its resistance to change in the

03:34.560 --> 03:35.250
motion.

03:35.250 --> 03:38.430
And it strongly depends on the mass of the body itself.

03:38.430 --> 03:41.010
And also this mass is distributed.

03:41.280 --> 03:47.220
So starting from the first link from this one, the base link, let's add the inertia matrix of the

03:47.220 --> 03:50.850
body using the tag inertial.

03:51.330 --> 03:57.840
Don't worry if these terms are unfamiliar to you, they are physical parameters of a rigid body that

03:57.840 --> 04:01.650
help understand how it moves under the action of external forces.

04:01.770 --> 04:05.370
So let's add this tag for the base link for the moment.

04:05.370 --> 04:12.210
And this tag will contain a mass and also an inertia.

04:16.310 --> 04:19.040
And let's assign the value of the mass of the body.

04:19.040 --> 04:20.900
So here within the mass tag.

04:21.440 --> 04:25.250
So let's assign it a value of one.

04:26.000 --> 04:28.820
So for the first link, let's assign a value of one.

04:28.820 --> 04:30.800
And for the inertia tag.

04:30.800 --> 04:38.930
So for this one here, we need to assign six attributes that indicate the value of the inertia matrix

04:38.930 --> 04:40.400
of this rigid body.

04:40.700 --> 04:46.610
Once again, we are going to use some default values for this matrix since it is not required in this

04:46.610 --> 04:50.540
course to calculate the correct inertia values of the robot.

04:50.630 --> 04:56.360
And we are going to use these same values for the inertia of all the links that belongs to the robot.

04:57.100 --> 04:59.450
So let's start by adding the property i.

04:59.500 --> 04:59.890
X.

04:59.890 --> 05:00.520
X.

05:01.630 --> 05:06.460
Then i x, y and then i x.

05:06.640 --> 05:07.360
Z.

05:08.530 --> 05:10.330
And let's set this 1 to 1.

05:10.510 --> 05:13.900
So 1.0, then zero.

05:14.590 --> 05:16.390
So 0.0.

05:16.750 --> 05:18.910
And again, 0.0.

05:18.940 --> 05:31.380
Then let's add other properties that are i y y that we set to 1.0 and i y z that we set instead to zero.

05:31.390 --> 05:37.660
And then finally there is the property i, z, z that we set to 1.0.

05:38.710 --> 05:43.840
Just to give you an idea of the meaning of these parameters, they correspond to a matrix with three

05:43.840 --> 05:51.190
rows and three columns called identity matrix because it contains all values equal to zero except for

05:51.190 --> 05:53.230
the main diagonal where it has value.

05:53.230 --> 05:53.740
One.

05:54.010 --> 06:00.190
The logical meaning of this matrix is that the inertia of the link will be the same in all the directions

06:00.190 --> 06:02.290
without any multiplicative factor.

06:03.080 --> 06:03.770
In theory.

06:03.790 --> 06:06.440
Now we should add these same tag inertial.

06:06.440 --> 06:09.740
So basically this is same one for each link.

06:10.010 --> 06:15.860
But since we are assuming that the inertia matrix is the same for all the links, so the only thing

06:15.860 --> 06:18.980
that we would need to change is the inertial tag.

06:18.980 --> 06:22.040
So basically it's the mass value, this one.

06:22.610 --> 06:29.180
To avoid rewriting all the code and in order to adhere to one of the good programming practices, which

06:29.180 --> 06:33.020
is not to repeat the code but use reusable components.

06:33.360 --> 06:39.920
Chakra provides a tool called macro, which can be compared to the functions in the standard programming

06:39.920 --> 06:40.700
languages.

06:40.820 --> 06:46.550
So with a macro, we can define a reusable portion of code simply by using this name.

06:46.550 --> 06:51.890
So we can refer to the full content of the macro simply by calling the name of the macro.

06:52.190 --> 06:57.740
And optionally, we can also pass some parameters to the macro as if it was a function.

06:58.370 --> 07:02.570
So let's create our first macro with the exact format.

07:02.690 --> 07:08.330
So let's use the tag Sakura macro and let's close it.

07:08.480 --> 07:13.820
And like a regular function, we need to assign a name to it, which is the one that we are going to

07:13.820 --> 07:15.190
use in order to call.

07:15.200 --> 07:22.880
So in order to use this macro, so let's assign a name and optionally we can also assign so we can also

07:22.880 --> 07:24.500
pass some parameters.

07:25.520 --> 07:33.290
So this one, in order to configure the behavior of the macro itself, let's call this macro default

07:34.490 --> 07:35.300
inertia.

07:38.000 --> 07:44.870
And the only parameter that it received and that we want to configure is the mass of the link.

07:45.080 --> 07:48.650
Now, inside this function, let's copy.

07:49.820 --> 07:55.820
All the content of the inertia that we have just created for the base link and let's paste it here.

07:55.820 --> 08:02.960
So now we have that the inertial tag, instead of being copied within each link, is within this macro.

08:02.960 --> 08:08.060
So the macro that we called default inertial and here we just need to change.

08:08.060 --> 08:13.340
So in order to use this macro, we need to replace the value of the mass with the mass tag.

08:13.340 --> 08:20.240
So here, instead of using an hardcoded value, we can use the mass.

08:20.240 --> 08:26.510
So basically the value that this macro here received as input, so received as parameter.

08:27.190 --> 08:29.860
Now we can start using this macro here.

08:29.860 --> 08:32.380
So the default inertial in each link.

08:32.380 --> 08:35.620
So whenever we need to define the inertia of the link.

08:36.230 --> 08:42.890
To use these macro, we can use the tag sacrum followed by the name of the macro that we want to use

08:42.920 --> 08:45.950
that we called default.

08:47.470 --> 08:48.220
Inertial.

08:49.980 --> 08:53.820
And to this tag here, we need to pass the mass.

08:53.820 --> 08:55.500
So we need to provide the mass.

08:55.500 --> 08:56.820
And for the first link.

08:56.820 --> 09:00.120
So for the base link, let's use a mass of one.

09:00.600 --> 09:05.300
Now we just need to copy this line and paste it within each link.

09:05.310 --> 09:07.860
So let's start with the base plate.

09:07.980 --> 09:15.190
And here let's set the mass to 0.1, then into the forward drive arm.

09:15.510 --> 09:18.720
And here let's set again the mass to 0.1.

09:19.700 --> 09:21.380
Then the horizontal arm.

09:23.210 --> 09:26.390
And this also uses a mass of 0.1.

09:27.610 --> 09:29.590
Then the close support.

09:29.590 --> 09:31.780
So here and here.

09:31.780 --> 09:35.710
Instead, let's use a mass of 0.05.

09:35.920 --> 09:43.000
And finally, for the gripper right here, let's use a mass of 0.01.

09:43.000 --> 09:45.940
And the same for the gripper left.

09:45.940 --> 09:47.770
So 0.01.

09:48.370 --> 09:51.370
We can save this file with this.

09:51.370 --> 09:56.620
Our RDF model contains all the necessary tags for the simulation of the robot in Gazebo.

09:57.040 --> 10:03.880
In the next lesson, we are going to start the simulation in Gazebo using again the Ros two launch files.
