Today’s mission 5 min
Make your robot quicker without making it less accurate, and drive a curved route without stopping.
Every WRO run is a race against two minutes. Most teams try to win time by turning the speed up. The robot then slips, overshoots and loses more time fixing itself. Today you find the settings that are fast and repeatable, and you prove it with a timer.
The idea — a speed profile 10 min
Every move has three parts: speed up, cruise, slow down. That shape is a speed profile. Pybricks plans it for you from four numbers:
straight_speed— cruising speed, in mm per secondstraight_acceleration— how quickly it gets there, in mm per second per secondturn_rate— turning speed, in degrees per secondturn_acceleration— in degrees per second per second
Set them with robot.settings(...). Call it with no numbers and it hands back the current four, so you can see where you start.
Two more tools for smooth routes. robot.arc(radius, angle=...) drives round a curve instead of stop-turn-go. And then=Stop.NONE on a move means “do not slow down at the end”: the next move carries straight on.
Too much acceleration spins the wheels, and the robot thinks it has gone further than it has. Every distance after that is wrong. This is the most common reason a fast program is less accurate.
Blocks vs Python 15 min
SPIKE word blocks
when program starts :: events hat set movement motors to (A+B v) :: movement set movement speed to (60) % :: movement move [↑ v] for (50) [cm v] :: movement
Pybricks Python
robot.settings(straight_speed=400) robot.straight(500)
| Block | Python | Watch out |
|---|---|---|
| set movement speed to 60 % | robot.settings(straight_speed=400) | Percent of top speed in SPIKE. Millimetres per second in Pybricks. |
| move ↑ for 50 cm | robot.straight(500) | Centimetres in SPIKE, millimetres in Pybricks. |
SPIKE word blocks
Pybricks Python
from pybricks.parameters import Stop robot.settings(straight_acceleration=600) robot.straight(300, then=Stop.NONE) robot.arc(150, angle=90, then=Stop.NONE) robot.straight(300)
| Block | Python | Watch out |
|---|---|---|
| (no block) | straight_acceleration=600 | Lower is gentler. Too high spins the wheels. |
| (no block) | then=Stop.NONE | The robot keeps moving into the next command. |
| (no block) | robot.arc(150, angle=90) | Radius in mm. Give angle OR distance, never both, never neither. |
Notice the last straight(300) has no then. It uses the default, Stop.HOLD, so the route ends with the robot stopped and held still.
Write it from scratch 20 min
New file, profiles. Type the set-up from memory, and turn the gyro on as in lesson 7. Then:
- Print the starting settings.
print(robot.settings()). Write the four numbers down. - Time one move. Use a
StopWatchto time a 600 mm straight. Print the time androbot.distance(). - Build the curve route. Straight, arc, straight, chained with
Stop.NONE, ending held.
A timing harness you can reuse
from pybricks.tools import StopWatch clock = StopWatch() robot.reset() robot.straight(600) print("time ms", clock.time(), "distance mm", robot.distance())
clock.time() is in milliseconds, like wait(). Keep this harness. Lesson 20 uses it to test reliability.
Test and measure 15 min
Put a tape mark at 600 mm. Change one number at a time. Three runs each, and record time and where the robot stopped against the mark.
straight_speed: 200, 400, 600.- Keep the best speed.
straight_acceleration: 300, 800, 2000. - Put a light attachment on top. Does a hard stop tip it?
Pick the pair with the best worst run, not the best single run. A setting that is quick once and wrong twice is a losing setting.
Break it, fix it 10 min
One mistake in each. Run it, read the result, fix it alone.
Bug 1
from pybricks.parameters import Stop robot.straight(300, then=Stop.None) robot.straight(300)
Bug 2
robot.straight(300) robot.arc(150) robot.straight(300)
Bug 3
from pybricks.parameters import Stop
robot.straight(300, then=Stop.NONE)
robot.arc(150, angle=90, then=Stop.NONE)
print("route done")Bug 3 does not crash. The robot just never stops, because the last move was told not to. A program that ends is not the same as a robot that stops. Always finish a route with a move that holds or brakes, or call robot.stop().
Solo challenge — no coach 10 min
No coach, no help. At WRO your coach may not touch the robot or the code. Close this page. You may use your own earlier programs and the Pybricks documentation, nothing else.
The S-bend. Lay out two tape marks 600 mm apart and 300 mm to the side of each other. Drive from the first to the second in an S shape, never stopping until the end.
- Work out the arc radius and angles on paper first.
- Time it with a
StopWatchand print the time. - Then make it faster by changing settings only.
Done means: three runs in a row end within 20 mm of the mark, and your fastest reliable time is in the journal.
Engineering journal 5 min
- the four starting settings your robot printed
- the speed and acceleration table, with your chosen pair
- the units of each setting
- why a route must not end on Stop.NONE
- your S-bend time and the settings that gave it