← Baunuri

XL-Duck

A walking duck for a one-year-old

A 40 cm walking duck I built as a toy for my one-year-old. It's made from servos left over from my hexapod, runs on a controller board I designed around one ESP32-S3, and learned to walk in a simulator. The trained walking network is small enough to run on the ESP32-S3 itself, with no computer attached. Everything is open source.

XL-Duck standing on a wooden table against a grey wall: a white shell head with an orange beak plate on a neck of black servos, a white body, and orange printed feet

Why

I wanted a MicroDuck, the little open-source walking duck. It isn't available yet, and the lead time looked long. Meanwhile I had a box of RX-28 Dynamixels left over from my hexapod: a lot of 20 I bought used about six years ago. My kid had just turned one. So instead of waiting, I scaled the duck up to fit the servos I already had.

The "XL" is a fossil. The first version was designed around XL430 servos I had lying around, but I switched to an all-RX-28 build early on. The name stayed.

The story so far

Walking, falling, getting back up, and driven from the phone
  1. Two weeks, start to finish

    The first commit (October 16) is a torque budget for an XL430 duck. Two weeks and about 250 commits later, the robot walks around the living room, driven from a phone, and gets back up when it falls.

  2. Scaling up

    I took the MicroDuck's proportions and joint layout and rebuilt them around the larger RX-28. Each leg has five joints, and the neck and head have four: 14 servos in total. Everything else is 3D printed.

    XL-Duck mid-build on a workbench in front of drawers of parts: black servos and orange printed brackets, no shells yet, with the white head shell pieces lying on the bench beside it
    On the workbench, before any shells
  3. Teaching it in simulation

    A walking robot like this isn't programmed step by step. A small neural network is trained in a physics simulator by trial and error, over millions of simulated falls, and then copied onto the robot. I used the MicroDuck's training recipe and adapted it to my robot and its servos.

    XL-Duck in MuJoCo: three views of the bipedal duck standing, with a white shell head, grey body and orange brackets on black servos
    The simulation model from three sides
  4. The head was too heavy

    It walked fine until I put the full printed head on: shell, beak and a servo to open the mouth. Then it kept tipping forward. I took the mouth servo out and retrained the walking network on robots with randomly heavier heads, so it learned to cope with whatever the real head weighs.

    XL-Duck mid-build on a striped rug, seen from the side: the white head shell on a neck of black servos and orange brackets, no body shell yet, with the power cable trailing behind
    With the head shell on, before the body shell, still on a power cable
  5. Now

    It walks forward and backward, turns, looks around with its head, sits, stands, and picks itself up after a fall. Since November it also quacks and sings.

    Getting up after a fall
    Playing with my son
    Skating across the wooden floor
  6. A new brain, and a voice

    In November the duck moved off the Waveshare servo board onto the Baunuri HAT, the controller board I designed for Popm. It brought a speaker amp, so the duck got a voice: a quack that follows its beak, and a keyboard on the phone page to make it sing. More on both below.

Try it

This is the same simulator I trained in, running in your browser, with the exact networks that are on the robot. Drive it with the keyboard or a gamepad. Push it over and watch it get back up.

MuJoCo and ONNX in the browser, running the networks that are on the robot. Open the simulator on its own, or drive it with the phone app.

Specs

Height
~40 cm
Weight
~2.1 kg
Joints
14: 5 per leg (hip yaw, hip roll, hip pitch, knee, ankle), neck pitch, head pitch / yaw / roll; plus a servo for the beak
Servos
Dynamixel RX-28 (used), 1 Mbps bus
Brain
The ESP32-S3 (16 MB flash, 8 MB PSRAM) on my Baunuri HAT; servos on its RS485 port. Until November: the ESP32 on a Waveshare Bus Servo Driver HAT (A)
Sensors
IMU (LSM6DS3TR-C on the board; tilt and rotation), servo positions
Voice
MAX98357A amp and a speaker; the quack is synthesized on the board
Power
4S pack I made from spare 18650 cells, 14.8 V
Control
Neural network, 50 times per second
Remote
Phone web page over Wi-Fi (joystick, head stick, sit / stand buttons, a keyboard to make it sing)
Rough cost
The controller started as a $20 Waveshare Bus Servo Driver HAT (A) and is now my own Baunuri HAT. The 14 RX-28 servos are left over from my hexapod (about $50 each used, ~$700 if bought for this), and everything else came from my parts bin: screws, wires, connectors, even the battery.

Mechanics

CAD render of the whole XL-Duck: white head and body shells, black servos, orange printed brackets and feet
The full CAD assembly
CAD render of one leg: five black servos stacked from hip to ankle, joined by orange brackets, with a white thigh cover and an orange foot
One leg: five servos, hip to ankle
CAD render of the head and neck with the head shell see-through: the neck servo below, and the head's pitch, yaw and roll servos inside an orange frame
Head and neck, shell see-through

The body is MicroDuck-shaped but sized around the RX-28. The servos are mounted on both sides wherever possible, and the battery sits low in the body. The head has three joints (pitch, yaw, roll) on top of a neck pitch joint, so it can look around and nod independently of walking.

The head is where most of the design iterations went. It's the part that gives the duck its character, but every gram up there makes walking harder. The mouth servo came out for a while; it's back now, opening the beak, and the duck's voice follows it.

Everything is printed in PLA, and most parts didn't need much support. Assembly is straightforward, but taking it apart and putting it back together, which I do often, isn't very ergonomic.

Brains on one microcontroller

Everything runs on one ESP32, the same kind of chip that's in smart plugs. Since November it's the ESP32-S3 on the Baunuri HAT:

A voice

The new board has a small speaker amp, so the duck can quack. The quack isn't a recording. My first tries built one from scratch, a buzzy pulse through a couple of formant filters, and they sounded more like "owahhh" than a duck. What fixed it was measuring a real one.

I took a recording of a real mallard and analysed it with linear prediction (LPC): 20 frames of 20 ms, each a 14-pole filter plus a level and a pitch that glides from 200 to 250 Hz. The firmware drives that filter with a pulse train and some noise. About 300 numbers ship on the board, no audio.

The real mallard (XC62258, Jonathon Jongsma, via Wikimedia Commons, CC BY-SA 3.0)
The duck's quack, rebuilt from those ~300 numbers

The sound follows the beak. Opening it sets off a quack. Held open, the quack sustains (the middle frames loop), and closing the beak fades it out. Each of the 12 animations has its own voice, with its own pitch, length and breath. The ones that don't move the beak get short scripted sounds instead: a "hm" on a nod, a grumble on a head shake, a sigh when it's sleepy.

Singing

The phone page has a Sing tab: a two-octave keyboard, multi-touch, with four voices at once and slides between keys. The duck opens its beak while it sings, every note pops the beak open, and each key press nudges the head (high notes look up). Knobs shape the synth: attack, release, scoop (the duck's slide up into a note), vibrato, breath and tone.

It also knows 42 Bach pieces, all sung in the same quack voice. Most come from Popm's set: minuets, chorales, Goldberg variations and more. For the duck I added all four movements of the Partita for solo flute (BWV 1013), the Air on the G string, Sheep May Safely Graze, the Toccata and Fugue in D minor, movements from the violin partitas, and two-part inventions 1, 4, 8 and 13. A piece plays either as a duck solo, one melody line taken from the top of the score, or as the full arrangement in up to four parts. It can be transposed up to two octaves either way, and played at 25 to 200 % speed.

Air on the G string, duck solo, rendered from the firmware's voice

You can try all of it in the browser. The phone app demo is the robot's own phone page, unchanged, connected to the simulator instead of the duck, with the voice code ported to JavaScript. Drive it, play the animations, play the keyboard, or have it sing while it walks. Tap anything once first: browsers only play sound after a tap.

The scores are from the Mutopia Project (public domain or CC BY-SA 3.0). The chorales are from Craig Stuart Sapp's digital edition of the 371 chorales, CC BY-NC-SA 4.0.

Teaching it to walk

Dozens of XL-Ducks on a blue checkered floor, facing different ways; a few have fallen over
An illustration of training: many ducks at once, each a little different (not a frame from a real run)

Training runs thousands of simulated ducks at once on a gaming GPU. Each tries to follow a joystick command without falling, and gets rewarded for doing it well and smoothly. Overnight that adds up to years of practice.

The trick to making it work on the real robot is domain randomization. If the simulator always used the same robot, the network would only work on that exact imaginary robot. So every simulated duck is a little different: weaker or stiffer servos, gears with play in them, a heavier head, a shifted center of mass, delays in the commands. A network that walks on all of them has a good chance of walking on the real one.

Making the sim honest

The servos are six-year-old used RX-28s, and no two behave quite the same. So I measured them:

How I built it with Claude Code

I built this with Claude Code, Anthropic's coding agent, working as a collaborator across several sessions at once: one on CAD, one on training and firmware. I made the calls and did all the hands-on robot testing. The agents wrote and ran the code, kept training running on two GPUs (my desktop and a small server), and left notes in the repo.

A typical loop: I'd test on the robot and describe what I saw ("it keeps falling forward since I put the head on"). The agent would reproduce it in simulation, start retraining on both GPUs, test the results against a set of checks, and have a network ready to flash when I came back. Some of that ran overnight while I slept.

Should you build this?

Probably not, at least not as it is. The RX-28 has been discontinued for years, so the only way to get them is used, and used ones vary a lot (see above). The whole robot is designed around the RX-28's size and mounting holes, so switching to a current servo means redesigning most of the brackets and retraining the networks.

If you want a walking duck of your own, start from the MicroDuck it's based on. This page is more useful as a record of how one adaptation went: scaling a design to the parts you have, and making a simulator match worn servos.

The whole thing is on GitHub at baunuri/xl-duck: the MuJoCo model, the training code and run log, the firmware with the voice and songs, and the CAD with the printable parts. Code is MIT, the mechanical design CERN-OHL-S.

What's next