A fast line follower with the FloorPro's built-in PD controller
A minimal robot that follows a line at 300 mm/s, steered by a PD controller running inside the FloorPro — on a PeakHub, a SPIKE Prime hub and an EV3. Why the controller belongs there, how to find its gains, and what really limits the speed.
November 3, 2026 · updated November 15, 2026
The FloorPro can do more than report where the line is: it also runs a PD controller for line following on the sensor itself. The hub no longer computes the steering; it just applies what the FloorPro tells it.
Since firmware 0x30000009 this works with a PeakHub over our PUMP port protocol. Since 0x3000000A it also works on LEGO hubs, over LEGO’s LUMP protocol: a SPIKE Prime or Robot Inventor hub, or an EV3, both running Pybricks.
This guide shows the demo robots built around it, explains why the controller
belongs in the FloorPro rather than on the hub, walks through what the three
parameters KP, KD and TF_MS mean and how we found good values, and shows
what really limits the speed. The programs, calibration helpers and analysis
notebooks are in the
demo repository.
A word on the goal: this demo is about going as fast as possible, and we accepted compromises for that. 300 mm/s is a poor choice if you want accurate driving, and the robot still oscillates slightly around the line — we did not fully suppress that.
The robots
The main demo robot is deliberately simple, so that the controller does all the work:
- a PeakHub, with two SPIKE medium angular motors on ports B (left) and H (right), 56 mm wheels and a 112 mm track;
- a FloorPro on port D, mounted under the front with about 6 mm between its housing and the floor; its sensor row sits about 62 mm ahead of the wheel axle;
- a ball caster at the front, and the FloorPro’s external display on top.
There is no gyro loop, no heading control and no distance control: the robot drives at a constant speed and turns as the FloorPro says.

The PeakHub demo robot: the PeakHub on top with the FloorPro Display in front of it, and a ball caster at the front.

From below: the FloorPro sits low between the caster and the wheel axle.

Taken apart: the FloorPro (top left), its display on the frame, and the PeakHub, still connected by their cables.
Two more robots run the same controller over LUMP, and a third one on a PeakHub:
- SPIKE Prime / Robot Inventor hub on Pybricks: the same chassis with 56 mm wheels and a 112 mm track, motors on B and F, FloorPro on D. That makes it a direct comparison with the PeakHub.
- EV3 on the Pybricks EV3 firmware: large motors on A and D, FloorPro on sensor port 1 through the EV3 PUP Adapter, 55 mm wheels and a 144 mm track.
- Robolix2026, a clone of the robot that won the WRO European Open 2026: a PeakHub on a faster chassis with 63 mm wheels.
The course is a 16 mm black line on white: a circle with a radius of 100 mm, with a 200 mm straight inserted. One end is not round but built from straight segments joined at 45°, which makes for sharp corners at speed.
How it works
The FloorPro measures where the line is: the error e is the position of the
dark line under the 15-channel sensor row, in pitches (the spacing between
two neighboring channels), from −7 to +7. Inside the FloorPro, at 400 Hz, the
controller computes the steering output
u = KP · e + KD · de/dt
where de/dt is the rate at which the error changes, smoothed by a filter
with the time constant TF_MS. The hub uses u directly as the turn rate.
On the PeakHub, it subscribes to the controller’s own stream and applies
u every 5 ms:
fp = FloorPro(Port.D)
fp.pd.set_gains(KP, KD, tf_ms=TF_MS)
fp.pd.subscribe(PUMPDevice.PERIODIC, 0) # every sample
while drive_base.distance() < target:
u, e, de, valid = await fp.pd.read()
drive_base.drive(SPEED, u if valid else 0)
await wait(5)
On a LEGO hub, a small driver (floor_pro.py, next to the program) does
the same over LUMP. It sets the gains, switches to the controller’s mode and
stays there while driving, reading u every 10 ms:
fp = FloorPro(Port.D)
await fp.set_gains(KP, KD, tf_ms=TF_MS) # confirmed by reading back
await fp.select(FloorPro.PD) # stay in this mode while driving
while drive_base.distance() < target:
u, e, de, valid = await fp.pd()
drive_base.drive(SPEED, u if valid else 0)
await wait(10)
That is the whole control program. valid is false when the sensor sees no
line; the demo then drives straight on.
Why the controller runs in the FloorPro
A P controller (KD = 0) could just as well run on the hub. The D term is
what makes the difference — and it is where the hub is at a disadvantage.
The derivative needs to know how fast the error changes, so it divides small
differences in e by small time steps. That only works with exact timing:
- In the FloorPro, every sample is taken exactly 2.5 ms after the previous one, and the controller sees every single sample. The derivative is computed on that clean, evenly spaced signal and then filtered.
- On the hub, the line position arrives over the port connection, a little later and not always at the same moment. A MicroPython loop running every few milliseconds adds its own jitter. Dividing by a time step that wobbles by a millisecond or two turns into noise in the derivative — at exactly the moments it matters.
So the FloorPro runs a tight, regular loop with accurate timing, and the hub
is left with a simple job: apply u. It also frees the hub for everything else
the robot has to do. This holds on LEGO hubs too: even when the hub only gets
a new value every 10 ms, the derivative behind it was computed on the
FloorPro’s 400 Hz samples.
PUMP or LUMP
How u reaches the hub depends on the port protocol:
- PUMP (PeakHub) carries several independent streams over one port. The controller output is simply one more stream, which the hub subscribes to at the rate it wants — here every 2.5 ms — alongside the line data. Gains can be changed without interrupting anything.
- LUMP (LEGO hubs) organizes a device’s data in modes, and the hub reads one mode at a time; switching takes about 40 ms. Firmware 0x3000000A adds two modes: PD, which carries the line data together with the controller output, and PDSET, which holds the controller settings. The program sets the gains in PDSET before it starts and then stays in PD. New values arrive about every 10 ms.
The practical difference is time: over LUMP, u reaches the hub roughly 10 ms
later than over PUMP. That shows in the results below.
What you need:
- a FloorPro with firmware 0x3000000A or later for LEGO hubs, or 0x30000009 or later for a PeakHub;
- for a PeakHub: firmware
-121or later; - for a SPIKE Prime / Robot Inventor hub: Pybricks 3.6.1, or 4.0.0-b11 or later;
- for an EV3: the Pybricks EV3 firmware.
The FloorPro and the PeakHub can be updated in the browser on their FloorPro and PeakHub firmware pages.
The parameters
| Parameter | Meaning | Unit |
|---|---|---|
KP |
How hard to steer per pitch of offset from the line | deg/s of turn rate per pitch |
KD |
How hard to steer against a changing offset — the damping | deg/s per pitch/s |
TF_MS |
Time constant of the filter that smooths the derivative | ms |
KPalone already follows the line: the further the robot is off, the harder it turns back. Too little and it drifts wide in the curves; too much and it overshoots and starts to oscillate around the line.KDreacts to how fast the error changes. When the robot swings back toward the line,de/dtalready pulls the other way before the robot overshoots. That damping is what allows a higherKP, and so a faster, tighter robot.TF_MStrades noise against delay. The raw derivative of a signal sampled every 2.5 ms is noisy; the filter smooths it, but every millisecond of filtering also delays the derivative — and a late damping force can make things worse instead of better.
Without settings from the hub, the FloorPro starts with KP = 40, KD = 0 and
TF_MS = 20: a plain, gentle P controller.
How we found the values
The values below are for the PeakHub demo robot at 300 mm/s; a different robot or speed needs its own. The method carries over:
- Let the robot turn fast first. The drive base’s default limits for
turn rate and turn acceleration add about 200 ms of lag between “turn now”
and the robot actually turning. That lag limits
KPlong before the controller does, so raise the limits before tuning anything else. The careful way is to measure what the drive base can do and set the limits to about 80 % of that: asking for more turn acceleration than the motors deliver can itself cause a steady oscillation. The demo simply sets them very high,drive_base.settings(turn_rate=500, turn_acceleration=2000), almost certainly above what the robot can actually do. These values were not tuned: for this demo we wanted the maximum, and accuracy did not matter. - Start with P only. Set
KD = 0and raiseKPstep by step. Place the robot a few pitches off a straight line and let it go: at some point it rings — swings back and forth around the line. Read the periodTuof that ringing from the recorded data. - Back off and add D. Reduce
KPby about 20 % and setKD = KP · Tu / 8. For the demo,Tuwas about 0.3 s. - Check the filter. The derivative only helps if its time scale,
KD / KP, is several timesTF_MS— keepTF_MSat about a quarter to an eighth of it, but not below about 3 ms. WithTF_MS = 20the robot kept oscillating in a steady rhythm. The filter delayed the derivative so much that, at the ringing frequency of about 5 Hz, the derivative lost about 30° of its phase lead — its damping came too late. WithTF_MS = 10, at the same gains, the oscillation was almost gone.
The result for the PeakHub demo robot:
KP = 100, KD = 5.5, TF_MS = 10
KP = 120 is the edge: some runs stay clean, others start ringing on the
straight after the segmented end. KP = 100 leaves room for a weaker battery
or less grip.
PeakHub and SPIKE Prime: same robot, same gains
The SPIKE Prime robot uses the same chassis, so we ran it with exactly the same
settings — KP = 100, KD = 5.5, TF_MS = 10, 300 mm/s, about three rounds.
The only difference is the hub and with it the protocol: PUMP with values
every 2.5 ms, or LUMP with values every 10 ms.
- Overall, both follow equally well: the average error is nearly the same (1.99 vs 2.06 pitches). On both, it is dominated by the steady offset on the round end and the spikes at the 45° corners (more on both below).
- On the straights, the SPIKE rings about twice as hard: the error scatters with 1.38 pitches against 0.67, with a 3–4 Hz wobble the PeakHub does not show.
- At
KP = 120, the PeakHub rings but holds the line; the SPIKE loses it.
Our explanation is the slower path from sensor to motors: about 10 ms more
delay costs roughly 10° of stability margin at that wobble frequency. As a
rule of thumb: on a LEGO hub, expect the usable KP to be about 20 % lower
than on a PeakHub with the same robot.
How fast can it go?
We also tried both robots at a commanded 375 mm/s. Neither got there: the PeakHub averaged 336 mm/s, the SPIKE 314. The limit was not the controller but the wheels:
- In a curve, the outer wheel has to run faster than the robot:
speed + turn rate × track / 2. The round end at 375 mm/s alone needs a turn rate of about 215 deg/s, which puts the outer wheel at about 585 mm/s. - A SPIKE medium motor tops out at about 1100 deg/s, about 530 mm/s on a 56 mm
wheel. So the outer wheel is pinned at its maximum, the drive base slows the
robot to about 200 mm/s on every arc, and
uhits its limit about 30 % of the time. - The loop then turns into a slow (about 1.3 Hz) swing between hard left and hard right, out to the edge of the sensor. The PeakHub lost the line once. Its size is set by the motor limit — no choice of gains fixes it.
For this course and 56 mm wheels, the budget runs out at about 340 mm/s, with no room left for corrections; at about 280 mm/s there are roughly 100 deg/s of turn rate in reserve. Even 300 mm/s is already tight.
The battery moves the limit too: on the evening of the tests, the SPIKE’s motors topped out about 8 % lower. That made it slower — and, by accident, kept it further from the sensor’s edge. If a robot loses the line only now and then at a given speed, this is the usual reason, not the gains.
To go faster, change the hardware or the course, not the gains: bigger wheels or a gear ratio, wider curves, or steering ahead into a curve you know is coming.
Faster: Robolix2026
Robolix2026 is a clone of the robot that won the WRO European Open 2026. It
runs the same controller on a PeakHub, and it is by far the fastest of our
robots — not because of different gains, but because of a better chassis,
63 mm wheels and Technic L motors instead of the medium motors. That is exactly the lever from the section above. Its
current tuning follows this course at 500 mm/s with KP = 60, KD = 1.8 and
TF_MS = 5, with little margin left on the round end.
On an EV3
The FloorPro also works on a LEGO EV3 — including the PD controller — with the EV3 PUP Adapter between the EV3’s sensor port and the FloorPro, and the Pybricks EV3 firmware on the brick.
Don’t compare this robot’s speed with the others: its chassis is quite
different — larger, slower motors and a much wider track. For the record, its
outer wheel runs at about 1.72 times the robot’s speed on the round end, so for
it 200 mm/s is about what 300 mm/s is for the smaller robots. A first run
with KP = 70, KD = 2, TF_MS = 10 at 200 mm/s followed the line with an
offset of about 1.1 pitches on the round end and no line loss; it is not tuned
further yet. The point here is a different one: the FloorPro and its
controller can be used on an EV3.
Reading the recorded run
The demo programs record every run at 100 Hz, and the notebook in the
repository plots it. The plots below are from the PeakHub robot at KP = 120 —
right at the edge, which shows the effects nicely.

The robot’s path, reconstructed from wheel distance and the hub’s heading,
colored by the error e. On the round end, e stays at a steady offset; the
45° segments on the other end show as red spikes.

Top: the error e. Middle: its filtered rate de/dt. Bottom: the
controller output u, the commanded and the measured turn rate.
Two effects are visible that no choice of gains removes:
- The constant offset on the round end. A P controller needs an offset to
produce a turn: driving a 100 mm radius at 300 mm/s takes about 172 deg/s,
so with
KP = 100the robot runs about 1.7 pitches off center. That is expected. - The spikes at the 45° corners. There,
uhits its limit and the motors top out at about 270 deg/s of turning at this speed. The robot simply cannot turn faster; only a lower speed (or steering ahead of the corner) helps.
Try it yourself
The demo repository
has one folder per robot — demo_peak, demo_spike, demo_ev3 and
robolix2026 — each
with the run program line_follow_pd.py, a calibration helper calibrate.py,
an analysis notebook and a README with the details.
- Update the firmware: the FloorPro to 0x3000000A or later, and the hub as listed under PUMP or LUMP.
- Calibrate the FloorPro once for your surface with
calibrate.py, sweeping the sensor over line and background while it counts down. - Set
SPEED,KP,KDandTF_MSat the top ofline_follow_pd.py, put the robot on the line and run it. If the robot steers away from the line, flipTURN_SIGN. Each run is saved asdata/kp<KP>_kd<KD>_v<SPEED>.csv, so different settings never overwrite each other. - Open
analysis.ipynbto look at the run, and overlay runs with different gains — or from another robot.
How to run it depends on the hub:
- PeakHub: install
scirodev0.7.8 or later (pip install "scirodev>=0.7.8") and runscirodev run ble line_follow_pd.py; the run is written todata/. - SPIKE Prime / Robot Inventor: run
pybricksdev run ble line_follow_pd.py, or Run in the SciRo Dev extension for VS Code. Keepfloor_pro.pynext to the program; both tools send it along. At the end, the hub prints the recording between two marker lines, which both tools save todata/— over Bluetooth this takes a few seconds. - EV3: connect the FloorPro through the
EV3 PUP Adapter. The Pybricks EV3 firmware
connects over Bluetooth like any Pybricks hub. Run it with
pybricksdev run ble line_follow_pd.py, or from Pybricks Code; there, the recording only appears in the output pane — copy it from the# kp…line to the last row intodata/. The pane holds only about 500 rows, so the EV3 program drives a shorter distance. The SciRo Dev extension does not find the EV3 yet.
A few things differ on stock Pybricks, and the demo programs already handle
them: there is no array module (the recording uses a preallocated list —
lower LOG_SECONDS if you get a MemoryError), and the EV3 has no gyro, so
its heading in the recording comes from the wheels.