To simulate our robot in gazebo.
We only need the Urdf model and a launch file.
To start the simulation.
However, the Urdf model we have developed so far is not enough for the simulation as it doesn't contain
all the information needed for Gazebo to simulate the physics and the forces that are acting on the
robot.
So let's add the missing tags inside the Urdf model of our robot.
So in Visual Studio Code, let's go back to the Arduino board description, to the folder, and let's
continue modifying the Arduino Urdf acro model.
First of all, let's notice that each link only has a visual component associated with it that is represented
by the robot mesh.
So here we set for each link a certain robot mesh.
However, while this is enough for RVs to display the robot model, it is not enough for Gazebo to simulate
it.
To achieve this, gazebo needs to know the volume occupied in the space by the link, not just its visualization.
This is indicated with another tag that is called Collision.
And so inside this tag we have the freedom to define the volume.
So the space occupied by a certain link.
For example, we can set that the base link occupy the exact same space as defined in the mesh.
So basically we can copy the content of the visual tag and we can paste it within the collision tag.
In this case, we have decided to use the same mesh both for the visualization and also for the simulation
of the base link.
However, this is not always the case.
A mesh is in general a complex geometry consisting of many surfaces and edges, and it can be computationally
very easy to simulate such geometries, especially when they interact with each other or with other
surfaces.
However, since our robot is very simple and there are very few links and so very few meshes, we can
afford to use the entire mesh.
So the complete mesh also for simulating the robot and so for defining the volume it occupies.
So now let's continue adding the collision tag also to the other links.
And within it.
Let's paste still for all the links, the content of the visual tag.
So for all the links, we are going to use the same mesh that we visualize in our vs also for simulating
the volume.
So let's continue with the forward drive arm.
And then with the horizontal arm.
Then with the closer port.
So let's copy the content.
And then with the gripper.
Right?
And finally the gripper left.
In which you copy its content.
Now let's add another essential piece of information for the simulation of each link.
And this is the inertia.
The inertia of a body, or in this case of a link, is a measure of its resistance to change in the
motion.
And it strongly depends on the mass of the body itself.
And also this mass is distributed.
So starting from the first link from this one, the base link, let's add the inertia matrix of the
body using the tag inertial.
Don't worry if these terms are unfamiliar to you, they are physical parameters of a rigid body that
help understand how it moves under the action of external forces.
So let's add this tag for the base link for the moment.
And this tag will contain a mass and also an inertia.
And let's assign the value of the mass of the body.
So here within the mass tag.
So let's assign it a value of one.
So for the first link, let's assign a value of one.
And for the inertia tag.
So for this one here, we need to assign six attributes that indicate the value of the inertia matrix
of this rigid body.
Once again, we are going to use some default values for this matrix since it is not required in this
course to calculate the correct inertia values of the robot.
And we are going to use these same values for the inertia of all the links that belongs to the robot.
So let's start by adding the property i.
X.
Then i x, y and then i x.
Z.
And let's set this 1 to 1.
So 1.0, then zero.
So 0.0.
And again, 0.0.
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.
And then finally there is the property i, z, z that we set to 1.0.
Just to give you an idea of the meaning of these parameters, they correspond to a matrix with three
rows and three columns called identity matrix because it contains all values equal to zero except for
the main diagonal where it has value.
One.
The logical meaning of this matrix is that the inertia of the link will be the same in all the directions
without any multiplicative factor.
In theory.
Now we should add these same tag inertial.
So basically this is same one for each link.
But since we are assuming that the inertia matrix is the same for all the links, so the only thing
that we would need to change is the inertial tag.
So basically it's the mass value, this one.
To avoid rewriting all the code and in order to adhere to one of the good programming practices, which
is not to repeat the code but use reusable components.
Chakra provides a tool called macro, which can be compared to the functions in the standard programming
languages.
So with a macro, we can define a reusable portion of code simply by using this name.
So we can refer to the full content of the macro simply by calling the name of the macro.
And optionally, we can also pass some parameters to the macro as if it was a function.
So let's create our first macro with the exact format.
So let's use the tag Sakura macro and let's close it.
And like a regular function, we need to assign a name to it, which is the one that we are going to
use in order to call.
So in order to use this macro, so let's assign a name and optionally we can also assign so we can also
pass some parameters.
So this one, in order to configure the behavior of the macro itself, let's call this macro default
inertia.
And the only parameter that it received and that we want to configure is the mass of the link.
Now, inside this function, let's copy.
All the content of the inertia that we have just created for the base link and let's paste it here.
So now we have that the inertial tag, instead of being copied within each link, is within this macro.
So the macro that we called default inertial and here we just need to change.
So in order to use this macro, we need to replace the value of the mass with the mass tag.
So here, instead of using an hardcoded value, we can use the mass.
So basically the value that this macro here received as input, so received as parameter.
Now we can start using this macro here.
So the default inertial in each link.
So whenever we need to define the inertia of the link.
To use these macro, we can use the tag sacrum followed by the name of the macro that we want to use
that we called default.
Inertial.
And to this tag here, we need to pass the mass.
So we need to provide the mass.
And for the first link.
So for the base link, let's use a mass of one.
Now we just need to copy this line and paste it within each link.
So let's start with the base plate.
And here let's set the mass to 0.1, then into the forward drive arm.
And here let's set again the mass to 0.1.
Then the horizontal arm.
And this also uses a mass of 0.1.
Then the close support.
So here and here.
Instead, let's use a mass of 0.05.
And finally, for the gripper right here, let's use a mass of 0.01.
And the same for the gripper left.
So 0.01.
We can save this file with this.
Our RDF model contains all the necessary tags for the simulation of the robot in Gazebo.
In the next lesson, we are going to start the simulation in Gazebo using again the Ros two launch files.