These are the codes of RS274/NGC, the machining language described by NIST. The line
format, parameters and modal groups are on the
RS274/NGC language page. In the tables,
axes means any of X Y Z A B C with a value. Printer firmware
gives several of these numbers other meanings; compare the
command register.
Motion, set-up and mode codes
| Code and words | Meaning | Errors and notes |
|---|---|---|
G0 axes | Rapid straight move, all axes coordinated | At least one axis word |
G1 axes | Straight move at the feed rate | At least one axis word |
G2, G3 axes with R or I J K | Clockwise and anticlockwise arc or helix | See arcs below |
G4 P | Dwell for P seconds | Negative P is an error. (Printer firmware commonly counts P in milliseconds.) |
G10 L2 P axes | Set the origin of coordinate system P (1–9) in machine coordinates; only the axes given change | P outside 1–9. An existing G92 offset stays |
G17, G18, G19 | Select the XY, XZ or YZ plane | |
G20, G21 | Inches, millimetres | |
G28 axes, G30 axes | Rapid to the point given, then to home position 1 or 2 (parameters 5161–5166, 5181–5186); without axes, straight home | |
G38.2 axes | Straight probe: move at feed rate until the probe trips, retract slightly; parameters 5061–5066 get the trip point | No X, Y or Z word; rotary motion; target closer than 0.254 mm (0.01 in); inverse time mode; no trip |
G40 | Cutter radius compensation off | |
G41 [D], G42 [D] | Compensation with the cutter left or right of the path (positive radius). D is a tool slot; without it the tool in the spindle; 0 means radius 0 | D not a valid slot; XY plane not selected; already on |
G43 H | Use tool length offset H from the tool table; 0 means none | H not a valid slot |
G49 | No tool length offset | |
G53 with G0 or G1 | This line’s move is in machine coordinates; not modal | No G0/G1 in force; compensation on |
G54–G59, G59.1–G59.3 | Select coordinate system 1–6 and 7–9 | Compensation on |
G61, G61.1, G64 | Exact path (slowing at corners as needed), exact stop (halt after each move), continuous (corners may be rounded) | |
G80 | Cancel the motion mode, including canned cycles | Axis words while in force, unless a group 0 code uses them |
G81–G89 | Canned cycles, below | |
G90, G91 | Absolute or incremental axis values. I and J are always increments, K except in G87 | |
G92 axes | Without moving, shift the origin so that the current point has these coordinates; the offsets apply to all nine systems and are stored in 5211–5216 | No axis word. A second G92 takes the old offset into account; G91 has no effect on it |
G92.1 | Remove the offsets and zero 5211–5216 | |
G92.2 | Remove the offsets but keep the parameters | |
G92.3 | Apply the offsets stored in 5211–5216, for example those of an earlier program | |
G93 | Inverse time feed: the move takes 1/F minutes | Every G1, G2, G3 line needs F; G0 is unaffected |
G94 | Feed in units per minute (millimetres, inches or degrees) | |
G98 | Canned cycles retract to the starting height if it is above R | |
G99 | Canned cycles retract to R |
Arcs
The arc lies in the selected plane; movement along the third axis makes a helix.
G2 or G3 may be left out while it is the motion in
force.
- Radius format: end point and
R. A positive radius gives an arc of at most 180°, a negative one of 180° to 359.999°. At least one axis word of the plane is needed, and the end must differ from the start. Near semicircles and near full circles are very sensitive to rounding. - Centre format: end point and the offsets of the centre from the start:
I Jin XY,I Kin XZ,J Kin YZ. At least one axis word and one offset of the plane are needed; start and end may be the same. The two distances to the centre may differ by at most 0.002 mm (0.0002 in).
G17 G2 X10 Y15 R20 Z5
G17 G2 X10 Y16 I3 J4 Z9
Canned cycles
All take axes, R (retract position) and optionally
L (repeats, a positive integer; not 0). With the XY plane selected,
Z is the depth; other planes work in the same way on their third
axis.
Rand the depth word are “sticky”: needed on the first line of a run of the same cycle, kept afterwards.Lis not.- In
G91,X,YandRare increments from the current position andZan increment from where the Z move starts; each repeat stepsXandYon. - Preliminary motion: once, rise to
Rif below it; before each repeat, traverse to the XY position, then toR. - Errors: no
X,YorZ; negativeP; badL; missing depth on the first line;Rbelow the depth; rotary motion; inverse time feed; cutter radius compensation on.
| Cycle and extra words | Use | Steps after the preliminary motion |
|---|---|---|
G81 | Drilling | Feed to depth; rapid retract |
G82 P | Drilling with dwell | Feed to depth; dwell P seconds; rapid retract |
G83 Q | Peck drilling | Feed down by Q (not beyond depth); rapid out; rapid back to just above the bottom; repeat; retract. Q must be positive |
G84 | Right-hand tapping | Synchronise speed and feed; feed in; stop; run anticlockwise; feed out; restore synchronising; stop; run clockwise. The spindle must already turn clockwise; speed equals feed times threads per unit length |
G85 | Boring or reaming | Feed to depth; feed back out |
G86 P | Boring | Feed to depth; dwell; stop spindle; rapid out; restart. Spindle must be turning |
G87 I J K | Back boring | Traverse to the point offset by I J; stop the spindle at a fixed angle; lower to Z; move to XY; start; feed up to K and back to Z; stop at the same angle; move to the offset point; rise to the retract height; move to XY; start. I J are always increments |
G88 P | Boring, manual retract | Feed to depth; dwell; stop spindle; stop the program for the operator to retract; restart spindle |
G89 P | Boring with dwell | Feed to depth; dwell; feed out |
G90 G81 G98 X4 Y5 Z1.5 R2.8
M codes
| Code | Meaning |
|---|---|
M0 | Stop until the operator presses cycle start |
M1 | The same, only if the optional stop switch is on |
M2 | End of program |
M3, M4, M5 | Spindle clockwise, anticlockwise, stop |
M6 | Change to the tool last selected with T; stops the spindle, leaves coolant running |
M7, M8, M9 | Mist coolant on, flood coolant on, all coolant off |
M30 | Exchange pallets and end the program |
M48, M49 | Enable or disable the speed and feed override switches |
M60 | Exchange pallets and stop until cycle start |
M2 and M30 also reset the machine: axis offsets zeroed
(as G92.2), coordinate system 1 (G54),
G17, G90, G94, M48,
G40, spindle stopped, motion mode G1, coolant off.
F, S and T
Fsets the feed rate, read according toG93orG94.Ssets the spindle speed in revolutions per minute; negative is an error, 0 means it does not turn.Tselects a carousel slot for the nextM6; 0 selects no tool. A negative number or one beyond the carousel is an error.
Cutter radius compensation
G41 keeps the tool to the left of the programmed contour and
G42 to the right, seen in the direction of travel;
G40 turns compensation off, and may be given when it is already off.
It works only in the XY plane. Z may move meanwhile, for example to
lift over part of the contour, and rotary axes may move, though that is unusual.
Under G94 the feed rate applies to the actual path of the tool tip.
A G40, G41 or G42 on the same line as a
move takes effect before the move.
D is optional on G41 and G42. It names the
tool table slot whose radius is used, which need not be the tool in the spindle;
D0 means a radius of zero. Without D the slot of the
tool in the spindle is used. Changing tools while compensation is on is not an
error, but the old radius stays until compensation is turned off.
| Programmed contour | Diameter in the tool table | Entry moves |
|---|---|---|
| The edge of the material that is to remain | The tool’s actual diameter, positive. The program is the same for any tool | Two moves before the contour and one onto it; at a convex corner one before (or none) and one onto it are enough |
| The nominal path: where the centre of a tool of the intended size would go, keeping contact with the part | The actual diameter minus the intended one: 0.97 for an intended 1.0 gives −0.03. A negative value compensates on the opposite side by its absolute value | Two moves before the contour and one onto it; the corner shortcut does not work, as such a path has no corners |
For the general entry, choose a point A on the contour and add an arc outside it
from a point B, ending at A tangent to the contour in the direction of travel, then
a straight line from some point C to B, tangent to the arc. For a material edge the
arc radius must exceed the tool radius and BC must be longer than the tool radius.
For a nominal path both must exceed the largest expected difference between the
real and intended radius. G41 or G42 goes on the move
from C to B. The report’s material edge example, for a tool of diameter 1:
N0010 G1 X1 Y5
N0020 G41 G1 Y4
N0030 G3 X2 Y3 I1
N0040 G2 X3 Y2 J-1
N0050 G1 Y-1
N0060 G2 X2 Y-2 I-1
N0070 G1 X-2
N0080 G2 X-2.6 Y-0.2 J1
N0090 G1 X1.4 Y2.8
N0100 G2 X2 Y3 I0.6 J-0.8
N0110 G40
For the corner shortcut, extend the side to be cut beyond the convex corner, move to a point on the material’s side of that line (or on it) where the tool does not touch the material, then make a straight move to the corner with compensation turned on.
- If the first compensated move is straight, the tool goes to a destination where it touches the tangent drawn from the programmed end point to the circle of the tool at its current position. A programmed point already inside that circle is a gouging error.
- If it is an arc, an auxiliary arc is built with the programmed centre, through the programmed end point and tangent to the tool where it is; the tool moves staying tangent to it. If no such arc exists, it is an error.
- After entry the tool stays tangent to the programmed path on the chosen side. At a convex corner an arc of the tool radius is inserted. The Interpreter never extends the two sides to a sharp point instead.
- A concave corner, or a concave arc too small for the tool, is an error rather than being gouged or rounded.
- There is no exit move: after
G40the next move starts from where the tool is.
| Errors the Interpreter reports |
|---|
Changing axis offsets or units, probing, using G28, G30 or G53, or selecting the XZ or YZ plane while compensation is on |
Turning compensation on outside the XY plane, or when it is already on (so neither side nor D can change without G40 first) |
| A concave corner; gouging; an arc radius not larger than the tool radius |
D without G41 or G42; two D words on a line; a negative D; a D beyond the carousel (68 slots in the report’s stand-alone program) |
Two of G40, G41 and G42 on one line |
Sources
- The NIST RS274NGC Interpreter – Version 3 – Kramer, Proctor and Messina, NISTIR 6556, 17 August 2000, sections 2.1.2.16 and 3.5 to 3.7 and appendix B