NEWS
emc2_2.2.7 Release
A fresh bugfix release (2.2.7) - (Changelog).
You can get it: as a source package from sourceforge , from CVS , or as a precompiled package which works on Ubuntu as described here.
 
Ubuntu 8.04&EMC2 Live CD
The EMC2 team now has a brand new custom Live-CD (EU mirror) based on Ubuntu 8.04 with emc 2.2.x included, that will let you try out EMC2 before installing, and it's also the easiest way to install Ubuntu and EMC2 together. (more)
 
emc2_2.2.6 Release
A fresh bugfix release (2.2.6) - (Changelog).
You can get it: as a source package from sourceforge , from CVS , or as a precompiled package which works on Ubuntu as described here.
 
Language
Site Search
Google
Web LinuxCNC
Polls
EMC Version you are using
 
What type of machine do you run with EMC? Vote once for each machine
 

Table of Contents

List of figures

List of tables

1 Language Overview

The RS274/NGC language is based on lines of code. Each line (also called a “block”) may include commands to a machining center to do several different things. Lines of code may be collected in a file to make a program.

A typical line of code consists of an optional line number at the beginning followed by one or more “words.” A word consists of a letter followed by a number (or something that evaluates to a number). A word may either give a command or provide an argument to a command. For example, “G1 X3” is a valid line of code with two words. “G1” is a command meaning “move in a straight line at the programmed feed rate”, and “X3” provides an argument value (the value of X should be 3 at the end of the move). Most RS274/NGC commands start with either G or M (for General and Miscellaneous). The words for these commands are called “G codes” and “M codes.”

The RS274/NGC language has no indicator for the start of a program. The Interpreter, however, deals with files. A single program may be in a single file, or a program may be spread across several files. A file may demarcated with percents in the following way. The first non-blank line of a file may contain nothing but a percent sign, “%”, possibly surrounded by white space, and later in the file (normally at the end of the file) there may be a similar line. Demarcating a file with percents is optional if the file has an M2 or M30 in it, but is required if not. An error will be signalled if a file has a percent line at the beginning but not at the end. The useful contents of a file demarcated by percents stop after the second percent line. Anything after that is ignored.

The RS274/NGC language has two commands (M2 or M30), either of which ends a program. A program may end before the end of a file. Lines of a file that occur after the end of a program are not to be executed. The interpreter does not even read them.

1.1 Format of a line

A permissible line of input RS274/NGC code consists of the following, in order, with the restriction that there is a maximum (currently 256) to the number of characters allowed on a line.

  1. an optional block delete character, which is a slash “/” .
  2. an optional line number.
  3. any number of words, parameter settings, and comments.
  4. an end of line marker (carriage return or line feed or both).

Any input not explicitly allowed is illegal and will cause the Interpreter to signal an error.

Spaces and tabs are allowed anywhere on a line of code and do not change the meaning of the line, except inside comments. This makes some strange-looking input legal. The line “g0x +0. 12 34y 7” is equivalent to “g0 x+0.1234 y7”, for example.

Blank lines are allowed in the input. They are to be ignored.

Input is case insensitive, except in comments, i.e., any letter outside a comment may be in upper or lower case without changing the meaning of a line.

1.2 Line Number

A line number is the letter N followed by an integer (with no sign) between 0 and 99999 written with no more than five digits (000009 is not OK, for example). Line numbers may be repeated or used out of order, although normal practice is to avoid such usage. Line numbers may also be skipped, and that is normal practice. A line number is not required to be used, but must be in the proper place if used.

1.3 Word

A word is a letter other than N followed by a real value.

Words may begin with any of the letters shown in Table [.]. The table includes N for completeness, even though, as defined above, line numbers are not words. Several letters (I, J, K, L, P, R) may have different meanings in different contexts. Letters which refer to axis names are not valid on a machine which does not have the corresponding axis.

Letter Meaning
A A axis of machine
B B axis of machine
C C axis of machine
D Tool radius compensation number
F Feed rate
G General function (See table [.])
H Tool length offset index
I X offset for arcs and G87 canned cycles
J Y offset for arcs and G87 canned cycles
K Z offset for arcs and G87 canned cycles.
Spindle-Motion Ratio for G33 synchronized movements.
M Miscellaneous function (See table [.])
N Line number
P Dwell time in canned cycles and with G4.
Key used with G10.
Q Feed increment in G73, G83 canned cycles
R Arc radius or canned cycle plane
S Spindle speed
T Tool selection
U U axis of machine
V V axis of machine
W W axis of machine
X X axis of machine
Y Y axis of machine
Z Z axis of machine
Table: Words and their meanings

1.3.1 Number

The following rules are used for (explicit) numbers. In these rules a digit is a single character between 0 and 9.

  • A number consists of (1) an optional plus or minus sign, followed by (2) zero to many digits, followed, possibly, by (3) one decimal point, followed by (4) zero to many digits - provided that there is at least one digit somewhere in the number.
  • There are two kinds of numbers: integers and decimals. An integer does not have a decimal point in it; a decimal does.
  • Numbers may have any number of digits, subject to the limitation on line length. Only about seventeen significant figures will be retained, however (enough for all known applications).
  • A non-zero number with no sign as the first character is assumed to be positive.

Notice that initial (before the decimal point and the first non-zero digit) and trailing (after the decimal point and the last non-zero digit) zeros are allowed but not required. A number written with initial or trailing zeros will have the same value when it is read as if the extra zeros were not there.

Numbers used for specific purposes in RS274/NGC are often restricted to some finite set of values or some to some range of values. In many uses, decimal numbers must be close to integers; this includes the values of indexes (for parameters and carousel slot numbers, for example), M codes, and G codes multiplied by ten. A decimal number which is supposed be close to an integer is considered close enough if it is within 0.0001 of an integer.

1.3.2 Numbered Parameters

A numbered parameter is the pound character # followed by an integer between 1 and 5399. The parameter is referred to by this integer, and its value is whatever number is stored in the parameter.

A value is stored in a parameter with the = operator; for example "#3 = 15" means "set parameter 3 to 15." A parameter setting does not take effect until after all parameter values on the same line have been found. For example, if parameter 3 has been previously set to 15 and the line “#3=6 G1 x#3” is interpreted, a straight move to a point where x equals 15 will occur and the value of parameter 3 will be 6.

The # character takes precedence over other operations, so that, for example, “#1+2” means the number found by adding 2 to the value of parameter 1, not the value found in parameter 3. Of course, #[1+2] does mean the value found in parameter 3. The # character may be repeated; for example ##2 means the value of the parameter whose index is the (integer) value of parameter 2.

1.3.3 Named Parameters

Named parameters work like numbered parameters but are easier to read. All parameter names are converted to lower case and have spaces and tabs removed. Named parameters must be enclosed with < > marks.

#<named parameter here> is a local named parameter. By default, a named parameter is local to the scope in which it is assigned. You can't access a local parameter outside of its subroutine - this is so that two subroutines can use the same parameter names without fear of one subroutine overwriting the values in another.

#<_global named parameter here> is a global named parameter. They are accessible from within called subroutines and may set values within subroutines that are accessible to the caller. As far as scope is concerned, they act just like regular numeric parameters. They are not stored in files.

Examples:

  • Declaration of named global variable

#<_endmill_dia> = 0.049

  • Reference to previously declared global variable

#<_endmill_rad> = [#<_endmill_dia>/2.0]

  • Mixed literal and named parameters

o100 call [0.0] [0.0] [#<_inside_cutout>-#<_endmill_dia>] [#<_Zcut>] [#<_feedrate>]

Notes:

The global parameters _a, _b, _c, ... _z have been reserved for special use. In the future, they may provide access to the last Aword, Bword, Cword, etc.

1.3.4 Expressions

An expression is a set of characters starting with a left bracket [ and ending with a balancing right bracket ]. In between the brackets are numbers, parameter values, mathematical operations, and other expressions. An expression is evaluated to produce a number. The expressions on a line are evaluated when the line is read, before anything on the line is executed. An example of an expression is [1 + acos[0] - [#3 ** [4.0/2]]].

1.3.5 Binary Operators

Binary operators only appear inside expressions. There are four basic mathematical operations: addition (+), subtraction (-), multiplication (*), and division (/). There are three logical operations: non-exclusive or (OR), exclusive or (XOR), and logical and (AND). The eighth operation is the modulus operation (MOD). The ninth operation is the “power” operation (**) of raising the number on the left of the operation to the power on the right. The relational operators are equality (EQ), inequality (NE), strictly greater than (GT), greater than or equal to (GE), strictly less than (LT), and less than or equal to (LE).

The binary operations are divided into several groups according to their precedence. (see table [.]) If operations in different precedence groups are strung together (for example in the expression [2.0 / 3 * 1.5 - 5.5 / 11.0]), operations in a higher group are to be performed before operations in a lower group. If an expression contains more than one operation from the same group (such as the first / and * in the example), the operation on the left is performed first. Thus, the example is equivalent to: [[[2.0 / 3] * 1.5] - [5.5 / 11.0]] , which is equivalent to to [1.0 - 0.5] , which is 0.5.

The logical operations and modulus are to be performed on any real numbers, not just on integers. The number zero is equivalent to logical false, and any non-zero number is equivalent to logical true.

Operators Precedence
** highest
* / MOD
+ -
EQ NE GT GE LT LE
AND OR XOR lowest
Table: Operator Precedence

1.3.6 Functions

A function is either “ATAN” followed by one expression divided by another expression (for example “ATAN[2]/[1+3]”) or any other function name followed by an expression (for example “SIN[90]”). The available functions are shown in table [.]. Arguments to unary operations which take angle measures (COS, SIN, and TAN) are in degrees. Values returned by unary operations which return angle measures (ACOS, ASIN, and ATAN) are also in degrees.

The FIX operation rounds towards the left (less positive or more negative) on a number line, so that FIX[2.8] =2 and FIX[-2.8] = -3, for example. The FUP operation rounds towards the right (more positive or less negative) on a number line; FUP[2.8] = 3 and FUP[-2.8] = -2, for example.

Function Name Function result
ATAN[Y]/[X] Four quadrant tangent
ABS[arg] Absolute value
ACOS[arg] Inverse cosine
ASIN[arg] Inverse sine
COS[arg] Cosine
EXP[arg] e raised to the given power
FIX[arg] Round down to integer
FUP[arg] Round up to integer
ROUND[arg] Round to nearest integer
LN[arg] Base-e logarithm
SIN[arg] Sine
SQRT[arg] Square Root
TAN[arg] Tangent
Table: Functions

1.4 Comments

Printable characters and white space inside parentheses is a comment. A left parenthesis always starts a comment. The comment ends at the first right parenthesis found thereafter. Once a left parenthesis is placed on a line, a matching right parenthesis must appear before the end of the line. Comments may not be nested; it is an error if a left parenthesis is found after the start of a comment and before the end of the comment. Here is an example of a line containing a comment: “G80 M5 (stop motion)”. Comments do not cause a machining center to do anything.

1.5 Messages

A comment contains a message if “MSG,” appears after the left parenthesis and before any other printing characters. Variants of “MSG,” which include white space and lower case characters are allowed. The rest of the characters before the right parenthesis are considered to be a message. Messages should be displayed on the message display device. Comments not containing messages need not be displayed there.

1.6 Probe Logging

A comment can also be used to specify a file for the results of G38.x probing. See section [.].

Often, general logging is more useful than probe logging. Using general logging, the format of the output data can be controlled.

1.7 General Logging

1.7.1 (LOGOPEN,filename)

Opens the named log file. If the file already exists, it is truncated.

1.7.2 (LOGCLOSE)

If the log file is open, it is closed.

1.7.3 (LOG,…)

The message “…” is expanded as described below and then written to the log file if it is open.

1.8 Debugging Messages

Comments that look like: (debug, rest of comment) are the same as comments like (msg, rest of comment) with the addition of special handling for parameters.

Comments that look like: (print, rest of comment) are output to stderr with special handling for parameters.

1.9 Parameters in special comments

In the DEBUG, PRINT and LOG comments, the values of parameters in the message are expanded.

For example: to print a named global variable to stderr (the default console window) add a line to your gcode like...

(print,endmill dia = #<_endmill_dia>)

Inside the above types of comments, sequences like #123 are replaced by the value of the parameter 123. Sequences like #<named parameter> are replaced by the value of the named parameter. Remember that named parameters will have white space removed from them. So, #<named parameter> is the same as #<namedparameter>.

1.10 Repeated Items

A line may have any number of G words, but two G words from the same modal group (see Section [.]) may not appear on the same line.

A line may have zero to four M words. Two M words from the same modal group may not appear on the same line.

For all other legal letters, a line may have only one word beginning with that letter.

If a parameter setting of the same parameter is repeated on a line, “#3=15 #3=6”, for example, only the last setting will take effect. It is silly, but not illegal, to set the same parameter twice on the same line.

If more than one comment appears on a line, only the last one will be used; each of the other comments will be read and its format will be checked, but it will be ignored thereafter. It is expected that putting more than one comment on a line will be very rare.

1.11 Item order

The three types of item whose order may vary on a line (as given at the beginning of this section) are word, parameter setting, and comment. Imagine that these three types of item are divided into three groups by type.

The first group (the words) may be reordered in any way without changing the meaning of the line.

If the second group (the parameter settings) is reordered, there will be no change in the meaning of the line unless the same parameter is set more than once. In this case, only the last setting of the parameter will take effect. For example, after the line “#3=15 #3=6” has been interpreted, the value of parameter 3 will be 6. If the order is reversed to “#3=6 #3=15” and the line is interpreted, the value of parameter 3 will be 15.

If the third group (the comments) contains more than one comment and is reordered, only the last comment will be used.

If each group is kept in order or reordered without changing the meaning of the line, then the three groups may be interleaved in any way without changing the meaning of the line. For example, the line “g40 g1 #3=15 (foo) #4=-7.0” has five items and means exactly the same thing in any of the 120 possible orders (such as “#4=-7.0 g1 #3=15 g40 (foo)”) for the five items.

1.12 Commands and Machine Modes

In RS274/NGC, many commands cause a machining center to change from one mode to another, and the mode stays active until some other command changes it implicitly or explicitly. Such commands are called “modal”. For example, if coolant is turned on, it stays on until it is explicitly turned off. The G codes for motion are also modal. If a G1 (straight move) command is given on one line, for example, it will be executed again on the next line if one or more axis words is available on the line, unless an explicit command is given on that next line using the axis words or cancelling motion.

“Non-modal” codes have effect only on the lines on which they occur. For example, G4 (dwell) is non-modal.

1.13 Modal Groups

Modal commands are arranged in sets called “modal groups”, and only one member of a modal group may be in force at any given time. In general, a modal group contains commands for which it is logically impossible for two members to be in effect at the same time - like measure in inches vs. measure in millimeters. A machining center may be in many modes at the same time, with one mode from each modal group being in effect. The modal groups are shown in Table [.].

Modal Group Meaning Member Words
Motion (“Group 1”) G0 G1 G2 G3 G33 G38.x G73 G76 G80 G81
G82 G83 G84 G85 G86 G87 G88 G89
Plane selection G17, G18, G19
Distance Mode G90, G91
Feed Rate Mode G93, G94
Units G20, G21
Cutter Radius Compensation G40, G41, G42, G41.1, G42.1
Tool Length Offset G43, G43.1, G49
Return Mode in Canned Cycles G98, G99
Coordinate System Selection G54, G55, G56, G57, G58
G59, G59.1, G59.2, G59.3
Stopping M0, M1, M2, M30, M60
Tool Change M6 Tn
Spindle Turning M3, M4, M5
Coolant M7, M8, M9. Special case:
M7 and M8 may be active at the same time
Override Switches M48, M49
Flow Control O-
Non-modal codes (“Group 0”) G4, G10 G28, G30, G53
G92, G92.1, G92.2, G92.3
M100 to M199
Table: Modal Groups

For several modal groups, when a machining center is ready to accept commands, one member of the group must be in effect. There are default settings for these modal groups. When the machining center is turned on or otherwise re-initialized, the default values are automatically in effect.

Group 1, the first group on the table, is a group of G codes for motion. One of these is always in effect. That one is called the current motion mode.

It is an error to put a G-code from group 1 and a G-code from group 0 on the same line if both of them use axis words. If an axis word-using G-code from group 1 is implicitly in effect on a line (by having been activated on an earlier line), and a group 0 G-code that uses axis words appears on the line, the activity of the group 1 G-code is suspended for that line. The axis word-using G-codes from group 0 are G10, G28, G30, and G92.

It is an error to include any unrelated words on a line with O- flow control.

2 Order of Execution

The order of execution of items on a line is critical to safe and effective machine operation. Items are executed in the order shown below if they occur on the same line.

  1. Comment (including message)
  2. set feed rate mode (G93, G94).
  3. set feed rate (F).
  4. set spindle speed (S).
  5. select tool (T).
  6. change tool (M6).
  7. spindle on or off (M3, M4, M5).
  8. coolant on or off (M7, M8, M9).
  9. enable or disable overrides (M48, M49).
  10. dwell (G4).
  11. set active plane (G17, G18, G19).
  12. set length units (G20, G21).
  13. cutter radius compensation on or off (G40, G41, G42)
  14. cutter length compensation on or off (G43, G49)
  15. coordinate system selection (G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3).
  16. set path control mode (G61, G61.1, G64)
  17. set distance mode (G90, G91).
  18. set retract mode (G98, G99).
  19. home (G28, G30) or change coordinate system data (G10) or set axis offsets (G92, G92.1, G92.2, G94).
  20. perform motion (G0 to G3, G33, G73, G76, G80 to G89), as modified (possibly) by G53.
  21. stop (M0, M1, M2, M30, M60).

3 G Code Best Practices

3.1 Use an appropriate decimal precision

Use at least 3 digits after the decimal when milling in millimeters, and at least 4 digits after the decimal when milling in inches. In particular, arc tolerance checks are made to .001 and .0001 depending on the active units.

3.2 Use consistent white space

G-code is most legible when at least one space appears before words. While it is permitted to insert white space in the middle of numbers, there is no reason to do so.

3.3 Prefer “Center-format” arcs

Center-format arcs (which use I- J- K- instead of R-) behave more consistently than R-format arcs, particularly for included angles near 180 or 360 degrees.

3.4 Put important modal settings at the top of the file

When correct execution of your program depends on modal settings, be sure to set them at the beginning of the part program. Modes can carry over from previous programs and from the MDI commands.

As a good preventative measure, put a line similar to the following at the top of all your programs:

G17 G20 G40 G49 G54 G80 G90 G94 

(XY plane, inch mode, cancel diameter compensation, cancel length offset, coordinate system 1, cancel motion, non-incremental motion, feed/minute mode)

Perhaps the most critical modal setting is the distance units--If you do not include G20 or G21, then different machines will mill the program at different scales. Other settings, such as the return mode in canned cycles may also be important.

3.5 Don't put too many things on one line

Ignore everything in Section [.], and instead write no line of code that is the slightest bit ambiguous. Similarly, don't use and set a parameter on the same line, even though the semantics are well defined. (Exception: Updating a variable to a new value, such as #1=[#1+#2])

3.6 Don't use line numbers

Line numbers offer no benefits. When line numbers are reported in error messages, the numbers refer to the line number in the file, not the N-word value.

3.7 When moving more than one coordinate system, consider inverse time feed mode

Because the meaning of an F-word in feed-per-minute mode varies depending on which axes are commanded to move, and because the amount of material removed does not depend only on the feed rate, it may be easier to use G93 inverse time feed mode to achieve the desired material removal rate.

4 G Codes

G codes of the RS274/NGC language are shown in Table 5 and described following that.

In the command prototypes, the hyphen (-) stands for a real value. As described earlier, a real value may be (1) an explicit number, 4, for example, (2) an expression, [2+2], for example, (3) a parameter value, #88, for example, or (4) a unary function value, acos[0], for example.

In most cases, if axis words (any or all of X-, Y-, Z-, A-, B-, C-, U-, V-, W-) are given, they specify a destination point. Axis numbers are in the currently active coordinate system, unless explicitly described as being in the absolute coordinate system. Where axis words are optional, any omitted axes will have their current value. Any items in the command prototypes not explicitly described as optional are required. It is an error if a required item is omitted. In prototypes, this will be written as axes.

In the prototypes, the values following letters are often given as explicit numbers. Unless stated otherwise, the explicit numbers can be real values. For example, G10 L2 could equally well be written G[2*5] L[1+1]. If the value of parameter 100 were 2, G10 L#100 would also mean the same. Using real values which are not explicit numbers as just shown in the examples is rarely useful.

If L- is written in a prototype the “-” will often be referred to as the “L number”. Similarly the “-” in H- may be called the “H number”, and so on for any other letter.

4.1 Quick Reference Table

Code Description Parameters Section
G0 Coordinated Straight Motion Rapid n/a [.]
G1 Coordinated Straight Motion Feed Rate n/a [.]
G2, G3 Coordinated Helical Motion Feed Rate I J K or R [.]
G10 L1 Set Tool Table Entry P R X Z [.]
G10 L2 Coordinate System Origin Setting P X Y Z A B C [.]
G17, G18, G19 Plane Select n/a [.]
G20, G21 Units n/a [.]
G28, G30 Return To n/a [.]
G33 Spindle Synchronized Motion K [.]
G33.1 Rigid Tapping K [.]
G38.2-G38.5 Probing n/a [.]
G40 Cancel Cutter Compensation n/a [.]
G41, G42 Cutter Compensation D [.]
G41.1, G42.1 Cutter Compensation Transient D L [.]
G43 Use Tool Length Offset from Tool Table H [.]
G49 Cancel Tool Length Offset I K [.]
G53 Motion in Machine Coordinate System n/a [.]
G54-G59 Select Coordinate System n/a [.]
G59.1-G59.3 Select Coordinate System n/a [.]
G61, G61.1 Path Mode n/a [.]
G64 Continuous Mode with Optional Tolerance P [.]
G73 Drilling Cycle with Chip Breaking R L Q [.]
G76 Multipass Threading Cycle (Lathe) P Z I J R K Q H L E [.]
G80 Cancel Motion Modes n/a [.]
G81 Canned Drilling Cycle R L P [.]
G82-G89 Other Canned Cycles R L P Q [.]
G90, G91 Distance Mode n/a [.]
G92 Offset Coordinate Systems & Set Parameters X Y Z A B C [.]
G92.1, G92.2 Cancel Offsets n/a [.]
G92.3 Apply Parameters to Offset Coordinate Systems n/a [.]
G93, G94, G95 Feed Modes n/a [.]
G96 Constant Surface Speed D S [.]
G97 RPM Mode n/a [.]
G98, G99 Canned Cycle Z Retract Mode n/a [.]
F, S F=Feed, S=Speed n/a [.][.]
M0, M1, M2 Program Control n/a [.]
M3, M4, M5 Spindle Control S [.]
M6 Change Tool T=Tool Number T [.]
M7, M8, M9 Coolant Control n/a [.]
M30, M60 Pallet Shuttle n/a [.]
M50, M51 Feed Override P [.]
M51 Spindle Override n/a [.]
M52 Adaptive Feed Override P [.]
M53 Feed Hold Override P [.]
M100-M199 User Defined M-Codes P Q [.]
O O Codes n/a [.]

4.2 G0 Rapid Linear Motion

For rapid linear motion, program G0 axes, where all the axis words are optional, except that at least one must be used. The G0 is optional if the current motion mode is G0. This will produce coordinated linear motion to the destination point at the current traverse rate (or slower if the machine will not go that fast). It is expected that cutting will not take place when a G0 command is executing.

It is an error if:

  • all axis words are omitted.

If cutter radius compensation is active, the motion will differ from the above; see Section [->]. If G53 is programmed on the same line, the motion will also differ; see Section [.].

4.3 G1 Linear Motion

For linear motion at feed rate (for cutting or not), program G1 axes, where all the axis words are optional, except that at least one must be used. The G1 is optional if the current motion mode is G1. This will produce coordinated linear motion to the destination point at the current feed rate (or slower if the machine will not go that fast).

It is an error if:

  • all axis words are omitted.

If cutter radius compensation is active, the motion will differ from the above; see Section [->]. If G53 is programmed on the same line, the motion will also differ; see Section [.].

4.4 G2, G3 Arc

A circular or helical arc is specified using either G2 (clockwise arc) or G3 (counterclockwise arc). The axis of the circle or helix must be parallel to the X, Y, or Z-axis of the machine coordinate system. The axis (or, equivalently, the plane perpendicular to the axis) is selected with G17 (Z-axis, XY-plane), G18 (Y-axis, XZ-plane), or G19 (X-axis, YZ-plane). Planes 17.1, 18.1, and 19.1 are not currently supported. If the arc is circular, it lies in a plane parallel to the selected plane.

If a line of RS274/NGC code makes an arc and includes rotational axis motion, the rotational axes turn at a constant rate so that the rotational motion starts and finishes when the XYZ motion starts and finishes. Lines of this sort are hardly ever programmed.

If cutter radius compensation is active, the motion will differ from what is described here. See Section [->].

Two formats are allowed for specifying an arc: Center Format and Radius Format.

4.4.1 Center format arcs (preferred format)

In the center format, the coordinates of the end point of the arc in the selected plane are specified along with the offsets of the center of the arc from the current location. In this format, it is OK if the end point of the arc is the same as the current point. It is an error if:

  • When the arc is projected on the selected plane, the distance from the current point to the center differs from the distance from the end point to the center by more than 0.0002 inch (if inches are being used) or 0.002 millimeter (if millimeters are being used).

When the XY-plane is selected, program G2 axes I- J- (or use G3 instead of G2). The axis words are all optional except that at least one of X and Y must be used. I and J are the offsets from the current location (in the X and Y directions, respectively) of the center of the circle. I and J are optional except that at least one of the two must be used. If only one is specified, the value of the other is taken as 0. It is an error if:

  • X and Y are both omitted
  • or I and J are both omitted.

When the XZ-plane is selected, program G2 axes I- K- (or use G3 instead of G2). The axis words are all optional except that at least one of X and Z must be used. I and K are the offsets from the current location (in the X and Z directions, respectively) of the center of the circle. I and K are optional except that at least one of the two must be used. If only one is specified, the value of the other is taken as 0. It is an error if:

  • X and Z are both omitted,
  • or I and K are both omitted.

When the YZ-plane is selected, program G2 axes J- K- (or use G3 instead of G2). The axis words are all optional except that at least one of Y and Z must be used. J and K are the offsets from the current location (in the Y and Z directions, respectively) of the center of the circle. J and K are optional except that at least one of the two must be used. If only one is specified, the value of the other is taken as 0. It is an error if:

  • Y and Z are both omitted
  • or J and K are both omitted.

Here is an example of a center format command to mill an arc: G17 G2 x10 y16 i3 j4 z9.

That means to make a clockwise (as viewed from the positive z-axis) circular or helical arc whose axis is parallel to the Z-axis, ending where X=10, Y=16, and Z=9, with its center offset in the X direction by 3 units from the current X location and offset in the Y direction by 4 units from the current Y location. If the current location has X=7, Y=7 at the outset, the center will be at X=10, Y=11. If the starting value of Z is 9, this is a circular arc; otherwise it is a helical arc. The radius of this arc would be 5.

In the center format, the radius of the arc is not specified, but it may be found easily as the distance from the center of the circle to either the current point or the end point of the arc.

4.4.2 Radius format arcs (discouraged format)

In the radius format, the coordinates of the end point of the arc in the selected plane are specified along with the radius of the arc. Program G2 axes R- (or use G3 instead of G2). R is the radius. The axis words are all optional except that at least one of the two words for the axes in the selected plane must be used. The R number is the radius. A positive radius indicates that the arc turns through less than 180 degrees, while a negative radius indicates a turn of more than 180 degrees. If the arc is helical, the value of the end point of the arc on the coordinate axis parallel to the axis of the helix is also specified.

It is an error if:

  • both of the axis words for the axes of the selected plane are omitted
  • the end point of the arc is the same as the current point.

It is not good practice to program radius format arcs that are nearly full circles or nearly semicircles because a small change in the location of the end point will produce a much larger change in the location of the center of the circle (and, hence, the middle of the arc). The magnification effect is large enough that rounding error in a number can produce out-of-tolerance cuts. For instance, a 1% displacement of the endpoint of a 180 degree arc produced a 7% displacement of the point 90 degrees along the arc. Nearly full circles are even worse. Other size arcs (in the range tiny to 165 degrees or 195 to 345 degrees) are OK.

Here is an example of a radius format command to mill an arc: G17 G2 x 10 y 15 r 20 z 5.

That means to make a clockwise (as viewed from the positive Z-axis) circular or helical arc whose axis is parallel to the Z-axis, ending where X=10, Y=15, and Z=5, with a radius of 20. If the starting value of Z is 5, this is an arc of a circle parallel to the XY-plane; otherwise it is a helical arc.

4.5 G4 Dwell

For a dwell, program G4 P- . This will keep the axes unmoving for the period of time in seconds specified by the P number. It is an error if:

  • the P number is negative.

4.6 G10 L1 Set Tool Table

Set a tool table entry.

G10 L1 P[tool number] R[radius] X[offset] Z[offset] Q[orientation]

For more information on tool orientation see figure ([->])

4.7 G10 L2 Set Coordinate System

The RS274/NGC language view of coordinate systems is described in Section[->].

To set the origin of a coordinate system, program G10 L2 P- axes, where the P number is in the range 1 to 9 (corresponding to G54 to G59.3) and all axis words are optional. The origin of the coordinate system specified by the P number is set to the given values (in terms of the not offset machine coordinate system). Only those coordinates for which an axis word is included on the line will be set. Being in incremental distance mode (G91) has no effect on G10 L2.

It is an error if:

  • the P number does not evaluate to an integer in the range 1 to 9.

If a G92 origin offset was in effect before G10 L2, it will continue to be in effect afterwards.

The coordinate system whose origin is set by a G10 command may be active or inactive at the time the G10 is executed. If it is currently active, the new coordinates take effect immediately.

Example: G10 L2 P1 x 3.5 y 17.2 sets the origin of the first coordinate system (the one selected by G54) to be X=3.5 and Y=17.2. Because only X and Y are specified, the origin point is only moved in X and Y; the other coordinates are not changed.

4.8 G17, G18, G19, G17.1, G18.1, G19.1 Plane Selection

These codes set the current plane as follows:

G17 XY (default)
G18 ZX
G19 YZ
G17.1 UV
G18.1 WU
G19.1 VW

The effects of having a plane selected are discussed in Section [.] and Section [.]

4.9 G20, G21 Length Units

Program G20 to use inches for length units. Program G21 to use millimeters.

It is usually a good idea to program either G20 or G21 near the beginning of a program before any motion occurs, and not to use either one anywhere else in the program. It is the responsibility of the user to be sure all numbers are appropriate for use with the current length units.

4.10 G28, G30 Return to Predefined Absolute Position

Two positions are defined (by parameters 5161-5166 for G28 and parameters 5181-5186 for G30). The parameter values are in terms of the absolute coordinate system and the machine's native coordinate system.

G28 and G30 do not use home switches to find the predefined position. They merely command a rapid motion to the position defined by the parameters, assuming that the machine has already been homed.

To return one or more axes to the predefined position by way of the programmed position, program G28 axes (or use G30). The path is made by a traverse move from the current position to the programmed position, followed by a traverse move of the named axes to the predefined position.

To return all axes to the predefined position without an intermediate position, program G28 or G30 without any axis words.

It is an error if :

  • Radius compensation is turned on

4.11 G33, G33.1 Spindle-Synchronized Motion

For spindle-synchronized motion in one direction, code G33 X- Y- Z- K- where K gives the distance moved in XYZ for each revolution of the spindle. For instance, if starting at Z=0, G33 Z-1 K.0625 produces a 1 inch motion in Z over 16 revolutions of the spindle. This command might be part of a program to produce a 16TPI thread.

For rigid tapping (spindle synchronized motion with return) code G33.1 X- Y- Z- K- where K- gives the distance moved for each revolution of the spindle. A rigid tapping move consists of the following sequence:

  • A move to the specified coordinate, synchronized with the spindle at the given ratio and starting with a spindle index pulse
  • When reaching the endpoint, a command to reverse the spindle (e.g., from 300 RPM clockwise to 300RPM counterclockwise)
  • Continued synchronized motion beyond the specified end coordinate until the spindle actually stops and reverses
  • Continued synchronized motion back to the original coordinate
  • When reaching the original coordinate, a command to reverse the spindle a second time (e.g., from 300RPM counterclockwise to 300RPM clockwise)
  • Continued synchronized motion beyond the original coordinate until the spindle actually stops and reverses
  • An unsynchronized move back to the original coordinate.

All spindle-synchronized motions wait for spindle index, so multiple passes line up. G33 moves end at the programmed endpoint; G33.1 moves end at the original coordinate.

All the axis words are optional, except that at least one must be used.

It is an error if:

  • all axis words are omitted.
  • the spindle is not turning when this command is executed
  • the requested linear motion exceeds machine velocity limits due to the spindle speed

4.12 G38.x Straight Probe

Program G38.2 axes, G38.3 axes, G38.4 axes, or G38.5 axes to perform a straight probe operation. The axis words are optional, except that at least one of them must be used. The tool in the spindle must be a probe.

It is an error if:

  • the current point is the same as the programmed point.
  • no axis word is used
  • cutter radius compensation is enabled
  • the feed rate is zero
  • the probe is already in the target state

In response to this command, the machine moves the controlled point (which should be at the end of the probe tip) in a straight line at the current feed rate toward the programmed point. In inverse time feed mode, the feed rate is such that the whole motion from the current point to the programmed point would take the specified time. The move stops when the programmed point is reached, or when the requested change in the probe input takes place1. Table [.] shows the meaning of the various probing codes.

Code Target state Direction Signal Error
G38.2 Contact Toward workpiece Yes
G38.3 Contact Toward workpiece No
G38.4 No Contact Away from workpiece Yes
G38.5 No Contact Away from workpiece No
Table: Probing codes

After successful probing, parameters 5061 to 5069 will be set to the coordinates of the location of the controlled point at the time the probe changed state. After unsuccessful probing, they are set to the coordinates of the programmed point. Parameter 5070 is set to 1 if the probe succeeded and 0 if the probe failed. If the probe failed, G38.2 and G38.4 will signal an error.

A comment of the form (PROBEOPEN filename.txt) will open filename.txt and store the 9-number coordinate of each successful straight probe in it. The file must be closed with (PROBECLOSE).

4.13 G40, G41, G41.1, G42, G42.1 Cutter Radius Compensation

To turn cutter radius compensation off, program G40. It is OK to turn compensation off when it is already off.

Cutter radius compensation may be performed only if the XY-plane is active.

The behavior of the machining center when cutter radius compensation is on is described in Section [->]

4.13.1 Cutter Radius Compensation from Tool Table

To turn cutter radius compensation on left (i.e., the cutter stays to the left of the programmed path when the tool radius is positive), program G41 D- . To turn cutter radius compensation on right (i.e., the cutter stays to the right of the programmed path when the tool radius is positive), program G42 D- . The D word is optional; if there is no D word, the radius of the tool currently in the spindle will be used. If used, the D number should normally be the slot number of the tool in the spindle, although this is not required. It is OK for the D number to be zero; a radius value of zero will be used.

It is an error if:

  • the D number is not an integer, is negative or is larger than the number of carousel slots,
  • the YZ plane is active,
  • or cutter radius compensation is commanded to turn on when it is already on.

4.13.2 Dynamic Cutter Radius Compensation

To turn cutter radius compensation on left, program G41.1 D- L-. To turn cutter compensation on right, program G42.1 D- L-. The D word specifies the cutter diameter. The L word specifies the cutter orientation, and defaults to 0 if unspecified. For more information on cutter orientation see Section ([->]).

It is an error if:

  • the yz plane is active,
  • the L number is not in the range from 0 to 9 inclusive.
  • or cutter compensation is commanded to turn on when it is already on

4.14 G43, G43.1, G49 Tool Length Offsets

4.14.1 G43, G43.1: Activate Tool length compensation

G43 and G43.1 change subsequent motions by offsetting the Z and/or X coordinates by the length of the tool. G43 and G43.1 do not cause any motion. The next time a compensated axis is moved, that axis's endpoint is the compensated location.

4.14.1.1 G43: Offsets from tool table

To use a tool length offset from the tool table, program G43 H-, where the H number is the desired index in the tool table. The H number will typically be, but does not have to be, the same as the slot number of the tool currently in the spindle. It is OK for the H number to be zero; an offset value of zero will be used.

It is an error if:

  • the H number is not an integer, is negative, or is larger than the number of carousel slots.

4.14.1.2 G43.1: Dynamic tool compensation

To use a tool length offset from the program, use G43.1 I- K-, where I- gives the X tool offset (for lathes) and K- gives the Z tool offset (for lathes and mills).

It is an error if:

  • motion is commanded on the same line as G43.1

4.14.2 G49: Cancel tool length compensation

To use no tool length offset, program G49.

It is OK to program using the same offset already in use. It is also OK to program using no tool length offset if none is currently being used.

4.15 G53 Move in Absolute Coordinates

For linear motion to a point expressed in absolute coordinates, program G1 G53 X- Y- Z- A- B- C- (or use G0 instead of G1), where all the axis words are optional, except that at least one must be used. The G0 or G1 is optional if it is the current motion mode. G53 is not modal and must be programmed on each line on which it is intended to be active. This will produce coordinated linear motion to the programmed point. If G1 is active, the speed of motion is the current feed rate (or slower if the machine will not go that fast). If G0 is active, the speed of motion is the current traverse rate (or slower if the machine will not go that fast).

It is an error if:

  • G53 is used without G0 or G1 being active,
  • or G53 is used while cutter radius compensation is on.

See Section [->] for an overview of coordinate systems.

4.16 G54 G59.3 Select Coordinate System

To select coordinate system 1, program G54, and similarly for other coordinate systems. The system-number-G-code pairs are: (1-G54), (2-G55), (3-G56), (4-G57), (5-G58), (6-G59), (7-G59.1), (8-G59.2), and (9-G59.3).

It is an error if:

  • one of these G-codes is used while cutter radius compensation is on.

See Section [->] for an overview of coordinate systems.

4.17 G61, G61.1, G64 Set Path Control Mode

Program G61 to put the machining center into exact path mode, G61.1 for exact stop mode, or G64 P- for continuous mode with optional tolerance. G61 visits the programmed point exactly, even though that means temporarily coming to a complete stop. G64 without P means to keep the best speed possible, no matter how far away from the programmed point you end up. G64 P- means that it should slow down as required to keep no more than P- away from the programmed endpoint. In addition, when you activate G64 P- it turns on the "naive cam detector"; when there are a series of linear XYZ feed moves at the same feed rate that are less than P- away from being collinear, they are collapsed into a single linear move. On G2/3 moves in the G17 (XY) plane when the maximum deviation of an arc from a straight line is less than the G64 P- tolerance the arc is broken into two lines (from start of arc to midpoint, and from midpoint to end). those lines are then subject to the naive cam algorithm for lines. Thus, line-arc, arc-arc, and arc-line cases as well as line-line benefit from the “naive cam detector”. This improves contouring performance by simplifying the path. It is OK to program for the mode that is already active. See also Section [->] for a discussion of these modes.

4.18 G73 Drilling Cycle with Chip Breaking

The G73 cycle is intended for deep drilling or milling with chip breaking. The retracts in this cycle cut off any long stringers (which are common when drilling in aluminum). This cycle takes a Q number which represents a “delta” increment along the Z axis. Program G73 X- Y- Z- A- B- C- R- L- Q-

  1. Preliminary motion, as described above.
  2. Move the Z-axis only at the current feed rate downward by delta or to the Z position, whichever is less deep.
  3. Rapid up a bit.
  4. Repeat steps 2 and 3 until the Z position is reached at step 2.
  5. Retract the Z-axis at traverse rate to clear Z.

It is an error if:

  • the Q number is negative or zero.

4.19 G76 Threading Canned Cycle

Program G76 P- Z- I- J- R- K- Q- H- E- L- to perform a threading canned cycle. It is an error if:

  • The active plane is not the ZX plane
  • Other axis words, such as X- or Y-, are specified
  • The R- digression value is less than 1.0.
  • All the required words are not specified
  • P-, J-, K- or H- is negative
  • E- is greater than half the drive line length

The “drive line” is a safe line outside the thread material. The “drive line” goes from the initial location to the Z- value specified with G76. The Z extent of the thread is the same as the drive line.

The “thread pitch”, or distance per revolution, is given by the P- value.

The “thread peak” is given by the I- value, which is an offset from the drive line. Negative I values indicate external threads, and positive I values indicate internal threads. Generally the material has been turned to this size before the G76 cycle.

The “initial cut depth” is given by the J- value. The first threading cut will be J beyond the “thread peak” position. J- is positive, even when I- is negative.

The “full thread depth” is given by the K- value. The final threading cut will be K beyond the “thread peak” position. K- is positive, even when I- is negative.

The “depth digression” is given by the R- value. R1.0 selects constant depth on success