Using data to improve robots
What you’ll learn
- What to measure and how to log it
- How to run a fair test
- How to turn numbers into decisions
Measure, don’t guess
“It feels faster” isn’t evidence. Measure:
- Time (lap time, time to goal)
- Accuracy (distance from target, times it lost the line)
- Reliability (successes out of 10 runs)
- Energy (battery drop per run)
Logging
Print data with a timestamp so you can copy it into a spreadsheet:
if (millis() % 500 < 20) print(millis() + "," + linePosition());On a real Arduino, Serial.println() the values and copy them from the Serial Monitor, or use the Serial Plotter to see graphs live.
Fair tests
- Change one variable at a time.
- Keep everything else the same (track, battery level, start position).
- Repeat each test (3–5 runs) and use the average.
- Write it down straight away.
Decide with evidence
Compare averages in a table, and pick the setting that best meets your requirements, not just the fastest one. A robot that’s 10% faster but fails 3 times out of 10 usually isn’t better.
Example: a tuning table
| KP | Run 1 | Run 2 | Run 3 | Average | Lost line? |
|---|---|---|---|---|---|
| 20 | 41 s | 42 s | 40 s | 41 s | 0/3 |
| 40 | 33 s | 34 s | 33 s | 33.3 s | 0/3 |
| 80 | 30 s | — | 31 s | — | 1/3 |
Decision: KP = 40. KP = 80 is a little faster but unreliable.
Example: a lap timer in the simulator
let lapStart = 0, away = false;function loop() { // the start is on the top straight; linePosition is near 0 there const t = millis(); if (t - lapStart > 5000) away = true; // ...your controller here...}Try it
Robot commands
motors(left, right): wheel power, −100 to 100lineLeft(),lineRight():trueover the black linedistance(): cm to the nearest thing ahead (max 200)distanceLeft(),distanceRight(): cm to the sideslinePosition(): where the line is, −1 (left) to 1 (right), ornullmillis(): milliseconds since Runprint(value): show a message belowsetup()runs once;loop()runs 50 times a second
Average three runsEasy
Time three laps (watch the time under the arena) at BASE = 50 and work out the average.
Fair testMedium
Test BASE = 40, 55 and 70 with KP fixed, three runs each. Fill in a table and choose the best setting.
Justify itHard
Write two sentences recommending a final setting to your team, using your numbers as evidence.
Quick check
Finished this lesson?