By the end of this lab you will be able to:
- Create a minimal
ament_pythonROS 2 package that contains only launch files (no executable nodes) - Build and install the package with
colcon - Launch the full turtlesim system with a single
ros2 launchcommand - Declare and override launch arguments from the command line
After creating and populating the package, your workspace should look like this:
turtle_ws/
└── src/
└── turtle_bringup/
├── launch/
│ ├── turtle_bringup.launch.py ← Part 1
│ └── turtle_bringup_args.launch.py ← Part 2
├── resource/
│ └── turtle_bringup ← empty marker file (required)
├── turtle_bringup/
│ └── __init__.py ← empty (required by Python)
├── package.xml
├── setup.cfg
└── setup.py
Install xterm (needed for the teleop terminal window):
sudo apt install xtermCreate your workspace folder and clone the repository directly into the src directory. All files,
except for the launch file we just created, are already in place.
mkdir -p ~/turtle_ws/srccd ~/turtle_ws/srcgit clone https://github.com/KSU-Chad/turtle_bringup.gitls turtle_bringup/You should see: package.xml resource/ setup.cfg setup.py turtle_bringup/
ls turtle_bringup/launch/You should see: turtle_bringup_args.launch.py
Copy the launch file you created in the previous activity into the 'turtle_ws/src/turtle_bringup/launch folder'
cd
mv launch/turtle_bringup.launch.py turtle_ws/src/turtle_bringup/launch/cd ~/turtle_ws
colcon buildYou should see output ending in:
Starting >>> turtle_bringup
Finished <<< turtle_bringup [...]
Summary: 1 package finished [...]
This step is required every time you open a new terminal after building.
source ~/turtle_ws/install/setup.bashCommon mistake: Forgetting to source after building. If
ros2 launchreports "Package 'turtle_bringup' not found", you need to source.
ros2 pkg list | grep turtle_bringupros2 launch turtle_bringup turtle_bringup.launch.pyYou should see:
- The turtlesim window open with a blue background
- A separate xterm window open with the teleop node running
Click the xterm window to give it keyboard focus, then use arrow keys to drive the turtle.
In a new terminal (remember to source first):
# How many nodes are running?
ros2 node list
# What topics exist?
ros2 topic list
# Confirm the background parameters were applied
ros2 param get /sim background_r
ros2 param get /sim background_g
ros2 param get /sim background_bQuestions to answer in your lab notebook:
- Run
ros2 node listwhile the simulation is running. Write down the node names you see. In the launch file, find thename=argument for each node — what does changing that argument appear to do to the node name? - Run
ros2 param get /sim background_b. Write down the value. Now look at the launch file wherebackground_bis set. Do the two numbers match?
ros2 launch turtle_bringup turtle_bringup_args.launch.py --show-argsYou should see the three arguments (bg_r, bg_g, bg_b) with their defaults and descriptions.
ros2 launch turtle_bringup turtle_bringup_args.launch.pyTry each of these and observe the simulator background:
# Red background
ros2 launch turtle_bringup turtle_bringup_args.launch.py bg_r:=255 bg_g:=0 bg_b:=0
# Green background
ros2 launch turtle_bringup turtle_bringup_args.launch.py bg_r:=0 bg_g:=200 bg_b:=0
# Orange background
ros2 launch turtle_bringup turtle_bringup_args.launch.py bg_r:=255 bg_g:=165 bg_b:=0Question: What happens if you pass bg_r:=999? (Try it.) Write down what you observe.
Answer these in your lab notebook before leaving:
-
After building the package, open a new terminal without sourcing
install/setup.bashand try to runros2 launch turtle_bringup turtle_bringup.launch.py. Write down the exact error message you get. -
Look at
turtle_bringup_args.launch.py. Find the threeDeclareLaunchArgumentblocks. What is thedefault_valueforbg_b? Now run the launch file without passing any arguments — what color is the background? Do they match? -
Run
ros2 launch turtle_bringup turtle_bringup_args.launch.py --show-args. Write down what the output looks like. -
Remove
prefix='xterm -e'from your local copy ofturtle_bringup.launch.py, rebuild, and relaunch. Try using the arrow keys. -
You used
bg_r:=255 bg_g:=0 bg_b:=0to get a red background. Without running it first, predict what values would give you a purple background. Then try it and see if you were right.
| Symptom | Likely Cause | Fix |
|---|---|---|
Package 'turtle_bringup' not found |
Haven't sourced install | source ~/turtle_ws/install/setup.bash |
No executable found |
Launch file not installed | Check data_files in setup.py, rebuild |
| Teleop window opens but arrow keys do nothing | xterm doesn't have focus | Click the xterm window |
xterm: command not found |
xterm not installed | sudo apt install xterm |
| Background stays grey after setting parameters | turtlesim reads bg params on init only | Kill and relaunch — params can't be hot-reloaded on this node |