In this laboratory lesson, we will add support for the Ros2 control library to our robot so that we
can start the robot's joint control system when we launch the gazebo simulation.
To do this, we will need to slightly modify the Urdf model of our robot and add some tags and plugins
that are required by the Ros2 control library for the simulation in gazebo and for the proper functioning.
So back to Visual Studio Code.
Let's open the Arduino board description package and here within the Urdf folder, let's continue modifying
this file here.
So the Arduino bot dot Urdf dot acro here at the beginning of this file.
So we can do it here.
Let's declare a new macro argument with the tag macro argument.
And let's close it here within the same line and accept the argument.
Basically works like a variable for other programming languages.
In fact, we are going to use this argument, this variable, in order to load the proper version of
the Ros2 control plugin for gazebo.
In fact, you will need to load a different Ros2 control plugin for gazebo depending on which Ros2 version
you are using.
So let's call this variable.
Is ignition perfect and by default.
Let's set it to true.
Perfect.
And that's it for this file.
So for this file we just need actually to declare this argument here that now we are going to use in
order to decide which Ros2 control plugin to load.
Now instead of configuring the gazebo plugins and the Ros2 control library in this same file.
So in the Arduino board Erfc Sacro.
And so this will create a huge and hard to read CSV file.
So this is already pretty huge and only contains the links and the joints of the robot.
Now, instead of adding to this file, also the configuration for the gazebo and for the Ros2 control
library, we can do it in a different file.
So we can use another interesting feature of the exact format that is to include a Docker file from
another profile.
So basically we can create a new file.
And for example let's call it Arduino robot gazebo dot Sacro.
So for the moment this is an empty file.
But the cool thing is that we can include.
So here with the Sacro include like this.
We can include the file name that we have just created.
So let's find within the Arduino bot.
description package.
And from this package here we want to load.
So from the Urdf folder we want to load the Arduino bot gazebo dot profile.
Perfect.
And so this instruction here basically so these include instruction is equivalent to copy all the content
of this file here that now we are going to create just copy pasting it here.
So this instruction is exactly equivalent.
And the advantage of course is that we have separated all the links and the joints that are declared
here in this Sacro file from the gazebo configuration that we are going to insert here.
And so this is now easier to maintain.
So if we want to load a new gazebo plugin, or if we want to change the configuration for our gazebo
simulation, we just need to touch.
So to modify this file here and instead this one will just contain the links and the joints of the robot,
and so it will not change.
Perfect.
So let's start also this file here.
So the Arduino board the gazebo file.
And actually we can copy the first line from this one here.
So from the Arduino bot Urdf dot sacro.
So let's copy and let's paste it.
In fact this is still an XML file.
And then we have opened the robot tag.
And here our robot is called Arduino bot.
Also in this case let's insert the closing tag for the robot tag.
Perfect.
And now we can actually start configuring gazebo so we can actually start loading the gazebo plugins.
To do so we can use the tag gazebo.
And now in this tag we need to load a different Ros2 control plugin for the gazebo depending on the
Ros2 version that you are using.
So to do so, we can use the exact argument that we have created here.
So this exact argument here.
And so we can check its value with the exact row if perfect.
And now let's check the value of the is ignition argument.
So if the argument is ignition perfect.
So we are checking the value of this one.
And if this one is set to true in this case it means that you are using ros2 humble.
And so if you are using Ros2 humble you need to load the plugin that is called.
So here the file name is called ignition Ros2 Control system and the name of the class that we want
to load from this plugin here.
So the name is the from the package ignition Ross two.
Control is the ignition.
Ross two control plugin.
Perfect.
Eventually we can also configure this plugin here with some parameters with the tag parameters.
And for the moment we can leave this tag here empty as we are going to configure it.
So we are going to modify it.
We are going to assign some parameters to this plugin.
When in the following lessons we will learn about YAML files.
Perfect.
And so this is if you are using the humble version of Ross two.
Otherwise.
So let's use the exact pro and less perfect.
And if the value of the argument is ignition is set to false, it means that you are using a newer version
of Ros2, and so you need to load a different plugin.
Perfect.
And the file name.
So here the file name that you need to load is called gazebo underscore Ros2 control system.
And the name of the class that we want to load from this plugin is from the gazebo Ros2 control package.
And then the class is called gazebo SIM Ros2 control plugin.
Perfect.
Also in this case we can configure this plugin here with some parameters.
So we can copy the parameters tag.
And also in this case actually we can leave this one empty as we will come back to modify this file
in the future when we will learn about YAML files.
For the moment, we have done with this file so we can save it, and we can move on to the creation
of another exact file.
So still here, still in the Urdf folder, let's create a new file and let's call it Arduino bot Ros2
control dot sacrum.
And as the name of this file suggests, basically here in this new file we are just going to insert
the Ros2 control configuration for our robot.
And actually this one will contain both the Ros2 control configuration for the simulated robot.
And also in the following sections of this course, it will contain the Ros2 control configuration for
the real robot as well.
Now remember that we have declared a new macro file.
And so actually we can include it here in the main urdf file.
So this one here will be the one that we will load with the robot state publisher.
So we can copy this include statement and we can paste it in order to include also the file that we
have just created.
And that is called Arduino bot Ros2 control dot Sacro.
And so remember that this instruction here is equivalent to copying all the content of this file here
that we are going to create right now and pasting here.
And the advantage is of course, that we have smaller files that we can maintain easily.
So again let's copy the first two instructions of this file and let's paste them here within the Arduino
bot to control.
Let's also close the robot tag.
Perfect.
And now within this tag here.
So within the robot tag we can start configuring the Ros2 control library for our robot.
We can do so using the Ros2 control tag.
Perfect and now here let's set the type.
And the type that we want to represent is a complete system.
So a complete robot composed of several joints.
So let's set the type to system.
And also we can set the name to robot system perfect.
Also in this case so also in the Ros2 control tag.
Depending on the Ros2 version that you are using, you need to load a different Ros2 control plugin
for the hardware interface.
So for interacting with the simulated hardware on gazebo for this reason.
Also in this case we can use the is ignition variable.
So let's check whether the variable.
So the value of the argument is ignition is set to true.
Again if this one is set to true.
It means that you are working with Ros2 humble, and in this case, you need to load the hardware interface.
So let's call it hardware.
And this is implemented in the plugin that is from the ignition Ros2 control library.
And that is called ignition system.
Perfect.
And so this is the hardware interface for the simulated robot that you need to load if you are working
with Ros2 Campbell.
Otherwise.
So sacral unless if the value of the argument is ignition is set to false.
So it means that we are here.
And so it means that on your PC you have installed a newer version of Ros2, like for example Ros2 Jessie.
In this case the Hardware interface that you need to load is defined in the plugin that is from the
gazebo Ros2 control library, and that is called gazebo SIM system.
Perfect.
And so with this one here, we have loaded the Arduino interface for the simulated robot.
Whether you are using Ros2 humble or whether you are using any newer version.
Now in the last section of this course, actually, we will come back to modify this file here.
So the Arduino Ros2 control file in order to add another hardware interface, this time not with gazebo,
but for the real robot.
So the Arduino interface that will actually communicate with the real motors, that will drive the real
robot arm.
For the moment, let's just conclude the configuration of the Ros2 control plugin.
Also, by adding some joint tag in order to define the interface that each movable joint of the robot
has to use in order to interact with the Ros2 control library.
Namely, each joint will specify how it will be controlled.
So let's start with the first joint that is called joint one.
And now, as you may recall from the theoretical lessons to connect the Ros2 control library to an hardware
interface.
So to an hardware resource, we need to define the two interfaces for communicating with the resource.
And the first interface is called command.
Interface.
And this one.
So the command interface is the one that we use in order to send commands to the hardware.
So to send commands to the motors.
And then there is also another interface that instead is called state
Interface, we can close it in the same line.
Perfect.
And the second interface.
So the state interface instead is used for reading the feedback from the hardware, namely to read the
current state of the motor and for example, to read the current position or the current velocity of
the motors in both cases.
So for the command interface we want to use a position interface.
So let's set the name to be position for the command interface.
And also we can copy this one and we can set it here for the state interface.
So we want to use a position interface both for sending commands to the hardware and also for receiving
its feedback.
So we want to know the position of the motors.
And also we want to send the commands expressed in the position of the robot.
And here in the command interface, we can also limit the maximum and the minimum command that we want
to set.
So let's set the parameters.
So the name is called min.
And also let's set another parameter for the command interface that is called max.
And so this one is in order to limit the rotation of the first joint.
And for the first joint we want to limit it from -90 degrees to 90 degrees.
So actually this has to be expressed in radians.
So if we go back here in the Arduino urdf we can copy the declaration of this variable here.
And we can use it here as well.
So let's paste it.
Perfect.
And now we can use this variable in order to define the minimum that is minus.
And then the variable pi divided by two.
Perfect.
And the maximum.
so we can copy this one.
It's simply pi divided by two.
So as we said 90 degrees.
Perfect.
And with this one we have completed the joint one.
Now we are missing all the other joints of the robot.
However, since all the movable joints of the robot will use the same command interface and will also
provide the same state interface, we can simply copy paste this same instruction and we can use it
for the joint two.
Then we can paste it also for the joint three.
And with this we have completed the joints of the arm.
And then let's also set it for the joints of the gripper that are the joint four.
And also we have the joint five.
Perfect.
Now we need to do some few changes, especially for these last two joints which control the fingers
of the gripper.
And actually these two joints here.
So the joint four and the joint five are not independent, but they will move together.
In fact, they are connected with a gearbox.
And so, for example, when the joint four opens, also the joint five will open as they are moved together
by the same motor.
For this reason we need to set.
So here for the joint four we need a different limit.
And so the minimum is still -90 degree.
But then when it closes it reaches the maximum position of 0.0.
Perfect.
And this is for the joint four instead for the joint five.
So here this one will actually not have its own command interface.
So we can remove it.
And it will not have its state interface.
So we can remove also this one.
And this is because the joint five is not, as I said, the independent.
But the joint five will simply mimic the behavior of the joint four.
And now in order to indicate also to the Ros2 control library that this joint here will replicate.
So we'll mimic the behavior of the joint for.
We need to set here a parameter.
So let's set the parameter that is called mimic.
And here let's set the name of the joint that this joint here so that the joint five will mimic.
And this is the joint four.
And so with this parameter we are simply saying to the Ros2 control library that the joint five will
move as the joint four.
And then let's also set another parameter.
And this one is called multiplier.
And let's set it to minus one.
And this simply indicates that the joint five will move as the joint four but in the different direction.
So for example if the joint four will move 45 degrees, the joint five will move -45 degrees.
And so this is because we have set the multiplier to minus one.
So the intensity of the two movements will be the same but in the opposite direction.
Perfect.
So we can save this file.
And with this we have completed the Urdf model of our robot.
To support also the usage of the Ros2 control library in the gazebo simulation.
And so here we have added we have loaded the proper Ros2 control plugin for gazebo.
And here we have configured it.
So we have configured all the joints of our robot in order to be actuated in the gazebo simulation.
Now as we have added, as you can see here, the dependencies from these two libraries.
So from the ignition cross to control if you are on Ros2 or from gazebo Ros2 control if you are on Ros2.
Jazzy, we need to declare these dependencies also here.
So in the package dot XML.
So here let's add an execution dependency from the gazebo Ros2 control.
However, as I said you're going to need this package here only if you are on newer version of Ros2.
So for example, only if you are on Ros2.
Jessie.
So let's add a conditional dependency.
So we want to add this dependency only if this condition is satisfied.
And the condition that we want to verify is that the variable.
So the environmental variable that is called Ros distro.
So this variable here is bigger than or equal to iron.
So if you are working with a ros2 version that is newer than iron.
And for example if you are working with Jessie you need this package here.
Otherwise let's add another execution dependency, this time from the ignition Ros2.
Control package.
And you need this package here only.
If so, the condition is that you have the Ros distro.
So the Ros version that you are using is equal to humble perfect.
So if you are on Ros two humble you are going to need this package here.
Otherwise if you are on any newer version you are going to need this other package here.
So let's save also this file and that's it.
Later in the course we will return to modify especially this file here.
So the Arduino Ros to control file in order to add the support not only to the simulated hardware interfaces.
So these other interfaces that will communicate with the simulated motors in gazebo.
But also we will add the support to the real hardware interface.
So to the hardware interface that will interact with the real motors and with the real robot.