To create the XML model of the robot following the Urdf format.
Let's start by creating a new Ros two package inside our Arduino bot workspace.
So let's go within the workspace and within the source folder.
And here we have already created the Arduino bot Pi examples package and the Arduino bot CP examples
package.
So to add a new package to this folder, let's use again the command Ros2 package create followed by
the build type that we want to use for creating this package.
And since we won't be including any Python or Cplusplus code in this package, let's use the default
Ros to build type.
So as build type, let's use the amend cmake.
That is the default one for Ros two.
And then we also need to assign a name to this package which we can call Arduino bot.
This option and let's press enter to create also this package here.
So in the Arduino bot description package, we are going to include all the components related to the
Urdf model of our robot and we are not going to develop a so to insert any cplusplus or Python code
within this package, but only XML files.
So let's go back to the workspace now and let's build it again.
So that also the new package, as we can see here, is compiled.
And now it's available in Ros two.
Now let's move on to the fun part in which we are going to develop the urdf model of our robot.
So in the Arduino bot description package that we have just created, let's create a new folder.
So this one called Urdf, and this folder will contain the XML file with the robots model.
So the robot's link and the robot's joint.
And so let's create a new file within this folder.
And this is called Arduino bot dot Urdf dot Acro.
And as you can see, this is not a regular urdf file, but this is a acro file and this is a format.
So the acro format extends the urdf format and allows us to do more advanced things with our robots
XML tags.
Then before starting implementing the model of our robot still within the Arduino board description
package, let's create another folder.
And this one is called Meshes.
So let's create this folder and this will contain the 3D models.
So the 3D CAD of our robot, which we are going to use for the visualization and the simulation of our
robot.
So let's download the attached archive to this lesson.
So the file Arduino board meshes and let's extract its content and then let's copy all the content.
So all the STL files that are in this folder, let's copy this one and let's paste them within the Arduino
bot workspace, the source folder and within the Arduino board description and within the meshes folder
that we have just created.
So let's paste all the 3D models of the robot within this folder.
So within the meshes folder.
Now back in our model, so back in the Arduino board dot Urdf file, let's start by declaring that this
is an XML model.
So let's declare that this is an XML model and also let's say which version of XML we are using.
So the version is the 1.0.
As we learned in the theoretical lessons, when we create a new RDF model of a robot, we need to use
the tag robot, which then contains all the other components of the robot.
An XML tag can be seen as a container in which we can nest other containers, so in which you can declare
other properties related to the tag itself, or also in which you can insert other components of the
robot attack starts with the angular bracket and then followed by the name of the tag that in this case
is robot.
And then it's still closed by another angular bracket.
And now, as we can see, thanks to the XML extension for Visual Studio code that we installed in one
of the first lessons, the tag is also automatically closed.
And so we can see that here.
This one is our container.
So the robot container and this is the opening tag and this is the closing tag of our container that
was automatically inserted by the visual Studio code extension.
Now between these two tags.
So between the opening and the closing tags, we are going to insert all the components of the robot.
So let's start by giving the robot a name and let's call it Arduino bot.
And then since this is a sacral model, so since we are using the sacral format and not plain urdf,
we also need to indicate where the definition of this format is located with the command x, m, l,
n s and then sacral.
And this is in the http ww w ross.org and then in the wiki and then sacral.
Let's start by adding the very first link to our robot.
So let's use a tag link which we can close in the same line by using the forward slash.
So this tag link will be opened and closed within the same line.
And let's call this one word.
Since we are not going to assign any other properties to this link, we can directly close this link
within the same line.
So that's why we use the forward slash.
Actually, this first link of the model doesn't belong to the robot yet, but will only serve to anchor
the manipulator to the word reference frame.
This link then is the parent of all the other links that compose the robot, and we will also be the
interface link between the robot and the external world.
Now let's add another link.
That is the very first link of the robot.
Now we can open and close this link in two separate lines since we are going to insert some attributes
to this link.
And so let's name this link, this time the base link.
And now we can associate a mesh with this link that defines how we want this component to be rendered.
So to be visualized.
In order to do so, we can use the tag visual.
So within the tag link we can use the tag visual and then within this tag we can use a geometry.
So we want to display a geometry.
And this geometry is defined within a mesh.
And the mesh that we want to render for the base link is in the package Arduino but description and
within the meshes folder.
So within this folder here that we created and in which we inserted all the STL file of our robot.
For this first link, we want to display the basement dot STL file.
Now since this file, this mesh is quite large, let's scale its resolution equally in all the directions.
Using the property scale.
And so let's set it to 0.010.01 and 0.01 in all direction.
Then we also need to specify the origin of this mesh.
So the origin of this mesh with respect to the base link.
So where this mesh is located and how this mesh is oriented with the respect of the base link.
So still within the visual tag, let's use another tag that is called origin.
And this origin tag has two properties that are r.p that defines the orientation.
And then there is X, Y, Z that instead defines the position.
As I mentioned, these values express the placement and the orientation of the mesh relative to the
link It belongs.
So in this case to the base link.
And these values depend on how the mesh was generated.
And typically they are obtained by trying different values and also observing how the mesh moves relative
to the link until we are satisfied about the result.
For the moment, let's set all of this to zero and then we are going to visualize this model with these
values set to zero and we are going to see if the mesh renders properly.
So if the mesh renders in the proper position and orientation that we desire in order to simulate and
visualize them correctly.
But before doing so, but before starting visualizing our robot, let's connect.
So let's add a joint that connects the two links that we have just created.
So this is done with a tag joint and let's give it a name.
So the name of the joint is the virtual joint, as this is not a proper joint.
So as this joint doesn't belong properly to the robot, but just serve to attach the robot to the world.
So to attach the first link of the robot that is the base link to the world.
So the parent of this joint.
Is the link named.
World and the child of this joint.
So of this connection is the link that we called base link.
This connection is fixed.
So basically the base link cannot move with the respect to the world.
And so we can set the type of this joint to be fixed.
And so this means that the base link.
Cannot move, cannot rotate or translate with respect to the frame world.
Also, we need to indicate.
How these two links are connected to each other so their relative position and orientation again.
With the tag origin.
And in this case, let's set the r p so the orientation to zero.
And this means that the base link and the world link.
Are oriented the same way.
And also let's set the X, y, z property to zero.
And this means that also these two links have the same center.
So the base link is exactly oriented and positioned the same as the world frame.
This two despite having the same name.
So the origin tag here, they have a completely different meaning.
In fact, as I said, this one is needed in order to attach.
So in order to express the transformation matrix between the base link and the word link.
So between these two reference frames.
And so we can see that here the transformation matrix is zero among these two links.
Instead, these are their tag origin is useful in order to render properly the mesh.
So in order to set the orientation and the position of this mesh so of the basements with respect to
the base link.
And so this is just used for visualization and simulation.
And now let's already visualize our robot in order to see the two links that we have created and how
they are connected to each other.
And also in order to customize these variables here, in order to render properly the RDF model.
And so these mesh here.
To do so, we first need to install the meshes folder and also the Urdf folder.
So we need to install these two folder in Ros two so that they are recognized within our package.
To do.
So let's go to the Cmakelists.txt file.
And here let's delete all the commented rows in order to have a more readable file.
Okay.
And now here, let's add an install instruction and we want to install the directory that is called.
Meshes and also the directory that is called Urdf.
So we want to install basically this folder and also this folder so that when we do the build of our
package, these two folders are recognized by Ros2 and so we can use its content and we want to install
this one.
So the destination is the shared folder and within the shared folder we want to install in the sub folder
that has the same name of the package.
So Arduino bot description and we can access to this folder by using also the variable project project
name.
So basically this will contain the string arduino bot description.
Now let's save this file and let's build our workspace.
In order to start visualizing our urdf model.
So in our new terminal, let's go to the workspace and let's start by building it.
Now the build is complete so we can open a new window of the terminal.
And here we can start by sourcing the workspace.
So the file setup dot bash.
And now in order to display our Urdf model, we are going to use a library that is available in Ros
two and that is called Urdf tutorial.
So let's start by installing this library.
So with apt get install and then we want to install the package.
Then the Ross version that in my case is.
And then also the name of the package.
That is the Urdf tutorial package.
So let's press enter to install this package.
And then now, as you can see in my case, I already have it, so I can already start using it.
Now to display our Erdf model.
So the Erdf model of our robot in RVs, we need to execute a command that we haven't encountered so
far and also some files, some Ros, two files that we haven't encountered so far.
So don't worry if you don't know these command yet, it will be clear in the following lessons.
So the command that we are going to use to visualize our Erdf model is Ros two launch, and then from
the Erdf tutorial package that we have just created, let's start the display dot launch.
And then to this one we need to pass the full directory of our Erdf model that we want to visualize.
So in my case this is in the OLM and then in the Workspace Arduino Bot workspace in the source folder,
then in the Arduino bot description in the Erdf folder, and I want to render the Arduino bot Erdf exact.
So let's press enter and this will open the visualization of the robot model.
So here we can see that we have our robot model and also we can see the frames.
So we can already see the base link and the word that are basically here.
Those are overlapped and so we can see just one, but there are two actually.
Now we can see that, for example, the mesh is not rendered properly.
And with this I mean that the center so the reference frame base link is not properly centered with
the base.
And so we need to change a little bit our model of the robot and specifically we need to modify this
one here.
So this tag here in order to match the mesh of the robot.
So this one that is the base of the robot with this frame.
So with the center of this frame, I have already tested some values and the ones that are working are
-0.5.
So let's translate along the x axis, about -0.5 and also about -0.5 along the Y axis.
So let's save this again.
And now let's interrupt the visualization.
Let's build again the workspace and let's restart the visualization.
And now we can see that the mesh is perfectly centered.
So this is the meaning of changing this parameter here.
So the origin here.
And so this will change the position of the mesh relative to the link it belongs to.
Now let's close the visualization and let's continue adding new links and new joints to the robot.
So let's start by adding a new link and let's call this one.
So the name of this link is the base plate.
And also to this one, let's attach a mesh.
So again, let's use the visual tag and within it let's use the geometry tag.
And within this geometry tag we want to visualize a mesh.
And this time the mesh that we want to visualize is still in the package.
Arduino But description within the Meshes folder.
And now we want to visualize the mesh that is called base plates.
So this one base plate dot STL, and also in this case, let's scale it so by 0.01 in all the directions
since this mesh is quite large.
Also let's specify the origin of this mesh by adding the tag origin within the tag visual.
And so we need to specify the orientation of the mesh so r pi and its translation.
So x, y, z.
And this is specify how the mesh is positioned and oriented with respect to the base plate.
So this frame here, let's set the Pi to zero and instead the x, y, z.
I tried several values and the ones that are working better are -0.39 -0.39 and -0.56.
So these are the values that render the base plates in the correct position of the robot.
Now let's continue by adding a new joint.
So let's add a new joint and let's call this one.
So the name of this joint is joint one and this connects the parent link.
So the link that is the previous one.
So the base link.
To the new one that we have created.
So the child in this case the child link, is the one that we have just created, and that is called
base plate.
Now if for this connection.
So for this link, we used the type fixed as we did for the previous joint.
This means that we are implementing a static connection between the base link and the base plate, and
this means that the base plate cannot move, cannot rotate or translate with respect to the base link.
But this is not the case, in fact, for our robot.
The base plate is the rotating base of the robot.
So the first joint that is already actuated by a motors for our robot.
So in order to implement this, let's set the type of this connection to be revolute.
And this means that the base plate can rotate with the respect to the base link so to its parent.
And now since we are using a movable joint, so a joint that can rotate, let's also indicate which
is the rotation axis.
So here let's set the property axis and this as X, y, z.
So we need to set the X, y, z, and we need to set which is the rotation axis.
And in this case it is the Z axis.
So let's indicate this one by setting 001.
And so this indicates that the rotation axis that the base plate can use for rotate along the base link
is the Z axis.
Finally, we also need to indicate the origin of this connection.
And so we need to indicate which is the transformation matrix that connects these two frames.
So the transformation matrix that connects the base link to the base plate.
So let's set the properties R, P and the property X, Y, Z, and these express the rotation and these
instead express the orientation.
Now we can take these values from the CAD model of our robot, and here we can see that the base plate
link is oriented the same way as the base link, so we can set the Rpy property to zero since they are
oriented the same way.
Also still from the CAD model, we can see that the base plate is translated along the Z axis by three
centimeters.
And so let's set the X, y, z to be zero zero and 0.307.
Now since this joint one here, it's a movable joint.
So a joint that allows the rotation of the two links that are connected between each other.
We need also to specify which are the limits of this rotation.
And this is done with the tag limit.
So here we need to specify the minimum and the maximum angle.
So the lower angle of rotation and the upper angle of rotation.
And also we need to specify the maximum force.
So the maximum effort and also the maximum velocity.
Now since we are going to use the same actuators, so the same motors for all the movable joints of
our robotic arm, basically their mechanical and kinematic limits will be the same.
And so in order to avoid hard coding all these values for each joint of our Erdf model, we can use
one of the amazing features provided by the Acro format, which is the ability to create some variables
also known as properties in the Acro format that function the same way as the variables in any other
programming language.
So we can start by defining a new property.
Let's go at the beginning of our robot tag.
And so let's create a new variable, a new Sakura
property, and for example, let's name this one Pi, and this will contain the value 3.14 159.
So it will contain this number here.
And so from now on in the urdf model of our robot, whenever we want to use this value here, instead
of retyping all these value here, we can just use the variable pi.
Now the same way.
Let's create other two properties, so other two variables.
So let's copy this one and let's paste it two more times.
And these are the effort.
And the velocity and let's set them respectively to 30.0 and to 10.0.
Now we can start using these properties to set the limits So the rotation, the effort and the velocity
limits for the joint one.
So let's set that the joint one.
So the minimum angle that the joint one can reach is -90 degrees.
So minus in radians is pi divided by two.
And also the maximum angle that it can reach is plus 90 degrees.
So in radians it is pi divided by two.
So this is the way in which we can use exact property.
So a variable in the exact model.
Also, let's do the same for the effort.
So here, let's use the effort variable.
And here for the velocity, let's use the velocity variable.
Now we can save this model and let's visualize it one more time.
So let's open again the terminal.
Let's build our workspace and let's use the same mysterious command we have been using so far in order
to visualize our robot.
And so now we can see that it is composed of two meshes.
So there are two links here that are the world and the base link.
And then we have another frame here, and this is the base plate.
And these two links are attached to each other.
And also we can see that by using this slider that was also automatically launched, we can also move
the base plate.
And so we can rotate actually the base plate with the respect to the base link, we can see how the
base plate frame is rotating.
So this frame here is rotating with the previous one that instead is fixed.
So this is the rotation.
And also we can see the limits of this rotation.
So it goes from 1.57, so 90 degrees to -1.57 radians.
So -90 degrees.