Align AXIS Web control lifecycle with LinuxCNC
This commit is contained in:
@@ -118,9 +118,8 @@ function projection(result: Record<string, unknown>, message: MessageEnvelope, p
|
||||
};
|
||||
}
|
||||
if (panel?.schema === "axis-panel-snapshot.v1") {
|
||||
const visualSegments = (Array.isArray(panel.visual.toolpath) ? panel.visual.toolpath : previous.toolpath)
|
||||
.filter((segment) => segment && typeof segment === "object" && Number.isSafeInteger((segment as { id?: unknown }).id ?? 0))
|
||||
.map((segment, index) => {
|
||||
const visualSegments = Array.isArray(panel.visual.toolpath)
|
||||
? panel.visual.toolpath.filter((segment) => segment && typeof segment === "object" && Number.isSafeInteger((segment as { id?: unknown }).id ?? 0)).map((segment, index) => {
|
||||
const value = segment as Record<string, unknown>;
|
||||
return {
|
||||
id: Number(value.id ?? index + 1),
|
||||
@@ -142,7 +141,8 @@ function projection(result: Record<string, unknown>, message: MessageEnvelope, p
|
||||
...(typeof value.turn === "number" ? { turn: value.turn } : {}),
|
||||
active: value.id === panel.visual.active_segment_id,
|
||||
};
|
||||
});
|
||||
})
|
||||
: previous.toolpath;
|
||||
const pose = panel.visual.pose;
|
||||
const axes = [pose.x, pose.y, pose.z, pose.a, pose.c].map((value) => Number.isFinite(value) ? value : 0);
|
||||
const snapshot = {
|
||||
@@ -203,10 +203,10 @@ function projection(result: Record<string, unknown>, message: MessageEnvelope, p
|
||||
].filter((segment): segment is NonNullable<typeof segment> & { id: number; start: Record<string, number>; end: Record<string, number> } => Number.isSafeInteger(segment.id) && Boolean(segment.start) && Boolean(segment.end));
|
||||
const command = String(result.command ?? "");
|
||||
const visualClear = command === "VISUAL_CLEAR";
|
||||
const resetPath = visualClear || command === "PROGRAM_LOAD" || command === "PROGRAM_RESTART";
|
||||
const resetPath = command === "PROGRAM_LOAD" || command === "PROGRAM_RESTART";
|
||||
const known = resetPath ? new Set<number>() : new Set(previous.toolpath.map((segment) => segment.id));
|
||||
const nextToolpath = resetPath
|
||||
? visualClear ? [] : previewSegments.map((segment, index) => ({ ...segment, id: index + 1, source_line: typeof segment.source_line === "number" ? segment.source_line : null, start: segment.start as Record<string, number>, end: segment.end as Record<string, number>, active: false }))
|
||||
? previewSegments.map((segment, index) => ({ ...segment, id: index + 1, source_line: typeof segment.source_line === "number" ? segment.source_line : null, start: segment.start as Record<string, number>, end: segment.end as Record<string, number>, active: false }))
|
||||
: previous.toolpath.map((segment) => ({ ...segment, start: { ...segment.start }, end: { ...segment.end } }));
|
||||
for (const segment of plannerSegments) {
|
||||
if (!known.has(segment.id)) nextToolpath.push({ id: segment.id, source_line: segment.source_line, start: segment.start, end: segment.end, active: segment.id === planner?.active?.id });
|
||||
@@ -224,7 +224,14 @@ function projection(result: Record<string, unknown>, message: MessageEnvelope, p
|
||||
active_progress: 0,
|
||||
motion_trace: [],
|
||||
}
|
||||
: previous.snapshot?.visual;
|
||||
: visualClear && previous.snapshot?.visual
|
||||
? {
|
||||
...previous.snapshot.visual,
|
||||
toolpath: nextToolpath,
|
||||
live_path_epoch: Number(result.live_path_epoch ?? previous.snapshot.visual.live_path_epoch ?? 0),
|
||||
motion_trace: [],
|
||||
}
|
||||
: previous.snapshot?.visual;
|
||||
const snapshot = { simulation_tick: message.simulation_tick ?? previous.tick, state_hash: String(result.state_hash ?? previous.snapshot?.state_hash ?? ""), task: result.task as SimSnapshotV1["task"], motion: { axes, joints, velocity: Array.isArray(motionState.velocity) ? motionState.velocity as number[] : [], homed: typeof motionState.homed === "boolean" ? motionState.homed : undefined, homed_axes: Array.isArray(motionState.homed_axes) ? motionState.homed_axes as boolean[] : undefined }, overrides: (result.overrides as SimSnapshotV1["overrides"]) ?? previous.snapshot?.overrides, authoritative, ...(visual ? { visual } : {}) } satisfies SimSnapshotV1;
|
||||
return { snapshot, toolpath: nextToolpath, task: (result.task as Record<string, unknown>) ?? previous.task, program: programResult as Record<string, unknown> ?? previous.program, devices: (result.devices as Record<string, unknown>) ?? previous.devices, deviceIo: (result.device_io as Record<string, unknown>) ?? previous.deviceIo, hal: (result.hal_runtime as Record<string, unknown>) ?? previous.hal, plc: (result.plc as Record<string, unknown>) ?? previous.plc, python: (result.python as Record<string, unknown>) ?? previous.python, ioAck: (result.io_ack as Record<string, unknown>) ?? previous.ioAck, axisState: (result.axis_state as AxisStateView) ?? previous.axisState, gates: (result.gates as FrontendState["gates"]) ?? previous.gates, executionTrace };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user