📖 Scenario: You are working with a robot that needs several programs (nodes) to start together. Manually starting each program one by one is slow and can cause mistakes.
🎯 Goal: Build a simple ROS launch file that starts two nodes automatically, so the robot programs run together with one command.
📋 What You'll Learn
Create a launch file named robot_start.launch
Include two nodes: talker and listener
Set the package for both nodes to rospy_tutorials
Use the launch tag as the root element
Use the node tag to define each node
💡 Why This Matters
🌍 Real World
Robots often need many programs running together. Launch files let engineers start all needed programs quickly and correctly.
💼 Career
Knowing how to write launch files is essential for robotics developers to manage complex robot systems efficiently.
Progress0 / 4 steps
1
Create the launch file skeleton
Create a file named robot_start.launch and write the root <launch> tag to start the file.
ROS
Hint
The launch file must start with <launch> and end with </launch>.
2
Add the talker node
Inside the <launch> tags, add a <node> tag for the talker node with pkg="rospy_tutorials" and type="talker.py".
ROS
Hint
Use the node tag with attributes pkg, type, and name.
3
Add the listener node
Add another <node> tag inside <launch> for the listener node with pkg="rospy_tutorials" and type="listener.py".
ROS
Hint
Remember to add the listener node with the same attributes but different type and name.
4
Complete the launch file
Ensure the launch file has both talker and listener nodes inside the <launch> tags and save it as robot_start.launch.
ROS
Hint
Check that both nodes are inside the launch tags and the file is saved correctly.
Practice
(1/5)
1. Why do ROS launch files help automate the startup process of a robot system?
easy
A. They automatically fix errors in the robot's hardware.
B. They replace the need for writing any code in ROS.
C. They start multiple nodes and set parameters together with one command.
D. They only work for simulation, not real robots.
Solution
Step 1: Understand what launch files do
Launch files group many commands to start nodes and set parameters in one place.
Step 2: Compare options to this function
Only They start multiple nodes and set parameters together with one command. correctly describes this automation; others are incorrect or unrelated.
Final Answer:
They start multiple nodes and set parameters together with one command. -> Option C
Quick Check:
Launch files automate startup = A [OK]
Hint: Launch files bundle commands to run nodes and set parameters [OK]
Common Mistakes:
Thinking launch files replace all coding
Believing launch files fix hardware issues
Assuming launch files only work in simulation
2. Which of the following is the correct way to include a node in a ROS launch file?
easy
A.
B.
C.
D.
Solution
Step 1: Recall ROS launch file syntax for nodes
The correct tag is <node> with attributes pkg, type, and name.
Step 2: Check each option's correctness
uses correct tags and attributes; others use wrong tags or attribute names.
Final Answer:
<node pkg="turtlesim" type="turtlesim_node" name="sim" /> -> Option A
A. Node name cannot be 'node1'; use 'node' instead.
B. Attribute 'exec' is wrong; use 'type' instead.
C. Missing closing tag for <launch>.
D. Package name 'my_pkg' is invalid; must be 'pkg'.
Solution
Step 1: Identify incorrect attribute in node tag
The attribute 'exec' is not valid; ROS launch files use 'type' to specify executable.
Step 2: Correct the attribute to fix the launch file
Replace 'exec' with 'type' to properly start the node.
Final Answer:
Attribute 'exec' is wrong; use 'type' instead. -> Option B
Quick Check:
Use 'type' attribute for node executable = C [OK]
Hint: Use 'type' not 'exec' for node executable in launch files [OK]
Common Mistakes:
Confusing 'exec' with 'type' attribute
Forgetting to close launch tags
Changing node names unnecessarily
5. You want to start two nodes and set a shared parameter using one launch file. Which approach best automates this startup?
hard
A. Start each node manually in separate terminals and set parameters individually.
B. Use a script to start nodes but set parameters only after nodes run.
C. Write separate launch files for each node and run them one after another.
D. Create a launch file that includes both nodes and sets the parameter once.
Solution
Step 1: Understand launch file purpose
Launch files automate starting multiple nodes and setting parameters together.
Step 2: Evaluate options for automation
Create a launch file that includes both nodes and sets the parameter once. uses one launch file to start both nodes and set parameter once, saving time and avoiding errors.
Step 3: Compare with other options
Options A, C, and D require manual steps or multiple files, less efficient and error-prone.
Final Answer:
Create a launch file that includes both nodes and sets the parameter once. -> Option D
Quick Check:
One launch file for all nodes and params = B [OK]
Hint: Use one launch file to start all nodes and set shared params [OK]
Common Mistakes:
Running nodes manually instead of using launch files
Splitting nodes into multiple launch files unnecessarily
Setting parameters after nodes start causing delays
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.