Microduck Studio books · Book 3 of 4 · Advanced

Training Microducks

A Microduck's walk comes from reinforcement learning and the settings in Pollen Robotics' training code. This book covers both, and the honest measuring that has to come after. Ten lessons, each with a figure to run.

Who it is for: makers, students and club leaders who can read a little algebra and want to train a policy, or judge one. Code helps but is not required, and Book 2 has the same ideas without the formulas.

  1. States, actions, rewards, return
  2. Value, advantage and GAE
  3. PPO: better, but not too much
  4. 61 numbers in, 14 out
  5. The reward is the specification
  6. The actuator is most of the gap
  7. Randomize, then measure
  8. Honest numbers
  9. Learning from people
  10. Ship it, and say what it does

How a lesson works: read the left page and commit to a prediction, then run the figure on the right page one step at a time and check yourself. Each lesson ends with something to try, notes for whoever is teaching it, and the source of every number.

Lesson 1 · The problem

States, actions, rewards, return

Training starts by writing the duck's task as a loop, set up as a Markov decision process: the next moment depends only on this one and the action. Strictly it is a partially observed one, since the policy sees an observation rather than the whole state. Every tick t the policy reads an observation ot of 61 numbers and chooses an action at of 14 joint targets, then physics advances and the environment pays a reward rt. The policies run at 50 Hz, so a tick, which is also a step here, lasts 20 ms.

So what is the policy trained to raise? Not the next reward but the expected discounted return, every reward still to come, each weighted less the further away it is. With the discount γ = 0.99, a reward one tick further away weighs 0.99 times as much.

Gt = rt + γrt+1 + γ2rt+2 + …, with a horizon of about 1/(1 − γ) ticks.

Predict

With γ = 0.99 at 50 Hz, roughly how far into the future does the policy look?

Check your prediction

About 100 ticks, 2 s. 1/(1 − γ) = 100 ticks is the policy's working horizon, about 2 s of the future, and a reward 100 ticks away weighs 0.99100 ≈ 0.37 of one paid now. The horizon is soft, though: a reward 200 ticks away still counts 0.13, but the further off a payoff sits, the less it shapes the policy.

The figure

  1. Ticks. A reward arrives every 20 ms tick, one bar each.
  2. Discount. Each bar shrinks by γ for every tick of distance, so the far ones count for less.
  3. Horizon. A flag at 1/(1 − γ) ticks: 100 ticks, 2 s at 50 Hz, where the weight is 0.37.
  4. Return. The weighted bars stack into one number, the return the policy is trained to raise.
Drag γ to move the horizon. The rewards are made up; γ and the tick are Microduck's.

Big idea: a policy optimizes the near future it can see, about 1/(1 − γ) ticks, which for Microduck is about 2 s.

Lesson 2 · Credit

Value, advantage and GAE

Which earlier action earned a reward? PPO, the method in lesson 3, answers with two networks: the actor is the policy, and the critic learns V(s), the return the actor can expect from state s, so each action is judged against what was expected rather than against zero.

That judgment is the advantage, and one step of it is the temporal-difference (TD) error δt. Generalized advantage estimation blends the errors that follow, each weighted by (γλ)k. Microduck uses λ = 0.95: a low λ leans on the critic's guesses, a high one on what really happened.

The critic may also see more than the actor. In the walking task only the critic sees the trunk's linear velocity, and it gets every signal clean and on time, while in the ball kick only the critic sees the ball.

δt = rt + γV(st+1) − V(st), and Ât = Σk (γλ)k δt+k

Predict

The ball-kick critic sees the ball and the actor does not. What runs on the robot?

Check your prediction

Only the actor. The critic exists only in training, so it is allowed to cheat, and the exported graph is the actor, 61 inputs to 14 outputs. The critic's privileged inputs never have to exist on the robot, which is exactly why it can be given them.

The figure

  1. Value. Posts along the duck's path rise to the critic's estimate of the return from each spot.
  2. Surprise. Each step leaves a TD error: green where things went better than the critic expected, red where worse.
  3. Blend. For one step, the errors after it are weighted by (γλ)k and summed into its advantage.
  4. Export. The critic gets an extra eye on the ball. At export it folds away, and only the actor ships.
Drag λ to blend more or less of the future into the advantage. The values and errors are made up; γ and λ are Microduck's.

Big idea: the critic turns "was that good?" into "was that better than expected?", and because it never ships, it may see more than the robot can.

Lesson 3 · The update

PPO: better, but not too much

How far should one batch of experience move a policy? Each PPO iteration collects a batch with the current policy, then makes several passes over it: Microduck's runner takes 24 steps from each of 4,096 environments, 98,304 transitions, and makes 5 epochs over them in 4 minibatches.

Reusing data is risky, because the policy can drift far from the one that collected it. So PPO measures the drift per action with the ratio ρ = πnew(a|o) / πold(a|o), and its clipped objective stops paying once ρ leaves 1 ± ε in the helpful direction, with ε = 0.2 for Microduck.

L = E[ min( ρÂ, clip(ρ, 1 − ε, 1 + ε)  ) ], with ε = 0.2

Predict

An action had a positive advantage, and the update has already raised its ratio to 1.3. What does pushing it further earn?

Check your prediction

Nothing. For  > 0 the objective is ρ only up to 1 + ε = 1.2 and flat after that, with zero gradient, and for  < 0 it flattens below 0.8.

The figure

  1. The ratio. The axis is ρ: how much likelier the new policy makes a recorded action. At 1 nothing has changed.
  2. A good action. For  > 0 the objective climbs with ρ, then goes flat at 1.2, and the ball stops being pushed.
  3. A bad action. For  < 0 the objective rises as ρ falls, and goes flat below 0.8.
  4. The passes. 5 epochs of 4 minibatches make 20 small steps on one batch, while a meter watches the KL against its 0.01 target.
Drag ε to widen or narrow the clip. The curves are the real objective for  = ±1; the KL meter's level is drawn.

Big idea: PPO takes the improvement the batch supports a small step at a time, and never bets the policy on any one action.

Lesson 4 · The interface

61 numbers in, 14 out

Every Microduck policy has one shape, obs[1,61] → actions[1,14], and the robot's daemon builds one observation for all of them in this order: gyro (3), projected gravity (3), joint positions (14), joint velocities (14), last action (14) and command (13). Because the shape never changes, the runtime can hot-swap walk, stand and trick policies. In training, an action is a joint target, the home pose plus 1.0 × the output, but the daemon's defaults scale walking actions by 0.9 and smooth the head and leg targets, so Pollen's two repositories do not agree on this yet.

Training also copies the robot's flaws on purpose: joint velocity arrives 1 tick late, the IMU (the motion sensor) lags 0 to 1 tick, joint readings carry a fixed bias of up to ±0.015 rad, and the IMU a mounting tilt of up to 6°.

The same 61 inputs and 14 outputs, in the same order, for every policy.

Predict

Your new trick never uses the head command. What do you do with its 4 inputs?

Check your prediction

Keep them, with small sampled values. Deleting them breaks the contract, so unused command slots stay in, and Pollen's notes say to sample small values in them from step 0, because a command input that is never non-zero keeps dead weights forever, though the ball kick, for one, feeds plain zeros. Big random noise is no answer either, since it is not small and no robot will ever send it.

The figure

  1. 61 in. The observation lights up group by group: 3, 3, 14, 14, 14 and 13.
  2. 14 out. In training, the outputs become joint targets, the home pose plus 1.0 × the action, and the duck's joints follow.
  3. Late on purpose. Joint velocity slides a tick behind, the IMU wobbles between 0 and 1 tick late, and the joint readings carry a small bias.
  4. Hot swap. A kick policy slides in where the walk was, same plug, then hands back.
The order and sizes are the robot's own. The signals drawn on the bars are made up.

Big idea: a fixed contract lets policies trade places mid-stride, and every flaw trained in is one the robot cannot surprise it with.

Lesson 5 · Rewards

The reward is the specification

RL optimizes the letter of the reward, not its spirit: PPO reads a reward the way a lawyer reads a contract, looking for the cheapest way to comply. Pollen's training notes keep hard-won rules for writing one:

  • Get the signs right. A cost that returns 0 or more takes a negative weight, and a penalty that is already negative, returning 0 or less, takes a positive one. Mix them up and the policy is paid to misbehave.
  • No jackpots, and no pay for a bad state. Limit how often a "reach X" reward can pay, and never pay for just being in a bad state: pay the change in a potential instead, a score like cos(tilt), so rising pays and holding still pays zero.
  • Judge a term by its share of the total. The same weight counts a quarter as much when the task reward is 4 times bigger.

Pay progress, γΦ(st+1) − Φ(st), not presence.

Predict

A get-up task pays a point every tick the duck is low and trying. What does PPO find?

Check your prediction

Staying low. The cheapest state that qualifies gets parked in and farmed, which is exactly what the reward asked for.

The figure

  1. Gated. The left duck is paid every tick it is low. It finds the cheapest low pose and stays there, and its total keeps climbing.
  2. Potential. The right duck is paid the change in cos(tilt). Rising pays; once it stands, the payments stop.
  3. Double negative. A penalty that is already negative gets a negative weight, and its bar jumps above zero: a prize for the violation.
  4. The check. Flip the sign, and every penalty bar sits at or below zero again. One look catches it, on every run.
Toy totals: the shapes of the two rewards are the point, not their sizes.

Big idea: write the reward so the cheapest way to score is the behaviour you want, and check its signs on every run.

Lesson 6 · Hardware

The actuator is most of the gap

Pollen's training repository says it plainly: at this scale, "actuator fidelity is most of the sim2real gap." That scale is a robot of about 800 g, whose policies drive 14 small Dynamixel XL330 servos, with a 15th for the beak.

So instead of an ideal PD controller, a spring and damper toward the target that always gets the torque it asks for, training models each servo with BAM's M6 model: the voltage control law, back-EMF, and Coulomb, Stribeck and load-dependent friction. Back-EMF makes torque fall as the motor speeds up, and friction makes a slow joint stick, then break away. Each environment draws its own battery voltage, sag, command delay and friction.

Backlash variants add ±1° of gear play, 2° in all, at every servo joint, read through the play as the real encoder on the output side reads it.

A servo is not an ideal PD controller: its torque falls with speed, and it sticks when slow.

Predict

The battery runs down. What happens to the line of torque the servo can give at each speed?

Check your prediction

The whole line drops. A lower battery voltage leaves less torque at every speed, so a tired battery makes a weaker servo, where an ideal controller's flat line would not move at all. The actuator is most of the gap, which is why the simulator models the XL330 down to its voltage control law and each environment draws its own battery voltage.

The figure

  1. Ideal. An ideal controller gives the asked torque at any speed: a flat line, and a horn that snaps to where it is told.
  2. Back-EMF. A real motor's torque falls as it speeds up, to nothing at its top speed. A lower battery drops the whole line.
  3. Friction. Near zero speed the joint sticks until enough torque breaks it free.
  4. Backlash. Between motor and output there is play: the output can wobble ±1° while the motor holds still.
The curves show shapes, not the XL330's measured numbers. Drag the battery slider to see what a weaker battery does.

Big idea: model the motor you have, not the one you wish you had, or the policy learns to count on torque that is not there.

Lesson 7 · Robustness

Randomize, then measure

A simulator is wrong in ways nobody can list, so the walking task trains across many wrong worlds. Each duck keeps its own foot friction (×0.7 to 1.3) and trunk mass and inertia (±5%), each reset redraws the trunk's center of mass (up to ±15 mm) and joint friction (×0.9 to 1.1), and pushes of ±0.3 m/s come every 3 to 6 s.

Randomizing is a hypothesis, though, and testing it is a separate step. We tested cards meant to walk one square, played in rows (a row is a program of Duck Cards), with Pollen's v8 policy in duck-sim, under test ranges of our own fixed first. Of the short rows, 95 to 98% landed within 10 cm and 15°, but of rows of 10 cards or more, only 33 to 42%. duck-sim drives plain position servos, not lesson 6's servo model.

Randomize what you cannot know; measure against criteria fixed before looking.

Predict

Why do long rows miss so much more often than short ones?

Check your prediction

Drift. The duck's belief about where it is drifts with time and with distance walked, so a longer row ends further off. We split long rows into chapters of up to 7 cards, with the duck re-seated between them on a nest, the square where the child sets it back down, and that lifted long rows from 42% to 63%. A mat under each nest, printed for the duck's head camera to read as a compass, took them to 97.5% in simulation.

The figure

  1. Shake. Every practice duck gets its own floor grip and its own pushes.
  2. A long row. The duck's belief about where it is, the ghost, drifts away from where it really is.
  3. Chapters. Split the row at nests. Re-seating the duck resets the drift, so it builds over one chapter, not the whole row.
  4. Measure. Long rows that landed, as measured: 37% for the shipped loop, the card player Studio first shipped; 42% with merged cards, a pair of walks run as one; 63% with nests; 97.5% with the mat on the nest.
Ranges from the walking task; the long row's path is drawn. Landing rates from the evidence page: Pollen's duck-sim under Studio's own test ranges, at Studio's 10 Hz state rate.

Big idea: train across worlds you cannot rule out, test on conditions you fixed in advance, and report the part that fails.

Lesson 8 · Evidence

Honest numbers

No falls in 100 rows (a row is a program of Duck Cards) does not mean a fall rate of zero, so how many clean rows does it take to bound the rate at 1%? The Wilson 95% interval is a range that should hold the true rate 95 times in 100, and with 0 falls, that takes 381 rows.

Rows are rarely independent, either. On the evidence page each condition's physics is drawn once per session of 12 rows, "so 400 rows are about 34 ducks", and intervals that count rows come out too narrow, so later candidates were judged by a permutation test over sessions.

And decide what counts before you look: those criteria were written down on 2026-10-15, "before any result was in, and not changed since."

For 0 events in n trials, the Wilson 95% upper bound is z2/(n + z2), with z = 1.96.

Predict

No falls in 100 rows. What is the upper end of the Wilson 95% interval on the fall rate?

Check your prediction

About 3.7%. 1.962 / (100 + 1.962) = 0.037, so the interval runs up to 3.7% at n = 100, while the rule of three, 3/n, a one-sided bound, says 3%.

The figure

  1. No falls. 100 rows, every one clean.
  2. The interval. The fall rate could plausibly be anywhere from 0 up to 3.7%.
  3. More rows. The count climbs to 381, and the bar shrinks until it touches the 1% line.
  4. Sessions. The rows clump into sessions of 12 that share a duck: 400 rows are about 34 ducks. Counted by duck, no falls bounds the rate at about 10%. The honest interval lies between the two.
Drag n to move the bound. The bound is the real Wilson formula; the sessions are the evidence page's.

Big idea: report the interval, count what is really independent, and decide what counts before you look.

Lesson 9 · People

Learning from people

Some of what makes a duck good company will not fit in a formula, so people supply it.

Episodes. Kith, a web game by this site's author, records an agent's own view five rows a second: what it sensed, what it did next, and its reward under a published schedule. It can release the walks people give as an open LeRobot dataset, though so far its release holds only scripted walks.

Picks. Studio's Compare plays two runs side by side and you pick the better, which the docs call "the human-feedback half of RLHF", reinforcement learning from human feedback. Picks can train a scorer learned from picks, which can then shape a policy's reward.

Poses. Mimic puts the duck in the pose of whoever stands in front of the camera.

P(A picked over B) = σ(SA − SB), where S is a run's score and σ is the logistic curve, which turns a gap in score into a chance.

Predict

What do your picks in Compare train on your phone?

Check your prediction

A taste that re-weights Pollen's reward. With enough picks, Studio's Train from your picks fits your taste on the phone as a simple scorer learned from picks, then scales Pollen's reward terms up or down, within bounds, for a training run off the phone. So it re-weights the reward Pollen wrote rather than replacing it, and Settings decides whether the picks may be shared.

The figure

  1. Episodes. A walk is recorded as rows, five a second: what the duck sensed, what it did, what it earned.
  2. Picks. Two runs side by side. A person picks one, and the pick drops onto a pile of labels.
  3. A scorer. On the phone, the labels fit a curve: the more one run outscores the other, the likelier it is picked.
  4. Poses. A person strikes a pose, and the duck copies it.
Five rows a second is Kith's. The scorer curve is the standard logistic one, not fitted to real picks.

Big idea: people can teach what a reward cannot say: by walking along, by choosing, and by showing.

Lesson 10 · Shipping

Ship it, and say what it does

What has to happen between a config file and a robot? These gates, each one cheap next to a wasted run or a fallen robot:

  1. Smoke test: 64 environments, 5 iterations; it "catches ~95% of config errors for cents".
  2. Config tests on a CPU: indices, signs, gates.
  3. Train and read the run: penalties ≤ 0, the task term growing.
  4. Export with scripts/export.py, normalizer baked into the ONNX.
  5. Rehearse in scripts/infer_policy.py, swaps and all.
  6. Publish: checked, then uploaded, private until you say so.
  7. Measure where runs can be reset and scored, and share the EvalLog, one file that keeps the results beside the whole specification.

Rollouts are the policy's real runs: "Report what rollouts actually show." Whoever asked decides when it is good enough.

Predict

Publishing refuses your policy. What could the reason be?

Check your prediction

NaN outputs. Publishing checks the shape, [1,61] → [1,14], and refuses a file with NaN or constant output, but whether the policy is any good is a measurement, an EvalLog, not a publishing check.

The figure

  1. Smoke test. 64 small ducks run 5 iterations, and a config error is caught before it costs a night.
  2. Train and read. The run's chart: every penalty below zero, the main task term rising.
  3. Export and rehearse. The policy passes through the normalizer into one ONNX file, then rehearses its swaps on a computer.
  4. Publish. The gate checks the shape and the outputs. A broken file is turned away; the good one goes up, private.
  5. Measure. The run is scored and written to an EvalLog that anyone can check.
The gates and their numbers are microduck_rl's and Microduck Studio's; the run's chart is drawn.

Big idea: every gate is a cheap question asked before an expensive answer.

Next: Book 4, How a Policy Became, traces real training runs to why they turned out the way they did. Before this: Book 2, How a Microduck Learns, has the same ideas without the formulas, and Book 1, Meet the Microduck, starts from a body, senses and a brain. All four books are on the shelf.