L1 · PAI-110

React and Avoid

Build a reactive rule-based behavior using conditionals so the rover avoids an obstacle and still reaches the goal with zero collisions.

01
Challenge

Try this first — before any explanation.

Same rover, goal now 4.0 m ahead — but a wall blocks the direct route. Reach the goal without ever touching the wall. You have a new sensor, proximity, that reports how close an obstacle is ahead. Use if/else to react to it — no planning, no map, just react to what you see right now. Try it before the video.

The Bench

Add an if/else that reads proximity every tick so the rover reacts around the wall.

VISUAL · BLOCKS → PYTHON

React and Avoid

Add an if/else that reads proximity every tick so the rover reacts around the wall.

02
Model

The idea, built visually.

A thermostat controls a whole house's temperature with no map, no plan, no memory. It follows one rule: too cold, turn on; warm enough, turn off — it just reacts to the reading in front of it, over and over. That's a reactive controller, and it's enough to hold a house steady for years.

Give the rover the same idea: if something's close ahead, steer; otherwise head for the goal. It never plans a route around the wall — it keeps reacting, and the route emerges. Later you'll teach it to plan; not yet. Master the reflex first.

▣ Stage animation: A thermostat morphs into an if/else branch flipping on a sine-wave temperature trace; the same branch is reused for the rover with a proximity cone that dips below 0.6 to flip the branch and steer; a REACT-vs-DELIBERATE split shows the reflex threading the wall live next to a ghost that plans a full path first.

03
Guided practice

Build it up, step by step.

Step 1 (worked): the proximity branch is slotted into your 1.1 loop (if proximity < 0.6: steer else: drive). Step 2 (faded): rebuild the branch and pick the threshold and turn sharpness. Step 3 (independent): tune so the rover clears the wall AND re-aims at the goal — sharp enough to clear, gentle enough that the else branch recovers heading.

04
Feedback

How the Bench grades your run.

PASS WHEN Reached the goal (range <= 0.25 m) with zero collisions, the proximity branch read every tick inside the loop.

  • FAIL: clipped the wall — your turn starts too late; raise the proximity threshold toward 0.6 m so the rover reacts before it arrives.
  • FAIL: avoided the wall but never returned toward the goal — the turn is too sharp; reduce the pivot so the else branch can recover heading.
  • FAIL: ran out of step budget circling the wall — make proximity rise back above the threshold once clear so the else branch takes over.
05
Retrieve & space

Bring back what you've already mastered.

  • Carry-forward: re-place the 1.1 stop-on-goal check into a fresh stack (not pre-filled).
  • Name-the-phase harder: is read_proximity SENSE or DECIDE? (SENSE.) Is `if proximity < 0.6` SENSE or DECIDE? (DECIDE.)
  • Reactive-vs-deliberative: of 'follows a precomputed path / flips on the current reading / stores a map', which is reactive? (The second.)
06
Mastery gate

What you must demonstrate to advance.

From the fixed seed, the rover reaches the goal with zero collisions using a conditional that reads proximity every tick inside the loop (L1: closes a reactive loop).

07
Project

How this feeds your build.

Contributes the reactive AVOID behavior; in Module 2 you rebuild this reflex as a state in an FSM, and in Module 4 the proximity read becomes an ADC interrupt.