Class 6 · Showcase¶
The car drives itself, keeps off the walls, and knows where it is. Today you make it reliable enough to show to people who didn't build it, and, if you have time, add one more ability: obeying road signs it was trained to recognize, or counting its wheel turns to know where it is between tags.
By the end of class
A visitor names a tag; the car drives there through the track by itself and stops in front of it.
New parts today¶
| Part | What it's for |
|---|---|
| LM393 slot speed sensors, ×2 | Stretch B: counting wheel turns |
| Rubik Pi 3 | Stretch A: running the sign classifier faster |
| Printed signs (stop, left, right) on foam board | Stretch A |
Mission 1 · Make it reliable
Run the full track ten times from different start spots to different tags, and keep a tally of what goes wrong (lost, touched a wall, wrong tag, stopped too far). Fix the most common problem first, then run again.
Things that usually help: fresh AA batteries (motors slow down as they drain), a slower speed near tags, a longer LOST search, and taping down tags that have peeled.
Done when
Your tally shows at least 8 successes out of the last 10 runs.
Mission 2 · The showcase run
Set up so a visitor can pick a tag number and watch: the car on the track, and the live plot on a laptop screen next to it.
Have ready, on a poster or a screen: the "two brains" diagram, your command list, your state diagram, a calibration graph from Class 2, and one sentence on what Claude Code helped with and what you wrote. Credit AprilTags, pupil-apriltags and OpenCV.
Done when
A visitor (or Dr. Alvear) picks three tags in a row and the car reaches at least two of them. You explain how the car knows where it is in under two minutes.
Stretch goals¶
Pick one. Get it working on the side; don't break the showcase car.
Teach the car to recognize three signs (stop, turn left, turn right) with a small neural network that you train on your own photos.
- With the car's webcam, take about 100 photos of each sign from different distances and angles, plus 100 photos of the track with no sign. The "no sign" class matters: without it, the network has to call everything a sign.
- Train an image model in Google's Teachable Machine (an Image Project) with those four classes. Test it in the browser with the webcam.
- Export it as TensorFlow Lite. The export page shows example code for running the model in Python.
- Run it on the Pi first, on each camera frame, and print the class and its confidence. Claude Code may help with loading the model and preparing the frames.
- Your decisions: add sign states to your state machine. What should the car do if it sees "stop" with 60 % confidence? Should one frame be enough, or should it see the sign in three frames in a row?
- Once it works on the Pi 5, try the Rubik Pi 3, which has an AI accelerator for exactly this kind of network. It runs on 12 V over USB-C PD, so check that your power bank offers a 12 V profile before it rides on the car. Its software is less common than the Pi's, so expect some setup.
Done when
The car, driving down a corridor, stops at a stop sign and turns at a turn sign, three times out of four. Note the frames per second on the Pi 5 (and the Rubik Pi, if you got there).
Between tag sightings, the car only guesses where it is. Counting slots on the encoder disks that came with the chassis tells you how far each wheel has turned: odometry.
Wiring. Each LM393 module straddles one encoder disk so the slots pass through its gap. Check the labels on your module.
| From | To |
|---|---|
| Left slot sensor VCC / GND | Uno 5V / GND |
| Left slot sensor D0 | Uno pin 2 |
| Right slot sensor VCC / GND | Uno 5V / GND |
| Right slot sensor D0 | Uno pin 3 |
Pins 2 and 3 are the only Uno pins that can trigger an interrupt, which is why they were kept free in Class 1.
Tool: interrupts with attachInterrupt()
A slot sensor can pulse faster than loop() checks it. An interrupt runs a tiny function the instant the pin changes, whatever loop() is doing. Example: counting the turns of a paper disk with one slot, spun by hand through the sensor.
#include <Arduino.h>
const int SENSOR = 2;
volatile long pulses = 0; // volatile: changed inside an interrupt
void countPulse() { // keep this tiny: no Serial, no delay
pulses++;
}
void setup() {
Serial.begin(115200);
pinMode(SENSOR, INPUT);
attachInterrupt(digitalPinToInterrupt(SENSOR), countPulse, RISING);
}
void loop() {
noInterrupts(); // copy the count without it changing mid-copy
long n = pulses;
interrupts();
Serial.println(n);
delay(200);
}
Then: count the slots on your disk and measure the wheel's diameter. Distance per pulse = wheel circumference ÷ slots. Have the Uno report both counts (add them to your ? reply), and have the Pi move the car's arrow on the plot between tag sightings. When a tag comes into view, the tag wins.
Done when
Driving 1 m straight, the count gives 1 m within 5 cm. On the track, the arrow on the plot keeps moving sensibly between tags instead of freezing.
If you finish early¶
- Add a second goal type: "go to the point (1.2, 0.8)" instead of a tag.
- Make the live plot show what state the car is in.
- Write a short README for whoever builds this car next year.
Sign-off with Dr. Alvear
- 8 of the last 10 runs successful
- Showcase run: a visitor's tags reached
- Poster or screen with diagrams, command list, state diagram and credits
- Stretch goal attempted (what worked, what didn't)
- Build log updated (photo + two sentences)