Challenge - 5 Problems
Collision Avoidance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output behavior of this ROS node snippet for collision avoidance?
Consider a ROS node that subscribes to a laser scan topic and publishes velocity commands to avoid obstacles. What will the robot do when an obstacle is detected within 0.5 meters?
ROS
def scan_callback(data): min_distance = min(data.ranges) if min_distance < 0.5: cmd.linear.x = 0.0 cmd.angular.z = 0.5 else: cmd.linear.x = 0.5 cmd.angular.z = 0.0 pub.publish(cmd)
Attempts:
2 left
💡 Hint
Think about how linear and angular velocities control robot movement.
✗ Incorrect
When the minimum distance from the laser scan is less than 0.5 meters, the code sets linear velocity to zero and angular velocity to 0.5, causing the robot to stop moving forward and turn left slowly to avoid collision.
📝 Syntax
intermediateWhich option correctly initializes a ROS publisher for velocity commands in Python?
You want to publish velocity commands to the topic '/cmd_vel' using geometry_msgs/Twist messages. Which code snippet correctly creates the publisher?
Attempts:
2 left
💡 Hint
Check the correct way to specify message type and queue size in rospy.Publisher.
✗ Incorrect
The correct syntax uses the message class (Twist) without parentheses, and queue_size as a named argument. Option A matches this pattern.
🔧 Debug
advancedWhat error does this ROS Python code raise when running?
Examine the code below that attempts to subscribe to a laser scan topic and print the minimum distance. Identify the error raised at runtime.
ROS
def callback(msg): print(min(msg.range)) rospy.Subscriber('/scan', LaserScan, callback) rospy.spin()
Attempts:
2 left
💡 Hint
Check the attribute name for laser scan ranges in the message.
✗ Incorrect
The LaserScan message has an attribute 'ranges' (plural), not 'range'. Accessing 'msg.range' causes an AttributeError.
❓ state_output
advancedWhat is the value of 'avoidance_active' after this ROS node callback runs?
Given the following callback that sets a signal to True if an obstacle is detected within 1 meter, what is the value of 'avoidance_active' after receiving a LaserScan with ranges [1.2, 0.8, 1.5]?
ROS
avoidance_active = False def scan_cb(msg): global avoidance_active if any(distance < 1.0 for distance in msg.ranges): avoidance_active = True else: avoidance_active = False # Simulated call class Msg: ranges = [1.2, 0.8, 1.5] scan_cb(Msg())
Attempts:
2 left
💡 Hint
Check if any value in the list is less than 1.0.
✗ Incorrect
Since 0.8 is less than 1.0, the condition is True and 'avoidance_active' is set to True.
🧠 Conceptual
expertWhich option best describes the role of the costmap in ROS navigation for collision avoidance?
In ROS navigation, the costmap is used to represent obstacles and free space around the robot. What is the primary purpose of the costmap in collision avoidance planning?
Attempts:
2 left
💡 Hint
Think about how the planner knows where obstacles are.
✗ Incorrect
The costmap is a grid that marks obstacles and free space, allowing the planner to find safe paths and avoid collisions.
