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

CodeNameDescription
G0Rapid positioningMove at maximum speed — no cutting
G1Linear interpolationMove in a straight line at specified feed rate — cutting
G2Circular interpolation CWMove in a clockwise arc at specified feed rate
G3Circular interpolation CCWMove in a counter-clockwise arc at specified feed rate
G41Cutter compensation leftOffset tool path to the left by tool radius
G42Cutter compensation rightOffset tool path to the right by tool radius
G40Cancel cutter compensationReturn to programmed path
G81Drill cycleDrill to specified depth and retract
G83Peck drill cycleDrill in increments with retract between each peck
G90Absolute positioningCoordinates are absolute from work zero
G91Incremental positioningCoordinates 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 arc
  • I, 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.