G-code is the standard language for CNC machine control. Every CNC machining program — whether written manually or generated by software — is ultimately expressed as G-code. Understanding the basics helps you verify that the programs XyzPilot generates are correct.
What G-Code Is
G-code is a text-based language where each line (block) contains one or more commands. The most common commands are G-codes (preparatory functions) and M-codes (miscellaneous functions).
A typical G-code block looks like:
G1 X50.000 Y30.000 F200
This means: move in a straight line (G1) to position X=50, Y=30 at feed rate 200mm/min.
The Essential G-Codes
| Code | Name | Description |
|---|---|---|
G0 | Rapid positioning | Move at maximum speed — no cutting |
G1 | Linear interpolation | Move in a straight line at specified feed rate — cutting |
G2 | Circular interpolation CW | Move in a clockwise arc at specified feed rate |
G3 | Circular interpolation CCW | Move in a counter-clockwise arc at specified feed rate |
G41 | Cutter compensation left | Offset tool path to the left by tool radius |
G42 | Cutter compensation right | Offset tool path to the right by tool radius |
G40 | Cancel cutter compensation | Return to programmed path |
G81 | Drill cycle | Drill to specified depth and retract |
G83 | Peck drill cycle | Drill in increments with retract between each peck |
G90 | Absolute positioning | Coordinates are absolute from work zero |
G91 | Incremental positioning | Coordinates are relative to current position |
Arc Moves: G2 and G3
Arc moves require additional parameters beyond the end point:
X, Y— the end point of the arcI, J— the offset from the start point to the arc centre (incremental)F— the feed rate
Example: G2 X80.000 Y50.000 I30.000 J0.000 F150 — clockwise arc ending at (80,50) with centre offset (30,0) from start point.
XyzPilot generates correct I/J values for all arc moves, including the correct arc direction (G2 for CW, G3 for CCW).
Cutter Compensation
Cutter compensation (G41/G42) tells the controller to offset the programmed path by the tool radius. This allows the same program to be used with tools of slightly different diameters.
XyzPilot generates the correct compensation sequence:
G41 Dn G1 X... Y...— engage compensation on a linear move- [cutting moves]
G40 G1 X... Y...— cancel compensation on a linear move with full XY coordinates
How XyzPilot Generates G-Code
XyzPilot generates G-code automatically from the 2D geometry and CAM setup. You do not need to write G-code manually. The system handles:
- Correct cyclic rotation for closed contours
- Correct I/J values for arc moves
- Correct cutter compensation transitions
- Correct drill cycle parameters
- Correct depth control
The generated G-code is ready to load directly into the CNC controller.