Today’s mission 5 min
Make your attachment find its own zero, then move to named positions — DOWN, CARRY, UP — the same way every single run.
Your robot can now drive anywhere on the mat. But WRO points come from moving objects, and that needs an arm, a lift or a gripper. An attachment that stops at a different height each run drops things. Today you make it repeatable.
Watch it fail first. Run the arm program below twice. Do not touch the arm between runs. The second run will miss. By the end of the lesson it never will.
The idea — a motor does not know where it is 10 min
A motor counts degrees from where it was when the program started. That starting point is called zero. If the arm started half-raised, zero is half-raised, and every target is off by that amount.
Homing gives the arm a zero you can trust. Drive it slowly into something solid — its own end stop. When it cannot turn any more, it has stalled. That place is the same every time, so you call it zero.
arm.run_until_stalled(-200, then=Stop.COAST, duty_limit=30)pushes gently down until the arm stops.arm.reset_angle(0)says “here is zero”.arm.run_target(300, 90)now means the same height on every run.
Name your positions. A number like 140 means nothing in a month. A constant like ARM_CARRY = 140 explains itself, and you change it in one place when the build changes.
Blocks vs Python 15 min
SPIKE has no “run until stalled” block. You can build one: start the motor, wait until its speed drops to almost nothing, then stop. Compare that with one line of Python.
SPIKE word blocks
when program starts :: events hat (C v) set speed to (20) % :: motors (C v) start motor [↺ v] :: motors wait (0.3) seconds wait until <((C v) speed :: motors) < (5)> (C v) stop motor :: motors (C v) set relative position to (0) :: motors (C v) set speed to (50) % :: motors (C v) go to relative position (90) :: motors wait (1) seconds (C v) go to relative position (140) :: motors
Pybricks Python
from pybricks.pupdevices import Motor from pybricks.parameters import Port, Stop from pybricks.tools import wait arm = Motor(Port.C) ARM_DOWN = 0 ARM_CARRY = 90 ARM_UP = 140 def home_arm(): arm.run_until_stalled(-200, then=Stop.COAST, duty_limit=30) arm.reset_angle(0) home_arm() arm.run_target(300, ARM_CARRY) wait(1000) arm.run_target(300, ARM_UP)
| Block | Python | Watch out |
|---|---|---|
| start motor + wait until speed < 5 + stop | arm.run_until_stalled(-200, …) | The 0.3 s wait stops the block version seeing "speed 0" before it starts. |
| set relative position to 0 | arm.reset_angle(0) | |
| set speed to 50 % | run_target(300, …) | Pybricks speed is degrees per second, not per cent. |
| go to relative position 90 | arm.run_target(300, ARM_CARRY) | run_target is absolute: 90 twice stays at 90. run_angle adds 90 each time. |
| (no block) | duty_limit=30 | Limits the push. Without it the motor can bend your attachment. |
Which way is “down” depends on how the motor is mounted. If the arm homes upwards, change -200 to 200. Do not flip every target instead.
Write it from scratch 20 min
Open a blank file called arm_test. Type it, in this order, running after each step:
- Imports and
arm = Motor(Port.C). Addprint(arm.angle()). Move the arm by hand, run again, and watch zero move with it. - The
home_arm()function. Run it with the arm in three different starting places. It should end in the same place each time. - Your own named positions. Measure them: home, then turn the arm by hand to the height you want and print
arm.angle(). Write each number into a constant. - Move between them. Use
run_target, neverrun_angle, for named positions.
When it works, move home_arm() and the constants into your base library, so every mission can use them:
In base
arm = Motor(Port.C) ARM_DOWN = 0 ARM_CARRY = 90 ARM_UP = 140 def home_arm(): arm.run_until_stalled(-200, then=Stop.COAST, duty_limit=30) arm.reset_angle(0)
Then a mission starts like this: from base import robot, arm, home_arm, ARM_UP.
Test and measure 15 min
Write every result in your journal:
- Run
home_arm()thenrun_target(300, ARM_UP)ten times, starting from different places. Printarm.angle()at the end. How far apart are the ten numbers? - Try
duty_limitat 15, 30 and 60. At 15, does the arm stop before the stop? At 60, does anything bend or click? - Try the homing speed at
-100and-500. A fast home bounces. A slow one wastes time. Find the fastest speed that still gives the same zero. - Pick up a real mission object at
ARM_CARRYand drive a square. Does it stay held? If not, is the fix in the code or in the build?
Break it, fix it 10 min
Each program has one mistake. Some give a red error. Some run but do the wrong thing. Find each one yourself.
Bug 1 — the arm ends lower every run
arm.run_until_stalled(-200, then=Stop.COAST, duty_limit=30) arm.run_target(300, ARM_UP)
Bug 2 — the arm keeps climbing
home_arm()
for i in range(3):
arm.run_angle(300, ARM_UP)
arm.run_angle(300, ARM_DOWN)Bug 3 — NameError
from pybricks.pupdevices import Motor from pybricks.parameters import Port arm = Motor(Port.C) arm.run_until_stalled(-200, then=Stop.COAST, duty_limit=30)
Two kinds of bug. A red message means Python could not run the line. A wrong movement means Python did exactly what you wrote. For the second kind, print arm.angle() after each move and compare it with what you expected.
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.
Pick, lift, place. Start with the arm in any position. Write a program that:
- homes the arm;
- drives forward to an object, lowers to
ARM_DOWNand lifts it toARM_CARRY; - turns 90° with the gyro and drives 200 mm;
- lowers the object gently and backs away.
Done means: it works three runs in a row, and someone else may set the arm anywhere before each run.
Engineering journal 5 min
Today’s entry:
- a sketch of the attachment, with the end stop marked
- your named positions and their angles
- the homing speed and duty limit you chose, and why
- the spread of your ten-run test, in degrees