Add AXIS state and gate contracts
This commit is contained in:
34
web/app/test_axis_contract.mjs
Normal file
34
web/app/test_axis_contract.mjs
Normal file
@@ -0,0 +1,34 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { AXIS_BOUNDARIES, AXIS_COMMANDS, axisGate, axisGateMatrix, normalizeAxisState } from "./axis-contract.mjs";
|
||||
|
||||
const ready = { task: { state: "ON", interp_state: "IDLE", mode: "MANUAL" }, taskfile: "main.ngc", motion: { mode: "COORD", homed: [true, true, true] }, devices: { tool: { current: 1 } } };
|
||||
assert.equal(normalizeAxisState(ready).taskState, "ON");
|
||||
assert.equal(axisGate("run", ready).enabled, true);
|
||||
assert.equal(axisGate("jogStart", ready).enabled, true);
|
||||
assert.equal(axisGate("touchOff", ready).enabled, true);
|
||||
assert.equal(axisGate("toolTouchOff", ready).enabled, true);
|
||||
|
||||
const running = { ...ready, task: { ...ready.task, interp_state: "READING" } };
|
||||
assert.equal(axisGate("run", running).enabled, false);
|
||||
assert.equal(axisGate("pause", running).enabled, true);
|
||||
assert.equal(axisGate("stop", running).enabled, true);
|
||||
assert.equal(axisGate("jogStart", running).reason, "axis_manual_state_gate");
|
||||
|
||||
const paused = { ...ready, task: { ...ready.task, interp_state: "PAUSED" } };
|
||||
assert.equal(axisGate("resume", paused).enabled, true);
|
||||
assert.equal(axisGate("pause", paused).enabled, false);
|
||||
|
||||
const estop = { ...ready, task: { ...ready.task, state: "ESTOP" } };
|
||||
assert.equal(axisGate("estop", estop).enabled, true);
|
||||
assert.equal(axisGate("jogStart", estop).reason, "axis_estop_active");
|
||||
|
||||
const queueFull = { ...ready, task: { ...ready.task, mode: "MDI", queued_mdi_commands: 10, max_queued_mdi_commands: 10 } };
|
||||
assert.equal(axisGate("mdi", queueFull).enabled, false);
|
||||
assert.equal(axisGate("mdi", queueFull).reason, "axis_mdi_queue_full");
|
||||
|
||||
const limit = { ...ready, motion: { ...ready.motion, on_any_limit: true } };
|
||||
assert.equal(axisGate("overrideLimits", limit).enabled, true);
|
||||
assert.equal(axisGateMatrix(ready).run.reason, "axis_run_available");
|
||||
assert.equal(AXIS_COMMANDS.run, "PROGRAM_RUN");
|
||||
assert.equal(AXIS_BOUNDARIES.physicalHardware, "REAL-EXCLUDED");
|
||||
console.log(JSON.stringify({ schema: "axis-contract-sample.v1", status: "verified", commands: Object.keys(AXIS_COMMANDS).length, matrix: Object.keys(axisGateMatrix(ready)).length, blocked_reasons: [axisGate("mdi", queueFull).reason, axisGate("jogStart", estop).reason] }));
|
||||
Reference in New Issue
Block a user