Creating launch files
The launch files in ROS are very useful for launching more than one node. In the preceding examples, we saw a maximum of two ROS nodes, but imagine a scenario in which we have to launch 10 or 20 nodes for a robot. It would be difficult if we had to run each node in a terminal one by one. Instead, we can write all the nodes inside an XML-based file called a launch file and, using a command called roslaunch, we parse this file and launch the nodes.
The roslaunch
command will automatically start the ROS master and the parameter server. So, in essence, there is no need to start the roscore
command and any individual nodes; if we launch the file, all operations will be done in a single command. Note that if you start a node using the roslaunch
command, terminating or restarting this command will have the same effect as restarting roscore
.
Let's start by creating the launch files. Switch to the package folder and create a new launch file called demo_topic...