Bird
Raised Fist0
ROSframework~20 mins

Setting parameters from launch file in ROS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ROS 2 Launch Parameter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the value of the parameter robot_speed inside the node after launch?
Given this ROS 2 launch file snippet, what will be the value of the parameter robot_speed inside the node when it starts?

<launch> <node pkg="my_robot" exec="controller" name="robot_controller"> <param name="robot_speed" value="2.5" /> </node> </launch>
ROS
<launch>
  <node pkg="my_robot" exec="controller" name="robot_controller">
    <param name="robot_speed" value="2.5" />
  </node>
</launch>
Anull (parameter not set)
B0.0 (default value)
C1.0 (hardcoded in node)
D2.5
Attempts:
2 left
💡 Hint
Look at the tag inside the element.
📝 Syntax
intermediate
2:00remaining
Which launch file snippet correctly sets a boolean parameter use_lidar to true?
Choose the correct XML snippet to set the boolean parameter use_lidar to true in a ROS 2 launch file.
A<param name="use_lidar" value="1" />
B<param name="use_lidar" value="True" />
C<param name="use_lidar" value="true" />
D<param name="use_lidar" value="yes" />
Attempts:
2 left
💡 Hint
ROS 2 parameters use lowercase true/false for booleans in launch files.
🔧 Debug
advanced
2:00remaining
What error occurs when this launch file tries to set a parameter with missing value attribute?
Examine this launch file snippet:

<launch> <node pkg="sensor_pkg" exec="sensor_node" name="sensor"> <param name="sensor_enabled" /> </node> </launch>

What error will ROS 2 raise when launching this?
ROS
<launch>
  <node pkg="sensor_pkg" exec="sensor_node" name="sensor">
    <param name="sensor_enabled" />
  </node>
</launch>
ANo error, parameter ignored
BLaunch file parsing error: missing 'value' attribute in <param>
CNode runs with 'sensor_enabled' set to null
DParameter 'sensor_enabled' set to false by default
Attempts:
2 left
💡 Hint
Check if tags require a value attribute.
❓ state_output
advanced
2:00remaining
What is the final value of parameter max_range if set twice in the launch file?
Consider this launch file snippet:

<launch> <node pkg="mapping" exec="mapper" name="mapper"> <param name="max_range" value="10.0" /> <param name="max_range" value="15.0" /> </node> </launch>

What value will the node receive for max_range?
ROS
<launch>
  <node pkg="mapping" exec="mapper" name="mapper">
    <param name="max_range" value="10.0" />
    <param name="max_range" value="15.0" />
  </node>
</launch>
A15.0
Bnull (parameter ignored)
CError: duplicate parameter name
D10.0
Attempts:
2 left
💡 Hint
Later parameter definitions override earlier ones.
🧠 Conceptual
expert
2:00remaining
Which statement about setting parameters from a ROS 2 launch file is TRUE?
Select the correct statement about how parameters are set from a ROS 2 launch file.
AParameters set in the launch file override parameters set by the node's default code.
BParameters set in the launch file are ignored if the node has the same parameter hardcoded.
CParameters can only be set globally, not per node, from the launch file.
DParameters must be set in the node code; launch files cannot set parameters.
Attempts:
2 left
💡 Hint
Think about how launch files configure nodes at startup.

Practice

(1/5)
1. What is the main purpose of using <param> tags in a ROS launch file?
easy
A. To start multiple nodes at the same time
B. To set parameters that nodes can use when they start
C. To define the order in which nodes run
D. To stop nodes after they finish

Solution

  1. Step 1: Understand the role of <param> in launch files

    The <param> tag is used to set parameters that nodes read when they start running.
  2. Step 2: Differentiate from other launch file tags

    Tags like <node> start nodes, but <param> specifically sets values nodes use.
  3. Final Answer:

    To set parameters that nodes can use when they start -> Option B
  4. Quick Check:

    Setting parameters = A [OK]
Hint: Remember: <param> sets values, <node> starts nodes [OK]
Common Mistakes:
  • Confusing <param> with <node> tag
  • Thinking <param> controls node start/stop
  • Assuming <param> sets node execution order
2. Which of the following is the correct syntax to set a string parameter named robot_name to "R2D2" in a ROS launch file?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Check the correct attribute names

    The <param> tag requires 'name' for the parameter name and 'value' for its value.
  2. Step 2: Verify proper quoting of string values

    String values must be inside quotes, so value="R2D2" is correct.
  3. Final Answer:

    <param name="robot_name" value="R2D2" /> -> Option C
  4. Quick Check:

    Correct attributes and quotes = B [OK]
Hint: Use name="" and value="" with quotes for strings [OK]
Common Mistakes:
  • Missing quotes around string values
  • Swapping name and value attributes
  • Using incorrect attribute names
3. Given this launch file snippet:
<launch>
  <param name="speed" value="2.5" />
  <node pkg="robot_pkg" type="move_node" name="mover" />
</launch>

What will be the value of the speed parameter inside the move_node when it starts?
medium
A. 2.5 (as a float)
B. 0, the default value
C. Undefined, because parameters must be set inside the node tag
D. "2.5" (as a string)

Solution

  1. Step 1: Understand parameter value types in launch files

    Values in <param> tags are treated as strings by default unless explicitly converted in code.
  2. Step 2: Check the launch file snippet

    The value is "2.5" in quotes, so the parameter is set as a string "2.5".
  3. Final Answer:

    "2.5" (as a string) -> Option D
  4. Quick Check:

    Parameter values are strings by default = D [OK]
Hint: Parameter values are strings unless converted in code [OK]
Common Mistakes:
  • Assuming numeric values are auto-converted to float
  • Thinking parameters must be inside <node> tag
  • Believing default values apply if parameter is set
4. Identify the error in this launch file snippet:
<launch>
  <param name="use_sim" value=true />
  <node pkg="sim_pkg" type="sim_node" name="simulator" />
</launch>
medium
A. The value true should be in quotes: value="true"
B. The param tag should be inside the node tag
C. The node tag is missing the required args attribute
D. The launch tag is missing a closing slash

Solution

  1. Step 1: Check the value attribute format

    Boolean values in <param> tags must be strings, so true should be "true" in quotes.
  2. Step 2: Verify tag placement and syntax

    The <param> tag can be outside the <node> tag, and the <launch> tag is correctly closed.
  3. Final Answer:

    The value true should be in quotes: value="true" -> Option A
  4. Quick Check:

    Boolean values need quotes in <param> = C [OK]
Hint: Always put boolean values in quotes in <param> tags [OK]
Common Mistakes:
  • Leaving boolean values unquoted
  • Placing <param> tags only inside <node>
  • Misunderstanding launch tag syntax
5. You want to set a parameter max_retries to 5 only if it is not already set by another launch file. Which launch file tag should you use to achieve this?
hard
A.
B. 5
C.
D.

Solution

  1. Step 1: Understand conditional parameter setting

    The <param> tag supports the 'unless' attribute to set a parameter only if it is not already set.
  2. Step 2: Check the options for correct usage

    <param unless="max_retries" name="max_retries" value="5" /> uses 'unless="max_retries"' with name and value, which is the correct syntax.
  3. Final Answer:

    <param unless="max_retries" name="max_retries" value="5" /> -> Option A
  4. Quick Check:

    Use 'unless' attribute to avoid overwriting = A [OK]
Hint: Use 'unless' attribute to set param only if unset [OK]
Common Mistakes:
  • Omitting the 'name' attribute when using 'unless'
  • Using <rosparam> without condition
  • Misplacing 'unless' attribute
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