📖 Scenario: You are building a simple ROS (Robot Operating System) application where a node needs to read configuration parameters set from a launch file. This is common when you want to change settings without modifying the node code.
🎯 Goal: Create a ROS launch file that sets parameters, and write a ROS node that reads these parameters at startup.
📋 What You'll Learn
Create a ROS launch file named my_robot.launch that sets parameters robot_name and max_speed.
Write a Python ROS node named robot_node.py that reads robot_name and max_speed parameters from the parameter server.
Print the parameter values inside the node to verify they are read correctly.
💡 Why This Matters
🌍 Real World
Setting parameters from launch files is a common way to configure robot behavior without changing code. It helps in testing different settings quickly.
💼 Career
ROS developers often use launch files to manage parameters and node startup. Understanding this is essential for robotics software engineering roles.
Progress0 / 4 steps
1
Create the ROS launch file with parameters
Create a launch file named my_robot.launch that sets the parameter robot_name to "RoboBuddy" and max_speed to 1.5 using the <param> tag.
ROS
Hint
Use the <param> tag inside the <launch> root element to set parameters.
2
Initialize the ROS node and import necessary modules
In a Python file named robot_node.py, import rospy and initialize a ROS node called robot_node.
ROS
Hint
Use rospy.init_node() to initialize the node with the name robot_node.
3
Read parameters from the parameter server
Use rospy.get_param to read the parameters robot_name and max_speed from the parameter server and store them in variables robot_name and max_speed.
ROS
Hint
Use rospy.get_param('parameter_name') to get the parameter value.
4
Print the parameter values to verify
Add rospy.loginfo statements to print the values of robot_name and max_speed.
ROS
Hint
Use rospy.loginfo() to print messages to the ROS console.
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
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.
Step 2: Differentiate from other launch file tags
Tags like <node> start nodes, but <param> specifically sets values nodes use.
Final Answer:
To set parameters that nodes can use when they start -> Option B
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
Step 1: Check the value attribute format
Boolean values in <param> tags must be strings, so true should be "true" in quotes.
Step 2: Verify tag placement and syntax
The <param> tag can be outside the <node> tag, and the <launch> tag is correctly closed.
Final Answer:
The value true should be in quotes: value="true" -> Option A
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
Step 1: Understand conditional parameter setting
The <param> tag supports the 'unless' attribute to set a parameter only if it is not already set.
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.
Final Answer:
<param unless="max_retries" name="max_retries" value="5" /> -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.