Bird
Raised Fist0
ROSframework~10 mins

Launch file XML syntax in ROS - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Launch file XML syntax
Start: <launch> tag
↓
Parse <node> tags
↓
Parse <param> tags
↓
Parse <include> tags
↓
Parse <arg> tags
↓
Validate XML structure
↓
Launch nodes and set parameters
↓
End: </launch> tag
The launch file XML is read from the <launch> root tag, then nodes, parameters, includes, and arguments are parsed in order, validated, and finally executed to start the ROS system.
Execution Sample
ROS
<launch>
  <node pkg="demo_pkg" type="demo_node" name="demo"/>
  <param name="speed" value="10"/>
</launch>
This launch file starts a node named 'demo' from 'demo_pkg' and sets a parameter 'speed' to 10.
Execution Table
StepXML Tag ReadActionAttributesResult
1<launch>Start parsing launch filenoneRoot element created
2<node>Create node to launchpkg="demo_pkg", type="demo_node", name="demo"Node 'demo' prepared to launch
3<param>Set parametername="speed", value="10"Parameter 'speed' set to 10
4</launch>End parsingnoneLaunch file parsed, ready to execute nodes and params
5ExecutionLaunch node and apply paramsnoneNode 'demo' started with speed=10
💡 All tags parsed and launch file executed successfully
Variable Tracker
VariableStartAfter Step 2After Step 3Final
nodes[][{"name":"demo","pkg":"demo_pkg","type":"demo_node"}][{"name":"demo","pkg":"demo_pkg","type":"demo_node"}][{"name":"demo","pkg":"demo_pkg","type":"demo_node"}]
parameters{}{}{"speed":10}{"speed":10}
Key Moments - 3 Insights
Why do we need the <launch> root tag?
The <launch> tag defines the start and end of the launch file. Without it, the parser cannot understand the file structure (see execution_table step 1 and 4).
What happens if a <node> tag is missing required attributes?
The launch system will fail to start that node because it needs 'pkg' and 'type' to find and run the executable (see execution_table step 2).
How are parameters applied to nodes?
Parameters defined with <param> tags are set globally or for specific nodes before launching, as shown in execution_table step 3 and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the action taken at step 3?
ACreate a node to launch
BSet a parameter
CStart parsing the launch file
DEnd parsing the launch file
💡 Hint
Check the 'Action' column at step 3 in the execution_table
At which step does the launch file parsing end?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for the '' tag in the 'XML Tag Read' column in execution_table
If the <param> tag was removed, what would happen to the 'parameters' variable after step 3?
AIt would be empty {}
BIt would contain the parameter 'speed' set to 10
CIt would cause an error
DIt would contain an empty string
💡 Hint
Refer to variable_tracker 'parameters' row and what happens at step 3
Concept Snapshot
<launch> is the root tag for ROS launch files
Use <node> to specify nodes to run with pkg, type, and name
Use <param> to set parameters with name and value
Tags must be properly nested and closed
Launch file runs nodes and applies parameters in order
Full Transcript
A ROS launch file uses XML syntax starting with a <launch> root tag. Inside, <node> tags define which nodes to run, requiring attributes like pkg, type, and name. <param> tags set parameters by name and value. The parser reads each tag in order, builds a list of nodes and parameters, then launches the nodes applying the parameters. Proper XML structure is required for successful execution. This visual trace shows parsing steps, variable changes, and final launch execution.

Practice

(1/5)
1. What is the main purpose of a <launch> file in ROS?
easy
A. To compile the robot's source code
B. To write the robot's main program logic
C. To store sensor data during robot operation
D. To start and configure multiple robot nodes easily

Solution

  1. 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.
  2. 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.
  3. Final Answer:

    To start and configure multiple robot nodes easily -> Option D
  4. Quick Check:

    Launch files start nodes = A [OK]
Hint: Launch files group node startups in XML [OK]
Common Mistakes:
  • Confusing launch files with program code
  • Thinking launch files store data
  • Assuming launch files compile code
2. Which of the following is the correct way to declare a node in a ROS launch file?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Recall correct node tag attributes

    The correct attributes are pkg, type, and name inside a <node> tag.
  2. 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.
  3. Final Answer:

    <node pkg="my_pkg" type="my_node" name="node1" /> -> Option B
  4. Quick Check:

    Correct node syntax = A [OK]
Hint: Use pkg, type, name in <node> tag [OK]
Common Mistakes:
  • Using wrong attribute names like package or exec
  • Using incorrect tag names like launch_node
  • Confusing name with id or label
3. Given this launch file snippet, what will happen when it runs?
<launch>
  <node pkg="turtlesim" type="turtlesim_node" name="sim" />
  <param name="background_r" value="255" />
</launch>
medium
A. Starts the turtlesim node with a red background color
B. Fails because <param> is outside <node>
C. Starts the turtlesim node with default background color
D. Starts a node named 'background_r' with value 255

Solution

  1. Step 1: Understand node and param placement

    The <param> tag outside <node> sets a global parameter, not specific to the node.
  2. Step 2: Check if turtlesim uses this param

    The parameter background_r is not recognized globally by turtlesim, so it uses default background color.
  3. Final Answer:

    Starts the turtlesim node with default background color -> Option C
  4. Quick Check:

    Param outside node is global but unused = C [OK]
Hint: Params outside nodes are global, may not affect node [OK]
Common Mistakes:
  • Assuming param inside launch affects node color
  • Thinking param outside node causes error
  • Confusing param tag as node
4. Identify the error in this launch file snippet:
<launch>
  <node pkg="demo_pkg" type="demo_node" name="demo">
</launch>
medium
A. Missing closing tag for <node>
B. Incorrect attribute name 'type'
C. Missing 'pkg' attribute in <node>
D. Extra closing tag for <launch>

Solution

  1. Step 1: Check XML tag completeness

    The <node> tag is opened but not closed properly (no closing tag or self-closing slash).
  2. Step 2: Verify other attributes and tags

    Attributes 'pkg' and 'type' are correct. The <launch> tag is properly closed.
  3. Final Answer:

    Missing closing tag for <node> -> Option A
  4. Quick Check:

    Unclosed node tag = D [OK]
Hint: Every opened tag must be closed or self-closed [OK]
Common Mistakes:
  • Forgetting to close <node> tag
  • Confusing attribute names
  • Miscounting launch tag closures
5. How can you include another launch file named camera.launch inside your main launch file to start its nodes as well?
hard
A.
B.
C.
D.

Solution

  1. Step 1: Recall correct include syntax in ROS launch files

    The <include> tag uses the attribute file to specify the file path.
  2. Step 2: Understand file path usage with $(find package)

    To locate a launch file inside a package, use $(find package_name)/launch/filename.launch with file attribute.
  3. Step 3: Compare options

    Only <include file="$(find package_name)/launch/camera.launch" /> uses the correct attribute file and the proper path syntax with $(find ...).
  4. Final Answer:

    <include file="$(find package_name)/launch/camera.launch" /> -> Option A
  5. Quick Check:

    Include uses file and $(find) = C [OK]
Hint: Use [OK]
Common Mistakes:
  • Using 'launchfile' instead of 'file' attribute
  • Not using $(find package_name) for path
  • Omitting include tag or wrong syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard