完成 xyzbc-trt working 任务复核

This commit is contained in:
mes123456
2026-07-02 23:53:51 -04:00
parent b279fa17fd
commit 2722fe7f3c
33 changed files with 376795 additions and 171883 deletions

View File

@@ -25,6 +25,7 @@ import {
applyToolCommandSequence,
createToolDbReadiness,
createToolDbSimulation,
createToolRuntimeState,
editToolEntry,
extractToolCommandSequenceFromProgram,
listToolEntries,
@@ -46,6 +47,7 @@ import {
normalizeLinuxCncTaskMode,
} from "./linuxcnc-task-policy.js";
import { buildProgramExecutionTiming, timingAtMotionIndex } from "../runtime/execution-timing.js";
import { buildAxisPreviewPathFromProgram } from "../runtime/axis-preview-path.js";
const defaultProfile = getFiveAxisProfile("xyzbc-trt");
@@ -57,9 +59,9 @@ const initialControlledUserMSimulation = createControlledUserMSimulation();
const MACHINE_PROJECT_OPFS_ROOT = "web-rtcp-5axis-xyzbc-trt-sim-plan/machines";
const initialAxisPose = {
x: 43.0,
y: -32.15,
z: -11.306,
x: 0.0,
y: 0.0,
z: 0.0,
a: 0.0,
b: 0.0,
c: 0.0,
@@ -183,9 +185,9 @@ const initialState = {
axisPose: initialAxisPose,
jointPose: [],
tcpPose: {
x: 43.0,
y: -32.15,
z: -11.306,
x: 0.0,
y: 0.0,
z: 0.0,
a: 0.0,
c: 0.0,
},
@@ -202,6 +204,7 @@ const initialState = {
interpreterRuntimeReadiness: null,
programExecution: null,
programExecutionTiming: null,
programAxisPreviewPath: null,
programElapsedSeconds: 0,
programRemainingSeconds: 0,
programExecutionSourceMode: "fixture-line-playback",
@@ -224,6 +227,9 @@ const initialState = {
machineFileExecution: null,
toolDbSimulation: null,
toolDbReadiness: createToolDbReadiness(null),
toolRuntimeState: createToolRuntimeState(null, {
fallbackToolLength: 84.019,
}),
controlledUserMSimulation: initialControlledUserMSimulation,
controlledUserMReadiness: createControlledUserMReadiness(initialControlledUserMSimulation),
fullExecutionBoundary: null,
@@ -242,9 +248,9 @@ const initialState = {
missing: ["LinuxCNC INI not loaded"],
},
dro: {
x: 43.0,
y: -32.15,
z: -11.306,
x: 0.0,
y: 0.0,
z: 0.0,
a: 0.0,
b: 0.0,
c: 0.0,
@@ -374,6 +380,22 @@ export function createSimulationStore(seed = {}) {
dro: buildDroFromFrame(seedFrame, seed.programRuntimeFeedback || initialState.programRuntimeFeedback),
programLines: seed.programLines || programLines,
};
const initialAxisPreviewPath = seed.programAxisPreviewPath === undefined
? buildAxisPreviewPathFromProgram({
filename: state.activeProgram,
sourceRel: state.programSourceRel,
content: state.programLines.join("\n"),
tool: currentPathTool(state),
})
: seed.programAxisPreviewPath;
state = {
...state,
programAxisPreviewPath: initialAxisPreviewPath,
preview: {
...state.preview,
pathPoints: initialAxisPreviewPath?.sampleCount || state.preview.pathPoints,
},
};
state.linuxCncTaskPolicy = createLinuxCncTaskPolicyStatus(state);
state.machineProject = createMachineProjectState(state);
state.programValidation = createProgramValidationState(state);
@@ -552,6 +574,9 @@ export function createSimulationStore(seed = {}) {
kinematicsExecutionContext: "none",
toolDbSimulation: null,
toolDbReadiness: createToolDbReadiness(null),
toolRuntimeState: createToolRuntimeState(null, {
fallbackToolLength: state.toolPreview?.length,
}),
...createInitialControlledUserMState(),
linuxCncIniConfig: null,
iniConfigReadiness: initialState.iniConfigReadiness,
@@ -710,7 +735,7 @@ export function createSimulationStore(seed = {}) {
rtcpState: rtcpStateFromKinsType(firstKinsType),
preview: {
...state.preview,
pathPoints: Math.max(execution.summary.motionEventCount, 1),
pathPoints: state.programAxisPreviewPath?.sampleCount || Math.max(execution.summary.motionEventCount, 1),
},
feed: {
...state.feed,
@@ -738,6 +763,10 @@ export function createSimulationStore(seed = {}) {
programRuntimeFeedback: null,
programLineExecution: {},
interpreterExecutionPending: false,
preview: {
...state.preview,
pathPoints: state.programAxisPreviewPath?.sampleCount || state.preview.pathPoints,
},
operatorMessage: `LinuxCNC interpreter blocked: ${action.error}`,
});
break;
@@ -945,6 +974,15 @@ export function createSimulationStore(seed = {}) {
programText: selectedFile.text,
sourceRel: selectedFile.sourceRel,
});
const axisPreviewPath = buildAxisPreviewPathFromProgram({
filename: selectedFile.sourceRel,
sourceRel: selectedFile.sourceRel,
content: selectedFile.text,
tool: currentPathTool({
...state,
toolRuntimeState: toolUserPatch.toolRuntimeState,
}),
});
setState({
...loadedProgram,
...toolUserPatch,
@@ -959,11 +997,12 @@ export function createSimulationStore(seed = {}) {
},
axisPose: initialAxisPose,
runState: "idle",
programAxisPreviewPath: axisPreviewPath,
programRuntimeFeedback: null,
programLineExecution: {},
preview: {
...state.preview,
pathPoints: Math.max(loadedProgram.programLines.length, 1),
pathPoints: axisPreviewPath?.sampleCount || Math.max(loadedProgram.programLines.length, 1),
},
operatorMessage: `loaded LinuxCNC 5-axis source ${selectedFile.sourceRel}`,
});
@@ -1466,10 +1505,23 @@ export function createSimulationStore(seed = {}) {
const toolDbSimulation = state.toolDbSimulation && toolCommands.length > 0
? applyToolCommandSequence(state.toolDbSimulation, toolCommands)
: state.toolDbSimulation;
const toolRuntimeState = createToolRuntimeState(toolDbSimulation, {
fallbackToolLength: state.toolPreview?.length,
});
const axisPreviewPath = buildAxisPreviewPathFromProgram({
filename: loadedProgram.activeProgram,
sourceRel: loadedProgram.programSourceRel,
content: action.content,
tool: currentPathTool({
...state,
toolRuntimeState,
}),
});
setState({
...loadedProgram,
toolDbSimulation,
toolDbReadiness: createToolDbReadiness(toolDbSimulation),
toolRuntimeState,
machine: {
...state.machine,
mode: "auto",
@@ -1480,11 +1532,12 @@ export function createSimulationStore(seed = {}) {
},
axisPose: initialAxisPose,
runState: "idle",
programAxisPreviewPath: axisPreviewPath,
programRuntimeFeedback: null,
programLineExecution: {},
preview: {
...state.preview,
pathPoints: Math.max(loadedProgram.programLines.length, 1),
pathPoints: axisPreviewPath?.sampleCount || Math.max(loadedProgram.programLines.length, 1),
},
operatorMessage: `loaded ${loadedProgram.activeProgram}`,
});
@@ -2182,6 +2235,9 @@ export function createSimulationStore(seed = {}) {
setState({
toolDbSimulation,
toolDbReadiness: createToolDbReadiness(toolDbSimulation),
toolRuntimeState: createToolRuntimeState(toolDbSimulation, {
fallbackToolLength: state.toolPreview?.length,
}),
operatorMessage: `tool DB edited T${patch.toolNumber ?? patch.toolno ?? "-"}`,
});
return state.toolDbSimulation;
@@ -2195,6 +2251,9 @@ export function createSimulationStore(seed = {}) {
setState({
toolDbSimulation: save.toolDb,
toolDbReadiness: createToolDbReadiness(save.toolDb),
toolRuntimeState: createToolRuntimeState(save.toolDb, {
fallbackToolLength: state.toolPreview?.length,
}),
operatorMessage: `tool DB saved ${save.path} (${save.storageMode})`,
});
return save;
@@ -2726,6 +2785,9 @@ function createToolDbStatePatchFromStagedFiles({ profile, save }) {
return {
toolDbSimulation: null,
toolDbReadiness: createToolDbReadiness(null),
toolRuntimeState: createToolRuntimeState(null, {
fallbackToolLength: 84.019,
}),
};
}
const toolTable = parseLinuxCncToolTable(toolTableFile.text, {
@@ -2740,6 +2802,9 @@ function createToolDbStatePatchFromStagedFiles({ profile, save }) {
return {
toolDbSimulation,
toolDbReadiness: createToolDbReadiness(toolDbSimulation),
toolRuntimeState: createToolRuntimeState(toolDbSimulation, {
fallbackToolLength: 84.019,
}),
};
}
@@ -2759,6 +2824,9 @@ function createProgramToolUserSimulationPatch({ state, programText, sourceRel })
return {
toolDbSimulation,
toolDbReadiness: createToolDbReadiness(toolDbSimulation),
toolRuntimeState: createToolRuntimeState(toolDbSimulation, {
fallbackToolLength: state.toolPreview?.length,
}),
controlledUserMSimulation: userMScan.simulation,
controlledUserMReadiness: createControlledUserMReadiness(userMScan.simulation),
};
@@ -4003,6 +4071,35 @@ function buildLoadedProgram(action) {
};
}
function currentPathTool(state) {
const pathTool = state.toolRuntimeState?.pathTool;
if (
pathTool &&
(
Number(pathTool.id) > 0 ||
Number(pathTool.pocket) > 0 ||
Number(pathTool.length) > 0 ||
Number(pathTool.diameter) > 0
)
) {
return pathTool;
}
if (state.machineProfile === "xyzbc-trt") {
return {
id: 2,
pocket: 2,
length: 10,
diameter: 8,
};
}
return {
id: Number(state.toolPreview?.toolNumber) || 2,
pocket: Number(state.toolPreview?.toolNumber) || 2,
length: Number(state.toolPreview?.length) || 10,
diameter: Number(state.toolPreview?.diameter) || 8,
};
}
function parseProgramLines(content) {
const lines = content
.split(/\r?\n/)