按关节槽位驱动 13 个五轴案例的三维模型
关节契约扩为槽位制:以 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>
This commit is contained in:
46
web/worker/test_generic_machine_cases.mjs
Normal file
46
web/worker/test_generic_machine_cases.mjs
Normal file
@@ -0,0 +1,46 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
|
||||
import { loadSimulationCase, toWorkerConfiguration } from "../workspace/sim-case-loader.mjs";
|
||||
import { MACHINE_DEFINITIONS } from "../workspace/machine-definitions.mjs";
|
||||
import { CONTEXT_ID, SimSession } from "./sim-session.mjs";
|
||||
|
||||
const root = "/home/mes006/linuxcncWebWASM";
|
||||
const fetchImpl = async (url) => {
|
||||
const relative = String(url).replace(/^\.?\//, "");
|
||||
for (const path of [`${root}/${relative}`, `${root}/web/react/public/${relative}`]) {
|
||||
try { const body = await readFile(path); return { ok: true, text: async () => body.toString("utf8") }; } catch { /* try next root */ }
|
||||
}
|
||||
return { ok: false, text: async () => "" };
|
||||
};
|
||||
const wasmBinary = await readFile(`${root}/build-wasm/linuxcnc-sim-core.wasm`);
|
||||
const rows = [];
|
||||
|
||||
for (const machine of MACHINE_DEFINITIONS.filter((entry) => entry.runtime === "generic-wasm")) {
|
||||
const core = await createModule({ wasmBinary });
|
||||
const session = new SimSession(core, { sessionId: machine.id, planner: "queue" });
|
||||
let seq = 0;
|
||||
const send = (kind, payload = {}) => session.accept({ schema_version: 1, context_id: CONTEXT_ID, session_id: machine.id, kind, seq: ++seq, operation_id: `${machine.id}-${seq}`, payload });
|
||||
send("HELLO"); send("SESSION_ATTACH");
|
||||
const bundle = await loadSimulationCase({ path: machine.entrypoint, fetchImpl });
|
||||
assert.equal(bundle.status, "ready", machine.id);
|
||||
const configuration = toWorkerConfiguration(bundle);
|
||||
const workspace = send("LOAD_WORKSPACE", { root_path: "/workspace", configuration });
|
||||
assert.equal(workspace.kind, "COMMAND_RESULT", machine.id);
|
||||
const loaded = send("PROGRAM_LOAD", { source: bundle.files[machine.program], path: machine.program });
|
||||
assert.equal(loaded.kind, "COMMAND_RESULT", `${machine.id}: ${loaded.payload?.code ?? "load"}`);
|
||||
assert.equal(send("PROGRAM_RUN").kind, "COMMAND_RESULT", machine.id);
|
||||
let last = null;
|
||||
for (let tick = 0; tick < 12000; tick += 1) {
|
||||
last = send("SIM_STEP", { cycles: 1 });
|
||||
assert.notEqual(last.kind, "ERROR", `${machine.id}: ${last.payload?.code ?? "step"}`);
|
||||
if (last.payload?.program?.program_status === "completed" && Number(last.payload?.wasm_motion?.state?.queue_depth ?? 0) === 0) break;
|
||||
}
|
||||
assert.equal(last?.payload?.program?.program_status, "completed", machine.id);
|
||||
const joints = last.payload.wasm_motion.state.joint_commanded;
|
||||
assert.equal(joints.length, machine.joint_count, machine.id);
|
||||
assert.ok(joints.every(Number.isFinite), machine.id);
|
||||
rows.push({ id: machine.id, kinematics: machine.kinematics, coordinates: machine.coordinates, program: machine.program, joints });
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({ schema: "generic-wasm-machine-cases.v1", status: "verified", case_count: rows.length, rows }));
|
||||
Reference in New Issue
Block a user