File size: 4,806 Bytes
265686c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# G-code Reference for CNC Milling

## Motion Codes (Modal Group 1)

Modal codes remain active until replaced by another code from the same group.

| Code | Function | Parameters |
|------|----------|------------|
| G00 | Rapid positioning (max speed, no cutting) | X Y Z |
| G01 | Linear interpolation (cutting feed) | X Y Z F |
| G02 | Circular interpolation, clockwise | X Y Z I J K / R, F |
| G03 | Circular interpolation, counter-clockwise | X Y Z I J K / R, F |

## Arc Interpolation (G02/G03)

Two formats for specifying arcs:

**Center Offset (I, J, K)**:
- I = X-offset from current position to arc center
- J = Y-offset from current position to arc center
- K = Z-offset (for helical arcs)
- In XY plane (G17): uses I, J
- In XZ plane (G18): uses I, K
- In YZ plane (G19): uses J, K

**Radius (R)**:
- R > 0: arc < 180 degrees
- R < 0: arc > 180 degrees

Example:
```gcode
G02 X10 Y0 I5 J0 F200   ; CW arc to (10,0), center offset (5,0)
G03 X0 Y10 R10 F200      ; CCW arc to (0,10), radius 10
```

## Plane Selection (Modal Group 2)

| Code | Function |
|------|----------|
| G17 | XY plane (default for milling) |
| G18 | ZX plane |
| G19 | YZ plane |

## Distance Mode (Modal Group 3)

| Code | Function |
|------|----------|
| G90 | Absolute positioning |
| G91 | Incremental positioning |

## Units (Modal Group 6)

| Code | Function |
|------|----------|
| G20 | Inch mode |
| G21 | Millimeter mode |

## Canned Drilling Cycles (Modal Group 1)

| Code | Function | Key Params |
|------|----------|-----------|
| G80 | Cancel canned cycle | -- |
| G81 | Simple drilling | X Y Z R F L |
| G82 | Spot drill with dwell | X Y Z R P F L |
| G83 | Deep-hole peck drilling (full retract) | X Y Z R Q F L |
| G84 | Right-hand tapping | X Y Z R F L |
| G85 | Boring, feed out | X Y Z R F L |
| G86 | Boring, spindle stop, rapid out | X Y Z R F L |
| G73 | High-speed peck (chip break, short retract) | X Y Z R Q F L |

Parameters:
- R = retract plane (Z height for rapid between holes)
- Q = peck depth increment
- P = dwell time at bottom (milliseconds)
- L = repeat count

## Tool Compensation

| Code | Function |
|------|----------|
| G40 | Cancel cutter radius compensation |
| G41 | Cutter radius compensation left |
| G42 | Cutter radius compensation right |
| G43 | Tool length compensation positive |
| G49 | Cancel tool length compensation |

## Work Coordinate Systems

| Code | Function |
|------|----------|
| G54 | Work coordinate system 1 (default) |
| G55-G59 | Work coordinate systems 2-6 |
| G92 | Set position (coordinate system offset) |

## M-Codes (Miscellaneous Functions)

| Code | Function |
|------|----------|
| M0 | Program pause (operator resume) |
| M1 | Optional stop |
| M2 | Program end |
| M3 | Spindle on, clockwise |
| M4 | Spindle on, counter-clockwise |
| M5 | Spindle stop |
| M6 | Tool change |
| M7 | Mist coolant on |
| M8 | Flood coolant on |
| M9 | Coolant off |
| M30 | Program end and rewind |

## Feed Rate and Spindle

| Letter | Function |
|--------|----------|
| F | Feed rate (mm/min or in/min) |
| S | Spindle speed (RPM) |
| T | Tool number (e.g., T1, T2) |
| N | Line number (optional) |

## Complete G-code Program Example

```gcode
%
O0001 (POCKET MILLING EXAMPLE)
G21 G90 G17          (mm, absolute, XY plane)
G54                   (work coordinate system 1)

(TOOL 1 - 6MM ENDMILL)
T1 M6                (select tool 1, tool change)
S18000 M3            (spindle 18000 RPM, clockwise)
G43 H1               (tool length compensation)

(RAPID TO START POSITION)
G00 X0 Y0 Z10        (rapid above workpiece)

(POCKET - FIRST PASS)
G00 Z2               (rapid to clearance height)
G01 Z-2 F200         (plunge to depth at feed rate)
G01 X40 F800         (cut along X)
G01 Y30              (cut along Y)
G01 X0               (cut back)
G01 Y0               (cut back to start)

(POCKET - SECOND PASS)
G01 Z-4 F200         (plunge deeper)
G01 X40 F800
G01 Y30
G01 X0
G01 Y0

(RETRACT AND END)
G00 Z50              (rapid retract)
M5                   (spindle off)
M9                   (coolant off)
G28                  (return to reference point)
M30                  (program end)
%
```

## Modal vs Non-Modal

**Modal codes** stay active: G00, G01, G02, G03, G17-G19, G20/G21, G40-G43, G54-G59, G80-G89, G90/G91

**Non-modal codes** execute once: G04 (dwell), G28 (return to home), G92 (set position)

## Controller Dialects

| Feature | LinuxCNC | Grbl | FANUC | Haas |
|---------|----------|------|-------|------|
| Arc format | I/J/K and R | I/J/K and R | I/J/K and R | I/J/K and R |
| Canned cycles | Full G73-G89 | None | Full G73-G89 | Full G73-G89 |
| Tool change | M6 | Manual | M6 | M6 |
| Subroutines | O-codes | None | M98/M99 | M97/M98 |
| Variables | #1-#999 | None | #1-#999 | #1-#999 |
| Peck drilling | G83 | Manual | G83 | G83 |