Simulation
What the MuJoCo model predicts for the PID, and how the learned policy compares, all in simulation.
Generated by sim.py test. MuJoCo, 800 Hz physics, the firmware's filter, wheel sensor code and PID at 400 Hz. Motor and gearbox figures are estimates until the bench measurements exist. The model is the first (clamshell) body, 352 g; it has not been rerun for the snap body.
Two cases, one sketch. A: IMU only (no wheel sensor, as Teeter is built): speed comes from a model of the motor. B: optional wheel sensor (the snap body has no mount for it): one TCRT5000 reading a 16-window ring on the left wheel, 32 edges per turn, no direction; the firmware trusts it after 8 believable edges and falls back to A by itself if it stops. Randomised robots in B have the sensor fitted the honest way: 10 % unplugged or misaligned, 10 % flaky (missing 10-30 % of edges), and every ring with its own print errors, comparator hysteresis and chatter.
Motor model no-load speed (wnl, measured at bring-up step 3): 21.0 rad/s at 6 V. Dead-zone compensation 0.1.
| Gains (u per rad, per rad/s, per m/s, per m) | kp | kd | ki | kv | kx | tc (s) |
|---|---|---|---|---|---|---|
A, imu set |
1.62 | 0.37 | 0.0 | 2.4202 | 0.1372 | - |
B, ir set (used while the sensor is trusted) |
1.791 | 0.304 | 0.0 | 2.086 | 0.539 | 0.0 |
In B, v is still the motor model (tc 0: no correction from the measured speed, which is too coarse and too late to balance on) and x is counted from the wheel edges plus the change in pitch, so it holds position instead of integrating the model.
Side by side
| A: IMU only | B: wheel sensor | |
|---|---|---|
| Nominal robot, 20 s, released at 8 deg, two 50 mN s shoves | stays up, pitch rms 2.7 deg, ends 8 cm away, saturated 2 %, peak wheel 0.64 m/s | stays up, pitch rms 3.3 deg, ends 2 cm away, saturated 5 %, peak wheel 0.67 m/s |
| Nominal robot left alone, 60 s | stays up, ends 6 cm away | stays up, ends 4 cm away |
| Release angle, nominal (either way) | 14 deg | 14 deg |
| Release angle 90 % of 60 randomised robots recover from | 9 deg | 10 deg |
| Shove at battery height, nominal | 50 mN s | 50 mN s |
| Shove 90 % of randomised robots take | 30 mN s | 40 mN s |
| 300 randomised robots, 20 s, start lean up to 5 deg, two shoves of 20-50 mN s: stay up | 258 of 300 (86 %) | 277 of 300 (92 %) |
| ... median pitch rms; drift median (90th pct) | 2.3 deg; 40 cm (115 cm) | 2.5 deg; 10 cm (46 cm) |
| ... 90th-percentile peak wheel speed | 0.64 m/s | 0.60 m/s |
| 60 randomised robots left alone, 20 s: stay up; wobble about their own balance point | 60 of 60; 0.76 deg rms | 60 of 60; 0.91 deg rms |
| ... drift in 20 s, median | 52 cm | 15 cm |
| Same robots, 60 s: stay up; drift median (90th pct) | 60 of 60; 100 cm (364 cm) | 60 of 60; 26 cm (152 cm) |
| Gets up off a crash bar by itself (same fixed kick) | 57 % of 40; nominal yes | 62 % of 40; nominal yes |
B broken down by the state of the sensor:
| Sensor | 300 shoved robots: stay up | drift in 20 s, median | 60 robots left alone 60 s: stay up | drift in 60 s, median (90th pct) |
|---|---|---|---|---|
| working | 221 of 236 (94 %) | 9 cm | 46 of 46 (100 %) | 25 cm (51 cm) |
| flaky | 24 of 30 (80 %) | 10 cm | 4 of 4 (100 %) | 13 cm (27 cm) |
| unplugged (runs as A) | 32 of 34 (94 %) | 38 cm | 10 of 10 (100 %) | 130 cm (374 cm) |
With the sensor plugged in, the firmware trusts it a median 0.7 s after it arms (nominal: 0.24 s); until then it runs exactly as A.


What limits it (case A)
| Motor no-load speed (rpm) | 30 | 60 | 90 | 120 | 160 | 200 | 250 | 300 |
|---|---|---|---|---|---|---|---|---|
| Largest lean recovered (deg) | 0 | 2 | 8 | 10 | 12 | 14 | 16 | 16 |
| Centre of mass above axle (mm) | 25 | 45 | 65 | 85 | 105 | 125 | 145 |
|---|---|---|---|---|---|---|---|
| Largest lean recovered (deg) | 20 | 18 | 16 | 14 | 14 | 12 | 12 |
| Stall torque at 6 V (N m) | 0.03 | 0.04 | 0.06 | 0.08 | 0.1 | 0.12 | 0.16 |
|---|---|---|---|---|---|---|---|
| Largest lean recovered (deg) | 4 | 8 | 12 | 14 | 16 | 18 | 20 |

Trained and tested in simulation only. The policy has not driven the real robot. The simulator's motor numbers are estimates, and the one comparison there is says they are off: the gains tuned by hand on the real robot balance it well, and the same gains balance only a minority of the simulated robots (see
evaluate.py). Run the policy in shadow first (below) and fit the simulator to logs before trusting it.
Teeter normally balances on a PID. This folder trains a small neural network to do the PID's job: read the same numbers the firmware already has, 100 times a second, and output the motor command. It also takes the drive target, so it balances and rolls forward or back.
Where it stands (2026-12-04)
policies/teeter.zip: 8 M steps, then 4 M more with a heavier penalty on command jumps. On 60 random simulated
robots (evaluate.py, full table in ../out/rl_eval.json):
| Test | Policy | PID, simulator's gains | PID, gains tuned on the robot |
|---|---|---|---|
| Standing still 20 s: stay up | 59 of 60 | 56 of 60 | 38 of 60 |
| ... wobble, drift | 1.19 deg, 17 cm | 1.64 deg, 37 cm | 1.15 deg, 98 cm |
| Released at 5 deg, shoved twice: stay up | 56 of 60 | 52 of 60 | 34 of 60 |
| Command change per tick (rms) | 0.042 | 0.054 | 0.004 |
| Drive 0.15 m/s for 5 s, then stop | 59 of 60 up, 0.11 m/s | not simulated | not simulated |
Two warnings in that table. The robot's own gains fail on a third of the simulated robots, so the simulator is not the robot yet. And the policy's command is ten times busier than the hand-tuned PID's; the simulator's default PID was that busy too, and on the real robot it jittered. Expect the same from this policy until the simulator is fitted and it is retrained.
What the policy sees
Six numbers, computed in the firmware by the same lines env.py uses, three time steps stacked (18 inputs):
- pitch from the filter, minus trim
- pitch rate from the gyro
- wheel speed from the motor model (there is no wheel sensor)
- position: that speed minus the drive target, added up
- the drive target
- the command it sent last step
One output: the motor command, -1 to 1. The network is two layers of 64, about 5,400 numbers, 21 KB of flash.