Rescue robot challenge
What you’ll build
A robot for a rescue-style challenge, inspired by events such as RoboCup Junior Rescue Line: follow a line through a “disaster zone”, detour around obstacles blocking the line, and find a “victim” (a coloured or silver object) at the end. Rules differ between events, so this project uses simplified rules you can set up at home.
Home challenge rules
- Black line track with curves, on white.
- One obstacle (a box) placed on the line: go around it and re-find the line.
- A green or red end zone: stop there and signal (LED or buzzer).
- Time limit: 3 minutes.
Parts
Line follower car plus a front distance sensor and a colour sensor (TCS34725) looking down, or use a third line sensor and a coloured tape end zone.
Behaviour plan (state machine)
| State | Does | Leaves when |
|---|---|---|
| FOLLOW | Line following | Obstacle < 10 cm → DETOUR; end colour seen → FINISH |
| DETOUR | Turn right, arc left around the box | A line sensor finds the line → REALIGN |
| REALIGN | Turn until the line is between the sensors | Aligned → FOLLOW |
| FINISH | Stop, flash and beep | — |
Why this is hard
Every piece works alone; the challenge is integration: the detour must reliably end back on the line, and sensors must not confuse the obstacle box or the end zone with the line.
Skeleton of the program
enum State { FOLLOW, DETOUR, REALIGN, FINISH };State state = FOLLOW;unsigned long since = 0;
void enter(State s) { state = s; since = millis(); }
void loop() { switch (state) { case FOLLOW: followLine(); // from the line follower project if (frontCm() < 10) enter(DETOUR); if (endZoneSeen()) enter(FINISH); break; case DETOUR: if (millis() - since < 400) drive(150, -150); // turn right else drive(90, 170); // arc left round the box if (millis() - since > 800 && (leftOnLine() || rightOnLine())) enter(REALIGN); break; case REALIGN: drive(120, -120); if (!leftOnLine() && !rightOnLine()) enter(FOLLOW); // line now between sensors break; case FINISH: drive(0, 0); flashAndBeep(); break; }}Fill in followLine(), frontCm(), endZoneSeen() and the others from earlier projects. Tune the times on your own robot.
Practise each part in the simulator
Line following:
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
Obstacle detection and detours:
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
Build the trackEasy
Lay out a home rescue track with tape: one gentle curve, one sharp curve, an obstacle on the line and a coloured end zone.
Reliable detourMedium
Tune your detour so it gets back onto the line 5 times out of 5. Record each attempt in a table.
Full runHard
Complete the whole course in under 3 minutes three times in a row. Write down what you changed between attempts.
Quick check
Finished this lesson?