Physics simulation environment for the Microduck bipedal robot, built on Genesis World.
Provides drop-in simulation capabilities with full parity to microduck_rl:
- TCP
duck-bodyServer (Protocol 1): Serves simulated robot bodies to the real software daemons inmicroduck(robotd --sim,tofd --sim,mediad --sim-camera). - Interactive Policy Rehearsal (
genesis-infer): Test trained ONNX policies with keyboard teleoperation in an interactive 3D Genesis viewer. - Vectorized Reinforcement Learning: High-throughput parallel environment (
MicroduckEnv) leveraging GPU/Metal compilation.
Requires Python 3.10–3.13 and uv.
cd microduck_genesis
uv syncThe body server runs the physics simulation at 200 Hz (dt=0.005) with 50 Hz control loop decimation and listens on TCP port 7801 (Protocol 1):
Starts one duck folded on the floor (SIT), ready for robotd to initialize and stand it up:
uv run genesis-duck-bodySimulates 4 ducks sharing a floor with mutual collisions (ports 7801, 7802, 7803, 7804):
uv run genesis-duck-body --ducks 4Simulates the multi-room indoor scene, streaming length-prefixed raw UYVY head-camera frames to port 7901:
uv run genesis-duck-body --scene apartment --cameras a --frame-port 7901Runs the physics simulation without opening a GUI window (for background runs or CI):
uv run genesis-duck-body --headlessYou can run microduck_genesis directly through the official microduck/scripts/duck-sim launcher simply by pointing the DUCK_SIM_RL environment variable to this repository:
cd path/to/microduck
# Point the simulator path to microduck_genesis checkout
export DUCK_SIM_RL=$(pwd)/../microduck_genesis
# Launch everything in one command (simulator + daemons + standing gait)
./scripts/duck-simFrom there, all standard commands work identically:
./scripts/duck-sim drive 0.30 # walk forward 8 seconds (0.30 m/s)
./scripts/duck-sim ctl health # check daemon health (50 Hz control loop)
./scripts/duck-sim realtime # report real-time physics factor (1.00x)
./scripts/duck-sim down # cleanly shut down simulator and daemonsNote
Walking Policy Gait Initiation Threshold (alpha_walking.onnx):
In both MuJoCo and Genesis, the reinforcement-learning trained walking policy has a velocity threshold (0.15 in bare ./scripts/duck-sim drive) cause the policy to balance upright and sway in-place without lifting feet. Specifying 0.25 or 0.30 (e.g. ./scripts/duck-sim drive 0.30) triggers full alternating forward strides.
Tip
You can also pass standard flags like DUCK_SIM_VIEWER=0 ./scripts/duck-sim for headless execution or DUCK_SIM_SCENE=apartment ./scripts/duck-sim.
To run multiple ducks simultaneously in the same Genesis world:
cd path/to/microduck
export DUCK_SIM_RL=$(pwd)/../microduck_genesis
# Launch 4 ducks with host daemons and inter-duck radio
DUCK_SIM_DUCKS=4 ./scripts/duck-simNote
In scripts/duck-sim, positional arguments for duck count (e.g. ./duck-sim boot 4) apply only to the containerized boot command. For host daemon runs (./duck-sim or ./duck-sim up), duck count is controlled via the DUCK_SIM_DUCKS environment variable (DUCK_SIM_DUCKS=4 ./scripts/duck-sim).
What happens under the hood:
- Scene Placement: Genesis spawns 4 robot instances (
duck-a,duck-b,duck-c,duck-d) spaced along the Y-axis (0.5 m spacing) with full mutual physics collision. - Port Allocation: Sockets are allocated starting from base port 7801 (
7801 + i):duck-a: TCP port 7801, socket~/.cache/duck-sim/duck-a.sockduck-b: TCP port 7802, socket~/.cache/duck-sim/duck-b.sockduck-c: TCP port 7803, socket~/.cache/duck-sim/duck-c.sockduck-d: TCP port 7804, socket~/.cache/duck-sim/duck-d.sock
- Radio Mesh (
duck-ether): An inter-duck virtual radio network connects all activerobotddaemons so they can exchange chorale and beacon packets. - Early Socket Binding:
microduck_genesisbinds all TCP server sockets immediately on launch while the Genesis scene compiles in parallel, ensuringduck-sim's health probe (wait_for_port) passes reliably without timing out.
Once your duck simulation is running via ./scripts/duck-sim, open a second terminal to drive the robot with your keyboard in real time:
cd path/to/microduck_genesis
uv run genesis-teleopFor multi-duck setups, specify which duck to command:
uv run genesis-teleop --duck duck-bKeybindings:
| Category | Key | Action |
|---|---|---|
| Locomotion |
W / ▲ Up
|
Walk Forward (accelerates |
S / ▼ Down
|
Walk Backward / Decelerate ( |
|
A / ◀ Left
|
Turn Left ( |
|
D / ▶ Right
|
Turn Right ( |
|
Space |
E-Stop / Stop Motion ( |
|
| Postures & Skills | X |
Sit ⇄ Stand Toggle (sit_toggle via alpha_sitstand.onnx) |
P |
Ground Pick / Bow (ground_pick via alpha_ground_pick.onnx) |
|
J |
Left Kick (kick_left via ball_kick_left.onnx) |
|
K |
Right Kick (kick_right via ball_kick_right.onnx) |
|
R |
Roulade Somersault (roulade 360° roll) |
|
| Head Camera Gaze |
I / M
|
Look Up / Look Down |
U / O
|
Look Left / Look Right | |
C |
Center Head Straight Ahead | |
| Vocalizations |
Q / F
|
🦆 Quack! (chirp) |
G |
Greet (greet wak-wak) |
|
H |
Honk / Alarm (alarm) |
|
Z |
Coo / Purr (coo) |
|
| Multi-Duck Selection |
1–4
|
Switch active duck (duck-a, duck-b, duck-c, duck-d) |
| Exit |
Esc / Ctrl-C
|
Exit Teleoperation cleanly |
To view the live first-person head camera stream in your browser on macOS or Linux without requiring GStreamer or WebRTC plugins:
# Terminal 1: Start the duck with camera enabled
cd path/to/microduck
export DUCK_SIM_RL=$(pwd)/../microduck_genesis
DUCK_SIM_CAMERAS=a ./scripts/duck-sim
# Terminal 2: Start the Web Console
cd path/to/microduck_genesis
uv run genesis-consoleNow open http://127.0.0.1:8080/ in your browser to access the full web cockpit:
-
Upright First-Person Video:
$640 \times 360$ live stream rendered directly from the Genesis offscreen camera on the duck'sjaw_softlink, with roll-axis correction aligned with the horizon. - Universal Browser Compatibility: Works out-of-the-box on macOS (Safari, Chrome, Arc, Brave) and Linux. Features Motion-JPEG streaming with automatic double-buffered image polling fallback for smooth, zero-flicker playback on WebKit.
-
Instant Viewport Rotation: Click the on-screen "🔄 Rotate 90°" button or press V to cycle the video view in
$90^\circ$ increments on the fly. -
Interactive Teleoperation & Skills: Drive the robot using the on-screen D-pad or keyboard shortcuts:
-
W / S: Walk forward (
$+0.35\text{ m/s}$ ) / backward ($-0.15\text{ m/s}$ ) -
A / D: Turn left / right (
$\pm 0.40\text{ rad/s}$ ) - Space: Emergency stop
- X: Sit ⇄ Stand posture toggle
- P: Ground Pick bow
- R: Roulade 360° roll
- Q: Quack / chirp sound
- V: Rotate camera view
-
W / S: Walk forward (
- Telemetry & Feedback: Real-time RPC status logs, connection indicator, and live FPS readout.
microduck_genesis provides full scene and environment compatibility with microduck_rl. Genesis World dynamically loads the appropriate static collision geometries, room layouts, and interactive props.
Scenes can be chosen either via the DUCK_SIM_SCENE environment variable in scripts/duck-sim or via the --scene CLI flag in genesis-duck-body:
# Via scripts/duck-sim:
DUCK_SIM_SCENE=apartment ./scripts/duck-sim
# Or standalone via genesis-duck-body:
uv run genesis-duck-body --scene apartment| Preset | Scenery Model | Description | Primary Use Case |
|---|---|---|---|
apartment |
apartment.xml |
Full 6-room indoor apartment ( |
Autonomous navigation, indoor exploration, Monte Carlo localization (MCL), vision streaming |
ball |
ball.xml |
Infinite flat ground plane plus a free 6-DOF physical soccer ball ( |
Testing dynamic ball interactions and left/right kick skills (kick_left, kick_right) |
vslam |
vslam_room.xml |
Enclosed room with high-frequency structural floor/wall textures and visual landmarks. | Visual SLAM, optical flow, visual odometry, and feature tracking |
default / scene
|
scene.xml |
Minimalist high-friction flat checkerboard ground plane. | Baseline locomotion tuning, gait balance verification, zero-clutter testing |
The apartment environment is designed for multi-room mobile robotics navigation and state estimation:
+y=+3 ┌────────────┬─────┬─────────────┐
│ KITCHEN │ │ BEDROOM │
│ │ C │ │
+y=+1 ├──────┐ │ O ──┼─────────────┤
│ │ │ R │ │
│ LIV │ │ R │ OFFICE │
│ ING │ │ I │ │
+y=-1 │ ROOM │ │ D ──┼─────────────┤
│ │ │ O │ │
│ │ │ R │ BATHROOM │
│ │ │ │ │
+y=-3 └──────┴─────┴─────┴─────────────┘
x=-4 -1 0.5 +4
-
Corridor Spawn: The duck is initialized at
(0.0, 0.0, 0.12)in the central hallway facing forward. - Asymmetric Doorways: Interior door openings are offset to facilitate laser/ToF and visual localization.
- Wall Height & Visibility: Wall heights are 1.6 m so the head camera never sees the skybox indoors.
-
Sensor Parity: Both the offscreen head camera (
DUCK_SIM_CAMERAS=a) and the$8 \times 8$ VL53L5CX Time-of-Flight sensor (tofd) cast physical rays directly against room surfaces and furniture.
Once the simulator is running in one terminal:
uv run genesis-duck-body --port 7801 --keyframe SITOpen another terminal and connect the real binaries from microduck:
cd ../microduck
# 1. Connect the robot daemon (50 Hz control loop, policies, kinematics, IPC)
cargo run --bin robotd -- --sim 127.0.0.1:7801
# 2. (Optional) Connect the VL53L5CX Time-of-Flight depth daemon
cargo run --bin tofd -- --sim 127.0.0.1:7801 --socket /tmp/duck-tof.sock
# 3. (Optional) Connect the head camera daemon (if simulator started with --cameras a)
cargo run --bin mediad -- --sim-camera 127.0.0.1:7901 --robot-socket /tmp/duck.sockYou can verify the entire Protocol 1 lifecycle (handshake, joint reading, actuator commands, IMU gravity projection, and ToF depth) without running the real daemons:
# Terminal 1: Start simulator
uv run genesis-duck-body --headless
# Terminal 2: Run verification client
uv run python scripts/test_client.pyRun any exported walking or trick ONNX policy directly in Genesis with interactive keyboard controls:
uv run genesis-infer ../microduck_rl/walk.onnxKeyboard Controls:
| Key | Action |
|---|---|
W / S
|
Increase / decrease forward walking velocity ( |
A / D
|
Turn left / right ( |
Space |
Stop moving (zero all velocity commands) |
Q / Esc
|
Quit runner |
To train locomotion policies with rsl-rl or interact with 1,024 parallel environments on your GPU/Metal compiler:
import torch
from microduck_genesis.tasks import MicroduckEnv
# Initialize 1024 parallel environments on GPU
env = MicroduckEnv(num_envs=1024, show_viewer=False)
# Reset environments
obs = env.reset()
print("Observation batch shape:", obs.shape) # [1024, 61]
# Step simulation with actions [1024, 14]
actions = torch.zeros((1024, 14))
next_obs, rewards, dones, infos = env.step(actions)| Option | Default | Description |
|---|---|---|
--scene |
scene.xml |
Scene XML path or preset (apartment, scene.xml, etc.) |
--robot |
robot_groundcontact.xml |
Robot XML model path |
--ducks |
1 |
Number of ducks sharing the world |
--host |
127.0.0.1 |
TCP bind address |
--port |
7801 |
Base TCP port for duck-body protocol (+1 per duck) |
--headless |
false |
Run without graphical 3D viewer window |
--cameras |
"" |
Ducks with camera enabled (a, a,b, all) |
--frame-port |
7901 |
Base TCP port for UYVY camera frames (+1 per camera) |
--camera-fps |
15 |
Head camera frame rate |
--limp |
false |
Start with no torque (duck collapses on floor) |
--keyframe |
SIT |
Initial keyframe pose (SIT, STAND, HOME, FOLD) |
The simulator communicates over newline-delimited JSON on TCP (port 7801 + duck index):
Request (op) |
Arguments | Response |
|---|---|---|
hello |
{"protocol": 1, "joints": 15} |
{"protocol": 1} |
read |
— | {"positions": [15], "velocities": [15], "currents_ma": [15], "trunk_z": f64, "trunk": [3], "sim_time": f64, "imu": {"gyro": [3], "gravity": [3], "quat": [4]}} |
write |
{"targets": [15]} |
{} |
gain |
{"kp": u16} |
{} (scales stiffness relative to nominal 200) |
torque |
{"on": bool} |
{} (torque off puts joints limp) |
slow |
— | {"volts": 7.4, "temps_c": [15]} |
tof |
— | {"rows": 8, "cols": 8, "distance_mm": [64], "status": [64]} |
microduck_genesis/
├── pyproject.toml # uv package configuration
├── README.md # Comprehensive documentation & quickstart
├── src/microduck_genesis/
│ ├── constants.py # 15 wire joint names, default poses, timesteps
│ ├── sim/
│ │ ├── world.py # Genesis Scene wrapper & real-time sync loop
│ │ ├── body.py # Body state, actuation & IMU gravity projection
│ │ ├── body_server.py # TCP Protocol 1 server for robotd / tofd
│ │ ├── camera.py # Head camera & UYVY frame streamer for mediad
│ │ └── tof.py # VL53L5CX 8x8 Time-of-Flight depth sensor
│ ├── robot/
│ │ └── assets/ # Bundled MJCF definitions & 3D STL meshes
│ ├── tasks/
│ │ └── env.py # Vectorized parallel RL locomotion environment
│ ├── cli/
│ │ ├── body_cli.py # `genesis-duck-body` CLI entry point
│ │ ├── console_cli.py # `genesis-console` web camera viewer CLI
│ │ ├── infer_cli.py # `genesis-infer` CLI entry point
│ │ └── teleop_cli.py # `genesis-teleop` keyboard teleoperation CLI
│ └── infer.py # Interactive ONNX policy runner
├── scripts/
│ ├── console.py # Web console runner script
│ ├── run_body.py # Runner script
│ ├── teleop.py # Interactive keyboard teleoperation script
│ └── test_client.py # Protocol 1 verification client
└── tests/
├── test_constants.py # Constants and mapping tests
├── test_genesis_scene.py # Genesis scene build and step integration test
├── test_math.py # Analytical gravity & UYVY math tests
├── test_protocol.py # TCP Protocol 1 dispatch tests
└── run_tests.py # Standalone fast test runner
Run the full pytest suite in the Genesis environment:
uv run --python 3.12 --with pytest pytest tests/Or run the fast standalone test suite:
uv run python tests/run_tests.py- microduck: Official daemon, firmware, and control stack (
robotd,tofd,mediad,robotctl) for the Microduck robot. - microduck_rl: Reinforcement learning training environments, MuJoCo simulation, and official ONNX policies.
- genesis-world: Generative world and physics simulation platform for embodied AI and robotics.

