Advance simulation parity and 3-axis tutorial coverage
This commit is contained in:
45
web/worker/test_axis3_tutorial_sequence.mjs
Normal file
45
web/worker/test_axis3_tutorial_sequence.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
|
||||
import { fnv1a64 } from "./replay.mjs";
|
||||
import { loadSimulationCase, toWorkerConfiguration } from "../workspace/sim-case-loader.mjs";
|
||||
import { SimSession, CONTEXT_ID } from "./sim-session.mjs";
|
||||
|
||||
const CASE = "linuxcnc/configs/sim/axis/vismach/3axis-tutorial/3axis-tutorial.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 });
|
||||
const core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
|
||||
const session = new SimSession(core, { sessionId: "axis3-tutorial-sequence" });
|
||||
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
|
||||
let seq = 0;
|
||||
const rows = [];
|
||||
const send = (operation, kind, payload = {}) => {
|
||||
const response = session.accept({ ...base, kind, seq: ++seq, operation_id: operation, payload });
|
||||
rows.push({ operation, kind, seq, tick: response.simulation_tick ?? session.tick, response_kind: response.kind, status: response.payload?.status ?? null, code: response.payload?.code ?? null, state_hash: response.payload?.state_hash ?? response.payload?.snapshot?.state_hash ?? null });
|
||||
return response;
|
||||
};
|
||||
send("HELLO", "HELLO"); send("SESSION_ATTACH", "SESSION_ATTACH");
|
||||
const loaded = send("LOAD_WORKSPACE", "LOAD_WORKSPACE", { root_path: "/workspace", configuration: toWorkerConfiguration(bundle) });
|
||||
assert.equal(loaded.payload.configuration.state, "TASK_READY");
|
||||
assert.equal(send("HOME_Z", "HOME", { axis: "z" }).payload.status, "verified");
|
||||
assert.equal(send("HOME_X", "HOME", { axis: "x" }).payload.status, "verified");
|
||||
assert.equal(send("HOME_Y", "HOME", { axis: "y" }).payload.status, "verified");
|
||||
send("JOG_X", "JOG_START", { axis: "x", direction: 1, speed: 2 });
|
||||
send("JOG_X_TICK", "SIM_STEP", { cycles: 10 });
|
||||
send("JOG_STOP", "JOG_STOP");
|
||||
send("PROGRAM_LOAD", "PROGRAM_LOAD", { path: "sequence.ngc", source: "G21 G90\nG0 X0 Y0 Z0\nG1 X1 Y1 F60\nG1 Z-1\nG1 X2\nM2\n" });
|
||||
assert.equal(send("PROGRAM_RUN", "PROGRAM_RUN").payload.task.state, "RUNNING");
|
||||
const checkpoint = send("CHECKPOINT", "CHECKPOINT").payload.checkpoint;
|
||||
send("PROGRAM_TICK", "SIM_STEP", { cycles: 1 });
|
||||
send("PROGRAM_PAUSE", "PROGRAM_PAUSE");
|
||||
send("PROGRAM_RESUME", "PROGRAM_RESUME");
|
||||
send("PROGRAM_ABORT", "PROGRAM_ABORT");
|
||||
send("PROGRAM_RESTART", "PROGRAM_RESTART");
|
||||
send("TOOL_PREPARE_T1", "TOOL_PREPARE", { tool: 1, pocket: 1 });
|
||||
send("TOOL_PREPARED_T1", "TOOL_PREPARED", { prepared: true });
|
||||
send("TOOL_CHANGE_T1", "TOOL_CHANGE");
|
||||
send("TOOL_CHANGED_T1", "TOOL_CHANGED", { changed: true });
|
||||
const endpoint = session.workspacePackageState();
|
||||
assert.ok(checkpoint.checkpoint_hash);
|
||||
assert.ok(endpoint.state_hash);
|
||||
console.log(JSON.stringify({ schema: "axis3-tutorial-sequence.v1", status: "verified", case: CASE, operations: rows, checkpoint_hash: checkpoint.checkpoint_hash, endpoint_hash: endpoint.state_hash, sequence_hash: fnv1a64(rows), first_error: rows.find((row) => row.response_kind === "ERROR") ?? null }));
|
||||
Reference in New Issue
Block a user