Loading files
export type Operation = "rectangle" | "drill-grid";
export type Units = "mm" | "in";
type ToolParams = {
feedrate: number;
plungeRate: number;
spindleRpm: number;
safeZ: number;
units: Units;
};
export type RectangleParams = ToolParams & {
operation: "rectangle";
width: number;
height: number;
depth: number;
};
export type DrillGridParams = ToolParams & {
operation: "drill-grid";
cols: number;
rows: number;
spacingX: number;
spacingY: number;
depth: number;
};
export type GcodeParams = RectangleParams | DrillGridParams;
const unitsCode = (units: Units) => (units === "in" ? "G20" : "G21");
const generateRectangleProfile = ({
width,
height,
depth,
feedrate,
plungeRate,
spindleRpm,
safeZ,
units,
}: RectangleParams): string =>
[
"(Basic CAM - Rectangle profile)",
"(Generated by gSender Basic CAM plugin)",
unitsCode(units),
"G90",
`M3 S${spindleRpm}`,
`G0 Z${safeZ}`,
"G0 X0 Y0",
`G1 F${plungeRate} Z-${depth}`,
`G1 F${feedrate} X${width} Y0`,
`G1 X${width} Y${height}`,
`G1 X0 Y${height}`,
"G1 X0 Y0",
`G0 Z${safeZ}`,
"M5",
"M2",
].join("\n");
const generateDrillGrid = ({
cols,
rows,
spacingX,
spacingY,
depth,
plungeRate,
spindleRpm,
safeZ,
units,
}: DrillGridParams): string => {
const c = Math.max(1, Math.floor(cols));
const r = Math.max(1, Math.floor(rows));
const lines = [
"(Basic CAM - Drill grid)",
"(Generated by gSender Basic CAM plugin)",
unitsCode(units),
"G90",
`M3 S${spindleRpm}`,
`G0 Z${safeZ}`,
`G1 F${plungeRate}`,
];
for (let row = 0; row < r; row += 1) {
for (let col = 0; col < c; col += 1) {
const x = col * spacingX;
const y = row * spacingY;
lines.push(`G0 X${x} Y${y}`);
lines.push(`G1 Z-${depth}`);
lines.push(`G0 Z${safeZ}`);
}
}
lines.push("M5", "M2");
return lines.join("\n");
};
export const generateGcode = (params: GcodeParams): string =>
params.operation === "drill-grid"
? generateDrillGrid(params)
: generateRectangleProfile(params);
c8108e1c4This file is pinned to the selected release. Download the original to open it in your design tool.