Complete XYZAC LinuxCNC WASM parity and smooth 3D preview
This commit is contained in:
59
web/react/src/xyzac-panel-contract.ts
Normal file
59
web/react/src/xyzac-panel-contract.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import type { XyzacCapabilitySnapshot, XyzacKinematicsSnapshot } from "./protocol";
|
||||
|
||||
export const XYZAC_CASE = "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini" as const;
|
||||
export const XYZAC_AXES = ["x", "y", "z", "a", "c"] as const;
|
||||
export const XYZAC_COMMANDS = {
|
||||
power: "POWER",
|
||||
selectKinematics: "KINEMATICS_SELECT",
|
||||
clearVisual: "VISUAL_CLEAR",
|
||||
} as const;
|
||||
export const XYZAC_KINEMATICS = [
|
||||
{ type: 0, action: "switchkinsIdentity", label: "Identity", mcode: "M429" },
|
||||
{ type: 1, action: "switchkinsXyzac", label: "TCP: XYZAC", mcode: "M428" },
|
||||
{ type: 2, action: "switchkinsUserk", label: "User K", mcode: "M430" },
|
||||
] as const;
|
||||
|
||||
export type XyzacGate = { action: string; enabled: boolean; reason: string; required_type?: number; visual_only?: boolean };
|
||||
export type XyzacOperationTrace = { operation_id?: string; kind?: string; action?: string | null; phase?: string; reason?: string; response_kind?: string };
|
||||
export type XyzacPanelView = {
|
||||
status: "ready" | "unavailable";
|
||||
tick: number;
|
||||
stateHash: string;
|
||||
kinematics: XyzacKinematicsSnapshot | null;
|
||||
capability: XyzacCapabilitySnapshot | null;
|
||||
pose: XyzacKinematicsSnapshot["pose"] | null;
|
||||
joints: number[];
|
||||
gates: Record<string, XyzacGate>;
|
||||
recovery: Record<string, unknown> | null;
|
||||
};
|
||||
|
||||
type XyzacPanelSource = {
|
||||
simulation_tick?: number;
|
||||
state_hash?: string;
|
||||
kinematics?: XyzacKinematicsSnapshot;
|
||||
xyzac?: XyzacCapabilitySnapshot;
|
||||
gates?: Record<string, XyzacGate>;
|
||||
authoritative?: Record<string, unknown>;
|
||||
visual?: { pose?: Record<string, number>; joints?: number[] };
|
||||
};
|
||||
|
||||
export function projectXyzacPanel(snapshot: XyzacPanelSource | null | undefined): XyzacPanelView {
|
||||
const kinematics = snapshot?.kinematics?.coordinates === "XYZAC" && snapshot.kinematics.joint_count === 5 ? snapshot.kinematics : null;
|
||||
const capability = snapshot?.xyzac?.coordinates === "XYZAC" && snapshot.xyzac.joint_count === 5 ? snapshot.xyzac : null;
|
||||
const visualPose = snapshot?.visual?.pose;
|
||||
const pose = visualPose && [visualPose.x, visualPose.y, visualPose.z, visualPose.a, visualPose.c].every((value) => Number.isFinite(value))
|
||||
? { ...(kinematics?.pose ?? { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, u: 0, v: 0, w: 0 }), ...visualPose }
|
||||
: kinematics?.pose ?? null;
|
||||
const joints = snapshot?.visual?.joints?.length === 5 ? snapshot.visual.joints.slice(0, 5) : kinematics?.joints ? [...kinematics.joints] : [];
|
||||
return {
|
||||
status: kinematics && capability ? "ready" : "unavailable",
|
||||
tick: snapshot?.simulation_tick ?? 0,
|
||||
stateHash: snapshot?.state_hash ?? "",
|
||||
kinematics,
|
||||
capability,
|
||||
pose,
|
||||
joints,
|
||||
gates: snapshot?.gates ?? {},
|
||||
recovery: (snapshot?.authoritative?.recovery as Record<string, unknown> | undefined) ?? null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user