Pollen Robotics' Microduck is an open-source bipedal robot about 25 cm tall, with 14 small servos. Pollen publishes the simulator, an accurate servo model and walking policies that already work on the real robot. I used that as a base and trained it, in simulation, to play soccer: first scoring alone from anywhere on a small walled field, then one against one, then two against two. Everything here is a solo side project, trained on rented GPUs.
Each section starts in plain English; the boxes underneath show the math for anyone who wants it. The code is on the soccer branch of my fork.
Learning soccer from raw joint commands means learning to balance and to play at the same time, which takes far more compute than I had. Instead, I trained a small “soccer brain” that only decides where to go: ten times a second it asks for a forward speed, a sideways speed and a turn rate. Pollen's pretrained walking policy, kept frozen, turns those requests into joint targets fifty times a second. The brain learns strategy; balance comes from a gait that is already proven on hardware.
The catch is that the walker has to behave exactly as it did in its own training. I loaded its network into PyTorch so it runs batched on the GPU next to the simulator, and rebuilt its 61 inputs to match, down to the one-step sensor delay it was trained with. A test checks it against the original exported model, and its speeds matched Pollen's own deployment simulator.
The soccer policy \(\pi_\theta\) maps 22 observations \(o_t\) (ball, goal and robot state, all in the robot's own frame) to a command, held for five walker steps:
$$u_t = (v_x,\ v_y,\ \omega_z) = \pi_\theta(o_t) \quad \text{at 10 Hz}$$ $$q^{\text{target}} = \pi_{\text{walk}}(s,\ u_t) \in \mathbb{R}^{14} \quad \text{at 50 Hz}$$\(\pi_{\text{walk}}\) is a 61→512→256→128→14 network whose weights never change. \(\pi_\theta\) is a 256→128 network trained with PPO across 4,096 simulated fields at once.
The field is 1.6 × 1.1 m with 12 cm walls (an earlier 8 cm wall got climbed). The first reward paid for goals, for moving the ball toward the goal, and for the robot walking toward the ball. That last term was a mistake: a robot that pushes the ball sideways while following it keeps the distance constant but gets paid every step, roughly as much per game as a goal. I removed it before training. From then on, every reward measured the outcome (where the ball went), never the robot's own motion.
With \(d_t\) the distance from ball to goal, the progress reward is the change in that distance:
$$r^{\text{ball}}_t = k\,(d_{t} - d_{t+1}), \qquad k = 4\ \text{per metre}$$Summed over a game it telescopes, so dribbling back and forth earns nothing:
$$\textstyle\sum_{t=0}^{T-1} r^{\text{ball}}_t = k\,(d_0 - d_T)$$The full reward adds +10 for a goal, −5 for a fall and a small penalty on jerky commands. One trap: the framework multiplies every term by the step length \(\Delta t = 0.1\) s, so one-off bonuses are written as \(10/\Delta t\). Without that the goal would have been worth ten times less than intended.
Before spending any GPU money I measured the walker. It reaches only about 42% of the speed it is asked for, linearly, even beyond its training range, because its own training scored speed errors leniently. In simulation I simply doubled the soccer brain's speed range, which gets about 0.28 m/s with rare falls. That trick is outside what the walker was trained on, so it is simulation-only.
I also wrote a controller by hand that drives like a car: line up behind the ball, then push. It gave me a yardstick and a fixed exam of 60 starts in six categories, from easy (robot already behind the ball) to hard (ball against a wall, ball in a corner, robot facing away). It scores 41% overall. It does well in the open field and almost never frees a ball from a wall or a corner, because a robot that can only push forward drives a cornered ball deeper.
A first one-hour run reached only 28% on the exam. The rewards were fine; the training schedule was not. Three changes, with the rewards left alone, took the next run to 99%:
PPO maximises the discounted return \(\sum_t \gamma^t r_t\). At 10 steps per second, the weight on a goal 15 s (150 steps) away is
$$\gamma = 0.99: \quad 0.99^{150} \approx 0.22$$ $$\gamma = 0.995: \quad 0.995^{150} \approx 0.47$$Raising \(\gamma\) doubled the value of a distant goal, and moved the effective horizon \(1/(1-\gamma)\) from about 10 s to 20 s.
| Start | Hand-written | Run 1 (1 h) | Run 2 |
|---|---|---|---|
| Robot behind ball | 67% | 83% | 100% |
| Robot on wrong side | 75% | 38% | 100% |
| Robot far away | 67% | 8% | 100% |
| Ball against wall | 14% | 5% | 100% |
| Ball in corner | 12% | 12% | 100% |
| Robot facing away | 26% | 29% | 98% |
| Overall (falls) | 41% (31) | 28% (9) | 99% (1) |
The same 120 starts (the 60-start exam, twice) for each.
Nobody told the policy how to deal with walls and corners. It found its own way to free the ball, which the hand-written controller never managed. Two later lessons were less flattering. Run 2 got worse after iteration 1,000, and the cause was a push-robustness schedule I had inherited from Pollen's kicking task: random shoves quadrupled on a fixed timer. A follow-up run that cut the exploration bonus to fix the symptom collapsed exploration instead and stalled. The best checkpoint stayed run 2 at iteration 900.
Next, two robots on a field with a goal at each end. One shared policy plays both sides; the blue robot sees the field rotated 180°, so to the policy every game looks like attacking to the right. Its opponents are a mix: half the games against its current self, a quarter against the frozen single-player champion, and a quarter against its own past snapshots, which stops it from just chasing its latest habits in circles.
To avoid starting from scratch, I grafted the new inputs onto the trained network. The first 22 inputs are unchanged and the six new ones (the defended goal, where the opponent is and how it moves) start with zero weight, so the new policy begins as an exact copy of the 99% champion and has to learn what the opponent means.
The first layer of the 1v1 actor is the champion's, padded with zeros for the new inputs:
$$W_1^{\text{1v1}} = \big[\, W_1^{\text{solo}} \;\big|\; 0_{256 \times 6} \,\big]$$so at the start, for any opponent state \(o^{\text{opp}}\):
$$\pi^{\text{1v1}}(o, o^{\text{opp}}) = \pi^{\text{solo}}(o)$$I checked this numerically before training (identical actions). The same check caught a bug: my stand-alone copy of the champion normalised its inputs by \(\sigma\) where the training library uses \(\sigma + 0.01\), enough to change its actions by up to 0.66.
Three versions, each beating the one before. Version 2 stopped ending the game when a robot fell (the walker gets up on its own in under a second, and falls had been cutting a third of games short). Version 3 told the critic, the part of PPO that predicts how a game will go, which kind of opponent it was facing. Only the critic sees that, during training; the deployed policy does not.
| Against the champion | Wins | Losses | Draws |
|---|---|---|---|
| Champion (mirror match) | 41% | 41% | 19% |
| Version 1 | 47% | 23% | 30% |
| Version 2 | 57% | 19% | 24% |
| Version 3 | 66% | 12% | 22% |
128 games each, half from each side, with exploration noise off.
Version 4 tried to break draws with a −3 penalty for both robots when time ran out, and gave the critic the clock. It got worse, and the critic's error grew steadily through the run. The penalty was being counted against itself.
The library treats a time-out as a game cut short, not finished, so its value target adds the critic's own estimate of the future:
$$y_T = r_T + \gamma\, V(s_T), \qquad r_T = -3$$Knowing the clock, the critic learns \(V(s_T) \approx -3\) near the end, which lowers the target, which lowers \(V\) again. The only consistent value is
$$V = \frac{-3}{1-\gamma} = -600 \quad (\gamma = 0.995)$$instead of the true −3. Once a time limit carries a reward and the critic sees the time, time-outs have to be treated as the real end of the game.
Two copies of the 1v1 policy on each team play “kids' soccer”: all four robots clump on the ball and most games end in a scrum. I trained teams under three philosophies with the same compute, then played them against each other:
| Team | Wins–losses | Teammate spacing |
|---|---|---|
| Free, seed 1 | 181–60 | 0.3 m |
| Free, seed 2 | 187–81 | 0.3 m |
| Guided | 161–102 | 0.4 m |
| Over-constrained | 31–317 | 1.1 m |
Decided games against the other three teams, 256 games per pairing. The starting duos stand 0.2 m apart.
The over-constrained team kept a textbook formation, a defender deep and an attacker up front, and lost 8 to 12 times as often as it won against everyone, because its ball carrier was always outnumbered. The rules encoded my idea of good positioning, and the policy obeyed them even where the idea was wrong for this game. The free teams spread out on their own (0.3 m instead of 0.2 m) and fell less, because pile-ups cost goals. Free beat guided, but the two free teams also differed from each other by 1.7 : 1, so the fair conclusion is that guidance helped nothing, not that it hurt much.
The bigger finding is that no team scored more than the starting duos: 70 to 77% of games between decent teams were draws, often with the ball pinned against a wall. Every team learned not to lose. On this field, the next change belongs in the environment, not in the reward.