The mission 4 min
When something goes wrong, carry on — do not stop dead.
Everything you have built assumes things work. The line is there, the motor turns, the sensor reports. When one of those stops being true, most programs wait forever for a thing that is never going to happen.
The argument is arithmetic. A round is a fixed length. A robot stuck at twenty seconds keeps what it had already scored and gains nothing from the remaining time. A robot that abandons one leg and moves on can still score everything after it. Giving up on a mission is a scoring decision, and it is usually the right one.
You have done this twice already without naming it: the timeout on the synch flag in lesson 38, and the abandon plan in lesson 17. Today it becomes a habit.
Where this mat goes wrong 5 min
Walk the route and mark the places a run realistically breaks.
- The plaza at E — dead centre, so the robot passes it repeatedly. The most likely place to be knocked off line or caught on something.
- The corner at D and C — two stations close together at the top right, with a turn and a squaring stop between them. Arrive badly at the park strip and you arrive badly at the café too.
- Anything with a mechanism — the concert stage at A, the tour trucks at B. A jam here stops a program that has no opinion about jams.
- The chain, if you have a second Brick. A slave that drops off is now on the list of things that can fail, and it fails silently.
Mark the abandon points: for each mission, where can the robot be left, mid-mission, and still get to the next one? That is the position each recovery has to reach.
The technique — a way out that is not success 12 min
One idea, applied three times: every loop that could wait forever gets a way out that is not success. That is a watchdog.
The lost line. The follower loop keeps running but the sensor never sees the line. Detect it with a timer — start one when the leg starts, and if the line has not been seen for, say, two seconds, stop following.
Use a timer, not a count of loop passes. A pass count depends on how fast the loop runs, which changes with what is in it — and after lesson 28 you know the loop speed is not a constant.
Then search: a short arc one way, then a wider arc back the other. If the line appears, carry on. If it does not, that leg is over.
The stalled motor. Commanded to move, not moving — jammed, or up against something. Detect it by reading the motor’s rotation, waiting a moment, and reading again. If it has not changed while you are telling it to turn, it is stalled.
Back off, retry once, then skip. Never retry forever. A jam that did not clear twice will not clear on the tenth attempt, and the round is going.
The sensor that stops reporting. A disconnected sensor, or a slave that has dropped off the chain, reads a constant value. That is the tell: a reading that has not changed at all while the robot has been driving is not a reading. Fall back to driving the leg on distance and heading alone.
Recovery must be bounded too. A search pattern with no limit is the same bug as the infinite wait, wearing a helpful face. Every recovery gets its own timeout, and its failure path is abandon this leg and go to the next mission — never try again.
Build it — one watchdog first 10 min
Do the lost line first, because it is the most likely failure and the clearest to test.
Change the follow loop so it ends on any of three conditions:
- Success — the leg finished as it should.
- Timeout — the timer passed your limit.
- Line lost — nothing but background for two seconds.
Then set a variable saying which of the three ended it, because the code after the loop has to behave differently for each. A loop that exits without saying why leaves you guessing at exactly the moment you cannot afford to.
Wrap the search pattern in a My Block called Find Line, returning whether it succeeded. Then every follower in the program can use the same recovery, and you tune the search once.
Program it — abandoning well 12 min
Abandoning is not stopping. It is getting to a known place and continuing with the next mission, and it needs to be designed.
- Log it. Lesson 37’s log gets an entry saying this mission was abandoned. After the round, that is the difference between knowing and guessing.
- Get somewhere known. Usually back towards HOME in the bottom-left corner, or to the abandon point you marked for that mission.
- Re-establish where you are. Square up on a line, or re-zero the gyro somewhere you trust — the re-zero points from lesson 23.
- Start the next mission.
Step three is the one that gets skipped, and it is what makes abandoning worthwhile. A robot that gives up on a leg has been wandering — its heading and position are exactly what you should not trust. Carrying on without re-establishing them turns one lost mission into every mission after it.
Give the whole run a watchdog as well, not just each leg. If the round length is nearly up, skip straight to whatever scores at the end — returning to HOME, or a final action worth points. A robot still attempting mission two when the clock stops has thrown away whatever it could have collected on the way home.
Tune it — break it on purpose 9 min
A recovery you have not triggered is a recovery you do not have. Do all four, and watch what the robot does.
- Cover the line with a strip of paper mid-leg. The robot should search, find it or not, and carry on either way.
- Hold a mechanism so it cannot move. It should detect the stall, back off, try once, and move on.
- Unplug a sensor mid-run. It should notice the reading has frozen and fall back rather than steering on a number that means nothing.
- Unplug the chain cable, if you have a second Brick. The slave’s mechanisms stop responding — the robot should abandon those missions and still finish the rest.
Two things to watch for. Recovery that is too eager — abandoning a leg that would have been fine — costs you points you had. Recovery that is too patient costs you the rest of the round. Tune the timeouts against your leg times from lesson 41, not against a feeling.
Run it — a sabotaged round 6 min
Run the full route while somebody from another team sabotages one thing at a moment of their choosing, without telling you which or when.
The robot should lose one mission and complete the rest. Score it, and compare against a clean run.
The gap between those two scores is what today is worth. Before this lesson that gap was the whole round, because the robot stopped. Now it should be one mission.
Then read the log. It should say which mission was abandoned, and that record should match what the saboteur actually did.
The journal 4 min
Today’s entry:
- the three failures, with how each is detected and what the robot does about it
- your timeout values, and the leg times you set them against
- the search pattern, and how often it found the line
- the abandon procedure, as four steps, including re-establishing position
- the sabotaged round score against the clean one, and what the log said
- one sentence on why abandoning a mission is a scoring decision
That is the last technique in the course. Lessons 46, 47 and 48 are a rehearsal, a scrimmage against another team, and the final tournament. Nothing new is taught from here — what you have is what you compete with.