Once we have created the hardware interface and installed it as a plugin for the Ros two Control library,
we can now proceed to use this hardware interface and to ensure that when the robot control system is
started, instead of loading the hardware interface with the simulated motors in Gazebo, we activate
the real hardware interface.
So the Arduino board interface that we have been developing so far.
To do this.
Let's go back in Visual Studio Code modifying the urdf of our robot, which we previously created in
the package Arduino board description.
And for the moment which we have just interfaced with the Ros two Control library in Gazebo.
So basically with the Gazebo Ros two control plugin.
Let's go back to the RDF model and show to the Arduino bot dot Urdf dot Sacro.
And here let's add a new argument to configure the behavior of the Urdf file.
So let's create a new tag called ARG.
That stands for argument.
And let's give it a name.
Let's call this one is seam in order to indicate if we are using.
And so if we are loading the Urdf model for the simulated robot or for the real one, and by default,
let's set this one to true.
So by default, we are always going to load the urdf model for the simulated robot.
We can use this argument to make the urdf model of the robot to behave differently, which means loading
different Ros two plugins depending on whether we are starting the control system for the real robot
or for the simulated one.
Once declared.
So since we have declared this argument here within the Arduino board Urdf, we can also use it in any
of the two files that we are including.
So, for example, let's use this argument here within the Arduino board, Ros, to control.
So let's open this script here in this file, let's add a new group.
So basically a new conditional statement using the tag Sacro.
If so, let's use this group here and let's activate this group only when the value of the argument.
So let's take the argument is sim that you have just created.
So the content all all the tags that you are going to insert here within these two tags will be executed
and so will be loaded only if the argument is sim is set to true.
So in this case, let's use this Arduino interface.
So let's paste it here.
So in this case, if we are using and so we are loading the robot description of the robot, so the
Urdf model for the simulation, then we are going to use this one.
So we are going to use this hardware interface with Gazebo.
So it means that we need to activate the plugins and the interface for the simulated robot.
And within this block, let's also copy the tag for the joint five.
So this one here, so this one is needed only for the simulation.
And this allows the joint five to mimic the behavior of the joint four.
So also this one is only needed for the simulation as in the real robot, there will be an actual transmission.
So there will be an actual system of gears that will make the joint five to mimic the behavior of the
joint four.
So for the real robot, we just need to activate the joint four.
On the other hand, when we are starting the control system for the real robot, so let's use a similar
tag.
So that is called unless.
So unless the argument is SIM is set to true.
So this is quite easy to understand.
So this is only activated if the argument is sim is set to true and this is only activated if the argument
is sim is set to false.
So if we are loading the urdf model for the real robot in this case we want to load a different hardware
interface.
So let's use still the tag hardware.
And in this case we want to load a plugin and the plugin that we want to load is the Arduino boot controller.
And so the one that we called Arduino boot interface.
Regarding this plugin, as you might remember, we have also defined a parameter called port.
So let's set now this parameter that indicates the port to which the Arduino board is connected.
And so the port that the hardware interface has to use for the serial communication.
In my case, this is the port ACM zero and here basically it goes your port.
So the one that you are using to connect the Arduino board to your PC.
For the other joints.
So the configuration of the other joints can remain unchanged since they are going to use the same configuration.
Both in the real robot and also for the simulated one.
Let's conclude also this lesson by updating the controller dot launch dot pi.
So within the Arduino board controller, let's open the controller dot launched file.
And here let's declare an argument that allows us to customize the behavior of this launch file for
the simulation or for the real robot.
So if we are loading the control system for the real robot or for the simulated one.
So let's import a new library from the module actions.
Let's import the declare launch argument.
And let's use it within the generate launch description to create a new object called is same argument.
So to create a new argument for the controller dot launch dot pi file.
So let's create a new instance of the declare launch argument.
The argument is going to be called is sim and by default.
So let's keep the behavior unchanged.
So if we are not passing anything.
Let's set this one to true meaning that we want to activate by default the control system for the simulated
robot.
From now on, when we launch the controller dot launch file, we can also set this argument so we can
set a value for the argument.
Is C Now let's make this launch file to use it.
So to read, which is the value that we assigned to the SIM by importing a new library and from the
launch substitutions.
So from this one, let's import also the launch configuration and let's create a new variable called
is seen as an instance of the launch configuration class.
And so this variable contains the value that is assigned at runtime to the is SIM argument.
So let's take let's read which is the value of the is SIM argument.
Now let's slightly modify this one here.
So this variable here, the robot description as now the urdf model of our robot.
So basically this one also has an argument.
So we also added an argument to this one which indicates which discriminates which type of hardware
interface we want to start.
And so let's set here, let's pass an argument to this command that is the is SIM that we have just
created.
And let's set this one to false.
So let's load the robot description by setting the Is argument to false and also regarding the robot
state publisher.
Now, in the control system, we want to start the robot state PowerShell only if we are using.
So only if we are launching the control system for the real robot.
As if you remember if we launch the simulated robot.
So if we go into the description, launch the gazebo here, it's already started.
The robot state publisher.
So in the controller launch, we want to start the robot state publisher only if this one.
So this argument here, the is SIM argument is set to false.
So now let's import from the launch library and from the conditions module.
Let's import the class unless condition and so let's use it here in order to indicate that we want to
execute this one.
Unless so, let's use the unless condition, unless this node is started with the argument is set to
true.
So let's pass the argument is a C.
So basically what we are saying is that we want to start the robot state publisher only if we are starting
the control system for the real robot in this launch file.
Let's also start a new node and this is the controller.
Manager and this is an instance still of the Node class.
And with this node we want to start from the package.
Controller manager.
From this one, we want to start the executable that is called Ros to control Node.
And also we want to pass the configuration parameters of this node.
So let's pass some parameters and let's include the robot description.
So let's use a dictionary.
So let's pass the robot description to this dictionary.
So here and this is the variable robot description.
Then let's also pass the argument.
Use some time, then let's also pass the use same time argument and let's set this one equal to the
same argument.
So too the argument is same of the launch file.
Also to the controller manager.
We want to pass the directory.
Where is the configuration of the controller manager?
So basically we want to pass this directory here.
So the directory of this file here in which we have defined all the controllers and all the types of
the controllers that we want to start for the arm and for the gripper.
So still here within the controller manager and after here this dictionary.
Let's use the function.
Voice, but join.
So let's use this one to specify that the directory is within the package.
Arduino Board Controller.
Then within the config folder and the file which contains the configuration for the controller manager
is the one that we have called.
Arduino board controller dot yaml.
Anyway, let's also set that we want to start this node.
So we want to start these functionalities only if we are starting the control system for the real robot.
So not for the simulation.
And so let's set the condition to be unless condition, so unless the argument is a sim is set to true.
So we are doing the same as we did for the robot state publisher node.
So with this we are indicating that both of these nodes will be started only if the launch file that
is called controller approach is started with an argument is set to false.
So to start the control system for the real robot.
Let's conclude this lunch file by adding the new nodes and the new instructions that we have used.
So the is SIM ark.
Let's add the declaration of the argument is SIM.
And then also let's start the controller manager.
So here, let's start the one that we called here.
Controller Manager.
Finally to conclude this lesson and to check that we have not made any mistake, let's compile our workspace.
So let's go to the workspace and let's build it with the Qualcomm build.
The build finished correctly.
And so the next lesson, we can start using these new launch files and also the new hardware interface.