SPIKE Prime Robotics Camp — Day 5
Teach your robot to follow a line
The last day — and the big showcase.
Teach your robot to:
Then demo your best run of the week!
Bugs are sensor data.
The robot did exactly what the code said.
What did the code actually say?
A move sequence has one deliberate bug.
"Step left… clap… step left… spin." Wait — should that be step right?
Find it and fix it — that's reading the steps like the robot does.
Yesterday the robot sensed the world and decided what to do.
if sensor.distance() < 200:
robot.straight(-100)
robot.turn(90)
Today: turn a reading into smooth steering.
It can read how much light bounces back.
line_sensor = ColorSensor(Port.D)
print(line_sensor.reflection()) # 0 to 100
Black tape reflects little.
White floor reflects a lot.
Black electrical tape on white poster board or a light floor.
No contrast → the robot can't tell line from floor.
Measure on your tape and your floor.
BLACK = 10 # measured on the tape
WHITE = 80 # measured on the floor
threshold = (BLACK + WHITE) / 2
The threshold is the midpoint between them.
The robot rides the edge of the line —
half on black, half on white.
That's why a little wobble is normal.
Steer in proportion to how far off you are.
A little off → steer a little.
Way off → steer hard.
deviation = line_sensor.reflection() - threshold
How far the reading is from the edge.
Positive one way, negative the other.
while True:
deviation = line_sensor.reflection() - threshold
robot.drive(DRIVE_SPEED, GAIN * deviation)
wait(10)
drive(speed, turn_rate) drives continuously.
GAIN decides how hard it steers per unit of deviation.
Change only GAIN and watch. That's the lesson.
Get up, move, refuel.
Keep food away from the kits and laptops!
Calibrate, follow, then tune the gain.
"Smooth-ish" is a win!
This is the camp finale.
Each team demos their best run of the week —
and explains one thing they tuned.