Home · Module 4 · Autonomous Navigation
The car drives itself
A simulation of your Raspberry Pi car. The ultrasonic sweeps left/center/right. If anything is too close, the reactive controller turns. Drive manually with arrow keys, or hit "Auto" to let the algorithm take over.
← → ↑ ↓ to drive · click canvas first to focus · drop obstacles by clicking
Mode
Autonomous mode runs a Bug-style reactive policy: drive forward, if ultrasonic detects obstacle < threshold → turn toward the freest sweep angle.
Reactive controller
Live sensor (HC-SR04 sweep)
Map
The actual algorithm (Python on the Pi)
def autonomous_loop():
while True:
# 1. SENSE — sweep ultrasonic via servo
d_left = ping_at_angle(150)
d_center = ping_at_angle(90)
d_right = ping_at_angle(30)
# 2. THINK — reactive decision
if d_center > THRESHOLD:
forward(speed=CRUISE)
elif d_left > d_right:
turn_left(rate=TURN)
else:
turn_right(rate=TURN)
# 3. ACT — done above via motor calls
time.sleep(0.1) # ~10 Hz loop
This is intentionally simple — a purely reactive policy with no memory and no map. It can get stuck in corners (try driving into one in the sim). The course's competition will test exactly this kind of edge case.
Upgrade ideas — add a small state machine ("if stuck for >2s → back up and turn 180°"), record the trail (the green line) to detect loops, or fuse encoder data to know when you've truly stopped. These are great extensions for the competition.