Challenge 1
Add a previous-error variable: set it to zero BEFORE the loop, and store the current error into it at the end of every pass. Add Kd as a third input, set it to zero, and prove the robot behaves exactly as it did at the end of lesson 27.

EV3 Robotics›Level 4 · WRO Prep›Lesson 28
Level 4 · Lesson 28 · EV3-L04-2860 minutes · Block 4 of 6 · Mat: WRO 2024 — Earth Allies, Sustainable Farming
Kill the weaving — so the gain can finally go up.
Yesterday you proved that raising the gain shrinks the curve gap and makes the straights weave. Today you add one term that stops the weaving, which lets you raise the gain further than you ever could before.
Today fixes one wall, not both. The steady gap on the curve will get smaller, because a higher gain shrinks it — but it will still be there. Closing it needs a different idea, and that is lesson 29. Do not go looking for it today.
Same fast leg, same marked curve, same marked straight, same speed as yesterday. Everything about the test stays fixed so that today’s numbers sit under yesterday’s in the same table.
If a mark has come off the mat, put it back in the same place before you run anything. A test section that has quietly moved ten centimetres is a very convincing way to prove something false.
Battery too. A tired battery turns more slowly, which changes how the robot returns to the line — and you will read that as a gain effect if you are not watching for it.
Think about what happens as a weaving robot comes back to the line. The error is large and shrinking fast. Proportional control looks at the error and says: still large, keep pushing hard. So the robot is at full correction at the exact moment it arrives, and it sails straight across.
The missing information is not in the reading. It is in the change in the reading:
That is the D term — derivative, meaning rate of change. Each time round the loop you keep the previous error, subtract it from the current one, and the difference is your D value. Multiply it by its own gain Kd, and add it to the proportional part.
D is a brake applied before the crash, not after it. It contributes nothing on a steady error — if the error is not changing, the difference is zero. It only acts during the rush, which is exactly when P is wrong.
Two practical warnings, both of which will otherwise cost a team half a lesson:
D amplifies noise. The colour sensor reading jitters a little every pass, and D looks precisely at those jitters. Too much Kd turns a smooth follower into a buzzing, twitching one. If you see small fast twitching rather than large slow weaving, Kd is too high — the fix is a smaller number, not a bigger one.
D depends on loop speed. “How fast the error is changing” means per pass round the loop. Add a Display block or a Sound block inside the follow loop and every pass takes longer, so the same physical wobble produces a different D value. Keep the follow loop lean, and keep it the same between runs.
One variable is all this needs, and it is the first time this course has asked a loop to remember something between passes.
Inside Follow Line, each time round:
Step four is the one teams forget, and the failure is confusing: the previous error stays at whatever it was first set to, so the D term becomes a strange constant that never changes. The robot behaves oddly rather than badly, which is harder to spot.
Set the previous error to zero before the loop starts, not inside it. Inside, it gets wiped every pass and D is always zero.
Follow Line already takes speed and, since yesterday, Kp. Add Kd as a third input.
The reason is the same as it has been since lesson 14, and it is worth stating once more because today is when it pays off properly: you are about to run a dozen combinations, and any number you have to open a My Block to change is a number that will be wrong on some run and nobody will know which.
With three inputs, a run is fully described by three numbers written in a table row. That is what makes today’s tuning honest instead of remembered.
Set Kd to zero and run once. It should behave exactly as it did yesterday at the same Kp. If it does not, the arithmetic is wrong somewhere and no amount of tuning will fix it — find that first.
There is an order to this and it is not optional. A team that changes two gains at once cannot say which one did anything.
Step one — find the edge with Kd at zero. Raise Kp until the robot weaves steadily on the straight and does not settle. That is the edge. Write the number down. Yesterday this was the wall; today it is the starting point.
Step two — bring Kd up from zero. Small steps. Watch the swings count on the straight. It should fall: three swings, then two, then one, then none. Stop as soon as it settles cleanly.
Step three — watch for the buzz. Keep raising Kd past the settled point and the robot starts twitching rapidly. That is noise, not control. Come back down to where it was smooth.
Step four — now raise Kp again. With the weaving damped, the gain can go higher than it could yesterday. Go up until the weaving returns, then damp it with a little more Kd, and stop when either the buzz appears or the improvement gets small.
Run the marked leg with your best Kp and Kd, twice, and fill in the same three measurements as yesterday: curve gap in millimetres, swings on the straight, and leg time.
Put the row directly under yesterday’s circled row. You should see:
That last line is tomorrow. The gap survives because it is not caused by a gain being too low — it is caused by proportional control needing an error to produce a correction. No value of Kp or Kd changes that.
Today’s entry:
Do not lose these two numbers. Lesson 29 starts from them — it adds one more term on top rather than re-tuning from scratch, and it needs a P and D pair that already works.
This model drives, so its challenges are run on a mat. Mats differ between branches — check you are looking at the one in your room.

WRO 2024 RoboMission Elementary — Earth Allies — Sustainable Farming · official WRO game mat, 2362 × 1143 mm
The challenges name these places rather than distances, so the same challenge works on any mat:
Switch mats above and every route below is redrawn on the mat you chose.
Work through the challenges in order — each is harder than the last. The mission comes after all three, and it is meant to make you plan before you build.
Add a previous-error variable: set it to zero BEFORE the loop, and store the current error into it at the end of every pass. Add Kd as a third input, set it to zero, and prove the robot behaves exactly as it did at the end of lesson 27.

With Kd still at zero, raise Kp until the robot weaves steadily on the straight and will not settle. Write that number down — yesterday it was the wall, today it is the starting point.

Bring Kd up from zero in small steps and watch the swings fall. Keep going until the robot twitches rapidly rather than weaving slowly — that is noise, not control — then come back down and raise Kp again now that it is damped.

Run the marked leg with your best Kp and Kd and put the row directly under lesson 27's circled one. Swings should be much better and the leg faster. The curve gap will be smaller and still there — say in one sentence why no value of Kp or Kd closes it.
