Skip to main content
Module 5 · Pathfinding Around Obstacles

Lesson 5-7 · Obstacle Detection with the Rangefinder — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. How does an ultrasonic rangefinder measure distance?

    1. A.It uses a camera to estimate size
    2. B.It sends a sound pulse and times how long the echo takes to return✓
    3. C.It counts wheel rotations
    4. D.It reads a GPS signal

    Sound pulse out, echo back, time it — that round-trip time converts to a distance. The XRP returns it in centimeters.

  2. Why use a threshold instead of checking for an exact distance?

    1. A.Exact distances are illegal
    2. B.Sensor readings vary slightly (noise), so a cutoff is more reliable than an exact match✓
    3. C.To make the robot slower
    4. D.Thresholds use less memory

    Readings vary with angle, surface and noise. A threshold ('closer than 15 cm = blocked') absorbs that; an exact match would fail constantly.

  3. 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?

    1. A.(2,1) — where the robot is
    2. B.(1,1) — the next step on the path, which the robot is now facing✓
    3. C.(3,1)
    4. D.It depends on the heading number

    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.

  4. When the robot detects a new obstacle, what does it do to reroute?

    1. A.Stops permanently
    2. B.Calls add_blocked(next_pos), then compute_bfs_path(position, destination) from where it is✓
    3. C.Reverses back to the start
    4. D.Ignores it and drives through

    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.

  5. Why does the robot not need a separate 'rebuild the graph' step after add_blocked()?

    1. A.Because compute_bfs_path builds the graph from BLOCKED every time it is called✓
    2. B.Because the graph is never rebuilt — obstacles are checked while driving
    3. C.Because add_blocked rebuilds the graph itself
    4. D.It does need one — the code above is missing it

    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.

  6. Why test with a simulated rangefinder before using the real one?

    1. A.The real sensor never works
    2. B.To verify the detect-and-reroute logic in software first, separating code bugs from hardware bugs✓
    3. C.Simulation is required by Python
    4. D.To avoid writing the loop

    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.