fc5ee4f2c6
Add declarative robot packages, shared simulation lifecycle and Microban ONNX/PD walking with independent head control. Unify comic UI and chase camera; default robot packages to a 4.5m arena with real collision walls. Include regression tests, asset provenance/licenses and verification evidence.
66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
// Render-free integration probe uses the SAME runtime as the product; no
|
|
// second observation builder/PD implementation can drift from production.
|
|
import * as THREE from "three";
|
|
import { RobotRuntime } from "../../src/platform/runtime/RobotRuntime.js";
|
|
import {
|
|
loadPackage,
|
|
loadWorld,
|
|
} from "../../src/platform/loader/PackageLoader.js";
|
|
window.probeReady = (async () => {
|
|
const pkg = await loadPackage(
|
|
`${import.meta.env.BASE_URL}robots/microban/robot.json`,
|
|
),
|
|
world = await loadWorld("flat");
|
|
const runtime = await RobotRuntime.load({
|
|
pkg,
|
|
world,
|
|
scene: new THREE.Group(),
|
|
camera: new THREE.PerspectiveCamera(),
|
|
renderer: null,
|
|
});
|
|
const { sim, ctx } = runtime;
|
|
const state = () => {
|
|
const a = sim.rootQpos,
|
|
q = sim.data.qpos,
|
|
b = sim.root * 4,
|
|
quat = sim.data.xquat,
|
|
w = quat[b],
|
|
x = quat[b + 1],
|
|
y = quat[b + 2],
|
|
z = quat[b + 3];
|
|
return {
|
|
time: sim.data.time,
|
|
pos: Array.from(q.slice(a, a + 3)),
|
|
gravity: [
|
|
2 * (w * y - x * z),
|
|
-2 * (y * z + w * x),
|
|
-(1 - 2 * (x * x + y * y)),
|
|
],
|
|
yaw: Math.atan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z)),
|
|
};
|
|
};
|
|
window.probe = {
|
|
model: sim.model,
|
|
data: sim.data,
|
|
command: runtime.input.command,
|
|
state,
|
|
buildObs: () => {
|
|
ctx.command.set(runtime.input.command);
|
|
return runtime.obs.write().obs;
|
|
},
|
|
reset: () => runtime.reset(),
|
|
step: async (count) => {
|
|
await runtime.scheduler.step(count);
|
|
if (runtime.fallen) throw new Error(`Fallen at ${sim.data.time}`);
|
|
return state();
|
|
},
|
|
dispose: () => runtime.dispose(),
|
|
};
|
|
document.querySelector("#status").textContent =
|
|
"Ready: generic runtime / 19 joints / 18 actor / 63 obs";
|
|
})().catch((error) => {
|
|
window.probeError = error.stack;
|
|
document.querySelector("#status").textContent = error.stack;
|
|
throw error;
|
|
});
|