Challenge - 5 Problems
Safety Velocity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat happens when the velocity exceeds the safety limit in a ROS node?
Consider a ROS node that subscribes to velocity commands and applies safety velocity limits before publishing. What will be the output behavior if the input velocity exceeds the safety limit?
ROS
def velocity_callback(msg): max_speed = 1.0 # m/s safe_vel = min(msg.linear.x, max_speed) publish_velocity(safe_vel) # Input velocity message: linear.x = 1.5 m/s
Attempts:
2 left
💡 Hint
Think about how the min function limits the velocity value.
✗ Incorrect
The code uses min(msg.linear.x, max_speed) to ensure the velocity never exceeds 1.0 m/s. So if input is 1.5 m/s, it publishes 1.0 m/s.
📝 Syntax
intermediateIdentify the syntax error in this ROS velocity limiting code snippet
Which option contains the correct syntax to limit a velocity message's linear.x to a max of 2.0 m/s in Python ROS?
ROS
def limit_velocity(msg): max_vel = 2.0 if msg.linear.x > max_vel msg.linear.x = max_vel return msg
Attempts:
2 left
💡 Hint
Python if statements require a colon at the end.
✗ Incorrect
The if statement is missing a colon, which causes a syntax error. Adding ':' fixes it.
❓ state_output
advancedWhat is the final velocity published after applying safety limits?
Given this ROS Python code snippet that limits both linear and angular velocities, what will be the published velocities if input is linear.x=3.5 m/s and angular.z=2.5 rad/s?
ROS
def limit_velocities(msg): max_linear = 2.0 max_angular = 1.0 msg.linear.x = min(msg.linear.x, max_linear) msg.angular.z = min(msg.angular.z, max_angular) publish(msg) # Input velocities: linear.x=3.5, angular.z=2.5
Attempts:
2 left
💡 Hint
The min function caps values at the max limits.
✗ Incorrect
Both linear and angular velocities are capped at their max values, so output is 2.0 and 1.0 respectively.
🔧 Debug
advancedWhy does this ROS node fail to enforce velocity limits correctly?
Examine the code below. Why does the robot sometimes move faster than the safety velocity limit?
ROS
def callback(msg): max_speed = 1.0 if msg.linear.x > max_speed: msg.linear.x = max_speed # Missing else clause publish(msg) # Input velocities vary, sometimes below max_speed
Attempts:
2 left
💡 Hint
Think about what happens if velocity is negative and less than max_speed.
✗ Incorrect
Negative velocities less than max_speed are not limited, so robot can move faster backward than intended.
🧠 Conceptual
expertWhat is the main benefit of applying safety velocity limits in a ROS robot control system?
Why do ROS developers implement safety velocity limits on robot commands?
Attempts:
2 left
💡 Hint
Think about safety and physical limits of robots.
✗ Incorrect
Safety velocity limits protect hardware and people by preventing dangerous speeds.
