Finally, everything is ready to start the control system of our simulated robot in gazebo.
The Urdf model is configured to load the gazebo Ros2 control plugin and the interface the simulated
robot arm during gazebo with the Ros2 control library.
We have defined the input and the output interfaces of each joint of the robot, and also we have configured
the controller manager to interact with the robot's hardware and also with the other two applications.
In this lesson, we will create a new launch file that starts all of this logic and functionalities.
So let's open the Visual Studio Code and in the Arduino board controller let's create the new folder
called launch.
And here within this folder let's add a new file called controller dot launch dot pi.
Since this is our a rush to launch.
File.
It is composed of a launch description object that we import from the launch library.
So the launch description.
And then we need to define the function generate launch.
Description that returns.
An object of type launch description which takes as input the list of all the functionalities that we
want to start with this launch file.
So let's start by launching the Robot State publisher node, which reads the Urdf model and publish
its information into our Ros2 topic.
We have already done this inside the Arduino bot description package inside the display dot launch,
so let's copy this one.
The node that is in charge of launching the robot state publisher and let's paste it here.
Also let's remember to import the class node.
So this one this instruction here to import the node.
And now instead of using the model argument in the launch file as we did here.
So where we enable the possibility to use a different model here in the controller launch, let's directly
indicate the directory where the Urdf model of our robot is located.
So let's import the OS library.
And also let's import from the launch rose from the parameter description.
Let's import the parameter value class and also from launch substitutions.
So from launch substitutions let's import the class command.
Now we need to assign a value to the robot.
Description variable.
So before it is used let's assign a value.
And so here we need to indicate the directory where the Urdf model of the robot is located.
So let's use a parameter value.
So let's create a new object of this type.
Within this one let's run a new command and the command that we want to run.
Let's insert this one within a list.
And so we want to run the command zero to convert first the model into a plain urdf model.
And then we need to pass the full path of the Urdf model so we can use the function join.
Okay.
And here let's also remember to import the get package share directory.
So from amend.
Int index Python.
From the packages module, let's import the get package share directory and we can use it here within
the join function.
To get access to the Arduino bot.
Description.
Package in which we have created the Urdf model.
Then once we are in the Arduino bot description package, let's access to the Urdf folder and then within
this folder let's access to our file that we called Arduino bot dot u.
Dot.
And also we want this command.
So here we want this to be loaded with a value type Value type of a string.
So str.
Now the robot state publisher is completed.
Before spawning the controllers that we defined in the Arduino bot controllers YAML configuration file.
So actually before loading all the controllers that we defined here.
So the arm controller and the gripper controller we first need to start another node that is available
in the controller manager package.
And that actually manages and supervises all of these controllers.
So let's start a new node.
So let's create a new instance called controller Manager.
And this is an instance of the node class.
Perfect.
And we can use this one in order to start from the package that is the controller manager package.
So from this one here we can start the executable that is the Ros2 Control node executable.
And for this one here we can set some parameters.
So we can set a list of parameters in order to configure this node here.
So the Ros2 control node starting from the parameter.
So here let's create a dictionary.
And let's define the parameter that is called the robot description parameter.
And this one will contain the urdf description of the robot.
And so we can actually use this variable here.
So we already loaded the urdf of our robot.
So this one here.
And we have already stored it in this variable.
So in the robot description variable.
And now we can use it in order to set a value for this parameter here.
So we can simply set this variable so the robot description variable equal to the robot description
parameter.
So equal to this variable here then also.
So finally after this variable here we can also set.
So we can also provide the full directory to this configuration file here.
So to the Arduino board.
Controllers YAML so that the controller manager can be configured using these parameters here.
So using these parameters here that we have defined in this configuration file.
So here in order to provide the full directory to this file here we can use the OS path join function.
And now here we can use the get package share directory in order to access the directory of the Arduino
bot controller package.
And then from this package so we can go to the config folder and from the config folder.
So here we want to load this file here.
So the Arduino bot controllers dot YAML file.
Perfect.
And now here with this one here we have correctly started and configured the controller manager.
And now finally, for each of the controllers that we created and that we configured here.
So for the ARM controller, for the gripper controller and also for this one here.
So for the joint state broadcaster we can create a new node that actually starts.
So that spawns each controller in the controller manager.
So back here let's create a new instance that is called joint state.
Spawner.
So this is an instance of the node class.
And we can use this node in order to start again from the package.
That is the controller manager.
So from this package here we can start the executable that is called the spawner executable.
And so now we want to use this first instance of this node.
So this instance of the spawner node in order to spawn.
So in order to start this one here.
So the joint state broadcaster controller.
So here we can set some arguments.
And this is a list of arguments.
And so here let's start.
So let's set the name of the controller that we want to start using this node which is the joint state.
Broadcaster.
And so actually this name here should match this one here.
So the one that we have defined in the controller manager and also that we have configured.
And so that we have specified which is the controller that it should load.
Also here are the arguments that we need to set so we can set the flag controller manager perfect.
And also we can set the namespace which is again controller Manager.
And so this is just to set.
So in order to link this one here.
So this is pointer.
So we are saying that we want to spawn this controller here into the controller manager.
Now actually we need to use the same instruction.
So we need to use the same node in order to start.
So in order to spawn the remaining two controllers.
So the arm controller and the gripper controller as well.
So we can copy this instruction and we can paste it twice.
So here we go.
We have paste it twice and let's call the first one.
Let's call it our controller spawner.
And here we want to use this one in order to spawn the controller.
So this one here the ARM controller.
So we can copy it.
And we can paste it here in the list of the arguments.
And also in this case we want to spawn it into the controller manager.
Now for the last node here.
So let's call it instead Gripper controller spawner.
And with this note here we want to start instead.
So we want to spawn this one here.
So the gripper controller.
So let's copy it and let's paste it here.
So in order to spawn the gripper controller into the controller manager.
Now with this we have declared all the instructions.
So all the nodes that we need in order to start the control system for our robot.
So now in order to actually start using all of these classes so all of these objects, we need to declare
them here.
So in the list of the launch description class constructor.
So let's start with the robot state publisher node.
So let's first start this node.
Then we can start.
So as you can see here the controller manager.
Then after the controller manager we can spawn the three controllers namely the joint state broadcaster
Then the ARM controller and finally also the gripper controller spawner.
Perfect.
So with this we have completed our controller launch.py file.
So this one here that in the order starts the controller manager.
And then it spawns the three controller that we have configured.
So the ARM controller, the gripper controller and the joint state broadcaster that simply will publish.
So will provide the current state for each joint.
So we can save this file and we can install it.
So as we have created a new folder namely the launch folder in which we have created this file, we
also need to install it so we can open the file cmake list.
And here along with the config folder we also want to install the launch folder.
So apart from installing the Arduino bot controllers let's also install here the controller launch dot
Pi so that we can use the Ros2 launch command in order to start this file here.
Then also as here in this launch file here, we have used some dependencies from the robot estate publisher
and from the controller manager package.
We need to declare them here.
So we need to go in the package dot XML.
And so we need to add a execution dependency from the Ros2 launch package.
Then also we need another execution dependency from the robot estate publisher node.
Perfect.
We also need another one.
So another execution dependency from the package which we have used in order to convert the exact model
of our robot into a plain Urdf model.
And finally, let's add another execution dependency.
From the Controller manager node.
Perfect.
So with this also this file is completed and we can save it.