Up to this point, we have been running all of our rosters nodes independently, with each node needing
its own dedicated terminal to run.
We have also had to open extra terminals to do actions such as setting parameters.
Launch files are a feature in ROS which allow you to launch multiple nodes and configure them all with
a single command.
In this lecture we will create a launch file to launch our RPM publisher node.
So the first thing we will do is open up V's code and create a new folder in our package by right clicking
and clicking a new folder and we will call this folder launch within our newly created launch folder.
We'll create a new file which we will call RPM underscore node dot launch dot py.
Now I know this may be a bit confusing to have two file extensions in a file name, but in ROS two launch
files are essentially made from Python code.
That's why we edit it with the dot py extension.
But essentially the launch portion of it is a tribute to ROS one launch files which used to use XML
syntax rather than python code.
Just know that it's generally accepted to have the word launch near the end of the launch file.
So if you wanted to, you could have used an underscore instead of a period before the word launch for
this python file, we are going to be importing functionality from the launch module.
Specifically, we will be including launch description from launch and node from launch roster actions.
Note that this is not the same node object from the ROS client library we have been using in our code
so far.
In order for the ROS to launch command to interpret this python file, we will need to have a function
called Generate Launch description in it, which returns a launch description object.
This launch description object will contain a list of things we want to configure or run in this launch
file.
In this case, we just want to launch our RPM node, so I will create a node object.
So on the screen, I'm showing you the source code for this node class, which contains all the optional
parameters you can include with launching a node.
For this case, I will specify the package, which is our Udemy ras to package our executable, which
is RPM, pub node pie and the name of the node which I will just call RPM pub node.
No.
And I forgot a comma here.
Here we go.
If I wanted to add more nodes, I could simply add them to the list and then I could configure this
one just as I did the one above.
But for now, I'm just to keep the simple and just launch our RPM node.
Now we can save this file and head over to our make list text file.
So here we're going to have to configure our make list X file to be able to run launch files.
The only thing we need to do is to create another install function, which I will put after the one
we currently have to set up our Python scripts.
So the only thing we need to do is create another install function, which I will just put after the
one we currently have to set up our Python scripts.
Within this install function we will use the directory keyword and the directory we will be including
is our launch folder.
Then we will point the destination location to the share folder followed by the project name.
Ock with that saved the file.
And now we can run our newly created launch file by going ahead and rebuilding our workspace directory,
which you can do by either going to terminal run, build task or control shift B which will run our
can build Simulink install command.
Oh, and it seems I made a mistake here.
I accidentally placed our launch folder within the workspace.
I meant to place it within the package.
So I'll go ahead and move this.
Into our package.
All right, so now we're in our sauce raw stew package, and then we have our launch folder, RPM,
long shot pie.
And just to show you what this looks like inside the workspace directory.
So here we have our package, so we have our scripts folder with all our Python files and our launch
folder with our launch file.
All right.
Let's go ahead and try to rebuild that.
All right.
And that time we build successfully.
So let's go ahead and open up a terminal and we'll go ahead and source it.
And now we can run our launch file using the Ross to launch command, which takes in the name of the
package and the name of the launch file.
In this case, we will launch our raw package's RPM node launch file.
Oh, and it seems I made a typo within my launch file.
So our package name is Ros two package, so I only forgot the two there so we can go ahead and save
this.
And all the changes should take effect because we're using Simulink install.
So if I try to rerun this one more time,
we see process started with PID and the corresponding number and I can double check that this is running
by running across to node list and we see our RPM publisher node is running just as it would have been
with Ros to run.
So congratulations.
You have successfully launched your own node using a launch file.
Now it's worth noting the launch files can be used to run external system commands as well.
We can do this with the execute process object, which we will have to import from the launch actions
module.
Then within our launch subscription list, we will add an execute process to run a command.
In this case, I will run the ROS to topic list command.
This command will be the value of the CMD argument.
We split this command up word for word in a list like so.
Then I will set the output argument to screen, which means the output of this command will show up
in our terminal.
With that.
Let's save the file.
And again, it should automatically take effect because we're using Simulink install.
So now if I go ahead and rerun this launch file.
We see here.
We got a subset of information printing to the screen where it says Ross 2-2 because this is the second
command that's running within our launch file and it starts with Ross two and we see it prints out the
corresponding topics if we had run Ross to topic list.
So we see the same information here within our launch file.
So that's just one of the ways which you can configure your launch file to utilize terminal actions.
One thing I briefly want to mention before we head over to the next lecture is if you wanted to configure
parameters within your node object, you can also do that using the parameters argument.
And this takes in a list of dictionaries, which in this case each dictionary will have the value of
your particular parameter.
So you'd put in your parameter name with the colon and you'd specify the parameter value.
So I'm going to put this back to the way it was, but just know that this is the syntax in order to
set parameters of your node.
If they have been declared already, which we will be taking a look at in the next lecture.
Great.
You have learned how to use launch files to automatically start up ROS nodes and run terminal commands.
Let's review what we learned.
In this lecture, we learned how we could create launch files so that we could run multiple nodes as
well as other functionality with a single ROS to launch terminal Command.
We created our launch files in Python by importing the launch description node and execute process objects
from the different launch modules and then utilize them within our launch files.
Generate Launch Description function.
In our lunch description, we were able to run our Ross nodes we created using the node object and specifying
the package and executable name.
We can then also pass in a node name which will override the default node name specified in the code.
You can even specify values of particular parameters of that node.
We also took a look at the execute process instance in which we can run terminal commands utilizing
our launch file and we specify output to screen so that the output of these commands can be seen on
the terminal.
We run the launch file in.