Lesson 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?
Ultrasonic readings fluctuate with angle, surface, and noise. A threshold ('closer than 15 cm = blocked') absorbs that variation; an exact-match check would fail constantly.
The robot is at (2,1) facing NORTH and the rangefinder reads 8 cm (threshold 15). Which node is blocked?
Facing north means the next node is row − 1: (1,1). The robot sits on a clear node; the obstacle is the adjacent one it faces.
When the robot detects a new obstacle, what does it do to reroute?
Detecting an obstacle means reroute, not stop. A new Dijkstra with the updated blocked list and the robot's current position produces a path around it.
Why test with a simulated rangefinder before using the real one?
A simulated sensor lets you confirm the rerouting logic on screen. Once that's solid, real-sensor problems are clearly hardware, not logic — much easier to debug.