Launch files help start multiple parts of a robot system easily. They use XML to organize what runs and how.
Launch file XML syntax in ROS
<launch> <node pkg="package_name" type="executable_name" name="node_name" output="screen"> <param name="param_name" value="param_value" /> </node> <include file="other_launch_file.launch" /> <arg name="arg_name" default="default_value" /> </launch>
The root tag is always <launch> which wraps all commands.
Each <node> tag runs a program from a package with a name and output option.
<launch> <node pkg="turtlesim" type="turtlesim_node" name="sim" output="screen" /> </launch>
<launch> <arg name="speed" default="2.0" /> <node pkg="my_robot" type="move_node" name="mover" output="screen"> <param name="speed" value="$(arg speed)" /> </node> </launch>
<launch>
<include file="bringup.launch" />
</launch>This launch file starts the demo_node from demo_pkg. It uses an argument 'robot_name' with a default value. The node receives this as a parameter named 'robot'.
<launch> <arg name="robot_name" default="my_robot" /> <node pkg="demo_pkg" type="demo_node" name="demo" output="screen"> <param name="robot" value="$(arg robot_name)" /> </node> </launch>
Use output="screen" to see program messages in the terminal.
Arguments let you customize launch files without changing the XML.
Include other launch files to organize complex robot systems.
Launch files use XML to start and configure robot programs.
They include nodes, parameters, arguments, and other launch files.
This helps run many parts of a robot system easily and clearly.
Practice
<launch> file in ROS?Solution
Step 1: Understand the role of launch files
Launch files in ROS are XML files used to start and configure multiple nodes and parameters together.Step 2: Compare options with launch file purpose
Only To start and configure multiple robot nodes easily correctly describes this purpose. Other options describe unrelated tasks.Final Answer:
To start and configure multiple robot nodes easily -> Option DQuick Check:
Launch files start nodes = A [OK]
- Confusing launch files with program code
- Thinking launch files store data
- Assuming launch files compile code
Solution
Step 1: Recall correct node tag attributes
The correct attributes arepkg,type, andnameinside a<node>tag.Step 2: Match options with correct syntax
Only <node pkg="my_pkg" type="my_node" name="node1" /> uses the correct tag and attribute names. Others use wrong attribute names or tags.Final Answer:
<node pkg="my_pkg" type="my_node" name="node1" /> -> Option BQuick Check:
Correct node syntax = A [OK]
- Using wrong attribute names like package or exec
- Using incorrect tag names like launch_node
- Confusing name with id or label
<launch> <node pkg="turtlesim" type="turtlesim_node" name="sim" /> <param name="background_r" value="255" /> </launch>
Solution
Step 1: Understand node and param placement
The<param>tag outside<node>sets a global parameter, not specific to the node.Step 2: Check if turtlesim uses this param
The parameterbackground_ris not recognized globally by turtlesim, so it uses default background color.Final Answer:
Starts the turtlesim node with default background color -> Option CQuick Check:
Param outside node is global but unused = C [OK]
- Assuming param inside launch affects node color
- Thinking param outside node causes error
- Confusing param tag as node
<launch> <node pkg="demo_pkg" type="demo_node" name="demo"> </launch>
Solution
Step 1: Check XML tag completeness
The<node>tag is opened but not closed properly (no closing tag or self-closing slash).Step 2: Verify other attributes and tags
Attributes 'pkg' and 'type' are correct. The<launch>tag is properly closed.Final Answer:
Missing closing tag for <node> -> Option AQuick Check:
Unclosed node tag = D [OK]
- Forgetting to close <node> tag
- Confusing attribute names
- Miscounting launch tag closures
camera.launch inside your main launch file to start its nodes as well?Solution
Step 1: Recall correct include syntax in ROS launch files
The<include>tag uses the attributefileto specify the file path.Step 2: Understand file path usage with $(find package)
To locate a launch file inside a package, use$(find package_name)/launch/filename.launchwithfileattribute.Step 3: Compare options
Only <include file="$(find package_name)/launch/camera.launch" /> uses the correct attributefileand the proper path syntax with$(find ...).Final Answer:
<include file="$(find package_name)/launch/camera.launch" /> -> Option AQuick Check:
Include uses file and $(find) = C [OK]
- Using 'launchfile' instead of 'file' attribute
- Not using $(find package_name) for path
- Omitting include tag or wrong syntax
Ready to prove it?
Pass the test and this pattern moves unknown
