完善 xyzbc-trt 刀具偏置闭环

This commit is contained in:
mes123456
2026-07-02 09:41:10 -04:00
parent bb939644b9
commit 8fd9952dac
16 changed files with 15926 additions and 10971 deletions

View File

@@ -17,6 +17,11 @@ import {
import { getFiveAxisProfile } from "../../app/src/profiles/index.js";
import { createSimulationStore } from "../../app/src/state/store.js";
import { createLinuxCncTaskHalSdk } from "../../../wasm-port/runtime/sdk/src/linuxcnc-task-hal.js";
import { buildVismachModelState, XYZBC_TRT_VISMACH_PINS } from "../../app/src/runtime/vismach-model-state.js";
import {
applyToolCommandSequence,
createToolRuntimeState,
} from "../../app/src/runtime/tool-db-simulation.js";
const profile = getFiveAxisProfile();
@@ -30,6 +35,19 @@ assert.equal(profile.machineFileStaging.defaultProgramFilename, "xyzbc_switchkin
assert.equal(profile.panelSchema.id, "xyzbc-trt-switchkins-pyvcp");
assert.ok(profile.halPins.includes("xyzbc-trt-kins.x-offset"));
assert.ok(profile.halPins.includes("motion.switchkins-type"));
assert.deepEqual(profile.hal.halcmd.feedbackNets.map((net) => net.signal), [
"table-x",
"saddle-y",
"spindle-z",
"tilt-b",
"rotate-c",
]);
assert.deepEqual(profile.hal.halcmd.offsetNets.map((net) => net.target), [
"xyzbc-trt-kins.tool-offset",
"xyzbc-trt-gui.tool-offset",
"xyzbc-trt-gui.x-offset",
"xyzbc-trt-gui.z-offset",
]);
assert.deepEqual(profile.samplePrograms, [
"configs/sim/axis/vismach/5axis/table-rotary-tilting/demos/xyzbc_switchkins.ngc",
"configs/sim/axis/vismach/5axis/table-rotary-tilting/demos/boat-xyzbc.ngc",
@@ -80,6 +98,7 @@ assert.ok(staged.save.files.some((file) => file.sourceRel.endsWith("remap_subs/h
assert.ok(staged.save.gcodeSources.some((source) => source.filename === "xyzbc_switchkins.ngc"));
assert.ok(staged.save.gcodeSources.some((source) => source.filename === "boat-xyzbc.ngc"));
assert.equal(staged.save.files.some((file) => file.sourceRel.endsWith("xyzbc.var") && file.kind === "parameters"), true);
assert.equal(staged.save.files.find((file) => file.sourceRel.endsWith("xyzbc-trt.tbl")).text.includes("T2 P2 Z10 D8"), true);
const selectedPlan = selectMachineFileProgram(
staged.plan,
@@ -145,6 +164,58 @@ assert.equal(state.sessionName, "xyzbc-trt-web-session");
assert.equal(state.kinematicsRuntimeReadiness, null);
const storeStage = await store.stageMachineFiles({ storage: createMemorySessionStorage() });
const toolOffsetDb = applyToolCommandSequence(store.getState().toolDbSimulation, [
{ code: "T", toolNumber: 2 },
{ code: "M6" },
{ code: "G43", h: 2 },
]);
const toolRuntimeState = createToolRuntimeState(toolOffsetDb, {
fallbackToolLength: state.toolPreview.length,
});
assert.equal(toolRuntimeState.ready, true);
assert.equal(toolRuntimeState.activeOffsetApplied, true);
assert.equal(toolRuntimeState.activeToolNumber, 2);
assert.equal(toolRuntimeState.activePocket, 2);
assert.equal(toolRuntimeState.currentTool.offset.z, 10);
assert.equal(toolRuntimeState.currentTool.diameter, 8);
assert.equal(toolRuntimeState.kinematics.toolOffsetZ, 10);
assert.equal(toolRuntimeState.kinematics.halPin, "motion.tooloffset.z");
assert.deepEqual(toolRuntimeState.kinematics.downstreamPins, [
"xyzbc-trt-kins.tool-offset",
"xyzbc-trt-gui.tool-offset",
]);
assert.equal(toolRuntimeState.pathTool.id, 2);
assert.equal(toolRuntimeState.pathTool.pocket, 2);
assert.equal(toolRuntimeState.pathTool.length, 10);
assert.equal(toolRuntimeState.pathTool.diameter, 8);
assert.equal(toolRuntimeState.vismach.toolOffset, 10);
const vismachState = buildVismachModelState({
...state,
axisPose: { x: 12.5, y: -6.25, z: 3.75, b: 35, c: -90 },
toolPreview: { ...state.toolPreview, length: 84.019 },
toolRuntimeState,
});
assert.deepEqual(Object.keys(vismachState.pins), XYZBC_TRT_VISMACH_PINS);
assert.equal(vismachState.pins["table-x"], 12.5);
assert.equal(vismachState.pins["saddle-y"], -6.25);
assert.equal(vismachState.pins["spindle-z"], 3.75);
assert.equal(vismachState.pins["tilt-b"], 35);
assert.equal(vismachState.pins["rotate-c"], -90);
assert.equal(vismachState.pins["x-offset"], -20);
assert.equal(vismachState.pins["z-offset"], -15);
assert.equal(vismachState.pins["tool-offset"], 10);
assert.deepEqual(vismachState.transforms.table.sourcePins, ["table-x"]);
assert.deepEqual(vismachState.transforms.saddle.sourcePins, ["saddle-y"]);
assert.deepEqual(vismachState.transforms.spindle.sourcePins, ["spindle-z"]);
assert.deepEqual(vismachState.transforms.tilt.sourcePins, ["tilt-b"]);
assert.deepEqual(vismachState.transforms.rotary.sourcePins, ["rotate-c"]);
assert.deepEqual(vismachState.transforms.tool.sourcePins, ["tool-offset", "x-offset", "z-offset"]);
assert.equal(vismachState.transforms.tool.translate.x, -20);
assert.equal(vismachState.transforms.tool.translate.z, -25);
assert.equal(vismachState.halNets.length, 9);
assert.equal(vismachState.semanticBoundary, "web_threejs_vismach_equivalent_driven_by_xyzbc_trt_hal_pins");
const stagedState = store.getState();
assert.equal(storeStage.save.profileId, "xyzbc-trt");
assert.equal(stagedState.machineFileStaging.profileId, "xyzbc-trt");