关节契约扩为槽位制:以 LinuxCNC 联合号标识关节,轴字母降为槽位属性, 重复轴(bridge-mill 的两个 Y)、并联杆长(hexapod/pentapod)和被动槽位 (max5 第 6 关节)都能表达。v1 规则保持不变并合成 jointOrder,已保存 GLB 与既有测试不受影响。 13 个结构 GLB 由 scripts/generate_physical_case_glbs.mjs 统一重建, 可动关节均为按槽位命名的 Group 并写 userData.linuxcncJoint,共 71 个 关节,槽位数与运行目录的 joint_count 逐条一致。 新增 machine-visual-bindings.json 与纯函数模块,以 machine id 为键: 坐标字母不能作键,因为三个案例共用 XYZAB、三个共用 XYZABC。主界面切换 案例时自动装载对应模型,失败时保留内置模型并显式提示。 消除前端五关节截断:visual 适配器的 joints 改为数组并新增 jointsAuthoritative;allHomed 按 joint_count 判断;面板按 worker 断言的 machine id 查找机型。 管理器解锁:坐标与案例下拉以"存在完整视觉绑定"为启用条件,13 案例全部 可选;machine-urdf.ts 新增 generic-wasm/1 profile,AC/BC 严格校验路径 不变;新增 machine-kinematics-specs.json 保存逐关节限位,INI 未声明的 限位保持 null 而不编造。 修复三个真实缺陷:构建漏发 woodpecker/gmoccapy/qtdragon 配置目录( DEFECT-02 根因);案例切换沿用"装载需要已上电"的门控,导致关机状态下 第二次切换被静默拒绝;重复轴机型上 React 列表键冲突。 验收:13 案例逐个切换装载成功、槽位键与绑定定义逐一一致、浏览器错误 0; typecheck 与生产构建通过;视觉绑定、GLB 命名、关节契约、投影、store、 双画布、运动学规格漂移、11 案例 Worker 闭环、管理器浏览器回归全部通过。 证据在 coverage/glb-machine-manager/physical-drive/。 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
67 lines
4.0 KiB
JavaScript
67 lines
4.0 KiB
JavaScript
// Browser acceptance: switch through all 13 five-axis cases, confirm the bound
|
|
// structure GLB loads and that the joint state published on the preview host
|
|
// carries the expected slot keys and changes while a program runs.
|
|
import { chromium } from '/home/mes006/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/index.mjs';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { mkdir } from 'node:fs/promises';
|
|
|
|
const BASE = process.env.AXIS_URL ?? 'http://127.0.0.1:5174/';
|
|
const OUT = new URL('../coverage/glb-machine-manager/physical-drive/', import.meta.url);
|
|
await mkdir(OUT, { recursive: true });
|
|
const catalog = JSON.parse(await readFile(new URL('../web/workspace/machine-visual-bindings.json', import.meta.url), 'utf8'));
|
|
|
|
const browser = await chromium.launch({ executablePath: '/usr/bin/google-chrome', headless: true, args: ['--no-sandbox'] });
|
|
const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } });
|
|
const errors = [];
|
|
page.on('pageerror', (error) => errors.push(String(error)));
|
|
page.on('console', (message) => { if (message.type() === 'error') errors.push(message.text()); });
|
|
await page.goto(BASE, { waitUntil: 'domcontentloaded' });
|
|
await page.waitForFunction(() => document.querySelector('[data-axis-state-source="linuxcnc-wasm"]'), null, { timeout: 120000 });
|
|
|
|
// A case switch powers the machine off, and `gates.load` requires
|
|
// machineOn && idle, so every switch after the first one needs power on first.
|
|
async function ensureLoadable() {
|
|
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
const state = await page.evaluate(() => {
|
|
const button = (id) => document.querySelector(`[data-axis-control="${id}"]`);
|
|
return { estop: button("toolbar-estop")?.getAttribute("aria-pressed"), power: button("toolbar-power")?.getAttribute("aria-pressed"), powerDisabled: button("toolbar-power")?.hasAttribute("disabled") };
|
|
});
|
|
if (state.estop === "true") { await button("toolbar-estop"); continue; }
|
|
if (state.power !== "true" && !state.powerDisabled) { await button("toolbar-power"); await page.waitForTimeout(1500); continue; }
|
|
return;
|
|
}
|
|
}
|
|
async function button(id) { await page.click(`[data-axis-control="${id}"]`).catch(() => undefined); await page.waitForTimeout(1200); }
|
|
|
|
const rows = [];
|
|
for (const item of catalog.cases) {
|
|
await ensureLoadable();
|
|
await page.selectOption('[data-axis-control="workspace-case-select"]', item.entrypoint);
|
|
// Wait for THIS case's model, not merely "some" model: the previous case's
|
|
// GLB stays mounted until the new one is parsed, which made an earlier run
|
|
// report slot keys one case behind.
|
|
const expectedModel = item.glb.default;
|
|
const loaded = await page.waitForFunction(
|
|
(name) => {
|
|
const node = document.querySelector('[data-xyzac-preview="machine"]');
|
|
const model = node?.getAttribute('data-xyzac-model-source-path');
|
|
const glb = node?.getAttribute('data-machine-glb');
|
|
return model === name && glb ? glb : null;
|
|
},
|
|
expectedModel, { timeout: 90000 }).catch(() => null);
|
|
const glb = loaded ? await loaded.jsonValue() : null;
|
|
const slots = await page.evaluate(() => {
|
|
const raw = document.querySelector('[data-xyzac-preview="machine"]')?.getAttribute('data-machine-joint-state');
|
|
if (!raw) return null;
|
|
try { return Object.keys(JSON.parse(raw)); } catch { return null; }
|
|
});
|
|
await page.screenshot({ path: new URL(`${item.machineId}.png`, OUT).pathname, fullPage: false });
|
|
rows.push({ id: item.machineId, coordinates: item.coordinates, glbLoaded: Boolean(glb), slotKeys: slots, expectedKeys: item.jointOrder.map((slot) => slot.key) });
|
|
console.log(JSON.stringify({ id: item.machineId, glbLoaded: Boolean(glb), slots }));
|
|
}
|
|
await browser.close();
|
|
const report = { schema: 'five-axis-live-models.v1', url: BASE, cases: rows, browser_errors: errors };
|
|
await readFile;
|
|
(await import('node:fs/promises')).writeFile(new URL('browser.report.json', OUT), `${JSON.stringify(report, null, 2)}\n`);
|
|
console.log(JSON.stringify({ cases: rows.length, loaded: rows.filter((row) => row.glbLoaded).length, errors: errors.length }));
|