What is a ros2 launch file?
Let's start with the problem.
So let's take the camera driver node we used to explain ros2 parameters.
You start this node for one camera with three parameters the USB device name, the FPS, and a simulation
mode flag.
Note that you can also rename the node here.
Now you want to add another camera driver node for another camera on your robot.
You start a new camera driver node in another terminal, and of course you rename the node and set all
parameters values.
You could also use a YAML file here if you want.
Oh, and there is a third camera on your robot.
So that's another node that you start in another terminal.
And that's not all.
Let's say you want to add a robot new station node with one parameter.
This time your application is still not complete.
You add two LED panel nodes with more remappings and one parameter each, and add etc. etc. you continue
to add nodes to run your application, each node in its own terminal, with all the options required
to name the node, set the parameters, etc. as you can see, that's becoming a real mess and it will
take you forever to launch that every time.
Plus, with all that configuration, you may make some mistakes that will be long to debug.
So at this point you might want to run a script to start everything automatically and not manually.
That way you can truly scale your application.
Well, that's exactly what a launch file does.
Here I have put all the nodes and configuration inside the launch file.
A launch file will allow you to start everything from one single file.
You can start your nodes, apply some remapping, set some parameters, and even load YAML files.
That way you will be able to quickly launch your application and to create different launch files for
different startup modes of your robot.
In a real application, it's not uncommon for a robot to have something like ten nodes and maybe 200
or more parameters.
Without using launch files, it will be impossible to start the robot application.