This documentation outlines the methods available through the HaasGCodeGenerator
JavaScript class, allowing you to generate HAAS-compatible G-code from simple JS logic. It supports multiple tool types with parameter-based feed/speed selection.
end_mill
face_mill
drill
tap
(requires pitch
)thread_mill
(requires threadDirection
)Each tool type will have relevant machining data for RPM and feedrate calculation depending on the selected material.
This example does the following:
This is what the JavaScript above generates. If you're unfamiliar with G-code: it's a simple language used by CNC machines. Each line is a command to move, cut, or set a state. For example, G0
means rapid move, M06
is tool change, and M30
ends the program. The JavaScript shown earlier generates these commands automatically.
%
O0001 (My Program)
G17 G40 G80 G54 G20
M06 T1
G0 X0 Y0 Z0.5
... (face milling motions)
M30
%
new HaasGCodeGenerator(programNumber, programName)
REQUIREDConstructs a generator instance. Must be called before any G-code methods can be used.
programStart()
REQUIREDInitializes the program with standard setup commands (e.g., G17 G40 G80 G54 G20
).
toolChange(toolNumber)
REQUIREDSelects a tool by number and inserts the appropriate M06
and spindle commands.
startPosition(x, y)
REQUIREDMoves the tool rapidly to the starting XY location at a safe height above the part. Required before most cutting operations.
faceMill(x, y, width, length, depth, stepOver)
Generates a zigzag face milling pattern for the specified area.
drillHole(x, y, retractZ, bottomZ, peckDepth, dwell)
Performs drilling cycle at specified XY location with pecking.
tapHole(x, y, retractZ, bottomZ)
Performs a tapping cycle using calculated pitch and spindle direction.
threadMillHole(x, y, retractZ, bottomZ)
Performs circular thread milling. Requires thread direction.
polygonalFaceMill(points[], depth, stepDown, overlap)
Faces inside a closed polygon with spiral offsets.
comment(text)
Inserts a comment line into the G-code.
programEnd()
REQUIREDCloses the program with M30
. Must be called to finish the G-code correctly.
Feeds and speeds are determined dynamically from the selected material/tool type. The internal library uses a lookup via getMachiningData(material, toolType)
. If not found, defaults are applied.
Tool Type | Required Parameters | Additional Notes |
---|---|---|
end_mill | diameter, teeth | Default tool type |
face_mill | diameter, teeth | Used for flat facing |
drill | diameter | Feedrate depends on peck + dwell |
tap | diameter, pitch | Pitch used for spindle sync |
thread_mill | diameter, threadDirection | Requires thread milling pathing |