Complete XYZAC LinuxCNC WASM parity and smooth 3D preview
This commit is contained in:
75
web/worker/test_xyzac_trt_case.mjs
Normal file
75
web/worker/test_xyzac_trt_case.mjs
Normal file
@@ -0,0 +1,75 @@
|
||||
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 { XYZAC_TRT_SOURCE_SLICES } from "../workspace/xyzac-trt-source-slices.mjs";
|
||||
import { SimSession, CONTEXT_ID } from "./sim-session.mjs";
|
||||
|
||||
const CASE = "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini";
|
||||
const fetchImpl = async (url) => {
|
||||
try {
|
||||
const body = await readFile(new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url));
|
||||
return { ok: true, text: async () => body.toString("utf8") };
|
||||
} catch {
|
||||
return { ok: false, text: async () => "" };
|
||||
}
|
||||
};
|
||||
|
||||
const bundle = await loadSimulationCase({ path: CASE, fetchImpl });
|
||||
assert.equal(bundle.status, "ready");
|
||||
assert.deepEqual(bundle.missing, []);
|
||||
assert.ok(bundle.runtime_fixtures.some((fixture) => fixture.generated_hal?.endsWith("xyzac-trt-headless_cmds.hal")));
|
||||
|
||||
const core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
|
||||
const session = new SimSession(core, { sessionId: "xyzac-trt-case" });
|
||||
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
|
||||
let seq = 0;
|
||||
const send = (kind, operationId, payload = {}) => session.accept({ ...base, kind, seq: ++seq, operation_id: operationId, payload });
|
||||
|
||||
send("HELLO", "hello");
|
||||
send("SESSION_ATTACH", "attach");
|
||||
const loaded = send("LOAD_WORKSPACE", "workspace", { root_path: "/workspace", configuration: toWorkerConfiguration(bundle) });
|
||||
assert.equal(loaded.kind, "COMMAND_RESULT");
|
||||
assert.equal(loaded.payload.status, "verified");
|
||||
assert.equal(loaded.payload.motion_authority, "wasm");
|
||||
assert.equal(loaded.payload.configuration.state, "TASK_READY");
|
||||
assert.equal(loaded.payload.panel_snapshot.kinematics.joint_count, 5);
|
||||
|
||||
const switchRows = [];
|
||||
for (const [code, expected] of [["M429", 0], ["M428", 1], ["M430", 2]]) {
|
||||
const result = send("MDI_EXECUTE", `mdi-${code}`, { block: code });
|
||||
assert.equal(result.kind, "COMMAND_RESULT");
|
||||
assert.equal(result.payload.status, "verified");
|
||||
assert.equal(result.payload.kinematics.active_type, expected);
|
||||
assert.equal(result.payload.remap.hal_pin, "motion.switchkins-type");
|
||||
assert.equal(result.payload.remap.sync, "M66 E0 L0");
|
||||
switchRows.push({ code, tick: result.simulation_tick, active_type: expected, state_hash: result.payload.panel_snapshot.state_hash });
|
||||
}
|
||||
|
||||
const pose = session.xyzacKinematics.forward([100, 50, 100, 30, 45]);
|
||||
assert.equal(pose.status, "verified");
|
||||
assert.equal(pose.joint_count, 5);
|
||||
assert.ok(Number.isFinite(pose.pose.x) && Number.isFinite(pose.pose.y) && Number.isFinite(pose.pose.z));
|
||||
|
||||
const sourceSliceIds = new Set(XYZAC_TRT_SOURCE_SLICES.slices.map((slice) => slice.slice_id));
|
||||
const controls = [
|
||||
...XYZAC_TRT_SOURCE_SLICES.axis_controls.menus,
|
||||
...XYZAC_TRT_SOURCE_SLICES.axis_controls.toolbar,
|
||||
...XYZAC_TRT_SOURCE_SLICES.axis_controls.keyboard_bindings,
|
||||
];
|
||||
assert.ok(controls.length >= 110);
|
||||
assert.ok(controls.every((control) => sourceSliceIds.has(control.slice_id)));
|
||||
|
||||
console.log(JSON.stringify({
|
||||
schema: "xyzac-trt-wasm-worker-trace.v1",
|
||||
status: "verified",
|
||||
case: CASE,
|
||||
configuration: loaded.payload.configuration.state,
|
||||
motion_authority: loaded.payload.motion_authority,
|
||||
control_count: controls.length,
|
||||
switchkins: switchRows,
|
||||
pose: pose.pose,
|
||||
wasm_state_hash: pose.wasm_state_hash,
|
||||
state_hash: pose.state_hash,
|
||||
first_divergent_tick: null,
|
||||
}));
|
||||
Reference in New Issue
Block a user