S0 is the bottom layer of the duck’s software: the controller that turns “walk at 0.2 m/s” or “be curious” into servo targets 50 times a second. Everything above it (voice, an LLM, the phone app) only has to choose two things: a velocity and an emotion. This post covers the controller in simulation.

A 70 s tour: walking, turning and emotions, replayed from a CPU MuJoCo run with the servo model. The gauge shows the beak servo's target.

Try it

The controller running in this page: MuJoCo compiled to WebAssembly, a model of the duck's servos, and the same network that runs on the robot. W/S to walk, A/D to turn, Space to push. The Inputs button shows what the network sees.

What runs every 20 ms

Architecture: the velocity and emotion commands, the reference player, the policy network, and the servos of the duck
The emotion goes through the reference player. The policy reads the reference and the duck's sensors and drives the legs. The head and the beak follow the reference directly.

The robot is the XgoDuck: 0.79 kg, 14 joints and a beak, Feetech HLS1910 servos with ±1.5° of gear play. The head is 32% of the mass, so every head gesture shifts the balance.

One network, a 119 → 512 → 256 → 128 → 10 MLP, reads 119 numbers each tick and outputs 10 leg joint targets. 48 of the numbers are what the duck feels: gyro, gravity, the 14 joint angles and speeds as the encoders read them, and the last action. 3 are the velocity command. The other 68 come from the reference player.

The 4 head joints and the beak don’t go through the network. They follow the reference directly, and the network keeps the body balanced under them.

How an emotion gets in

The 119 policy inputs, and a timeline of an emotion change and the standing gate
Top: the 119 inputs. Bottom: what happens when you tap an emotion and then start walking.
  • An emotion is a one-hot over 21 classes: normal and 20 emotions.
  • The reference player plays one of that emotion’s 4 takes, moves to another take when it ends, and crossfades over 0.5 s when the emotion changes.
  • The network sees the reference pose now and 0.2 s ahead, where it is in the take (the phase), and a gate.
  • The gate is 1 while the duck stands, and the whole body performs the emotion. When the velocity command becomes non-zero, the gate fades to 0 in 0.4 s. The leg and trunk part of the reference fades with it, and the network walks. The head and the beak keep the emotion.
The 21 emotions, standing. Replayed from the training simulator.

How it is made

Pipeline: choreograph, make it physical, train two teachers, distill one student, check, then run
  1. Choreograph. Each emotion is a resting posture, a style and a set of gestures. A generator performs 4 looping takes of each emotion, with a beak track.
  2. Make it physical. A balance pass turns each take into something this robot can do: whole-body IK with flat soles, the zero-moment point inside the support polygon, joint speeds and torques under the servo limits. The duck can’t stand on one leg (its centre of mass reaches 17 mm to the side, and the sole starts at 20.5 mm), so foot lifts last 0.3 s at most. A take that fails a check is generated again.
  3. Train two teachers. Both train in mjlab on MuJoCo Warp, with 4096 ducks in parallel, a model of the HLS1910 (its torque curve, a 15 ms command delay, encoders reading through the gear play) and random pushes. PPO, started from a walking policy, learns walking and turning. FlashSAC, an off-policy SAC with a categorical critic, learns the standing emotions and the foot lifts.
  4. Distill one student. With DAgger: the student drives, and the teachers label the states it visits. PPO labels walking and FlashSAC labels standing, mixed by the gate, so the student also learns the switch between the two. This takes 12 minutes.
  5. Check, then run. Outside the training simulator, the student runs in a CPU MuJoCo with its own numpy servo model, and then with the duck’s runtime code in the loop: its sensor filters, packet timing and encoder quantization. On the robot it runs as ONNX at 50 Hz.

Numbers

All for the distilled policy:

  • Falls: 0 under the training pushes (192 runs), 0 in the CPU MuJoCo (21 emotions, a walking grid, a 70 s tour), and 0 in 225 runs with the duck’s runtime in the loop.
  • Turning: asked to turn in place at 0.8 rad/s, it turns at 0.73.
  • Emotions: the legs track the reference within 0.050 rad on average, and foot lifts reach 82% of the planned height.
  • The browser build: 0 falls in 48 minutes of random button presses, 24 of them with pushes.

Next

The policy is wired into the duck’s runtime behind a flag, with emotion buttons in the phone cockpit and the beak servo following the reference. The next post is the real duck.