17 lines
1.2 KiB
JavaScript
17 lines
1.2 KiB
JavaScript
import catalog from "./machine-catalog.json" with { type: "json" };
|
|
|
|
export const MACHINE_DEFINITIONS = Object.freeze(catalog.machines.map((entry) => {
|
|
if (!entry.id || !entry.entrypoint || !entry.program || !entry.source_path || !["XYZAC", "XYZBC"].includes(entry.coordinates)) throw new Error("machine_catalog_invalid");
|
|
return Object.freeze({ ...entry, label: `${entry.coordinates} TRT`, axes: [...entry.coordinates.toLowerCase()], joint_count: entry.coordinates.length, runtime: "trt" });
|
|
}));
|
|
if (new Set(MACHINE_DEFINITIONS.map((entry) => entry.id)).size !== MACHINE_DEFINITIONS.length) throw new Error("machine_catalog_duplicate");
|
|
export const DEFAULT_MACHINE = MACHINE_DEFINITIONS.find((entry) => entry.id === catalog.default_machine);
|
|
if (!DEFAULT_MACHINE) throw new Error("machine_catalog_default_missing");
|
|
export function machineDefinition(value) {
|
|
return MACHINE_DEFINITIONS.find((entry) => [entry.id, entry.entrypoint, entry.coordinates].includes(value)) ?? null;
|
|
}
|
|
export function machineAxes(snapshot) {
|
|
const coordinates = snapshot?.kinematics?.coordinates ?? snapshot?.visual?.machine_model?.coordinate_system;
|
|
return machineDefinition(coordinates)?.axes ?? DEFAULT_MACHINE.axes;
|
|
}
|