import { test, expect } from "@playwright/test"; test("Apollo: native MuJoCo/ONNX, WASD, stable locomotion and reset", async ({ page, }, info) => { const errors = []; page.on("pageerror", (e) => errors.push(e.message)); await page.goto("/"); await expect( page.getByRole("button", { name: "Pause", exact: true }), ).toBeEnabled(); await page.getByLabel("Robot", { exact: true }).selectOption("apollo"); await page.waitForFunction( () => window.__store.getState().robotId === "apollo" || window.__store.getState().runtimeError, ); expect( await page.evaluate(() => window.__store.getState().runtimeError), ).toBeNull(); await page.evaluate(() => window.rl.pause()); expect(await page.evaluate(() => window.rl.buildObs().length)).toBe(108); expect(await page.evaluate(() => window.rl.lastAction.length)).toBe(32); // Apollo defaults disable visual-geom collisions: the World floor must // explicitly override those defaults rather than inherit a ghost floor. const floor = await page.evaluate(() => { const m = window.rl.model, id = m.geom("platform_floor").id; return [m.geom_contype[id], m.geom_conaffinity[id], m.geom_group[id]]; }); expect(floor).toEqual([1, 1, 0]); await page .locator("canvas") .first() .click({ position: { x: 700, y: 600 } }); for (const [key, expected] of [ ["KeyW", [0.5, 0, 0]], ["KeyS", [-0.3, 0, 0]], ["KeyA", [0, 0, 0.4]], ["KeyD", [0, 0, -0.4]], ]) { await page.evaluate(async () => { await window.rl.resetSim(); window.rl.resume(); }); await page.keyboard.down(key); const command = await page.evaluate(() => Array.from(window.rl.command)); command.forEach((v, i) => expect(v).toBeCloseTo(expected[i], 5)); await page.keyboard.up(key); expect(await page.evaluate(() => Array.from(window.rl.command))).toEqual([ 0, 0, 0, ]); await page.evaluate(() => window.rl.pause()); } const trials = await page.evaluate(async () => { const r = window.rl, reports = []; r.setPropsParked(true); for (const [name, command] of [ ["stand", [0, 0, 0]], ["forward", [0.5, 0, 0]], ["backward", [-0.3, 0, 0]], ["left", [0, 0, 0.4]], ["right", [0, 0, -0.4]], ]) { await r.resetSim(); r.command.set(command); for (let i = 0; i < 250; i++) { await r.step(1); if ( ![...r.data.qpos, ...r.data.qvel, ...r.lastAction].every( Number.isFinite, ) ) throw new Error("Non-finite Apollo state"); if (r.fallen) break; } const [w, x, y, z] = r.data.qpos.slice(3, 7); reports.push({ name, position: Array.from(r.data.qpos.slice(0, 3)), yaw: Math.atan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z)), fallen: r.fallen, time: r.data.time, }); } return reports; }); console.log("Apollo trials", JSON.stringify(trials)); await info.attach("apollo-trials.json", { body: JSON.stringify(trials, null, 2), contentType: "application/json", }); for (const trial of trials) { expect(trial.fallen, trial.name).toBe(false); expect(trial.position[2], `${trial.name}: upright height`).toBeGreaterThan( 1.04, ); } expect(trials[1].position[0]).toBeGreaterThan(1); expect(trials[2].position[0]).toBeLessThan(-0.5); expect(trials[3].yaw).toBeGreaterThan(0.8); expect(trials[4].yaw).toBeLessThan(-0.8); await page.keyboard.press("Space"); await expect.poll(() => page.evaluate(() => window.rl.data.time)).toBe(0); await page.screenshot({ path: info.outputPath("apollo.png") }); for (const id of ["microban", "rp1", "t1", "apollo"]) { await page.getByLabel("Robot", { exact: true }).selectOption(id); await expect .poll(() => page.evaluate(() => window.__store.getState().robotId)) .toBe(id); expect( await page.evaluate(() => window.__store.getState().runtimeError), ).toBeNull(); } expect(errors).toEqual([]); });