ted-gooseby

Simulation and training

Ted learns to walk in a physics simulation first, and the trained network will then run on the real robot. It’s like a flight simulator: crashing a thousand virtual robots costs nothing, while crashing the real one breaks parts.

The twin

cad/export_sim.py turns the CAD into a MuJoCo model, sim/biped.xml. The twin uses the exact meshes of the printed parts for looks, and simple boxes and capsules for collisions, which keeps the physics fast. The masses come from the real parts: printed PLA, servos, battery and boards, about 1062 g in total.

Hobby servos are the hard part to simulate. Every small-robot project we read says the servo model matters more than anything else, so the twin copies Open Duck Mini’s measured STS3215 values: stiffness 17, damping 0.62, friction 0.052, armature 0.026, force limit 3.5 N·m and a 5.2 rad/s speed limit. sim/biped_backlash.xml also adds ±0.5° of slop in every joint, because real gears wiggle. The policy is trained on that version.

To look at the twin yourself:

pip install -r requirements.txt
python -m mujoco.viewer --mjcf=sim/biped.xml      # on a Mac use mjpython instead of python

Why Ted rocks when he walks

Ted’s legs have five joints each: hip yaw, hip roll, hip pitch, knee and ankle pitch. There’s no ankle roll, which means a flat foot can’t tilt sideways. To get his weight over one foot, Ted has to tip his whole body over that hip, the way a penguin waddles. We found this while building the gaits. It’s also why the early policies rocked their heads ±21° from side to side.

The reference gait

The policy doesn’t learn walking from nothing. sim/gait_grid.py first computes a library of “textbook” steps, one for each combination of forward speed and turn rate: 0.225 s per step, 20 mm foot lift, solved with whole-body inverse kinematics so the feet stay flat. The policy is rewarded for following this library loosely while it keeps its balance and obeys the joystick. Disney’s BDX and Open Duck work the same way.

sim/gait_grid_hybrid.npz is the table the best policy used. Its straight-walking steps come from a calm version that sways less, and its turning steps come from the full-sway version, because only the full-sway steps actually turn.

Training

Training uses Brax PPO on MJX (MuJoCo on the GPU). 4096 copies of Ted train at once, and 150 million steps take 81 minutes on one RTX 2080 Ti. The policy sees what the real robot will see: the gyro, gravity direction, joystick command, joint angles and speeds, its last three actions and a gait clock. It never sees foot contacts, because Ted has no foot switches.

Randomisation keeps the policy from relying on the twin being perfect. Every episode changes the floor and foot friction, the part masses, the servo strength and friction, the sensor noise and delays and the joint calibration offsets, and random shoves knock Ted around.

What changed between rounds

Round What we changed Result
1 Open Duck’s recipe, with its randomisation bugs fixed Walks, but rocks ±21° and walks a bit slow
2 Scored speed more strictly Speed fixed, but turning broke
3 Hybrid gait table, speed scored over a whole stride Turns again, rock ±10°
4 Penalised the head swaying sideways Best: rock ±6.5°, head sway 40 mm

The final policy is in policies/walk_r4b/. On the current twin it walks forward at 0.105 m/s when asked for 0.10, backward at 0.074 m/s when asked for 0.08 and turns at 0.83 rad/s when asked for 0.80. Its biggest tilt is 11°, and it never falls.

Running the training yourself

The training code is a fork of Open Duck Playground. Clone it into train/ inside this repo, because it looks for sim/ two folders up:

git clone -b ted-gooseby https://github.com/TarunTomar122/Open_Duck_Playground train/Open_Duck_Playground
cd train/Open_Duck_Playground
python -m venv ../.venv && ../.venv/bin/pip install -e . "jax[cuda12]==0.5.3" mujoco==3.3.2 playground==0.0.4 brax==0.12.3

A quick CPU smoke test (about 10–15 minutes) checks that everything is wired up:

JAX_PLATFORMS=cpu ../.venv/bin/python -m playground.biped.runner --smoke --output_dir runs/smoke

The command for the best policy (round 4) on a GPU:

../.venv/bin/python -m playground.biped.runner --num_timesteps 150000000 --num_envs 4096 \
  --gait_table ../../sim/gait_grid_hybrid.npz --output_dir runs/walk_r4b \
  --set reward_config.vel_filter_tau=0.45 reward_config.tracking_sigma_lin=0.0025 reward_config.tracking_sigma=0.05 \
        reward_config.scales.tracking_lin_vel=4.0 reward_config.scales.torso_roll=-20 reward_config.scales.head_sway=-50

To watch a policy drive a fixed route (stand, forward, turn, backward):

JAX_PLATFORMS=cpu ../.venv/bin/python -m playground.biped.render_progress runs/walk_r4b ckpts=../../policies/walk_r4b/params.pkl walk.mp4

Before it walks for real

  1. Measure the real servos’ response and update the twin if they differ from Open Duck’s numbers.
  2. Retrain on the final model once the robot is assembled and weighed.
  3. Export the policy to run on the Pi at 50 Hz, then try it on a tether first.

The research behind this recipe, with sources, is in research/walk-policy-recipe.md.