In this lesson, we will create our first launch file to start visualizing the RDF model of the robot
in RVs.
The output will be very similar to the previous laboratory lesson, but this time we will be using just
one terminal and just one command to start the launch file.
To create a launch file.
Let's open Visual Studio code.
And so in the Arduino board description folder, where we have already created the Urdf model for our
robot, let's create a new folder called Launch.
And here let's create a new file called
display.launch.py.
As I mentioned in the theoretical lessons launch file in Ros two is a python file in which we can define
a list of instructions to be executed.
This list is called launch description.
So let's start importing this class.
So from the launch library, let's import the launch description class and then we need to define a
new function.
So let's call this one generate launch
description.
And this is executed when we launch the launch file.
So when we start this file and here we need to define all the components that needs to be started and
it will return a launch description object with all these components.
So let's return a launch description object that contains a list of all the applications.
So of all the nodes that we want to start over the action in general that we want to start with this
launch file.
As we did in the previous laboratory lesson.
Let's start by executing the first node.
So the robot estate publisher node, which is the one that reads the RDF model of the robot and publish
it within our Ros2 topic to start a node.
Let's import from the launch Ros library and from the actions module, let's import the node class and
now we can use it to create a new instance of this node.
So a new variable called Robot State.
Publisher, for instance, that is an object of the node class.
And here in the constructor of the Node class, we need to specify the package that contains the node
that we want to start.
So the package is the robot state publisher and the next we also need to specify the name of the node
that we want to start.
So let's start the X code table that has the same name of the package.
So also this one is called Robot State Publisher.
And the next we also need to configure this node with some parameters.
So specifically, we need to indicate where the Urdf model of our robot is located.
So let's set the parameters and let's set specifically the robot description parameter.
And to this one we need to assign the directory where in our PC is the robot description?
For the moment, let's store this one in a variable that we are going to call robot Description.
So now we need to assign a value to this variable here.
And to create this variable we need to declare an argument for this launch file which can be changed
when the launch file is started.
So for example, you can use in the future this same launch file to visualize also other urdf model
of other robot that you might create in the future.
To declare an argument for a launch file.
Let's import from the launch library and from the actions module, the declare launch argument class.
And now let's use this one to declare a launch argument.
Let's call, for example, this one model arc as an instance of the declare launch argument, and this
one will contain the name and the directory of the Urdf model that we want to visualize in our case.
So the name let's call this one model.
So this is the name of the argument.
And by default.
So if this argument is not set by the user who started this launch file, we want to visualize the urdf
model of our robot.
So the Arduino but Urdf sacrum.
And so here let's set a default value.
And as we want to indicate, a path to our directory.
So to the directory where the Urdf model is stored, let's import the OS library from Pi for Python
and let's use the OS path.
Join function and also let's import.
So here from the amend index python.
So from the packages module, let's import the function, get package share directory and so we can
use this function here for example within the join function.
So let's use it.
Get package share directory to obtain the full path, the full directory to the Arduino bot description
package so that we don't have to rewrite all the path to this directory.
So let's format this a little bit better.
Okay so that it is easier to read for this package.
So within the Arduino.
Description package, we want them to open the Urdf folder.
And then within this folder we want to open the Arduino bot dot Urdf dot acro file.
Let's also add a description.
So after the default value here, let's add a.
Description and is just says absolute path to the robot urdf file so that every person that uses this
launch file knows what the model argument does.
Now we can finally create the robot description variable.
So the one that we needed within the robot state publisher node.
So let's instantiate this variable before using it.
And this will contain the configuration parameter for the node.
Also, to declare a variable of this type, we need to import another class.
This time still from the Ros launch.
So from launch Ros.
This time from the parameter description.
Let's import the parameter value.
And now we can create the robot description as an instance of the parameter value class.
Anyway, this parameter cannot simply contain the path to the robot's urdf model because we didn't use
pure Urdf convention for its creation.
Instead we used.
So we use the exact format.
So before using it, before taking this parameter and loading with the robot state publisher, we first
need to convert our model into plain urdf format and we can do this by running a command.
So in order to run a command from a launch file, we need to import another class.
So from launch dot substitutions, let's import the command class and now let's use this one within
the parameter to execute a certain command.
And this command says Sacrow.
And so it is responsible for converting the model to the Urdf.
And also we need to pass the path to our model.
So the path which we defined in the model argument.
So here.
Since the launch file arguments can be set while the file is started, we use another class from the
launch substitutions modules.
So from this one that is called launch configuration and we use this one to read the content of the
modal argument when the launch file is started.
So here sakoura.
And then comma.
And then we read the content of the modal argument that basically contains the full directory to the
urdf modal of our robot.
Basically what we are saying here is that the robot description will be the full plain urdf modal.
And here we are going to take this full urdf model by converting.
So using the command acro, by converting what we encounter at the modal path.
So that by default was this one.
So was the exact model of our robot.
Now let's move on by launching another node.
So if we remember, we also needed to launch the joint state publisher node that offered those sliders
that allowed us to move the robot.
So let's create a new variable joint.
State publisher going.
And this is a new instance of the Node class.
And this time we want to start the node from the package joint state publisher and the executable.
That we want to start is also called Joint State Publisher.
This is Joint state publisher.
We also denote is called Joint State Publisher.
And then we just need to start one last note.
That is Rvhs.
So let's call this one Arv's node.
And so this is our node.
And from the package.
That is called RV two.
Let's start the executable.
That is also called RV two.
And let's name it.
So let's assign a name that is RV to.
We also want to see the output of this node in the terminal.
So with any log message that this node may run.
And so we set the output.
Here, a comma and then output to the screen.
If you remember by default when we start this, it shows the default graphical interface every time
without any visualization or plugins.
Anyway, we can make it load at different configuration at startup and for example, we can load the
one that we have created and we have stored in the RV's folder and that already contains, for example,
the visualization of the Urdf model of the robot and with its meshes.
To do so, we need to pass some arguments, so arguments and let's pass a vector and here let's use
the flag minus D to pass the directory of the RVs configuration that we want to visualize.
And in order to take the directory, we can use again the path join function from the library of Python.
And here again we can use the get package shared directory to get access to the full directory of the
Arduino bot description package.
And then within this one let's access to the Arviz folder and then we want to use the display dot RV.
So we want to load this one by default when we start arviz.
With this, we have created a variable, an object for each instruction that we want to start.
So here we have declared an argument.
Here we have started three nodes.
Now we can pass these variables so these instructions to the launch description file, so to this one
so that they can effectively be started when we execute the launch file.
Let's start with the instruction that defines the argument of the launch file.
So the model argument.
Then let's launch the robot state publisher, then the joint state publisher, and then let's execute
args.
With these, we have finished and now we can save.
And we only need to install the launch folder which we created in this lesson inside the Cmakelists.txt
file.
So let's open this file.
Here we have already installed the meshes and the urdf folder, so let's install also the launch folder
and the RV's folder which contains the configuration that RVs has to display by default.
Furthermore, to ensure that the launch file that we just created is started without any issue and that
all the packages that are needed to start the launch file are available.
We need to declare some dependencies in the package dot XML and so we need to declare an execution dependency
from the robot state publisher package which we used in our launch file and also another one from the
joint state publisher Gooey package.
Then also another one from our vs Chu and finally another one.
So another execution dependency from the Ros two launch library.
With this, we have finished.
And now we can finally execute this launch file.
So let's open a new terminal and let's go to the workspace and let's build it.
In order to install the new file and the new folders, when this is done, we can finally open a new
window of the terminal.
As always, let's source the workspace.
And now we can start the launch file with the command Ros to launch, followed by the name of the package
which contains the launch file that we want to start, which is the Arduino bot description, followed
by the name of the launch file itself.
So if we press tab twice, we can see that we have the display dot launch available.
So let's start this file.
As we press enter, we can see that there is an error, an error in the directory.
Since here there is no space between the command and the directory.
So let's go back in Visual Studio code.
And here we need to add a space.
So let's save again.
Let's build again the workspace.
And now we can launch the file again.
As we do so, we can see that just with one command.
So just with the command Ros to launch, basically we have reproduced and we have the same result as
the previous lesson.
And so now we have again the Urdf model of our robot that is perfectly displayed and perfectly moving
in the terminal.
Now we are going to use this additional tool, the launch files, in the subsequent lesson of the course
to start more complex application with more features with extremely ease.