Lesson 5-7 · Obstacle Detection with the Rangefinder — Knowledge ChecksAnswer key
How does an ultrasonic rangefinder measure distance?
Sound pulse out, echo back, time it — that round-trip time converts to a distance. The XRP returns it in centimeters.
Why use a threshold instead of checking for an exact distance?
Readings vary with angle, surface and noise. A threshold ('closer than 15 cm = blocked') absorbs that; an exact match would fail constantly.
The robot is at (2,1), has just turned to face the next step on its path, (1,1), and the rangefinder reads 8 cm. Which intersection is blocked?
turn_to(heading, desired_heading) pointed the robot at next_pos. Whatever the sensor sees now is at next_pos. The robot sits on a clear intersection; the obstacle is the one it faces.
When the robot detects a new obstacle, what does it do to reroute?
Detecting an obstacle means reroute, not stop. add_blocked tells the planner; compute_bfs_path from the current position returns a path around it, because the planner rebuilds its graph from BLOCKED on every call.
Why does the robot not need a separate 'rebuild the graph' step after add_blocked()?
Lesson 5-4 put build_graph() inside the planner precisely so that a wall found at step 3 is already missing from the graph used at step 4.
Why test with a simulated rangefinder before using the real one?
A simulated sensor proves the detection logic on screen. After that, real-sensor problems are hardware, not logic. The planner was already proven in Lesson 5-6.