Ubuntu Linux for Robotics · Lesson 48 of 96
Launch files
Writing, installing and running launch files from an Ubuntu workspace.
Estimated time · 45–75 min
Learning goals
What you will understand
- Explain launch files in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
A Python launch file starts several nodes with their parameters and remappings in one command. Put it in the package's launch/ folder and install that folder from CMakeLists.txt (install(DIRECTORY launch DESTINATION share/robot_nodes)); without that line ros2 launch cannot find it.
Use ros2 launch package file.launch.py, add arguments with name:=value, and check what started with ros2 node list. Read startup messages carefully: launch prints each process ID and any that exit. For a service on boot, combine this with a systemd unit.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the launch files commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
mkdir -p ~/ros2_ws/src/robot_nodes/launch
# Create the launch folder inside the package.
install(DIRECTORY launch config DESTINATION share/robot_nodes)
# CMakeLists.txt: install launch and config folders.
colcon build --packages-select robot_nodes --symlink-install
# Rebuild so the folders are installed.
source install/setup.bash
# Make the package visible.
ros2 launch robot_nodes bringup.launch.py use_sim_time:=false
# Start everything, passing an argument.
ros2 node list
# Check every expected node is running.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · Messages between nodes
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Launch files. Expected result: The launched nodes appear in ros2 node list
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
cd ~/ros2_ws && source install/setup.bash
# TODO: start the launch file bringup.launch.py from the package robot_nodesExpected output
The launched nodes appear in ros2 node listStuck? Show the full solution (try it yourself first)
cd ~/ros2_ws && source install/setup.bash
ros2 launch robot_nodes bringup.launch.pyExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Write bringup.launch.py that starts a talker and a listener with a launch argument, forget the install() line to see the error, fix it, and run it.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.