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.
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.
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.
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.
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 |
The following rules are used for (explicit) numbers. In these rules a digit is a single character between 0 and 9.
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.
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.
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:
#<_endmill_dia> = 0.049
#<_endmill_rad> = [#<_endmill_dia>/2.0]
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.
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]]].
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 |
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 |
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.
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.
A comment can also be used to specify a file for the results of G38.2 probing. See section [.].
Often, general logging is more useful than probe logging. Using general logging, the format of the output data can be controlled.
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.
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 whitespace removed from them. So, #<named parameter> is the same as #<namedparameter>.
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.
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.
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.
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.2 G73 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 |
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.
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.
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.
G-code is most legible when at least one space appears before words. While it is permitted to insert whitespace in the middle of numbers, there is no reason to do so.
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.
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.
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])
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.
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.
Tool length and diameter may come from the tool file (see section [->]) or from a word specified when tool compensation is enabled.
Tool compensation can cause problems for the best of nc code programmers. But it can be a powerful aid when used to help an operator get a part to size. By setting and reseting length and diameter of tools in a single tool table, offsets can be made durring a production run that allow for variation in tool size, or for minor deviation from the programmed distances and size. And these changes can be made without the operator having to search through and cange numbers in a program file.
Throughout this unit you will find ocasional references to cannonical functions where these are necessary for the reader to understand how a tool offset works in a specific situation. These references are intended to give the reader a sense of sequence rather than requiring the reader to understand the way that cannonical functions themselves work within the EMC.
Tool length offsets are given as positive numbers in the tool table. A tool length offset is programmed using G43 Hn, where n is the desired table index. It is expected that all entries in the tool table will be positive. The H number is checked for being a non-negative integer when it is read. The interpreter behaves as follows.
1. If G43 Hn is programmed, A USE_TOOL_LENGTH_OFFSET(length) function call is made (where length is the value of the tool length offset entry in the tool table whose index is n), tool_length_offset is reset in the machine settings model, and the value of current_z in the model is adjusted. Note that n does not have to be the same as the slot number of the tool currently in the spindle.
2. If G49 is programmed, USE_TOOL_LENGTH_OFFSET(0.0) is called, tool_length_offset is reset to 0.0 in the machine settings model, and the value of current_z in the model is adjusted. The effect of tool length compensation is illustrated in the screen shot below. Notice that the length of the tool is subtracted from the z setting so that the tool tip appears at the programmed setting. You should note that the effect of tool length compensation is immediate when you view the z position as a relative coordinate but it does affect actual machine position until you program a z move.
Test tool length program.
Tool #1 is 1 inch long.
N01 G1 F15 X0 Y0 Z0
N02 G43 H1 Z0 X1
N03 G49 X0 Z0
N04 G0 X2
N05 G1 G43 H1 G4 P10 Z0 X3
N06 G49 X2 Z0
N07 G0 X0

The effect of this is that in most cases the machine will pick up the offset as a ramp during the next xyz move after the g43 word.
Cutter Diameter Compensation (also called Cutter Radius Compensation) is something that was obviously added onto the RS-274D specification at the demand of users, as it is VERY useful, but the implementation was poorly thought out. The purpose of this feature is to allow the programmer of the tool path program to 'virtualize' the tool path, so that the control can, at run time, determine the correct offset from the surface to be cut, based on the tools available. If you resharpen the side cutting edges of end mills, then they will end up smaller than the standard diameters.
The problem is to describe to the control whether the tool is going to be cutting on the outside of an imaginary path, or on the inside. Since these paths are not necessarily closed paths (although they can be), it is essentially impossible for the control to know which side of the line it is supposed to offset to. It was decided that there would only be two choices, tool 'left' of path, and tool 'right' of path. This is to be interpreted as left or right 'when facing the direction of cutter motion'. The interpretation is as if you were standing on the part, walking behind the tool as it progresses across the part.
The cutter radius compensation capabilities of the interpreter enable the programmer to specify that a cutter should travel to the right or left of an open or closed contour in the XY-plane composed of arcs of circles and straight line segments. The contour may be the outline of material not to be machined away, or it may be a tool path to be followed by an exactly sized tool. This figure shows two examples of the path of a tool cutting using cutter radius compensation so that it leaves a triangle of material remaining.
In both examples, the shaded triangle represents material which should remain after cutting, and the line outside the shaded triangle represents the path of the tip of a cutting tool. Both paths will leave the shaded triangle uncut. The one on the left (with rounded corners) is the path the interpreter will generate. In the method on the right (the one not used), the tool does not stay in contact with the shaded triangle at sharp corners.

Z axis motion may take place while the contour is being followed in the XY plane. Portions of the contour may be skipped by retracting the Z axis above the part, following the contour to the next point at which machining should be done, and re-extending the Z-axis. These skip motions may be performed at feed rate (G1) or at traverse rate (G0). Inverse time feed rate (G93) or units per minute feed rate (G94) may be used with cutter radius compensation. Under G94, the feed rate will apply to the actual path of the cutter tip, not to the programmed contour.
The current interpreter requires a D number on each line that has the G41 or G42 word. The value specified with D must be a non-negative integer. It represents the slot number of the tool whose radius (half the diameter given in the tool table) will be used, or it may be zero (which is not a slot number). If it is zero, the value of the radius will also be zero. Any slot in the tool table may be selected this way. The D number does not have to be the same as the slot number of the tool in the spindle.
Cutter radius compensation uses data from the machining center's tool table. For each slot in the tool carrousel, the tool table contains the diameter of the tool in that slot (or the difference between the actual diameter of the tool in the slot and its nominal value). The tool table is indexed by slot number. How to put data into the table when using the stand-alone interpreter is discussed in the tool table page.
The interpreter handles compensation for two types of contour:
The interpreter does not have any setting that determines which type of contour is used, but the description of the contour will differ (for the same part geometry) between the two types and the values for diameters in the tool table will be different for the two types.
When the contour is the edge of the material, the outline of the edge is described in the NC program. For a material edge contour, the value for the diameter in the tool table is the actual value of the diameter of the tool. The value in the table must be positive. The NC code for a material edge contour is the same regardless of the (actual or intended) diameter of the tool.
Example 1 :
Here is an NC program which cuts material away from the outside of the triangle in figure above. In this example, the cutter compensation radius is the actual radius of the tool in use, which is 0.5, The value for the diameter in the tool table is twice the radius, which is 1.0.
N0010 G41 G1 X2 Y2 (turn compensation on and make entry move)
N0020 Y-1 (follow right side of triangle)
N0030 X-2 (follow bottom side of triangle)
N0040 X2 Y2 (follow hypotenuse of triangle)
N0050 G40 (turn compensation off)
This will result in the tool following a path consisting of an entry move and the path shown on the left going clockwise around the triangle. Notice that the coordinates of the triangle of material appear in the NC code. Notice also that the tool path includes three arcs which are not explicitly programmed; they are generated automatically.
When the contour is a tool path contour, the path is described in the NC program. It is expected that (except for during the entry moves) the path is intended to create some part geometry. The path may be generated manually or by a post-processor, considering the part geometry which is intended to be made. For the interpreter to work, the tool path must be such that the tool stays in contact with the edge of the part geometry, as shown on the left side of Figure 7. If a path of the sort shown on the right of Figure 7 is used, in which the tool does not stay in contact with the part geometry all the time, the interpreter will not be able to compensate properly when undersized tools are used.
For a tool path contour, the value for the cutter diameter in the tool table will be a small positive number if the selected tool is slightly oversized and will be a small negative number if the tool is slightly undersized. As implemented, if a cutter diameter value is negative, the interpreter compensates on the other side of the contour from the one programmed and uses the absolute value of the given diameter. If the actual tool is the correct size, the value in the table should be zero.
Tool Path Contour example
Suppose the diameter of the cutter currently in the spindle is 0.97, and the diameter assumed in generating the tool path was 1.0. Then the value in the tool table for the diameter for this tool should be -0.03. Here is an NC program which cuts material away from the outside of the triangle in the figure.
N0010 G1 X1 Y4.5 (make alignment move)
N0020 G41 G1 Y3.5 (turn compensation on and make first entry move)
N0030 G3 X2 Y2.5 I1 (make second entry move)
N0040 G2 X2.5 Y2 J-0.5 (cut along arc at top of tool path)
N0050 G1 Y-1 (cut along right side of tool path)
N0060 G2 X2 Y-1.5 I-0.5 (cut along arc at bottom right of tool path)
N0070 G1 X-2 (cut along bottom side of tool path)
N0080 G2 X-2.3 Y-0.6 J0.5 (cut along arc at bottom left of tool path)
N0090 G1 X1.7 Y2.4 (cut along hypotenuse of tool path)
N0100 G2 X2 Y2.5 I0.3 J-0.4 (cut along arc at top of tool path)
N0110 G40 (turn compensation off)
This will result in the tool making an alignment move and two entry moves, and then following a path slightly inside the path shown on the left in Figure 7 going clockwise around the triangle. This path is to the right of the programmed path even though G41 was programmed, because the diameter value is negative.
The interpreter will issue the following messages involving cutter radius compensation.
For some of these messages additional explanation is given below.
Changing a tool while cutter radius compensation is on is not treated as an error, although it is unlikely this would be done intentionally. The radius used when cutter radius compensation was first turned on will continue to be used until compensation is turned off, even though a new tool is actually being used.
When cutter radius compensation is on, it must be physically possible for a circle whose radius is the half the diameter given in the tool table to be tangent to the contour at all points of the contour.

In particular, the interpreter treats concave corners and concave arcs into which the circle will not fit as errors, since the circle cannot be kept tangent to the contour in these situations. This error detection does not limit the shapes which can be cut, but it does require that the programmer specify the actual shape to be cut (or path to be followed), not an approximation. In this respect, the interpreter differs from interpreters used with many other controllers, which often allow these errors silently and either gouge the part or round the corner. If cutter radius compensation has already been turned on, it cannot be turned on again. It must be turned off first; then it can be turned on again. It is not necessary to move the cutter between turning compensation off and back on, but the move after turning it back on will be treated as a first move, as described below.
It is not possible to change from one cutter radius index to another while compensation is on because of the combined effect of rules 4 and 11. It is also not possible to switch compensation from one side to another while compensation is on. If the tool is already covering up the next XY destination point when cutter radius compensation is turned on, the gouging message is given when the line of NC code which gives the point is reached. In this situation, the tool is already cutting into material it should not cut.
If a D word is programmed that is larger than the number of tool carrousel slots, an error message is given. In the current implementation, the number of slots is 68.
The error message. "two G Codes Used from Same Modal Group," is a generic message used for many sets of G codes. As applied to cutter radius compensation, it means that more than one of G40, G41, and G42 appears on a line of NC code. This is not allowed.
The algorithm used for the first move when the first move is a straight line is to draw a straight line from the destination point which is tangent to a circle whose center is at the current point and whose radius is the radius of the tool. The destination point of the tool tip is then found as the center of a circle of the same radius tangent to the tangent line at the destination point. This is shown in Figure 9. If the programmed point is inside the initial cross section of the tool (the circle on the left), an error is signalled.


If the first move after cutter radius compensation has been turned on is an arc, the arc which is generated is derived from an auxiliary arc which has its center at the programmed center point, passes through the programmed end point, and is tangent to the cutter at its current location. If the auxiliary arc cannot be constructed, an error is signalled. The generated arc moves the tool so that it stays tangent to the auxiliary arc throughout the move. This is shown in Figure 10.
Regardless of whether the first move is a straight line or an arc, the Z axis may also move at the same time. It will move linearly, as it does when cutter radius compensation is not being used.Rotary axis motions (A, B, and C axes) are allowed with cutter radius compensation, but using them would be very unusual.
After the entry moves of cutter radius compensation, the interpreter keeps the tool tangent to the programmed path on the appropriate side. If a convex corner is on the path, an arc is inserted to go around the corner. The radius of the arc is half the diameter given in the tool table.
When cutter radius compensation is turned off, no special exit move takes place. The next move is what it would have been if cutter radius compensation had never been turned on and the previous move had placed the tool at its current position.
In general, an alignment move and two entry moves are needed to begin compensation correctly. However, where the programmed contour is a material edge contour and there is a convex corner on the contour, only one entry move (plus, possibly, a pre-entry move) is needed. The general method, which will work in all situations, is described first. We assume here that the programmer knows what the contour is already and has the job of adding entry moves.
The general method includes programming an alignment move and two entry moves. The entry moves given above will be used as an example. Here is the relevant code again:
N0010 G1 X1 Y4.5 (make aligment move to point C)
N0020 G41 G1 Y3.5 (turn compensation on and make first entry move to point B)
N0030 G3 X2 Y2.5 I1 (make second entry move to point A)
See Figure 11. The figure shows the two entry moves but not the alignment move.
First, pick a point A on the contour where it is convenient to attach an entry arc. Specify an arc outside the contour which begins at a point B and ends at A tangent to the contour (and going in the same direction as it is planned to go around the contour). The radius of the arc should be larger than half the diameter given in the tool table. Then extend a line tangent to the arc from B to some point C, located so that the line BC is more than one radius long.
After the construction is finished, the code is written in the reverse order from the construction. Cutter radius compensation is turned on after the alignment move and before the first entry move. In the code above, line N0010 is the alignment move, line N0020 turns compensation on and makes the first entry move, and line N0030 makes the second entry move.

In this example, the arc AB and the line BC are fairly large, but they need not be. For a tool path contour, the radius of arc AB need only be slightly larger than the maximum possible deviation of the radius of the tool from the exact size. Also for a tool path contour, the side chosen for compensation should be the one to use if the tool is oversized. As mentioned earlier, if the tool is undersized, the interpreter will switch sides.
If the contour is a material edge contour and there is a convex corner somewhere on the contour, a simpler method of making an entry is available. See Figure 12.
First, pick a convex corner, D. Decide which way you want to go along the contour from D. In our example we are keeping the tool to the left of the contour and going next towards F. Extend the line FD (if the next part of the contour is an arc, extend the tangent to arc FD from D) to divide the area outside the contour near D into two regions. Make sure the center of the tool is currently in the region on the same side of the extended line as the material inside the contour near D. If not, move the tool into that region. In the example, point E represents the current location of the center of the tool. Since it is on the same side of line DF as the shaded triangle, no additional move is needed. Now write a line of NC code that turns compensation on and moves to point D
N0010 G41 G1 X2 Y2 (turn compensation on and make entry move)
This method will also work at a concave corner on a tool path contour, if the actual tool is oversized, but it will fail with a tool path contour if the tool is undersized.

The complete set of canonical functions includes functions which turn cutter radius on and off, so that cutter radius compensation can be performed in the controller executing the canonical functions. In the interpreter, however, these commands are not used. Compensation is done by the interpreter and reflected in the output commands, which continue to direct the motion of the center of the cutter tip. This simplifies the job of the motion controller while making the job of the interpreter a little harder.
The interpreter allows the entry and exit moves to be arcs. The behavior for the intermediate moves is the same, except that some situations treated as errors in the interpreter are not treated as errors in other machine controls.
Data for Cutter Radius Compensation
The interpreter machine model keeps three data items for cutter radius compensation: the setting itself (right, left, or off), program_x, and program_y. The last two represent the X and Y positions which are given in the NC code while compensation is on. When compensation is off, these both are set to a very small number (10 -20 ) whose symbolic value (in a #define) is "unknown". The interpreter machine model uses the data items current_x and current_y to represent the position of the center of the tool tip (in the currently active coordinate system) at all times.
All further system-specific information refers to NIST's EMC program, but much of it applies to most modern CNC controls. My method of checking these programs is to first select tool zero, which always has a diameter of zero, so offset commands are essentially ignored. Then, I tape a sheet of paper to a piece of material that sits level in my vise, as a sort of platen. I install a spring-loaded pen in the spindle. This is a standard ballpoint pen refill cartridge made of metal, in a 1/2" diameter steel housing. It has a spring that loads the pen against the front, and a 'collet' at the front that allows the pen to retract against the spring, but keeps it centered within a few thousandths of an inch. I run the program with tool zero selected, and it draws a line at the actual part's outline. (see figure below) Then, I select a tool with the diameter of the tool I intend to use, and run the program again. (Note that Z coordinates in the program may need to be changed to prevent plunging the pen through the platen.) Now, I get to see whether the G41 or G42 compensation that I specified will cut on the desired side of the part. If it doesn't, I then edit the opposite compensation command into the program, and try again. Now, with the tool on the correct side of the work, you get to see if there are any places where the tool is 'too fat' to fit in a concave part of the surface. My old Allen-Bradley 7320 was pretty forgiving on this, but EMC is a complete stickler. If you have ANY concavity where two lines meet at less than 180 degrees on the side that a tool of finite size cuts on, EMC will stop with an error message there. Even if the gouge will be .0001" deep. So, I always make the approach on the lead-in and lead-out moves such that they just nip the corner of the part a tiny bit, providing an angle just over 180 degrees, so that EMC won't squawk. This requires some careful adjustment of the starting and ending points, which are not compensated by cutter radius, but must be chosen with an approximate radius in mind.
The operative commands are :
G40 - Cancel Cutter compensation
G41 - Cutter Compensation, Tool Left of Path
G42 - Cutter Compensation, Tool Right of Path
Here is a short file that cuts one side of a part with multiple convex and concave arcs, and several straight cuts, too. It is to clamp a high speed drilling spindle to the side of the main Bridgeport spindle. Most of these commands are straight from Bobcad/CAM, but lines N15 and N110 were added by me, and some of the coordinates around those lines had to be fudged a bit by me.
N10 G01 G40 X-1.3531 Y3.4
N15 F10 G17 G41 D4 X-0.7 Y3.1875 (COMP LEAD IN)
N20 X0. Y3.1875
N40 X0.5667 F10
N50 G03 X0.8225 Y3.3307 R0.3
N60 G02 X2.9728 Y4.3563 R2.1875
N70 G01 X7.212 Y3.7986
N80 G02 X8.1985 Y3.2849 R1.625
N90 G03 X8.4197 Y3.1875 R0.3
N100 G01 X9.
N110 G40 X10.1972 Y3.432 (COMP LEAD OUT
N220 M02
Line 15 contains G41 D4, which means that the diameter of the tool described as tool #4 in the tool table will be used to offset the spindle by 1/2 the diameter, which is, of course, the tool's radius. Note that the line with the G41 command contains the endpoint of the move where the radius compensation is interpolated in. What this means is that at the beginning of this move, there is no compensation in effect, and at the end, the tool is offset by 100% of the selected tool radius. Immediately after the G41 is D4, meaning that the offset is by the radius of tool number 4 in the tool table. Note that tool DIAMETERS are entered in the tool table. (Jon's tool diameter is about 0.4890)
But, note that in line 110, where the G40 'cancel cutter compensation' command is, that cutter compensation will be interpolated out in this move. The way I have these set up, the moves in lines 15 and 110 are almost exactly parallel to the X axis, and the difference in Y coordinates is to line the tool up outside the portion of the program where cutter compensation is in force.

Some other things to note are that the program starts with a G40, to turn off any compensation that was in effect. This saves a lot of hassle when the program stops due to a concavity error, but leaves the compensation turned on. Also note in line 15 that G17 is used to select the XY plane for circular interpolation. I have used the radius form of arc center specification rather than the I,J form. EMC is very picky about the radius it computes from I,J coordinates, and they must match at the beginning and end of the move to within 10^-11 internal units, so you will have lots of problems with arbitrary arcs. Usually, if you do an arc of 90 degrees, centered at (1.0,1.0) with a radius of 1", everything will go fine, but if it has a radius that can not be expressed exactly in just a few significant digits, or the arc is a strange number of degrees, then there will be trouble with EMC. The R word clears up all that mess, and is a lot easier to work with, anyway. If the arc is more than 180 degrees, R should be negative.
This unit borrows heavily from the published works of Tom Kramer and Fred Proctor at NIST and the cutter compensation web page of Jon Elson.
Papers by Tom Kramer and Fred Proctor
http://www.isd.mel.nist.gov/personnel/kramer/publications.html
http://www.isd.mel.nist.gov/personnel/kramer/pubs/RS274NGC_22.pdf
http://www.isd.mel.nist.gov/personnel/kramer/pubs/RS274VGER_11.pdf
Pages by Jon Elson
http://artsci.wustl.edu/~jmelson/
http://206.19.206.56/diacomp.htm
http://206.19.206.56/lencomp.htm
G codes of the RS274/NGC language are shown in Table 5 and described following that.
In the command prototypes, the hypen (-) 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.
| 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 | 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 | Probing | n/a | [.] |
| G40 | Cancel Cutter Compenstation | n/a | [.] |
| G41, G42 | Cutter Compenstation | D | [.] |
| G41.1, G42.1 | Cutter Compensation Transient | D L | [.] |
| G43 | Use Tool Lenght Offset from Tool Table | H | [.] |
| G49 | Cancel Tool Lenght 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 | [.] |
| G76 | Multipass Threading Cycle (Lathe) | P Z I J R K Q H L E | [.] |
| G80 | Cancle 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 | [.] |
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:
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 [.].
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:
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 [.].
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). 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.
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 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:
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:
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:
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.
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:
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.
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 RS274/NGC language view of coordinate systems is described in Section[->].
To set the coordinate values for the origin of a coordinate system, program G10 L2 P- axes, where the P number must evaluate to an integer in the range 1 to 9 (corresponding to G54 to G59.3) and all axis words are optional. The coordinates of the origin of the coordinate system specified by the P number are reset to the coordinate values given (in terms of the absolute coordinate system). Only those coordinates for which an axis word is included on the line will be reset.
It is an error if:
If origin offsets (made by G92 or G92.3) were in effect before G10 is used, they 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.
Example: G10 L2 P1 x 3.5 y 17.2 sets the origin of the first coordinate system (the one selected by G54) to a point where X is 3.5 and Y is 17.2 (in absolute coordinates). The Z coordinate of the origin (and the coordinates for any rotational axes) are whatever those coordinates of the origin were before the line was executed.
Program G17 to select the XY-plane, G18 to select the XZ-plane, or G19 to select the YZ-plane. The effects of having a plane selected are discussed in Section [.] and Section [.]
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.
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 :
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:
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:
Program G38.2 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:
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 probe input closes1.
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.
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).
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 [.]
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:
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.
It is an error if:
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.
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:
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:
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.
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:
See Section [->] for an overview of coordinate systems.
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:
See Section [->] for an overview of coordinate systems.
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 colinear, 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.
Program G76 P- Z- I- J- R- K- Q- H- E- L- to perform a threading canned cycle. It is an error if:
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 degression” is given by the R- value. R1.0 selects constant depth on successive threading passes. R2.0 selects constant area. Values between 1.0 and 2.0 select decreasing depth but increasing area. Values above 2.0 select decreasing area. Beware that unnecessarily high degression values will cause a large number of passes to be used.
The “compound slide angle” Q- is the angle (in degrees) describing to what extent successive passes should be offset along the drive line. This is used to cause one side of the tool to remove more material than the other. A positive Q value causes the leading edge of the tool to cut more heavily. Typical values are 29, 29.5 or 30.
The number of “spring passes” is given by the H- value. Spring passes are additional passes at full thread depth. If no additional passes are desired, program H0.
Tapered entry and exit moves can be programmed using E- and L-. E- gives a distance along the drive line used for the taper. E0.2 will give a taper for the first/last 0.2 length units along the thread. L- is used to specify which ends of the thread get the taper. Program L0 for no taper (the default), L1 for entry taper, L2 for exit taper, or L3 for both entry and exit tapers.
The tool will pause briefly for synchronization before each threading pass, so a relief groove will be required at the entry unless the beginning of the thread is past the end of the material or an entry taper is used.
Unless using an exit taper, the exit move (traverse to original X) is not synchronized to the spindle speed. With a slow spindle, the exit move might take only a small fraction of a revolution. If the spindle speed is increased after several passes are complete, subsequent exit moves will require a larger portion of a revolution, resulting in a very heavy cut during the exit move. This can be avoided by providing a relief groove at the exit, or by not changing the spindle speed while threading.
The sample program g76.ngc shows the use of the G76 canned cycle, and can be previewed and executed on any machine using the sim/lathe.ini configuration.
Program G80 to ensure no axis motion will occur. It is an error if:
The canned cycles G81 through G89 have been implemented as described in this section. Two examples are given with the description of G81 below.
All canned cycles are performed with respect to the currently selected plane. Any of the three planes (XY, YZ, ZX) may be selected. Throughout this section, most of the descriptions assume the XY-plane has been selected. The behavior is always analogous if the YZ or XZ-plane is selected.
Rotational axis words are allowed in canned cycles, but it is better to omit them. If rotational axis words are used, the numbers must be the same as the current position numbers so that the rotational axes do not move.
All canned cycles use X, Y, R, and Z words in the NC code. These numbers are used to determine X, Y, R, and Z positions. The R (usually meaning retract) position is along the axis perpendicular to the currently selected plane (Z-axis for XY-plane, X-axis for YZ-plane, Y-axis for XZ-plane). Some canned cycles use additional arguments.
For canned cycles, we will call a number “sticky” if, when the same