|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| S | GetDrillCode () |
| Return the operation code for a drill operation. | |
| S | GetBoreCode () |
| Return the operation code for a bore operation. | |
| S | GetPocketCode () |
| Return the operation code for a pocket milling operation. | |
| S | GetHingeRectCode () |
| Return the operation code for a hinge rectangle operation. | |
| S | GetStrikeRectCode () |
| Return the operation code for a strike rectangle operation. | |
| S | GetSquaringCode () |
| Return the operation code for a squaring corners operation. | |
| S | CurrentSpindleSpeed () |
| Check if the spindle speed has changed and update the current speed tracker. | |
| S | CurrentTool () |
| Check if the active tool has changed and update the current tool tracker. | |
| S | ToolCall (tool_info, feed, speed, face) |
| Insert tool change, tool offset, feedrate, and spindle speed G-code into a gcode table. | |
| S | StopSpindle () |
| Conditionally insert a spindle stop command when the next operation uses a different tool. | |
| S | Bevel (y_cmd, d, z_depth, inv) |
| Calculate a beveled Z depth at a given Y position along a cut path. | |
| S | GetPlane () |
| Return axis label strings and working plane code for a given machine face. | |
| S | BuildShape () |
| Generate a complete G-code sequence for all operations in a shape. | |
| S | OrderOps () |
| Order a list of machining operations by weight and tool number. | |
| S | MakeHingeRect () |
| Generate G-code for milling a hinge recess rectangle. | |
| S | MakeStrikeRect () |
| Generate G-code for milling a strike plate rectangle. | |
| S | SquareCorners () |
| Generate G-code to square the corners of a previously milled rectangle. | |
| S | MakePocket () |
| Generate G-code for a pocket milling operation with semicircular ends. | |
| S | MakeDrill () |
| Generate G-code for a drill operation at one or more positions. | |
| S | MakeBore () |
| Generate G-code for a helical bore operation at a specified position. | |
| S Bevel | ( | y_cmd | , |
| d | , | ||
| z_depth | , | ||
| inv | ) |
Calculate a beveled Z depth at a given Y position along a cut path.
Applies a bevel angle to the nominal plunge depth based on how far the current Y position (y_cmd) has moved from the bevel reference position (start_y). The bevel offset is computed as the sine of the bevel angle times the Y distance traveled. If d is nil or zero, the original z_depth is returned unchanged. The inv parameter controls which direction the bevel slopes.
| start_y | (number) The Y reference position from which bevel is measured |
| y_cmd | (number) The current Y position for which to compute the beveled Z |
| d | (number|nil) Bevel angle in degrees, or 0/nil for no bevel |
| z_depth | (number) The nominal (unbeveled) Z plunge depth |
| inv | (number|nil) Bevel direction multiplier: 1 or -1. Defaults to 1 if nil |
| S BuildShape | ( | ) |
Generate a complete G-code sequence for all operations in a shape.
Resets the current tool tracker, orders all operations by weight and tool number via S:OrderOps(), then dispatches each operation to its corresponding generator function based on the operation's type field. The G-code lines from all operations are concatenated into a single flat array and returned. Supported operation types are DRILL, BORE, POCKET, H_RECT, S_RECT, and SQUARING. The current and next operation are tracked in S.current_op and S.next_op to support spindle stop decisions between operations.
| shape | (table) Array of operation parameter tables, each containing at minimum a 'type' field set to the appropriate operation code |
| S CurrentSpindleSpeed | ( | ) |
Check if the spindle speed has changed and update the current speed tracker.
Compares the requested spindle speed against S.CURRENT_SPINDLE. If different, updates S.CURRENT_SPINDLE to the new value and returns true to indicate the speed command should be output. Returns false if the speed is unchanged.
| spindle_speed | (number) The spindle speed to compare against the current speed |
| S CurrentTool | ( | ) |
Check if the active tool has changed and update the current tool tracker.
Compares the requested tool number against S.CURRENT_TOOL. If different, updates S.CURRENT_TOOL to the new value and returns true to indicate a tool change is required. Returns false if the tool is unchanged.
| tool | (number) The tool number to compare against the current tool |
Referenced by SetWheelData(), and WriteToolData().
| S GetBoreCode | ( | ) |
Return the operation code for a bore operation.
| S GetDrillCode | ( | ) |
Return the operation code for a drill operation.
| S GetHingeRectCode | ( | ) |
Return the operation code for a hinge rectangle operation.
| S GetPlane | ( | ) |
Return axis label strings and working plane code for a given machine face.
Maps the named cutting face to the appropriate G-code axis labels and arc plane selection code. This allows operation generators to write axis-agnostic G-code that works correctly regardless of which face of the part is being machined. The returned labels should be used in string.format() calls to build move commands. Mapping:
| side | (string) The face to cut on - 'Front', 'Back', 'Top', 'Bottom', 'Left', or 'Right' |
| S GetPocketCode | ( | ) |
Return the operation code for a pocket milling operation.
| S GetSquaringCode | ( | ) |
Return the operation code for a squaring corners operation.
| S GetStrikeRectCode | ( | ) |
Return the operation code for a strike rectangle operation.
| S MakeBore | ( | ) |
Generate G-code for a helical bore operation at a specified position.
Creates a helical boring cycle that incrementally plunges the tool in a circular path to reach the target depth. The tool spirals inward using G02 arc moves, stepping down by step_down increments each revolution until the full bore depth is reached. An additional EXTRA_BORE amount is added to the end depth to ensure full material removal. The working plane and movement directions are automatically determined from the side parameter.
| info | (table) Operation parameter table with the following keys:
|
| S MakeDrill | ( | ) |
Generate G-code for a drill operation at one or more positions.
Produces G-code for drilling multiple hole positions using one of four supported drill cycle types, selected by the info.drill_type field:
| info | (table) Operation parameter table with the following keys: |
| S MakeHingeRect | ( | ) |
Generate G-code for milling a hinge recess rectangle.
Creates toolpath G-code to mill out a hinge recess. The operation optionally uses a reversed tool to pre-cut the leading edge before switching to the primary milling tool. The profile pass cuts the rectangle boundary (with optional corner radii and bevel), followed by interior cleanup passes stepping down in Y from the top edge toward the bottom. Bevel angles are applied dynamically per move using S:Bevel(). Optional subroutine call strings can wrap the operation for use in parametric programs.
| info | (table) Operation parameter table with the following keys:
|
| S MakePocket | ( | ) |
Generate G-code for a pocket milling operation with semicircular ends.
Creates a pocket by incrementally plunging the tool while traversing a racetrack profile (rectangle with semicircular ends). The tool spirals to depth by advancing slightly in Z on each arc pass. The pocket profile consists of G02/G03 arc moves connecting the two semicircular ends, with straight G01 moves along the length. Depth is reached incrementally at a rate of tool_radius/5 per arc segment. Movement directions and the working plane are automatically determined from the side parameter.
| info | (table) Operation parameter table with the following keys:
|
| S MakeStrikeRect | ( | ) |
Generate G-code for milling a strike plate rectangle.
Creates toolpath G-code to mill out a strike plate recess. The operation begins by profiling the four edges of the rectangle, then cleans out the interior with successive back-and-forth passes stepping down in Y. Supports optional bevel angles and rounded corners. The working plane is selected automatically based on the side parameter. Unlike MakeHingeRect, this operation profiles all four edges (including the top) and does not support a reversed tool for edge cleanup.
| info | (table) Operation parameter table with the following keys:
|
| S OrderOps | ( | ) |
Order a list of machining operations by weight and tool number.
Sorts operations into an optimized execution sequence to minimize tool changes. Operations with a weight field are inserted first in ascending weight order. Among weighted operations, the last tool used is identified and any non-weighted operations sharing that tool are inserted next, reducing an unnecessary tool change. Remaining non-weighted operations are then appended grouped by tool number. Operations missing a type field are silently skipped.
| shape | (table) Array of operation tables as passed to S:BuildShape() |
| S SquareCorners | ( | ) |
Generate G-code to square the corners of a previously milled rectangle.
Uses a smaller tool to clean out the corner material left behind by the larger tool used to cut the parent rectangle. Supports both square corners (corner == 0 or nil) and rounded corners. When squaring a strike rectangle (sub_type == S.S_RECT), all four corners are squared; for hinge rectangles only the bottom two corners are addressed. The bevel reference and start positions are adjusted automatically based on sub_type. A safe rapid-in approach move precedes each corner plunge to protect the tool.
| info | (table) Operation parameter table with the following keys:
|
| S StopSpindle | ( | ) |
Conditionally insert a spindle stop command when the next operation uses a different tool.
Compares the tool number of the next operation (S.next_op) to the current operation (S.current_op). If they differ, or if there is no next operation, a spindle stop would be appropriate. The actual M5 D0 insertion is currently commented out in the implementation.
| gcode | (table) The G-code line array to which the stop command would be appended |
| S ToolCall | ( | tool_info | , |
| feed | , | ||
| speed | , | ||
| face | ) |
Insert tool change, tool offset, feedrate, and spindle speed G-code into a gcode table.
Checks whether the requested tool differs from the currently active tool using S:CurrentTool(). If a tool change is needed, generates the appropriate M6/G43 tool call sequence. For Right-side operations a G49 cancel and X positioning move are prepended. For Left-side operations a G53 machine-coordinate retract is used; otherwise a standard retract move is generated. Spindle speed is only output if it has changed from the current speed. The feedrate line is always appended when feed is non-nil, regardless of tool change. All generated lines are appended to the provided gcode table.
| gcode | (table) The G-code line array to append tool call lines into |
| tool_info | (table) Tool data table with keys: tool_number (number), dia (number), dir (number) |
| feed | (number|nil) Feedrate to set. If nil, no feedrate line is output |
| speed | (number) Spindle speed in RPM |
| face | (string) The cutting face - 'Left', 'Right', or other face name |