feat: legs <-> rollers locomotion switch (M key / DpadUp hold)

Add the Microduck's wheeled skating variant alongside the walking legs:
- robot_allcollisions_rollers.xml + 5 new meshes (decimated to match the
  existing set) + kinematics_rollers.json for the render rig
- BEST_roller.onnx (Drive: velocity-tracking skating, 0.6 m/s) and
  BEST_roller_crouch.onnx (one-shot phase-driven crouch-glide on R/X);
  both share the legs policies' exact 61D obs / 14-action interface
- M (or gamepad DpadUp held ~1 s) toggles variants: swaps the compiled
  MuJoCo model+data, ONNX sessions and three.js rig wholesale; roller
  assets lazy-load on first switch (BIOS-style LOADING ROLLERS OSD) so
  the default boot is untouched, then stay resident
- passive wheel hinges synced to the rig so the wheels visibly spin
- roller command limits from the robot runtime (0.6/-0.5 m/s, +-1 rad/s);
  kicks/sit disabled in roller mode (hints fade), ball played by driving
- ghosts broadcast an optional locomotion flag; roller peers render with
  the roller rig when this tab has it, leg rig fallback otherwise

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
tfrere
2026-08-20 18:12:04 +02:00
parent a370543271
commit 2470ca0b6d
14 changed files with 3187 additions and 90 deletions
+42 -17
View File
@@ -13,14 +13,21 @@ Real trained RL policies for the Microduck robot, running fully in the
browser: MuJoCo compiled to WebAssembly steps the physics, onnxruntime-web
runs the policy network at 50 Hz. No server, no backend.
Two locomotion variants of the same robot are included: **legs** (walking,
the default) and **rollers** (the wheeled skating variant). Press `M` (or
hold D-pad up ~1 s on a gamepad) to switch; the roller model, meshes and
policies are lazy-loaded on the first switch.
## Policies
| Button | Checkpoint | What it does |
| Mode | Checkpoint | What it does |
|--------|-----------|--------------|
| Run | `BEST_alpha_walking.onnx` | Velocity-tracking locomotion (arrows / WASD to steer) |
| Run (legs) | `BEST_alpha_walking.onnx` | Velocity-tracking locomotion (arrows / WASD to steer) |
| Sit | `BEST_alpha_sitstand.onnx` | Sits down on its hull, stands back up |
| Roll | `roulade.onnx` | Rolls over and recovers |
| Kick | `ball_kick_left.onnx` / `ball_kick_right.onnx` | Blind one-shot kick (0.5 s window, zeroed commands), left or right leg |
| Drive (rollers) | `BEST_roller.onnx` | Velocity-tracking skating on 4 passive wheels (higher top speed: 0.6 m/s) |
| Crouch (rollers) | `BEST_roller_crouch.onnx` | One-shot crouch-glide: sinks low over ~3.5 s and stands back up (phase-encoded command) |
Policies and MJCF model from
[apirrone/microduck_runtime](https://github.com/apirrone/microduck_runtime)
@@ -29,14 +36,18 @@ and [apirrone/mjlab_microduck](https://github.com/apirrone/mjlab_microduck).
## Controls
- Arrows or WASD (ZQSD): forward / back + turn
- Q / E (A / E on AZERTY): kick left / right
- R: roll (one barrel roll, then back to running)
- M: switch legs <-> rollers
- Q / E (A / E on AZERTY): kick left / right (legs only)
- R: roll (legs) / crouch-glide (rollers)
- B: pop / respawn a kickable ball in front of the duck
- C: toggle the chase camera (on by default; dragging detaches it)
- Space: reset
- Drag to orbit, scroll to zoom
- Colour dots: repaint the duck (it quacks)
In roller mode the legs-only actions (kicks, sit) are disabled and their
hints fade out; play the ball by driving into it.
The ball is local-only: it lives in your tab's physics and is not shared
with the multiplayer ghosts. A square arena (3 x 3 m) fences the play
area so neither the ball nor the duck can wander off.
@@ -48,10 +59,11 @@ Plug in a controller and the same mapping as the real robot runtime applies:
- Left stick: forward / back + turn
- Right stick: orbit the camera (detaches the chase cam)
- R3 (right stick click): toggle the chase cam back on
- X: roll
- X: roll (legs) / crouch-glide (rollers)
- Y: pop / respawn the ball
- RB / LB: right / left kick
- D-pad down: sit / stand toggle
- RB / LB: right / left kick (legs only)
- D-pad down: sit / stand toggle (legs only)
- D-pad up: hold ~1 s to switch legs <-> rollers (the real robot uses a 3 s hold)
- Right trigger: mouth (analog) + quack
## Multiplayer ghosts
@@ -60,16 +72,29 @@ Other people visiting the Space at the same time show up as translucent
ducks, live. Peer-to-peer WebRTC via [Trystero](https://github.com/dmotz/trystero)
(serverless signaling over public Nostr relays), so it works from a static
Space with no backend. Each tab broadcasts its duck's pose (trunk + 14
joints + jaw + colour) at 10 Hz; up to 3 ghosts are rendered, extra peers
stay connected but invisible. The camcorder-style OSD in the top-right
corner shows "N ONLINE" when peers are around.
joints + jaw + colour + locomotion variant) at 10 Hz; up to 3 ghosts are
rendered, extra peers stay connected but invisible. The camcorder-style OSD
in the top-right corner shows "N ONLINE" when peers are around.
Ghost limitations in v1: a peer in roller mode renders with the roller rig
only if your tab has already loaded it (otherwise it falls back to the leg
rig), and ghost wheels don't spin (passive wheel joints aren't broadcast).
Old clients simply ignore the new variant flag.
## How it works
- `rl.js` fetches the MJCF (`robot_allcollisions.xml`), strips the visual
geoms, injects a floor and a STAND keyframe, and compiles it with the
official `@mujoco/mujoco` WASM bindings.
- The 61D observation (gyro, projected gravity, joint pos/vel, last action,
command) matches `mjlab_microduck/scripts/infer_policy.py`.
- Rendering is a three.js rig built from `kinematics.json` + decimated STL
meshes, driven directly from MuJoCo `qpos`.
- `rl.js` fetches the MJCF (`robot_allcollisions.xml`, or
`robot_allcollisions_rollers.xml` for the roller variant), strips the
visual geoms, injects a floor, arena walls, a ball and a STAND keyframe,
and compiles it with the official `@mujoco/mujoco` WASM bindings.
- Both variants share the exact same policy interface: 61D observation
(gyro, projected gravity, 14 joint pos/vel, last action, 13D command)
and 14 position-targets, matching `mjlab_microduck/scripts/infer_policy.py`.
The roller variant adds 4 passive wheel hinges that appear in `qpos`
(zeroed in the keyframe) but not in the observation.
- Rendering is a three.js rig built from `kinematics.json` /
`kinematics_rollers.json` + decimated STL meshes, driven directly from
MuJoCo `qpos` (including the passive wheel spin).
- Switching variants swaps the compiled model + data + rig + ONNX sessions
wholesale; both stay resident after the first load so toggling back and
forth is instant.
+19 -2
View File
@@ -31,6 +31,10 @@ export async function initGhosts(env) {
}
const { scene, cloneRig, setJoint, setJawOpen, applyVariant, jointNames, getLocalState } = env;
// Locomotion-variant rig source: state.l 1 = rollers, 0/absent = legs
// (old clients never send it). Falls back to the leg rig when the local
// tab hasn't built the roller rig yet - known v1 limitation.
const rigFor = (l) => (env.getRigFor ? env.getRigFor(l ?? 0) : env.rig);
// trystero 0.25 (backed by @trystero-p2p): makeAction returns
// { send, onMessage, onReceiveProgress } where onMessage is a SETTER -
// the receive handler is registered by assignment, not by calling it.
@@ -60,7 +64,7 @@ export async function initGhosts(env) {
const ghosts = new Map(); // peerId -> ghost
const makeGhost = (state) => {
const rig = cloneRig(env.rig);
const rig = cloneRig(rigFor(state.l));
applyVariant(rig, state.v);
ghostify(rig);
scene.add(rig.placer);
@@ -68,7 +72,10 @@ export async function initGhosts(env) {
// Snap straight to the first received pose: no fly-in from the origin.
trunk.position.set(state.p[0], state.p[1], state.p[2]);
trunk.quaternion.set(state.p[4], state.p[5], state.p[6], state.p[3]);
return { rig, trunk, target: state, joints: state.j.slice(), jaw: state.w ?? 0, variant: state.v };
return {
rig, trunk, target: state, joints: state.j.slice(), jaw: state.w ?? 0,
variant: state.v, loco: state.l ?? 0,
};
};
const removeGhost = (peerId) => {
@@ -101,6 +108,16 @@ export async function initGhosts(env) {
}
g.lastSeen = performance.now();
g.target = state;
// Peer switched legs <-> rollers: rebuild its ghost on the other rig
// (cheap - cloneRig shares geometry).
if ((state.l ?? 0) !== g.loco) {
const seen = g.lastSeen;
removeGhost(peerId);
g = makeGhost(state);
g.lastSeen = seen;
ghosts.set(peerId, g);
return;
}
if (state.v !== g.variant) {
g.variant = state.v;
applyVariant(g.rig, state.v);
+26 -8
View File
@@ -299,6 +299,22 @@
font-variant-numeric: tabular-nums;
text-shadow: 0 0 6px rgba(255, 255, 255, 0.18);
}
/* BIOS-style line while the roller variant streams in on first switch */
#osd-load[hidden] { display: none; }
#osd-load {
font-size: 0.68rem;
letter-spacing: 0.14em;
color: var(--yellow, #ffd23f);
text-shadow: 0 0 8px rgba(255, 210, 63, 0.4);
}
.osd-load-cursor {
display: inline-block;
margin-left: 0.15em;
animation: rec-blink 0.8s steps(1) infinite;
}
/* Roller mode: legs-only actions (kicks, sit) are inert - fade their
hints; rl.js toggles body.rollers on every variant switch. */
body.rollers .legs-only { opacity: 0.25; }
@media (max-width: 700px) {
#hud { flex-direction: column; align-items: flex-start; }
#hud .keys { display: none; }
@@ -588,6 +604,7 @@
</div>
<div class="mode" id="mode-label"><span class="mode-text">Run</span></div>
<div id="stats"></div>
<div id="osd-load" hidden>LOADING ROLLERS<span class="osd-load-cursor">&#9608;</span></div>
</div>
<div id="hud" hidden>
<div class="stack">
@@ -608,20 +625,21 @@
</div>
<span class="hint"><span class="key" id="key-fwd">&uarr;</span><span class="key" id="key-back">&darr;</span> move</span> &nbsp;
<span class="hint"><span class="key" id="key-turnl">&larr;</span><span class="key" id="key-turnr">&rarr;</span> turn</span><br />
<span class="hint"><span class="key" id="key-roll">R</span> roll</span> &nbsp;
<span class="hint"><span class="key" id="key-kickl">A</span><span class="key" id="key-kickr">E</span> kick</span> &nbsp;
<span class="hint"><span class="key" id="key-roll">R</span> <span id="key-roll-label">roll</span></span> &nbsp;
<span class="hint legs-only"><span class="key" id="key-kickl">A</span><span class="key" id="key-kickr">E</span> kick</span> &nbsp;
<span class="hint"><span class="key" id="key-ball">B</span> ball</span> &nbsp;
<span class="hint"><span class="key" id="key-cam">C</span> camera</span> &nbsp;
<span class="hint"><span class="key" id="key-loco">M</span> rollers</span> &nbsp;
<span class="hint"><span class="key" id="key-reset">Space</span> reset</span> &nbsp;
drag to orbit &middot; scroll to zoom<br />
<span id="pad-hint">gamepad:
<span class="hint"><span class="key" id="key-pad-x">X</span> roll</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-x">X</span> <span id="key-pad-x-label">roll</span></span> &nbsp;
<span class="hint"><span class="key" id="key-pad-y">Y</span> ball</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-rb">RB</span><span class="key" id="key-pad-lb">LB</span> kick</span> &nbsp;
<span class="hint legs-only"><span class="key" id="key-pad-rb">RB</span><span class="key" id="key-pad-lb">LB</span> kick</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-rs">RS</span> camera</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-r3">R3</span> chase</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-sit">&dArr;</span> sit</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-run">&uArr;</span> run</span> &nbsp;
<span class="hint legs-only"><span class="key" id="key-pad-sit">&dArr;</span> sit</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-run">&uArr;</span> run &middot; hold: rollers</span> &nbsp;
<span class="hint"><span class="key" id="key-pad-rt">RT</span> quack</span>
</span>
</div>
@@ -679,7 +697,7 @@
<div class="t-hint">fresh start</div>
</div>
</div>
<div class="orbit-hint">drag to orbit &middot; scroll to zoom</div>
<div class="orbit-hint">drag to orbit &middot; scroll to zoom &middot; <b>M</b> swaps legs for roller skates</div>
</section>
<section class="extras">
<div class="x-item">
@@ -746,7 +764,7 @@
appended: a plain src attribute can 401 when the browser blocks the
*.static.hf.space auth cookie inside the hub iframe. -->
<script type="module">
const V = "33"; // bump on rl.js changes to defeat heuristic caching
const V = "35"; // bump on rl.js changes to defeat heuristic caching
const sign = new URLSearchParams(location.search).get("__sign");
const suffix = sign ? `&__sign=${encodeURIComponent(sign)}` : "";
import(`./rl.js?v=${V}${suffix}`);
Binary file not shown.
Binary file not shown.
+335 -63
View File
@@ -13,6 +13,14 @@
// command = [vx, vy, wz, head_pose(4), body_pose(6)]; for the sitstand
// policy, command[0] is the posture flag (1 = sit, 0 = stand).
// Action (14) = joint position targets relative to the default pose.
//
// Two locomotion variants share that exact interface (same 14 joints, same
// default pose, same 61D obs - verified from the ONNX metadata):
// legs - the walking robot (robot_allcollisions.xml), boot default
// rollers - the skating variant (robot_allcollisions_rollers.xml): the
// foot/sole assembly is replaced by a blade with 2 passive
// wheels per leg (extra unactuated hinges in qpos, zero in the
// keyframe). Lazy-loaded on the first M / DpadUp-hold switch.
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
@@ -53,6 +61,11 @@ const POLICIES = {
// the runtime swaps these in for a 0.5 s window, commands zeroed.
kickL: `${POLICY_DIR}/ball_kick_left.onnx`,
kickR: `${POLICY_DIR}/ball_kick_right.onnx`,
// Roller variant (lazy-loaded on first switch, never at boot):
// drive = velocity-tracking skating, crouch = one-shot crouch-glide
// driven by a phase encoding in the command slots (ground-pick style).
drive: `${POLICY_DIR}/BEST_roller.onnx`,
crouch: `${POLICY_DIR}/BEST_roller_crouch.onnx`,
};
// From the ONNX metadata (identical for all alpha policies) and the STAND
@@ -79,6 +92,15 @@ const CTRL_DT = TIMESTEP * DECIMATION; // 50 Hz
// Velocity command limits, same as infer_policy.py's keyboard mapping.
// No strafe input anymore: the lateral cmd slot stays zeroed for the obs.
const VEL_FWD = 0.25, VEL_BACK = -0.2, VEL_ANG = 1.0;
// Roller mode limits, from the runtime's roller branch: asymmetric vx
// (0.6 push / 0.5 brake), no lateral, +-1.0 rad/s heading.
const RVEL_FWD = 0.6, RVEL_BACK = -0.5, RVEL_ANG = 1.0;
// Crouch-glide one-shot: command = [cos(2pi*phase), sin(2pi*phase), 0],
// phase advancing at 1/CROUCH_PERIOD_S per second and the cycle exiting
// at 0.7 - exactly the runtime's ground-pick slot the policy was trained
// against (mjlab CROUCH_PERIOD = 5.0, cycle end 0.7 => 3.5 s gesture).
const CROUCH_PERIOD_S = 5.0;
const CROUCH_END_PHASE = 0.7;
// Kickable ball: radius and parking spot (far away = hidden by default).
const BALL_RADIUS = 0.05;
@@ -189,8 +211,11 @@ const traced = (label, p) => {
// explicit <inertial>, and visual geoms have contype=0 conaffinity=0.
// Stripping them means the MuJoCo VFS only needs the ~10 meshes referenced
// by collision geoms.
async function buildPhysicsXml() {
const src = await (await fetch(signed(`${MODEL_DIR}/robot_allcollisions.xml`))).text();
// Works for both variants: the roller XML only differs by the ankle/wheel
// subtree (4 extra passive hinges), which the keyframe builder below
// handles by walking the joints in document order.
async function buildPhysicsXml(xmlFile) {
const src = await (await fetch(signed(`${MODEL_DIR}/${xmlFile}`))).text();
const doc = new DOMParser().parseFromString(src, "text/xml");
for (const g of [...doc.querySelectorAll('geom[class="visual"]')]) g.remove();
const usedMeshes = new Set(
@@ -243,15 +268,23 @@ async function buildPhysicsXml() {
mass: "0.03", friction: "0.4 0.01 0.003", solref: "0.03 0.4", condim: "6",
}));
doc.querySelector("worldbody").appendChild(ballBody);
// STAND keyframe from mjlab's scene_walk.xml (STAND2 pose). The ball's
// 7 free-joint values MUST be appended or nq (21 + 7 = 28) won't match
// and the model won't compile; parked 50 m away = effectively absent.
// STAND keyframe from mjlab's scene_walk.xml (STAND2 pose; the roller
// scene_rollers.xml STAND uses the same trunk height and 14-joint pose).
// qpos must cover every joint in document order: the 14 actuated hinges
// take DEFAULT_POSE by name, anything else (the roller variant's passive
// wheels) starts at zero. The ball's 7 free-joint values MUST be
// appended or nq won't match and the model won't compile; parked 50 m
// away = effectively absent.
const qposFree = "0 0 0.12 1 0 0 0";
const poseByName = new Map(JOINT_NAMES.map((n, i) => [n, DEFAULT_POSE[i]]));
const qposJoints = [...doc.querySelectorAll("body > joint")]
.map((j) => poseByName.get(j.getAttribute("name")) ?? 0)
.join(" ");
const pose14 = Array.from(DEFAULT_POSE).join(" ");
const kf = doc.createElement("keyframe");
kf.appendChild(el("key", {
name: "STAND",
qpos: `${qposFree} ${pose14} ${BALL_PARK_POS} 1 0 0 0`,
qpos: `${qposFree} ${qposJoints} ${BALL_PARK_POS} 1 0 0 0`,
ctrl: pose14,
}));
root.appendChild(kf);
@@ -262,21 +295,29 @@ async function buildPhysicsXml() {
// ── Boot physics + policy in parallel with the render rig ──────────────
const [mujoco, { xml, meshFiles }, k] = await Promise.all([
traced("MUJOCO WASM", loadMujoco()),
traced("PHYSICS MJCF", buildPhysicsXml()),
traced("PHYSICS MJCF", buildPhysicsXml("robot_allcollisions.xml")),
traced("KINEMATICS", loadKinematics(`${MODEL_DIR}/kinematics.json`)),
]);
const doneMeshes = bootLine("MESH ASSETS");
const vfs = new mujoco.MjVFS();
await Promise.all(
meshFiles.map(async (f) => {
// Same cache-busted URL as duck.js so the browser reuses the render
// meshes instead of downloading the collision subset a second time.
const buf = await (await fetch(signed(`${MODEL_DIR}/meshes/${f}?v=${MESH_VERSION}`), { cache: "force-cache" })).arrayBuffer();
// meshdir="assets" in the MJCF, so the compiler looks up "assets/<f>".
vfs.addBuffer(`assets/${f}`, new Uint8Array(buf));
}),
);
// One shared VFS for both variants; already-loaded files are skipped so
// the roller lazy-load only fetches its 5 new meshes.
const vfsFiles = new Set();
async function addMeshesToVfs(files) {
await Promise.all(
files.map(async (f) => {
if (vfsFiles.has(f)) return;
vfsFiles.add(f);
// Same cache-busted URL as duck.js so the browser reuses the render
// meshes instead of downloading the collision subset a second time.
const buf = await (await fetch(signed(`${MODEL_DIR}/meshes/${f}?v=${MESH_VERSION}`), { cache: "force-cache" })).arrayBuffer();
// meshdir="assets" in the MJCF, so the compiler looks up "assets/<f>".
vfs.addBuffer(`assets/${f}`, new Uint8Array(buf));
}),
);
}
await addMeshesToVfs(meshFiles);
doneMeshes(`${meshFiles.length} FILES`);
const sessions = {};
@@ -300,20 +341,42 @@ const sessionOpts = { executionProviders: ["wasm"] };
donePolicies("5/5");
const doneCompile = bootLine("COMPILING PHYSICS");
const model = mujoco.MjModel.from_xml_string(xml, vfs);
const data = new mujoco.MjData(model);
let model = mujoco.MjModel.from_xml_string(xml, vfs);
let data = new mujoco.MjData(model);
doneCompile("COMPILED");
// Addresses resolved once. qpos/qvel/sensordata views are re-read at each
// use: the WASM heap can grow and detach earlier TypedArray views.
// Addresses resolved once per compiled variant. qpos/qvel/sensordata views
// are re-read at each use: the WASM heap can grow and detach earlier
// TypedArray views.
// NOTE: unlike the Python bindings, these accessor fields are plain numbers.
const qposAdr = JOINT_NAMES.map((n) => model.jnt(n).qposadr);
const dofAdr = JOINT_NAMES.map((n) => model.jnt(n).dofadr);
const gyroAdr = model.sensor("imu_ang_vel").adr;
const trunkId = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, "trunk_base");
const standKeyId = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_KEY.value, "STAND");
const ballQposAdr = model.jnt("ball_freejoint").qposadr;
const ballDofAdr = model.jnt("ball_freejoint").dofadr;
const JOINT_SET = new Set(JOINT_NAMES);
function resolveAddrs(model, kin) {
return {
qposAdr: JOINT_NAMES.map((n) => model.jnt(n).qposadr),
dofAdr: JOINT_NAMES.map((n) => model.jnt(n).dofadr),
gyroAdr: model.sensor("imu_ang_vel").adr,
trunkId: mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, "trunk_base"),
standKeyId: mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_KEY.value, "STAND"),
ballQposAdr: model.jnt("ball_freejoint").qposadr,
ballDofAdr: model.jnt("ball_freejoint").dofadr,
// Unactuated hinges (the roller variant's 4 passive wheels): not in
// the obs or ctrl, but synced to the render rig so the wheels spin.
extraJoints: kin.bodies
.filter((b) => b.joint && b.joint.type === "hinge" && !JOINT_SET.has(b.joint.name))
.map((b) => ({ name: b.joint.name, adr: model.jnt(b.joint.name).qposadr })),
};
}
// Active-variant address block, swapped wholesale by activateLoco.
let { qposAdr, dofAdr, gyroAdr, trunkId, standKeyId, ballQposAdr, ballDofAdr, extraJoints } =
resolveAddrs(model, k);
// Locomotion variants stay resident once built (model + data + rig +
// addresses); legs is registered when its render rig resolves below.
const locos = {};
let loco = "legs"; // "legs" | "rollers"
const velLims = () => (loco === "rollers"
? [RVEL_FWD, RVEL_BACK, RVEL_ANG]
: [VEL_FWD, VEL_BACK, VEL_ANG]);
let uiReady = false;
const lastAction = new Float32Array(NUM_JOINTS);
@@ -324,15 +387,25 @@ const velCmd = new Float32Array(3); // twist command, driven by held keys
// the control loop reads it before the input section below has evaluated.
const padCmd = new Float32Array(3);
let padActive = false;
const padPrev = { x: false, y: false, rb: false, lb: false, r3: false, dpadDown: false, dpadUp: false, rtArmed: true };
const padPrev = {
x: false, y: false, rb: false, lb: false, r3: false, dpadDown: false,
dpadUp: false, dpadUpAt: 0, dpadUpFired: false, rtArmed: true,
};
// Right-stick camera state, read by renderStats before the gamepad
// section below has evaluated (same reason as padCmd above).
let padOrbitLive = false; // HUD: RS keycap lit while deflected
// Declared before the control loop starts: buildObs reads it via
// effectiveCmd on the very first control step.
const held = new Set();
// Robot input gate: twist commands, mode changes, rolls, kicks and ball
// spawns all stay inert until the entrance sequence has fully played out
// (updateEntrance flips this exactly when the choreography completes).
let inputLocked = true;
let mode = "walk"; // "walk" | "sitstand" | "roll" | "kickL" | "kickR"
// "walk" is the main velocity-tracking mode in BOTH variants (legs walking
// policy or roller drive policy - activeSession() picks); "crouch" is the
// roller-only one-shot; the rest are legs-only.
let mode = "walk"; // "walk" | "sitstand" | "roll" | "kickL" | "kickR" | "crouch"
let sitFlag = 0;
const isKick = () => mode === "kickL" || mode === "kickR";
// Local-only kickable ball: false while parked at the keyframe spot
@@ -346,13 +419,18 @@ let ballActive = false;
// hands back to walk on its own - steering would only knock the roll over.
const ZERO_CMD = new Float32Array(3);
function effectiveCmd() {
if (mode === "roll" || isKick() || postKickLock > 0) return ZERO_CMD;
if (inputLocked || mode === "roll" || mode === "crouch" || isKick() || postKickLock > 0)
return ZERO_CMD;
return padActive ? padCmd : velCmd;
}
// One-shot roll tracking: trigger time + whether the trunk actually
// tipped over yet. Set by triggerRoll, cleared when we hand back to walk.
let rollRun = null;
let rollSource = "kb"; // which hint lights up: keyboard Space or pad X
// One-shot crouch-glide tracking (roller variant): phase 0 -> 0.7 over
// 3.5 s, driven per control step. Shares rollSource for keycap lighting
// (same R / pad-X trigger).
let crouchRun = null;
// One-shot kick tracking: the runtime swaps the kick policy in for a fixed
// 0.5 s window (25 control steps at 50 Hz) with zeroed commands, then hands
// straight back to walking. lastAction stays continuous across both swaps.
@@ -383,6 +461,7 @@ function resetSim() {
clearModeTimers();
rollRun = null;
kickRun = null;
crouchRun = null;
postKickLock = 0;
mode = "walk";
mujoco.mj_resetDataKeyframe(model, data, standKeyId);
@@ -402,6 +481,7 @@ resetSim();
// nearby instead of always on the same spot. qvel is zeroed so a respawn
// doesn't carry the old momentum.
function spawnBall() {
if (inputLocked) return;
const qpos = data.qpos, qvel = data.qvel;
// Trunk yaw from the free-joint quaternion (qpos[3..6] = w x y z);
// the duck walks toward its local +X.
@@ -444,11 +524,16 @@ function buildObs() {
for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = qpos[qposAdr[j]] - DEFAULT_POSE[j];
for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = qvel[dofAdr[j]];
for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = lastAction[j];
// command: walking/roll use the twist; sitstand uses cmd[0] as the
// posture flag.
// command: walking/drive use the twist; sitstand uses cmd[0] as the
// posture flag; the crouch-glide one-shot carries its phase encoding in
// the vel slots (ground-pick convention: [cos, sin, 0]).
cmd.fill(0, 0, 3);
if (mode === "sitstand") {
cmd[0] = sitFlag;
} else if (mode === "crouch" && crouchRun) {
const a = 2 * Math.PI * crouchRun.phase;
cmd[0] = Math.cos(a);
cmd[1] = Math.sin(a);
} else {
// walk uses the live twist; roll and kick see all-zero commands
// (via effectiveCmd), matching how they were trained.
@@ -459,13 +544,18 @@ function buildObs() {
return obs;
}
// The ONNX session for the current mode: in the roller variant the main
// velocity mode runs the drive (skating) policy instead of the walker.
const activeSession = () =>
sessions[loco === "rollers" && mode === "walk" ? "drive" : mode];
// ── Control loop (50 Hz, async because ONNX inference is async) ────────
let ctrlHz = 0;
let fallenSince = null;
async function controlStep() {
const feeds = { obs: new ort.Tensor("float32", buildObs(), [1, OBS_SIZE]) };
const out = await sessions[mode].run(feeds);
const out = await activeSession().run(feeds);
const act = out.actions.data;
lastAction.set(act);
const ctrl = data.ctrl;
@@ -522,6 +612,19 @@ async function controlStep() {
}
}
// Crouch-glide one-shot: advance the trained phase clock and hand back
// to the drive policy at the runtime's cycle end (0.7 x 5 s = 3.5 s:
// sink, glide low, stand back up). lastAction stays continuous, same as
// every other policy swap.
if (mode === "crouch" && crouchRun) {
crouchRun.phase += CTRL_DT / CROUCH_PERIOD_S;
if (crouchRun.phase >= CROUCH_END_PHASE) {
crouchRun = null;
mode = "walk";
if (uiReady) syncButtons();
}
}
if (mode === "roll" && rollRun) {
rollRun.steps++;
if (obs[5] > -0.3) rollRun.tipped = true;
@@ -603,7 +706,9 @@ function makeInfiniteGrid() {
uFadeDist: { value: 3.0 },
uFocus: { value: new THREE.Vector3() },
// Entrance draw-in progress; 1 = steady state (branch skipped).
uReveal: { value: 1.0 },
// Starts at 0: the world stays hidden behind the welcome modal and
// the BIOS readout until playBios cues startEntrance.
uReveal: { value: 0.0 },
},
vertexShader: /* glsl */ `
varying vec3 vWorld;
@@ -643,7 +748,9 @@ function makeInfiniteGrid() {
vec2 tile = floor(vWorld.xz / uSection);
float jit = fract(sin(dot(tile, vec2(127.1, 311.7))) * 43758.5453);
float at = rd * 0.78 + jit * 0.24;
alpha *= smoothstep(at - 0.12, at, uReveal * 1.06);
// step() clamps the smoothstep tail: center tiles have at < 0.12
// and would otherwise stay faintly visible at uReveal = 0.
alpha *= smoothstep(at - 0.12, at, uReveal * 1.06) * step(1e-4, uReveal);
}
if (alpha < 0.004) discard;
gl_FragColor = vec4(col, alpha);
@@ -678,7 +785,8 @@ function makeWallGridMaterial(alongX) {
uWallH: { value: ARENA_WALL_H },
uAlongX: { value: alongX ? 1.0 : 0.0 },
// Entrance draw-in progress; 1 = steady state (branch skipped).
uReveal: { value: 1.0 },
// Starts at 0, same as the floor grid: hidden until startEntrance.
uReveal: { value: 0.0 },
},
vertexShader: /* glsl */ `
varying vec3 vWorld;
@@ -719,7 +827,8 @@ function makeWallGridMaterial(alongX) {
vec2 tile = floor(p / uSection);
float jit = fract(sin(dot(tile, vec2(127.1, 311.7))) * 43758.5453);
float at = hN * 0.76 + jit * 0.24;
alpha *= smoothstep(at - 0.12, at, uReveal * 1.06);
// Same tail clamp as the floor: fully dark until reveal begins.
alpha *= smoothstep(at - 0.12, at, uReveal * 1.06) * step(1e-4, uReveal);
}
if (alpha < 0.004) discard;
gl_FragColor = vec4(col, alpha);
@@ -747,13 +856,89 @@ const wallMats = [];
}
}
const rig = await rigPromise;
let rig = await rigPromise;
scene.add(rig.placer);
const trunkGroup = rig.bodies.get("trunk_base");
let trunkGroup = rig.bodies.get("trunk_base");
locos.legs = {
model, data, rig, trunkGroup,
qposAdr, dofAdr, gyroAdr, trunkId, standKeyId, ballQposAdr, ballDofAdr, extraJoints,
};
// ── Locomotion variant switching (legs <-> rollers) ─────────────────────
// The roller stack (XML + 5 extra meshes + kinematics + 2 ONNX policies)
// is lazy-loaded on the first switch so the default boot stays untouched,
// then kept resident: switching back and forth only swaps references.
let rollersLoading = null;
function ensureRollers() {
rollersLoading ??= (async () => {
const [{ xml: rXml, meshFiles: rMeshFiles }, rk] = await Promise.all([
buildPhysicsXml("robot_allcollisions_rollers.xml"),
loadKinematics(`${MODEL_DIR}/kinematics_rollers.json`),
]);
const [rRig, sDrive, sCrouch] = await Promise.all([
buildRig(rk, { materialForMesh: materialHookFor(VARIANTS[currentVariant]) }),
ort.InferenceSession.create(signed(POLICIES.drive), sessionOpts),
ort.InferenceSession.create(signed(POLICIES.crouch), sessionOpts),
addMeshesToVfs(rMeshFiles),
]);
sessions.drive = sDrive;
sessions.crouch = sCrouch;
const rModel = mujoco.MjModel.from_xml_string(rXml, vfs);
const rData = new mujoco.MjData(rModel);
locos.rollers = {
model: rModel, data: rData, rig: rRig, trunkGroup: rRig.bodies.get("trunk_base"),
...resolveAddrs(rModel, rk),
};
})();
return rollersLoading;
}
function activateLoco(name) {
const L = locos[name];
loco = name;
scene.remove(rig.placer);
({ model, data, rig, trunkGroup, qposAdr, dofAdr, gyroAdr, trunkId,
standKeyId, ballQposAdr, ballDofAdr, extraJoints } = L);
// The rig may have been built (or last shown) under another colourway.
applyVariant(rig, currentVariant);
scene.add(rig.placer);
document.body.classList.toggle("rollers", name === "rollers");
resetSim();
refreshVelCmd(); // held keys re-map to the new variant's velocity limits
if (uiReady) syncLocoHints();
}
// OSD line while the roller stack streams in, BIOS-style.
let osdLoadEl = null;
let locoSwitching = false;
async function toggleLoco() {
// No switching mid one-shot (roll/kick/crouch end on their own and a
// teardown now would strand their timers), or while already switching.
if (locoSwitching || inputLocked || rollRun || kickRun || crouchRun || standTimer) return;
locoSwitching = true;
try {
const next = loco === "legs" ? "rollers" : "legs";
if (next === "rollers" && !locos.rollers) {
osdLoadEl?.removeAttribute("hidden");
await ensureRollers();
}
activateLoco(next);
} catch (e) {
rollersLoading = null; // allow a retry on transient fetch failures
console.error("[rl] roller switch failed", e);
} finally {
osdLoadEl?.setAttribute("hidden", "");
locoSwitching = false;
}
}
// ── Sci-fi entrance: Tron grid draw-in + duck dissolve-in ───────────────
// Plays once per page load, right as the BIOS overlay fades (playBios
// calls startEntrance). Gameplay stays live throughout. The duck dissolve
// calls startEntrance). Until then the world stays hidden (grids at
// reveal 0, duck fully dissolved) and every robot input is gated by
// inputLocked; the sim itself keeps running so the duck stands idle
// underneath and is mid-stride the moment it finishes materializing.
// The duck dissolve
// swaps each rig mesh onto a TEMPORARY clone of its material (the shared
// matFor cache and ghost cloning stay untouched) and restores the
// originals when the effect completes, so variants/ghosts behave exactly
@@ -798,7 +983,7 @@ if (uDissolveP < 1.0) {
dsvEdge = 1.0 - smoothstep(0.015, 0.1, dsvThr - dsvN);
}`)
.replace("#include <dithering_fragment>", /* glsl */ `#include <dithering_fragment>
gl_FragColor.rgb += dsvEdge * vec3(1.0, 0.824, 0.247);`);
gl_FragColor.rgb += dsvEdge * vec3(0.5, 0.41, 0.12);`);
};
m.needsUpdate = true;
dissolveSaved.push([o, orig]);
@@ -813,6 +998,11 @@ function restoreDissolve() {
}
dissolveSaved = null;
}
// Boot hidden: the duck is fully dissolved from the first rendered frame
// (the grids already start at uReveal 0), so nothing shows through the
// welcome modal's blur or during the BIOS replay.
dissolveP.value = 0;
applyDissolve();
const ENTRANCE_GRID_S = 1.5; // floor draw-in duration
const ENTRANCE_WALL_DELAY_S = 0.4; // walls start after the floor
@@ -822,6 +1012,10 @@ const clamp01 = (x) => Math.min(Math.max(x, 0), 1);
const easeOutCubic = (x) => 1 - Math.pow(1 - clamp01(x), 3);
let entranceT0 = null; // wall-clock start while the sequence is playing
let entranceDone = false; // latches: once per page load
// Resolved when the entrance completes; gates the ghosts join below so a
// translucent peer can't float around in the still-hidden world.
let entranceFinishedResolve;
const entranceFinished = new Promise((r) => { entranceFinishedResolve = r; });
function startEntrance() {
if (entranceT0 !== null || entranceDone) return;
entranceT0 = performance.now();
@@ -839,12 +1033,15 @@ function updateEntrance() {
const dp = clamp01((t - ENTRANCE_DISSOLVE_START_S) / ENTRANCE_DISSOLVE_S);
dissolveP.value = dp;
if (t >= ENTRANCE_WALL_DELAY_S + ENTRANCE_GRID_S && dp >= 1) {
// Park everything in exact steady state and drop the temp materials.
// Park everything in exact steady state, drop the temp materials and
// hand control to the user.
entranceT0 = null;
entranceDone = true;
grid.material.uniforms.uReveal.value = 1;
for (const m of wallMats) m.uniforms.uReveal.value = 1;
restoreDissolve();
inputLocked = false;
entranceFinishedResolve();
}
}
@@ -1068,6 +1265,8 @@ function syncRig() {
trunkGroup.position.set(qpos[0], qpos[1], qpos[2]);
trunkGroup.quaternion.set(qpos[4], qpos[5], qpos[6], qpos[3]);
for (let j = 0; j < NUM_JOINTS; j++) setJoint(rig, JOINT_NAMES[j], qpos[qposAdr[j]]);
// Passive hinges (roller wheels): purely visual, driven straight from qpos.
for (const ej of extraJoints) setJoint(rig, ej.name, qpos[ej.adr]);
// Ball: raw MJCF pose inside the Z-up group, hidden while parked.
ballMesh.visible = ballActive;
if (ballActive) {
@@ -1147,12 +1346,23 @@ const keyEls = {
roll: el("key-roll"), reset: el("key-reset"),
kickl: el("key-kickl"), kickr: el("key-kickr"),
ball: el("key-ball"), cam: el("key-cam"),
loco: el("key-loco"),
padX: el("key-pad-x"), padSit: el("key-pad-sit"),
padRun: el("key-pad-run"), padRt: el("key-pad-rt"),
padRb: el("key-pad-rb"), padLb: el("key-pad-lb"),
padY: el("key-pad-y"), padRs: el("key-pad-rs"),
padR3: el("key-pad-r3"),
};
osdLoadEl = el("osd-load");
// Roller mode re-labels the trick hints (R / pad X trigger the crouch-glide
// instead of the roll) and greys the legs-only actions via body.rollers.
const rollLabelEl = el("key-roll-label");
const padXLabelEl = el("key-pad-x-label");
function syncLocoHints() {
const rollers = loco === "rollers";
if (rollLabelEl) rollLabelEl.textContent = rollers ? "crouch" : "roll";
if (padXLabelEl) padXLabelEl.textContent = rollers ? "crouch" : "roll";
}
const STICK_R = 15; // px, max dot travel inside the 46px stick circle
let resetFlashAt = -Infinity;
let ballFlashAt = -Infinity;
@@ -1172,12 +1382,14 @@ function renderStats() {
`CTRL ${ctrlHz.toFixed(0)}HZ` + (peers ? ` \u00b7 ${peers + 1} ONLINE` : "");
// Mini sticks: the dot mirrors the effective twist, lit yellow while the
// user is actually driving.
// user is actually driving. Normalized against the ACTIVE variant's
// velocity limits so full deflection reads the same in both.
const manual = (padActive || held.size > 0) && mode !== "roll";
const yN = vx >= 0 ? vx / VEL_FWD : vx / -VEL_BACK;
const [limF, limB, limA] = velLims();
const yN = vx >= 0 ? vx / limF : vx / -limB;
// Move stick is vertical-only now that strafe is gone.
dotMove.style.transform = `translate(0px, ${-yN * STICK_R}px)`;
dotTurn.style.transform = `translate(${(-wz / VEL_ANG) * STICK_R}px, 0px)`;
dotTurn.style.transform = `translate(${(-wz / limA) * STICK_R}px, 0px)`;
boxMove.classList.toggle("live", manual && Math.abs(vx) > 0.01);
boxTurn.classList.toggle("live", manual && Math.abs(wz) > 0.01);
@@ -1187,13 +1399,15 @@ function renderStats() {
for (const k of ["fwd", "back", "turnl", "turnr"]) {
keyEls[k].classList.toggle("lit", held.has(k));
}
keyEls.roll.classList.toggle("lit", mode === "roll" && rollSource === "kb");
const trick = mode === "roll" || mode === "crouch"; // same R / pad-X slot
keyEls.roll.classList.toggle("lit", trick && rollSource === "kb");
keyEls.kickl.classList.toggle("lit", mode === "kickL" && kickSource === "kb");
keyEls.kickr.classList.toggle("lit", mode === "kickR" && kickSource === "kb");
keyEls.reset.classList.toggle("lit", performance.now() - resetFlashAt < 400);
keyEls.ball.classList.toggle("lit", performance.now() - ballFlashAt < 400);
keyEls.cam.classList.toggle("lit", chaseCam); // steady while chasing
keyEls.padX.classList.toggle("lit", mode === "roll" && rollSource === "pad");
keyEls.loco?.classList.toggle("lit", loco === "rollers" || locoSwitching);
keyEls.padX.classList.toggle("lit", trick && rollSource === "pad");
keyEls.padY.classList.toggle("lit", performance.now() - padYFlashAt < 400);
keyEls.padRb.classList.toggle("lit", mode === "kickR" && kickSource === "pad");
keyEls.padLb.classList.toggle("lit", mode === "kickL" && kickSource === "pad");
@@ -1231,8 +1445,9 @@ loop();
// ── Input: hold-to-command keys + HUD buttons ───────────────────────────
function refreshVelCmd() {
velCmd[0] = held.has("fwd") ? VEL_FWD : held.has("back") ? VEL_BACK : 0;
velCmd[2] = held.has("turnl") ? VEL_ANG : held.has("turnr") ? -VEL_ANG : 0;
const [limF, limB, limA] = velLims();
velCmd[0] = held.has("fwd") ? limF : held.has("back") ? limB : 0;
velCmd[2] = held.has("turnl") ? limA : held.has("turnr") ? -limA : 0;
}
// e.code is physical position, so one map covers QWERTY and AZERTY:
@@ -1249,6 +1464,7 @@ window.addEventListener("keydown", (e) => {
if (e.code === "Space") { e.preventDefault(); resetSim(); resetFlashAt = performance.now(); return; }
if (e.code === "KeyB") { spawnBall(); ballFlashAt = performance.now(); return; }
if (e.code === "KeyC") { chaseCam = !chaseCam; return; }
if (e.code === "KeyM") { toggleLoco(); return; }
if (e.code === "KeyR") { triggerRoll(); return; }
// Physical Q/E (A/E on AZERTY): explicit left / right kick, mirroring
// the pad's LB / RB.
@@ -1331,10 +1547,11 @@ pollPad = function pollGamepad() {
// (No strafe; the right stick no longer drives movement.)
const lx = dz(gp.axes[0] ?? 0), ly = dz(gp.axes[1] ?? 0);
const up = -ly; // browser sticks report up as -1
const [limF, limB, limA] = velLims();
const target = [
up >= 0 ? up * VEL_FWD : up * -VEL_BACK,
up >= 0 ? up * limF : up * -limB,
0,
-lx * VEL_ANG,
-lx * limA,
];
for (let i = 0; i < 3; i++) padCmd[i] += PAD_ALPHA * (target[i] - padCmd[i]);
// Sticks grab command authority on first input, release when back at rest
@@ -1374,16 +1591,26 @@ pollPad = function pollGamepad() {
padPrev.lb = lb;
const dpadDown = !!gp.buttons[13]?.pressed;
if (dpadDown && !padPrev.dpadDown) {
if (dpadDown && !padPrev.dpadDown && loco === "legs") {
const sitting = mode === "sitstand" && sitFlag === 1;
setMode(sitting ? "walk" : "sit");
}
padPrev.dpadDown = dpadDown;
// DpadUp: straight back to running. Ignored mid-roll (it hands back
// to walk on its own, and switching on a tipped duck would floor it).
// DpadUp: short press = straight back to running (ignored mid-roll: it
// hands back to walk on its own, and switching on a tipped duck would
// floor it). HOLD ~1 s = legs <-> rollers switch, like the robot's 3 s
// hold on the real controller (shortened for the web).
const dpadUp = !!gp.buttons[12]?.pressed;
if (dpadUp && !padPrev.dpadUp && mode !== "walk" && mode !== "roll") setMode("walk");
if (dpadUp && !padPrev.dpadUp) {
padPrev.dpadUpAt = now;
padPrev.dpadUpFired = false;
if (mode !== "walk" && mode !== "roll" && mode !== "crouch") setMode("walk");
}
if (dpadUp && !padPrev.dpadUpFired && now - padPrev.dpadUpAt >= 1000) {
padPrev.dpadUpFired = true; // latch: one switch per hold
toggleLoco();
}
padPrev.dpadUp = dpadUp;
// Triggers drive the mouth like the runtime (max of both), and the right
@@ -1403,11 +1630,15 @@ pollPad = function pollGamepad() {
const modeLabel = document.getElementById("mode-label");
function setMode(next) {
if (inputLocked) return;
// No policy switching mid-roll or mid-kick: both end on their own and
// return to walk - switching now would floor the duck.
if ((mode === "roll" && rollRun) || (isKick() && kickRun)) return;
// return to walk - switching now would floor the duck. Sitting is a
// legs-only skill (the roller stance has no sitstand policy).
if ((mode === "roll" && rollRun) || (isKick() && kickRun) || (mode === "crouch" && crouchRun)) return;
if (next === "sit" && loco === "rollers") return;
clearModeTimers();
rollRun = null;
crouchRun = null;
if (next !== "sit") {
// Leaving a sit: let the sitstand policy stand the duck back up first.
if (mode === "sitstand" && sitFlag === 1) {
@@ -1443,9 +1674,11 @@ function setMode(next) {
// continuous action history across policy switches, and the roll initiates
// more reliably mid-gait with the true last actions in the obs.
function triggerRoll(source = "kb") {
// Same trigger slot in the roller variant fires its own trick.
if (loco === "rollers") return triggerCrouch(source);
// Rolls only launch from a standing walk: from a sit (or mid sit/stand
// hand-over) the roll policy just faceplants the duck.
if (mode !== "walk" || standTimer) return;
if (inputLocked || mode !== "walk" || standTimer) return;
clearModeTimers();
rollSource = source;
mode = "roll";
@@ -1454,12 +1687,25 @@ function triggerRoll(source = "kb") {
syncButtons();
}
// Roller-only one-shot: crouch, glide low, stand back up (phase-driven,
// see the crouch constants up top). Reuses the roll's trigger + keycap.
function triggerCrouch(source = "kb") {
if (inputLocked || mode !== "walk" || locoSwitching) return;
clearModeTimers();
rollSource = source;
mode = "crouch";
crouchRun = { phase: 0 };
syncButtons();
}
// One blind kick (the duck can't see any ball - it's a scripted boot),
// left or right leg. Same launch constraints as the roll. Returns whether
// the kick actually launched so the keyboard's foot alternation only
// advances on real kicks.
function triggerKick(foot, source = "kb") {
if (mode !== "walk" || standTimer) return false;
// Kicks are legs-only: in roller mode the ball is played by driving.
if (loco === "rollers") return false;
if (inputLocked || mode !== "walk" || standTimer) return false;
clearModeTimers();
kickSource = source;
mode = foot === "left" ? "kickL" : "kickR";
@@ -1487,7 +1733,14 @@ function setModeLabel(text) {
function syncButtons() {
const sitting = mode === "sitstand" && sitFlag === 1;
setModeLabel(mode === "roll" ? "Roll" : isKick() ? "Kick" : sitting ? "Sit" : "Run");
setModeLabel(
mode === "roll" ? "Roll"
: mode === "crouch" ? "Crouch"
: isKick() ? "Kick"
: sitting ? "Sit"
: loco === "rollers" ? "Drive"
: "Run",
);
}
// ── Colour swatches: re-skin the rig live, with a quack ─────────────────
@@ -1521,12 +1774,20 @@ uiReady = true;
// Deterministic hooks for automated verification (rAF pauses in
// background tabs, and the control loop is async).
window.rl = {
model, data, mujoco, camera, controls,
// model/data are getters: activateLoco swaps them wholesale.
get model() { return model; },
get data() { return data; },
mujoco, camera, controls,
get mode() { return mode; },
get sitFlag() { return sitFlag; },
buildObs, cmd,
velCmd, lastAction, resetSim,
spawnBall, triggerKick, sessions, ort,
get loco() { return loco; },
get locoSwitching() { return locoSwitching; },
toggleLoco, ensureRollers,
triggerCrouch,
get crouchPhase() { return crouchRun?.phase ?? null; },
get kickSteps() { return KICK_STEPS; },
set kickSteps(v) { KICK_STEPS = v; },
get ballActive() { return ballActive; },
@@ -1540,9 +1801,11 @@ window.rl = {
// One full render-loop iteration, for tests driving frames manually.
frame: () => { syncRig(); syncJaw(); controls.update(); updateChaseCam(); updateEntrance(); renderStats(); renderer.render(scene, camera); },
get ghosts() { return ghosts; },
get inputLocked() { return inputLocked; },
// Deterministic entrance controls for screenshots/tests: setting values
// detaches the time-based driver; setDissolve(1) also restores the
// original materials (same cleanup as the real sequence).
// original materials and releases the input lock (same cleanup as the
// real sequence).
entrance: {
start: startEntrance,
setReveal: (floor, wall = floor) => {
@@ -1552,7 +1815,7 @@ window.rl = {
},
setDissolve: (p) => {
entranceT0 = null;
if (p >= 1) { dissolveP.value = 1; restoreDissolve(); }
if (p >= 1) { dissolveP.value = 1; restoreDissolve(); inputLocked = false; entranceFinishedResolve(); }
else { applyDissolve(); dissolveP.value = p; }
},
},
@@ -1563,10 +1826,18 @@ window.rl = {
// translucent ducks. Fire-and-forget: any failure just means no ghosts.
const r3 = (x) => Math.round(x * 1000) / 1000;
try {
// Ghosts only join once the entrance has fully played: the world (and
// this duck) must stay hidden until then, translucent peers included.
await entranceFinished;
const { initGhosts } = await import(signed(`./ghosts.js?v=${SELF_V}`));
ghosts = await initGhosts({
scene, rig, cloneRig, setJoint, setJawOpen, applyVariant,
jointNames: JOINT_NAMES,
// Ghost rig per locomotion flag: peers in roller mode clone the roller
// rig once this tab has built it, and fall back to the leg rig until
// then (their wheels also don't spin - joints aren't broadcast for
// the passive hinges). Known v1 limitation, documented in the README.
getRigFor: (l) => (l && locos.rollers ? locos.rollers.rig : locos.legs.rig),
getLocalState: () => {
const qpos = data.qpos;
const j = new Array(NUM_JOINTS);
@@ -1576,6 +1847,7 @@ try {
j,
w: r3(jawOpenNow()),
v: currentVariant,
l: loco === "rollers" ? 1 : 0,
};
},
});
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+470
View File
@@ -0,0 +1,470 @@
<?xml version="1.0" ?>
<!-- Generated using onshape-to-robot -->
<!-- Onshape https://cad.onshape.com/documents/804927696f06d877f3f1803e/w/5b75db19292e71970de02dee/e/ed34b749f5a3718f68024fd5 -->
<mujoco model="microduck">
<compiler angle="radian" meshdir="assets" autolimits="true"/>
<default>
<default class="microduck">
<joint frictionloss="0.1" armature="0.005"/>
<position kp="50" dampratio="1"/>
<default class="visual">
<geom type="mesh" contype="0" conaffinity="0" group="2"/>
</default>
<default class="collision">
<geom group="3"/>
</default>
</default>
</default>
<!-- Additional joints_properties.xml -->
<default>
<default class="perfect_actuator">
<geom contype="0" conaffinity="0"/>
<joint damping="0.15" frictionloss="0.1" armature="0.001"/>
<position kp="10.0" kv="0.1" forcerange="-20.0 20.0"/>
</default>
<default class="chosen_actuator_old">
<geom contype="0" conaffinity="0"/>
<joint damping="0.048" frictionloss="0.006" armature="0.002"/>
<position kp="0.52" kv="0.0" forcerange="-0.91 0.91" ctrlrange="-10.0 10.0"/>
</default>
<default class="chosen_actuator_new">
<!-- removing contaminated data -->
<geom contype="0" conaffinity="0"/>
<joint damping="0.041" frictionloss="0.032" armature="0.002"/>
<position kp="0.386" kv="0.0" forcerange="-0.67 0.67" ctrlrange="-10.0 10.0"/>
</default>
<default class="chosen_actuator_antoine">
<geom contype="0" conaffinity="0"/>
<joint damping="0.044" frictionloss="0.013" armature="0.0017"/>
<position kp="0.43" kv="0.0" forcerange="-0.75 0.75" ctrlrange="-10.0 10.0"/>
</default>
<default class="chosen_actuator">
<!-- marc -->
<geom contype="0" conaffinity="0"/>
<joint damping="0.053" frictionloss="0.0048" armature="0.0018"/>
<!-- 200 kp -->
<position kp="0.55" kv="0.0" forcerange="-0.96 0.96" ctrlrange="-10.0 10.0"/>
<!-- 125 kp -->
<!-- <position kp="0.35" kv="0.0" forcerange="-0.96 0.96" ctrlrange="-10.0 10.0"/> -->
</default>
<default class="passive_wheel">
<geom contype="0" conaffinity="0"/>
<joint damping="0.0" frictionloss="0.0" armature="0.0001"/>
</default>
<default class="passive_joint">
<geom contype="0" conaffinity="0"/>
<joint damping="0.0" frictionloss="0.0" armature="0.0001"/>
</default>
</default>
<!-- Additional sensors.xml -->
<sensor>
<framequat name="orientation" objtype="site" noise="0.001" objname="imu"/>
<gyro name="angular-velocity" site="imu" noise="0.005"/>
<gyro name="imu_ang_vel" site="imu"/>
<velocimeter name="imu_lin_vel" site="imu"/>
<accelerometer name="imu_accel" site="imu"/>
<subtreeangmom name="root_angmom" body="trunk_base"/>
</sensor>
<!-- Additional additional.xml -->
<default>
<default class="self_collision_only">
<geom group="3" contype="2" conaffinity="2"/>
</default>
<equality solref="0.002 1" solimp="0.99 0.999 0.0005 0.5 2"/>
</default>
<!-- <contact> -->
<!-- Jaw collision mesh overlaps the bottom head shell by ~2cm because the closed -->
<!-- loop linkage positions it inside the head. Without these excludes the -->
<!-- self-collision sensor reports a constant 2 contacts, giving a -->
<!-- permanent ~-2.0 reward penalty in the standup env. -->
<!-- <exclude body1="jaw" body2="bottom_head_shell"/> -->
<!-- </contact> -->
<worldbody>
<!-- Link trunk_base -->
<body name="trunk_base" pos="0 0 0.12" quat="1 0 0 0" childclass="microduck">
<freejoint name="trunk_base_freejoint"/>
<inertial pos="-0.0226332 -2.70828e-05 0.00280064" mass="0.199224" fullinertia="0.000123975 0.000145931 0.000115351 7.1651e-08 -2.06915e-05 1.32429e-07"/>
<!-- Part seeed_bearing__configuration__22x16x4 -->
<geom type="mesh" class="visual" pos="0.006 0.0175 -0.005" quat="1 -0 -0 0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part right_shell -->
<geom type="mesh" class="visual" pos="0.004 -0.0005 -0.0175" quat="0.707107 -0 -0 0.707107" mesh="right_shell" material="right_shell_material"/>
<!-- Part banana_pcb_locker -->
<geom type="mesh" class="visual" pos="0.0042 -0 -0.0175215" quat="0.707107 -0 0 0.707107" mesh="banana_pcb_locker" material="banana_pcb_locker_material"/>
<!-- Part trunk_base -->
<geom type="mesh" class="visual" pos="0.004 -0 -0.0175" quat="0.707107 -0 -0 0.707107" mesh="trunk_base" material="trunk_base_material"/>
<!-- Part xl330 -->
<geom type="mesh" class="visual" pos="0.006 0.0175 0.0115" quat="0 0.707107 -0 0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part power_support -->
<geom type="mesh" class="visual" pos="0.004 -0 -0.0175215" quat="0.707107 -0 0 0.707107" mesh="power_support" material="power_support_material"/>
<geom type="mesh" class="self_collision_only" pos="0.004 -0 -0.0175215" quat="0.707107 -0 0 0.707107" mesh="power_support" material="power_support_material"/>
<!-- Part np_f970 -->
<geom type="mesh" class="visual" pos="-0.0359693 0 -0.00385049" quat="0.00617059 0.70708 -0.70708 -0.00617059" mesh="np_f970" material="np_f970_material"/>
<geom type="mesh" class="collision" pos="-0.0359693 0 -0.00385049" quat="0.00617059 0.70708 -0.70708 -0.00617059" mesh="np_f970" material="np_f970_material"/>
<!-- Part xl330_2 -->
<geom type="mesh" class="visual" pos="0.006 -0.0175 0.0115" quat="0 0.707107 -0 0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part left_shell -->
<geom type="mesh" class="visual" pos="0.004 -0 -0.0175785" quat="0.707107 0 -0 0.707107" mesh="left_shell" material="left_shell_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_2 -->
<geom type="mesh" class="visual" pos="0.006 -0.0175 -0.005" quat="1 -0 -0 0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Frame imu -->
<site group="3" name="imu" pos="-0.021 6.64098e-05 -0.0146984" quat="1 -0 -0 0"/>
<!-- Link yaw2roll -->
<body name="yaw2roll" pos="0.006 0.0175 -0.005" quat="0 -0.707107 -0.707107 -0">
<!-- Joint from trunk_base to yaw2roll -->
<joint axis="0 0 1" name="left_hip_yaw" type="hinge" range="-0.4363323129985824 0.5235987755982988" class="chosen_actuator"/>
<inertial pos="-8.8e-11 0.00099414 0.0168917" mass="0.0230406" fullinertia="4.1964e-06 3.41752e-06 2.3265e-06 -0 -0 -5.0881e-08"/>
<!-- Part yaw2roll -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 1 0 0" mesh="yaw2roll" material="yaw2roll_material"/>
<!-- Part xl330_3 -->
<geom type="mesh" class="visual" pos="-0 0 0.0125" quat="0 -0.707107 0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_3 -->
<geom type="mesh" class="visual" pos="-0 0.0165 0.0125" quat="0.5 0.5 0.5 -0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part bearing_roll -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 -1 -0 -0" mesh="bearing_roll" material="bearing_roll_material"/>
<!-- Link hip_l -->
<body name="hip_l" pos="0 0.0165 0.0125" quat="0.707107 -0.707107 -0 -0">
<!-- Joint from yaw2roll to hip_l -->
<joint axis="0 0 1" name="left_hip_roll" type="hinge" range="-0.3839724354387525 0.3839724354387525" class="chosen_actuator"/>
<inertial pos="0.014815 1.6179e-08 -0.00829992" mass="0.00618934" fullinertia="8.60626e-07 1.15753e-06 6.51588e-07 1e-12 3.89882e-07 -1e-12"/>
<!-- Part seeed_bearing__configuration__22x16x4_4 -->
<geom type="mesh" class="visual" pos="0.021 0 -0.0185" quat="0.5 0.5 0.5 0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part hip_l -->
<geom type="mesh" class="visual" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 0 -0" mesh="hip_l" material="hip_l_material"/>
<geom type="mesh" class="collision" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 0 -0" mesh="hip_l" material="hip_l_material"/>
<!-- Link upper_leg_left -->
<body name="upper_leg_left" pos="0.025 0 -0.0185" quat="0.5 -0.5 0.5 -0.5">
<!-- Joint from hip_l to upper_leg_left -->
<joint axis="0 0 1" name="left_hip_pitch" type="hinge" range="-1.570796326795005 1.5707963267947882" class="chosen_actuator"/>
<inertial pos="0.006766 0.0228838 0.0134531" mass="0.0482067" fullinertia="1.68753e-05 1.03691e-05 1.98269e-05 -4.41852e-06 2.27982e-07 3.89298e-07"/>
<!-- Part upper_leg_left -->
<geom type="mesh" class="visual" pos="-0 -0 -0.0425" quat="0.5 -0.5 -0.5 -0.5" mesh="upper_leg_left" material="upper_leg_left_material"/>
<!-- Part xl330_4 -->
<geom type="mesh" class="visual" pos="0.022 0.0357771 0.0125" quat="0 -0.707107 -0 -0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part upper_leg_rigidity_plate -->
<geom type="mesh" class="visual" pos="0 -0 -0.0425" quat="0.5 -0.5 -0.5 -0.5" mesh="upper_leg_rigidity_plate" material="upper_leg_rigidity_plate_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_5 -->
<geom type="mesh" class="visual" pos="0.022 0.0357771 -0.004" quat="0 0 0 1" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part xl330_5 -->
<geom type="mesh" class="visual" pos="-0 -0 0.0125" quat="0.5 0.5 -0.5 0.5" mesh="xl330" material="xl330_material"/>
<!-- Link leg -->
<body name="leg" pos="0.022 0.0357771 -0.004" quat="0 0.707107 0.707107 0">
<!-- Joint from upper_leg_left to leg -->
<joint axis="0 0 1" name="left_knee" type="hinge" range="-1.570796326795012 1.570796326794781" class="chosen_actuator"/>
<inertial pos="-1.52e-10 0.0318937 -0.00953505" mass="0.0215844" fullinertia="5.25056e-06 2.15507e-06 4.33925e-06 -1e-12 0 7.65005e-07"/>
<!-- Part leg -->
<geom type="mesh" class="visual" pos="-0.022 0.0357771 0.0385" quat="0.5 0.5 0.5 -0.5" mesh="leg" material="leg_material"/>
<geom type="mesh" class="collision" pos="-0.022 0.0357771 0.0385" quat="0.5 0.5 0.5 -0.5" mesh="leg" material="leg_material"/>
<!-- Part xl330_6 -->
<geom type="mesh" class="visual" pos="0 0.042 -0.0115" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Link ankle_l_v1 -->
<body name="ankle_l_v1" pos="0 0.042 -0.026" quat="0 1 -0 0">
<!-- Joint from leg to ankle_l_v1 -->
<joint axis="0 0 1" name="left_ankle" type="hinge" range="-1.5707963267949054 1.5707963267948877" class="chosen_actuator"/>
<inertial pos="-0.00680626 -0.0143677 -0.0151851" mass="0.02087" fullinertia="4.85529e-06 9.6767e-06 8.22681e-06 -3.18897e-07 5.6657e-08 1.31522e-07"/>
<!-- Part roller_blade -->
<geom type="mesh" class="visual" pos="-0.022 0.00622291 -0.0647" quat="0.5 -0.5 -0.5 -0.5" mesh="roller_blade" material="roller_blade_material"/>
<!-- Part seeed_bearing__configuration_default -->
<geom type="mesh" class="visual" pos="0 0 -0.0314" quat="0 -0 0 -1" mesh="seeed_bearing__configuration_default" material="seeed_bearing__configuration_default_material"/>
<!-- Part ankle_l_v1 -->
<geom type="mesh" class="visual" pos="-0.022 0.00622291 -0.0647" quat="0.5 -0.5 -0.5 -0.5" mesh="ankle_l_v1" material="ankle_l_v1_material"/>
<!-- Frame left_foot -->
<site group="3" name="left_foot" pos="-0 -0.0475 -0.0147" quat="0 -0 -0.707107 -0.707107"/>
<!-- Link tire -->
<body name="tire" pos="-0.0395 -0.0325 -0.0147" quat="1 -0 0 -0">
<!-- Joint from ankle_l_v1 to tire -->
<joint axis="0 0 1" name="passive_LF_wheel" class="passive_joint"/>
<inertial pos="-0 0 0" mass="0.00447401" fullinertia="2.8556e-07 2.8556e-07 5.3687e-07 -0 -6e-12 0"/>
<!-- Part tire -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
<geom type="mesh" class="collision" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
<!-- Part rim -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="rim" material="rim_material"/>
</body>
<!-- Link tire_2 -->
<body name="tire_2" pos="0.0255 -0.0325 -0.0147" quat="1 -0 0 -0">
<!-- Joint from ankle_l_v1 to tire_2 -->
<joint axis="0 0 1" name="passive_LR_wheel" class="passive_joint"/>
<inertial pos="-0 0 -0" mass="0.00447401" fullinertia="2.8556e-07 2.8556e-07 5.3687e-07 -0 -6e-12 0"/>
<!-- Part rim_2 -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="rim" material="rim_material"/>
<!-- Part tire_2 -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
<geom type="mesh" class="collision" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
</body>
</body>
</body>
</body>
</body>
</body>
<!-- Link neck -->
<body name="neck" pos="0.026 0.0145 0.0324215" quat="0 0 0.707107 -0.707107">
<!-- Joint from trunk_base to neck -->
<joint axis="0 0 1" name="neck_pitch" type="hinge" range="-1.5707963267948966 1.0471975511965976" class="chosen_actuator"/>
<inertial pos="0 -0.025 0.0141665" mass="0.0368414" fullinertia="1.72925e-05 3.12694e-06 1.63707e-05 0 0 0"/>
<!-- Part neck -->
<geom type="mesh" class="visual" pos="0.022 0.05 0.028" quat="0.5 0.5 0.5 -0.5" mesh="neck" material="neck_material"/>
<!-- Part xl330_7 -->
<geom type="mesh" class="visual" pos="0 0 0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Part xl330_8 -->
<geom type="mesh" class="visual" pos="0 -0.05 0.0145" quat="0.5 0.5 -0.5 0.5" mesh="xl330" material="xl330_material"/>
<!-- Part neck_2 -->
<geom type="mesh" class="visual" pos="0.022 0.05 0.003" quat="0.5 0.5 0.5 -0.5" mesh="neck" material="neck_material"/>
<!-- Link neck_pitch -->
<body name="neck_pitch" pos="0 -0.05 -0" quat="0 1 0 0">
<!-- Joint from neck to neck_pitch -->
<joint axis="0 0 1" name="head_pitch" type="hinge" range="-1.5707963267948974 1.5707963267948957" class="chosen_actuator"/>
<inertial pos="-6.533e-09 0.0116641 -0.0145" mass="0.00572" fullinertia="1.09186e-06 9.66855e-07 5.12111e-07 0 0 0"/>
<!-- Part neck_pitch -->
<geom type="mesh" class="visual" pos="-0 0.0287931 -0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="neck_pitch" material="neck_pitch_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_6 -->
<geom type="mesh" class="visual" pos="-0 0.0207931 -0.0145" quat="0.707107 0.707107 0 0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link yaw_roll_motion -->
<body name="yaw_roll_motion" pos="-0 0.0186931 -0.0145" quat="0 0 -0.707107 -0.707107">
<!-- Joint from neck_pitch to yaw_roll_motion -->
<joint axis="0 0 1" name="head_yaw" type="hinge" range="-2.967059728390373 2.967059728390348" class="chosen_actuator"/>
<inertial pos="-0.000166657 -0.00500964 0.0178065" mass="0.0486" fullinertia="6.97903e-06 8.10293e-06 9.57884e-06 3.21657e-07 -3.4797e-08 3.4295e-07"/>
<!-- Part yaw_roll_motion -->
<geom type="mesh" class="visual" pos="0 0 0.01" quat="0.707107 0 -0 0.707107" mesh="yaw_roll_motion" material="yaw_roll_motion_material"/>
<!-- Part xl330_9 -->
<geom type="mesh" class="visual" pos="0 0 0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_7 -->
<geom type="mesh" class="visual" pos="-0.016 0 0.0145" quat="0.707107 -0 -0.707107 -0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_8 -->
<geom type="mesh" class="visual" pos="0.018 0 0.0145" quat="0.707107 -0 -0.707107 -0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link jaw_soft -->
<body name="jaw_soft" pos="-0.0179 0 0.0145" quat="0.707107 -0 -0.707107 -0">
<!-- Joint from yaw_roll_motion to jaw_soft -->
<joint axis="0 0 1" name="head_roll" type="hinge" range="-0.43633231299859127 0.4363323129985735" class="chosen_actuator"/>
<inertial pos="0.00460523 0.00120047 -0.0324761" mass="0.188766" fullinertia="0.000320812 0.0002541 0.000149882 -6.32292e-07 6.57154e-06 4.18476e-06"/>
<!-- Part lens -->
<geom type="mesh" class="visual" pos="0.0155 -9.13778e-05 -0.05548" quat="0.5 -0.5 0.5 -0.5" mesh="lens" material="lens_material"/>
<!-- Part face_part -->
<geom type="mesh" class="visual" pos="-0.0045 -9.13778e-05 -0.0178" quat="0.5 0.5 0.5 0.5" mesh="face_part" material="face_part_material"/>
<!-- Part xl330_10 -->
<geom type="mesh" class="visual" pos="0.003 0.0255 -0.018" quat="0.707107 0 -0 -0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part jaw_soft -->
<geom type="mesh" class="visual" pos="-0.0046 0 -0.0179996" quat="0.5 0.5 0.5 0.5" mesh="jaw_soft" material="jaw_soft_material"/>
<!-- Part motor_support -->
<geom type="mesh" class="visual" pos="-0.0045 0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="motor_support" material="motor_support_material"/>
<!-- Part top_head_shell -->
<geom type="mesh" class="visual" pos="-0.0045 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="top_head_shell" material="top_head_shell_material"/>
<geom type="mesh" class="collision" pos="-0.0045 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="top_head_shell" material="top_head_shell_material"/>
<!-- Part xl330_11 -->
<geom type="mesh" class="visual" pos="0 0 0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration_default_2 -->
<geom type="mesh" class="visual" pos="0.0032 -0.04 -0.018" quat="0.5 -0.5 0.5 0.5" mesh="seeed_bearing__configuration_default" material="seeed_bearing__configuration_default_material"/>
<!-- Part elec_rpi_robot_hat_pcb -->
<geom type="mesh" class="visual" pos="0.02694 0.0289936 -0.0519" quat="0.707107 0 0 -0.707107" mesh="elec_rpi_robot_hat_pcb" material="elec_rpi_robot_hat_pcb_material"/>
<!-- Part soft_mouth_top -->
<geom type="mesh" class="visual" pos="-0.00420071 1.7776e-08 -0.0180814" quat="0.5 0.5 0.5 0.5" mesh="soft_mouth_top" material="soft_mouth_top_material"/>
<!-- Part noenoeil -->
<geom type="mesh" class="visual" pos="-0.0045 -9.13778e-05 -0.0178" quat="0.5 0.5 0.5 0.5" mesh="noenoeil" material="noenoeil_material"/>
<!-- Part jaw -->
<geom type="mesh" class="visual" pos="-0.0045 0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="jaw" material="jaw_material"/>
<geom type="mesh" class="collision" pos="-0.0045 0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="jaw" material="jaw_material"/>
<!-- Part bottom_head_shell -->
<geom type="mesh" class="visual" pos="-0.0043 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="bottom_head_shell" material="bottom_head_shell_material"/>
<geom type="mesh" class="collision" pos="-0.0043 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="bottom_head_shell" material="bottom_head_shell_material"/>
<!-- Part m12_lens_holder -->
<geom type="mesh" class="visual" pos="0.0155 -9.13778e-05 -0.05558" quat="0.5 -0.5 0.5 -0.5" mesh="m12_lens_holder" material="m12_lens_holder_material"/>
<!-- Part pcb__raspberry_pi_zero_2_w -->
<geom type="mesh" class="visual" pos="0.015435 -1.13778e-05 -0.06001" quat="0.5 -0.5 -0.5 0.5" mesh="pcb__raspberry_pi_zero_2_w" material="pcb__raspberry_pi_zero_2_w_material"/>
<!-- Part speaker -->
<geom type="mesh" class="visual" pos="0.01 -0.016786 0.0260226" quat="0.5 0.5 0.5 0.5" mesh="speaker" material="speaker_material"/>
<!-- Frame head_camera -->
<site group="3" name="head_camera" pos="0.0155 -9.13778e-05 -0.0733" quat="0.707107 0 0.707107 -0"/>
<camera name="head_camera" pos="0.0155 -9.13778e-05 -0.0733" quat="0 0 -1 0"/>
<!-- Frame tof -->
<site group="3" name="tof" pos="0.0135 0.0224086 -0.0733" quat="0.707107 0 0.707107 -0"/>
<!-- Frame head_imu -->
<site group="3" name="head_imu" pos="0.0152323 0.000111069 -0.05106" quat="1 0 0 -0"/>
<!-- Frame mouth_tip -->
<site group="3" name="mouth_tip" pos="-0.00809334 -0 -0.0777383" quat="0.704015 0 0.710185 -0"/>
</body>
</body>
</body>
</body>
<!-- Link bearing_roll -->
<body name="bearing_roll" pos="0.006 -0.0175 -0.005" quat="0 0.707107 0.707107 0">
<!-- Joint from trunk_base to bearing_roll -->
<joint axis="0 0 1" name="right_hip_yaw" type="hinge" range="-0.5235987755982988 0.4363323129985824" class="chosen_actuator"/>
<inertial pos="-8.8e-11 0.00099414 0.0168917" mass="0.0230406" fullinertia="4.1964e-06 3.41752e-06 2.3265e-06 -0 -0 -5.0881e-08"/>
<!-- Part yaw2roll_2 -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 1 0 0" mesh="yaw2roll" material="yaw2roll_material"/>
<!-- Part xl330_12 -->
<geom type="mesh" class="visual" pos="-0 0 0.0125" quat="0 -0.707107 0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part bearing_roll_2 -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 -1 -0 -0" mesh="bearing_roll" material="bearing_roll_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_9 -->
<geom type="mesh" class="visual" pos="-0 0.0165 0.0125" quat="0.5 0.5 0.5 -0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link hip_l_2 -->
<body name="hip_l_2" pos="-0 0.0165 0.0125" quat="0 -0 0.707107 0.707107">
<!-- Joint from bearing_roll to hip_l_2 -->
<joint axis="0 0 1" name="right_hip_roll" type="hinge" range="-0.3839724354387525 0.3839724354387525" class="chosen_actuator"/>
<inertial pos="0.014815 1.6212e-08 -0.00829992" mass="0.00618934" fullinertia="8.60626e-07 1.15753e-06 6.51588e-07 1e-12 3.89882e-07 -1e-12"/>
<!-- Part hip_l_2 -->
<geom type="mesh" class="visual" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 -0 -0" mesh="hip_l" material="hip_l_material"/>
<geom type="mesh" class="collision" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 -0 -0" mesh="hip_l" material="hip_l_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_10 -->
<geom type="mesh" class="visual" pos="0.025 0 -0.0185" quat="0.5 0.5 -0.5 -0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link upper_leg_right -->
<body name="upper_leg_right" pos="0.025 0 -0.0185" quat="0.5 -0.5 0.5 -0.5">
<!-- Joint from hip_l_2 to upper_leg_right -->
<joint axis="0 0 1" name="right_hip_pitch" type="hinge" range="-1.5707963267949268 1.5707963267948664" class="chosen_actuator"/>
<inertial pos="-0.006766 0.0228838 0.0134531" mass="0.0482067" fullinertia="1.68753e-05 1.03691e-05 1.98269e-05 4.41852e-06 -2.27982e-07 3.89298e-07"/>
<!-- Part xl330_13 -->
<geom type="mesh" class="visual" pos="-0.022 0.0357771 0.0125" quat="0.707107 -0 -0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_11 -->
<geom type="mesh" class="visual" pos="-0.022 0.0357771 0" quat="0 1 -0 -0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part upper_leg_rigidity_plate_2 -->
<geom type="mesh" class="visual" pos="0 0 0.0435" quat="0.5 -0.5 0.5 0.5" mesh="upper_leg_rigidity_plate" material="upper_leg_rigidity_plate_material"/>
<!-- Part upper_leg_right -->
<geom type="mesh" class="visual" pos="-0 0 -0.0425" quat="0.5 -0.5 0.5 0.5" mesh="upper_leg_right" material="upper_leg_right_material"/>
<!-- Part xl330_14 -->
<geom type="mesh" class="visual" pos="0 0 0.0125" quat="0.5 0.5 -0.5 0.5" mesh="xl330" material="xl330_material"/>
<!-- Link leg_2 -->
<body name="leg_2" pos="-0.022 0.0357771 -0.004" quat="0 1 -0 -0">
<!-- Joint from upper_leg_right to leg_2 -->
<joint axis="0 0 1" name="right_knee" type="hinge" range="-1.570796326794932 1.570796326794861" class="chosen_actuator"/>
<inertial pos="-0.0318937 -1.52e-10 -0.00953505" mass="0.0215844" fullinertia="2.15507e-06 5.25056e-06 4.33925e-06 1e-12 -7.65005e-07 0"/>
<!-- Part xl330_15 -->
<geom type="mesh" class="visual" pos="-0.042 0 -0.0115" quat="0.707107 -0 -0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part leg_2 -->
<geom type="mesh" class="visual" pos="-0.0357771 -0.022 0.0385" quat="0.707107 0 0.707107 -0" mesh="leg" material="leg_material"/>
<geom type="mesh" class="collision" pos="-0.0357771 -0.022 0.0385" quat="0.707107 0 0.707107 -0" mesh="leg" material="leg_material"/>
<!-- Link ankle_r_v1 -->
<body name="ankle_r_v1" pos="-0.042 0 -0.026" quat="0 -0.707107 -0.707107 0">
<!-- Joint from leg_2 to ankle_r_v1 -->
<joint axis="0 0 1" name="right_ankle" type="hinge" range="-1.5707963267949063 1.5707963267948868" class="chosen_actuator"/>
<inertial pos="0.00680653 -0.0143679 -0.0149822" mass="0.0208701" fullinertia="4.8595e-06 9.68066e-06 8.22663e-06 3.18865e-07 -6.7107e-08 1.66791e-07"/>
<!-- Part ankle_r_v1 -->
<geom type="mesh" class="visual" pos="0.022 0.00622291 -0.0647" quat="0.5 -0.5 0.5 0.5" mesh="ankle_r_v1" material="ankle_r_v1_material"/>
<!-- Part seeed_bearing__configuration_default_3 -->
<geom type="mesh" class="visual" pos="0 0 -0.0284" quat="0 1 0 -0" mesh="seeed_bearing__configuration_default" material="seeed_bearing__configuration_default_material"/>
<!-- Part roller_blade_2 -->
<geom type="mesh" class="visual" pos="0.022 0.00622291 0.0355181" quat="0.5 -0.5 0.5 0.5" mesh="roller_blade" material="roller_blade_material"/>
<!-- Frame right_foot -->
<site group="3" name="right_foot" pos="0 -0.0475 -0.0144819" quat="0.707107 -0.707107 -0 0"/>
<!-- Link tire_3 -->
<body name="tire_3" pos="0.0395 -0.0325 -0.0144819" quat="0 -0 1 -0">
<!-- Joint from ankle_r_v1 to tire_3 -->
<joint axis="0 0 1" name="passive_RF_wheel" class="passive_joint"/>
<inertial pos="-0 -0 0" mass="0.00447401" fullinertia="2.8556e-07 2.8556e-07 5.3687e-07 -0 -6e-12 -0"/>
<!-- Part tire_3 -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
<geom type="mesh" class="collision" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
<!-- Part rim_3 -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="rim" material="rim_material"/>
</body>
<!-- Link tire_4 -->
<body name="tire_4" pos="-0.0255 -0.0325 -0.0144819" quat="0 -0 1 -0">
<!-- Joint from ankle_r_v1 to tire_4 -->
<joint axis="0 0 1" name="passive_RR_wheel" class="passive_joint"/>
<inertial pos="-0 -0 0" mass="0.00447401" fullinertia="2.8556e-07 2.8556e-07 5.3687e-07 -0 -6e-12 -0"/>
<!-- Part rim_4 -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="rim" material="rim_material"/>
<!-- Part tire_4 -->
<geom type="mesh" class="visual" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
<geom type="mesh" class="collision" pos="0.0175 0.0387229 -0.05" quat="0.5 -0.5 -0.5 -0.5" mesh="tire" material="tire_material"/>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</worldbody>
<asset>
<mesh file="elec_rpi_robot_hat_pcb.stl"/>
<mesh file="soft_mouth_top.stl"/>
<mesh file="speaker.stl"/>
<mesh file="top_head_shell.stl"/>
<mesh file="power_support.stl"/>
<mesh file="motor_support.stl"/>
<mesh file="upper_leg_left.stl"/>
<mesh file="roller_blade.stl"/>
<mesh file="m12_lens_holder.stl"/>
<mesh file="hip_l.stl"/>
<mesh file="lens.stl"/>
<mesh file="xl330.stl"/>
<mesh file="bearing_roll.stl"/>
<mesh file="bottom_head_shell.stl"/>
<mesh file="ankle_r_v1.stl"/>
<mesh file="jaw_soft.stl"/>
<mesh file="ankle_l_v1.stl"/>
<mesh file="yaw_roll_motion.stl"/>
<mesh file="trunk_base.stl"/>
<mesh file="left_shell.stl"/>
<mesh file="np_f970.stl"/>
<mesh file="yaw2roll.stl"/>
<mesh file="tire.stl"/>
<mesh file="upper_leg_right.stl"/>
<mesh file="banana_pcb_locker.stl"/>
<mesh file="pcb__raspberry_pi_zero_2_w.stl"/>
<mesh file="leg.stl"/>
<mesh file="neck_pitch.stl"/>
<mesh file="jaw.stl"/>
<mesh file="neck.stl"/>
<mesh file="face_part.stl"/>
<mesh file="right_shell.stl"/>
<mesh file="seeed_bearing__configuration__22x16x4.stl"/>
<mesh file="upper_leg_rigidity_plate.stl"/>
<mesh file="seeed_bearing__configuration_default.stl"/>
<mesh file="noenoeil.stl"/>
<mesh file="rim.stl"/>
<material name="seeed_bearing__configuration__22x16x4_material" rgba="0.713725 0.760784 0.8 1"/>
<material name="right_shell_material" rgba="0.8 0.8 0.8 1"/>
<material name="banana_pcb_locker_material" rgba="0.647059 0.647059 0.647059 1"/>
<material name="trunk_base_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="xl330_material" rgba="0.286275 0.286275 0.286275 1"/>
<material name="power_support_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="np_f970_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="left_shell_material" rgba="0.8 0.8 0.8 1"/>
<material name="yaw2roll_material" rgba="0.647059 0.647059 0.647059 1"/>
<material name="bearing_roll_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="hip_l_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="upper_leg_left_material" rgba="0.866667 0.866667 0.866667 1"/>
<material name="upper_leg_rigidity_plate_material" rgba="0.537255 0.854902 0.827451 1"/>
<material name="leg_material" rgba="0.811765 0.858824 0.898039 1"/>
<material name="roller_blade_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="seeed_bearing__configuration_default_material" rgba="0.713725 0.760784 0.8 1"/>
<material name="ankle_l_v1_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="tire_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="rim_material" rgba="0.729412 0.25098 0.105882 1"/>
<material name="neck_material" rgba="0.8 0.8 0.8 1"/>
<material name="neck_pitch_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="yaw_roll_motion_material" rgba="0.768627 0.886275 0.952941 1"/>
<material name="lens_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="face_part_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="jaw_soft_material" rgba="0.85098 0.756863 0.866667 1"/>
<material name="motor_support_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="top_head_shell_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="elec_rpi_robot_hat_pcb_material" rgba="0.313725 0.486275 0.411765 1"/>
<material name="soft_mouth_top_material" rgba="0.85098 0.756863 0.866667 1"/>
<material name="noenoeil_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="jaw_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="bottom_head_shell_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="m12_lens_holder_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="pcb__raspberry_pi_zero_2_w_material" rgba="0.498039 0.498039 0.498039 1"/>
<material name="speaker_material" rgba="0.294118 0.290196 0.290196 1"/>
<material name="upper_leg_right_material" rgba="0.866667 0.866667 0.866667 1"/>
<material name="ankle_r_v1_material" rgba="0.980392 0.713725 0.00392157 1"/>
</asset>
<actuator>
<position class="chosen_actuator" name="left_hip_yaw" joint="left_hip_yaw"/>
<position class="chosen_actuator" name="left_hip_roll" joint="left_hip_roll"/>
<position class="chosen_actuator" name="left_hip_pitch" joint="left_hip_pitch"/>
<position class="chosen_actuator" name="left_knee" joint="left_knee"/>
<position class="chosen_actuator" name="left_ankle" joint="left_ankle"/>
<position class="chosen_actuator" name="neck_pitch" joint="neck_pitch"/>
<position class="chosen_actuator" name="head_pitch" joint="head_pitch"/>
<position class="chosen_actuator" name="head_yaw" joint="head_yaw"/>
<position class="chosen_actuator" name="head_roll" joint="head_roll"/>
<position class="chosen_actuator" name="right_hip_yaw" joint="right_hip_yaw"/>
<position class="chosen_actuator" name="right_hip_roll" joint="right_hip_roll"/>
<position class="chosen_actuator" name="right_hip_pitch" joint="right_hip_pitch"/>
<position class="chosen_actuator" name="right_knee" joint="right_knee"/>
<position class="chosen_actuator" name="right_ankle" joint="right_ankle"/>
</actuator>
<equality/>
</mujoco>
+7
View File
@@ -168,6 +168,13 @@ export function meshMaterialsFor(v) {
"ankle_right.stl": v.feet,
"sole_left.stl": v.soles,
"sole_right.stl": v.soles,
// Roller variant: the blade + ankle bracket take the shoe-upper slot,
// the rims take the sole accent, the tires are rubber-dark.
"ankle_l_v1.stl": v.feet,
"ankle_r_v1.stl": v.feet,
"roller_blade.stl": v.feet,
"rim.stl": v.soles,
"tire.stl": v.mechDark,
// Dark mechanics. leg.stl is the printed shin that wraps the ankle
// motor and its bearing ring: in gray they read as two gray motors,
// so both go dark with the motor they hold.