The mission 4 min
Do two things at once — then make certain both have finished.
Every time your robot drives to a pad and then raises the module, it spends seconds doing one thing while it could be doing both. Today those seconds come back. And today you meet the bug that comes with them.
Two beams know nothing about each other. The main beam carries straight on the moment it starts the second one. It does not wait, it does not check, and it will happily begin the job at the pad while the arm is still moving.
Where the seconds are 5 min
Look at the bottom row. HOME to launch pad 1 at A is a decent drive, then A to pad 3 at B, then B to pad 5 at C, then the longer run out to the gantry at D.
Four travelling legs, and at the end of each one the module has to be in position. If it moves after the robot arrives, that is four waits. If it moves during the drive, that is none.
The crossing up to the satellite row at E is the best case of all, because it is the longest leg on the mat — there is easily enough travel time to reconfigure the module completely on the way.
Time one of those waits before you start. It is what today is worth.
The technique — starting a second beam 12 min
On the EV3 canvas you make a second sequence beam by dragging a wire from a block’s sequence plug across to a new strip of blocks. From that point on, both strips run at the same time.
The main beam does not pause. It starts the helper and immediately continues, which is exactly what you want for the driving and exactly what causes the bug.
Rule one: one beam owns a motor. The main beam owns the drive motors on B and C. The helper beam owns the module on A. If both beams command the same motor, they fight, and the motor does neither thing properly. This rule has no exceptions.
Now the synch problem. The robot arrives at the pad; the arm is still travelling; the job starts anyway and misses. And the failure is intermittent — it works when the drive is slow, and fails when it is fast, because a slow drive gives the arm time by accident.
That is why this lesson exists before the milestone. An intermittent failure that depends on speed looks exactly like a mechanical fault or a bad gain, and a team that does not know about race conditions will spend lesson 39 retuning a follower that was never wrong.
The fix is a flag. EV3-G has no way to join two beams, so you build one:
- Before starting the helper, set a Logic variable — Arm Ready — to false.
- Start the helper beam. It moves the module.
- As its last act, the helper sets Arm Ready to true.
- The main beam, when it needs the arm, uses a Wait block comparing Arm Ready to true.
Step one is the one that gets forgotten. If the flag is left true from last time, the wait passes instantly and the bug comes straight back — with the added cruelty that it now works on the first run of the day and fails on the second. That is the same stale variable problem as the menu in lesson 35 and the lists in lesson 37, wearing a third disguise.
Build it — one leg, in parallel 10 min
Convert exactly one leg first. HOME to launch pad 1 at A:
- Set Arm Ready to false.
- Start the helper beam: move the module to the pad position.
- Main beam: drive from HOME to A as it already does.
- Main beam: wait for Arm Ready to be true.
- Main beam: do the job at the pad.
- Main beam: Log Stop, as in lesson 37.
One leg, then test it, then convert the rest. Converting the whole program at once and finding an intermittent fault leaves you with nothing to compare against.
Where not to use this. Never run the menu in parallel with anything — the choice must be finished before anything moves. Never put a line follower in a helper beam; it needs the drive motors, which belong to the main beam. Parallelism here is for module movement during travel, and very little else.
Program it — proving the wait works 12 min
A wait that is never actually needed proves nothing, because the arm happened to finish first. To know the flag works, make the arm slow on purpose.
Drop the module motor’s power right down, so it takes clearly longer than the drive. Run the leg.
- The robot should arrive and visibly wait for the arm before starting the job. That is the flag working.
- If it starts the job immediately, the wait is not wired to the flag, or the flag was left true from last time.
Then put the power back and confirm the wait now passes without a visible pause, which is what it should look like when everything is working: the arm finishes during the drive and the robot never stops.
Add one safety net while you are here. A helper beam that jams leaves the main beam waiting forever, and a robot frozen mid-round scores nothing. Set the wait to give up after a couple of seconds and carry on — a mission attempted with a half-raised arm may still score, and a robot standing still definitely will not.
Tune it — measure what it saved 9 min
Time the converted leg five times, and compare against the same leg before conversion. Five, not one — an intermittent fault will not show up in one run, and this is exactly the kind of bug that hides.
Three columns:
- Leg time before — arm moving after arrival.
- Leg time after — arm moving during the drive.
- Did the job succeed, every time, all five.
If the third column has a cross in it, stop and fix the synch before converting anything else. A leg that is half a second faster and occasionally misses the pad is a loss, not a gain — that is lesson 31’s reliability arithmetic again, and it has not stopped being true.
Run it — the whole pad run 6 min
Convert the remaining legs the same way, one at a time, testing each before moving on.
Then run the full sequence from the menu — HOME, the pad, the gantry at D, back to HOME — five times, with the log from lesson 37 running.
All five must complete and the logs must match. Compare the total run time against your Block 4 figure: the difference is what parallelism bought, and it should be a second or more per module movement you hid inside a drive.
The journal 4 min
Today’s entry:
- which beam owns which motors, written as a rule
- the four steps of the flag pattern, including setting it false before starting
- what happened in the slow-arm test, with the power turned down
- the five-run timing table — before, after, and whether the job succeeded every time
- the total time saved across the whole mission
- one sentence on why a race condition looks like a mechanical fault
Three lessons, one bug. The stale menu variable, the log that kept last round’s stops, and the flag left true from the previous run are the same mistake three times: state that outlives the run that made it. Initialise everything at the top. Lesson 39 assembles all of it, and that is where it would bite hardest.