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 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 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.
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 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 unoffset machine coordinate system). Only those coordinates for which an axis word is included on the line will be set.
It is an error if:
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.
Program G17 to select the XY-plane. Figure([.]) shows the orientation of the XZ plane.
Program G18 to select the XZ plane. Figure([.]) shows the orientation of the XZ plane.
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. For more information on cutter orientation see Section ([->]).
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 cycle is used on several lines of code in a row, the number must be used the first time, but is optional on the rest of the lines. Sticky numbers keep their value on the rest of the lines if they are not explicitly programmed to be different. The R word is always sticky.
In incremental distance mode: when the XY-plane is selected, X, Y, and R numbers are treated as increments to the current position and Z as an increment from the Z-axis position before the move involving Z takes place; when the YZ or XZ-plane is selected, treatment of the axis words is analogous. In absolute distance mode, the X, Y, R, and Z numbers are absolute positions in the current coordinate system.
The L number is optional and represents the number of repeats. L=0 is not allowed. If the repeat feature is used, it is normally used in incremental distance mode, so that the same sequence of motions is repeated in several equally spaced places along a straight line. In absolute distance mode, L>1 means “do the same cycle in the same place several times,” Omitting the L word is equivalent to specifying L=1. The L number is not sticky.
When L>1 in incremental mode with the XY-plane selected, the X and Y positions are determined by adding the given X and Y numbers either to the current X and Y positions (on the first go-around) or to the X and Y positions at the end of the previous go-around (on the repetitions). The R and Z positions do not change during the repeats.
The height of the retract move at the end of each repeat (called “clear Z” in the descriptions below) is determined by the setting of the retract mode: either to the original Z position (if that is above the R position and the retract mode is G98, OLD_Z), or otherwise to the R position. See Section [.]
It is an error if:
When the XY plane is active, the Z number is sticky, and it is an error if:
When the XZ plane is active, the Y number is sticky, and it is an error if:
When the YZ plane is active, the X number is sticky, and it is an error if:
At the very beginning of the execution of any of the canned cycles, with the XY-plane selected, if the current Z position is below the R position, the Z-axis is traversed to the R position. This happens only once, regardless of the value of L.
In addition, at the beginning of the first cycle and each repeat, the following one or two moves are made
If the XZ or YZ plane is active, the preliminary and in-between motions are analogous.
The G81 cycle is intended for drilling. Program G81 X- Y- Z- A- B- C- R- L-
Example 1. Suppose the current position is (1, 2, 3) and the XY-plane has been selected, and the following line of NC code is interpreted.
G90 G81 G98 X4 Y5 Z1.5 R2.8
This calls for absolute distance mode (G90) and OLD_Z retract mode (G98) and calls for the G81 drilling cycle to be performed once. The X number and X position are 4. The Y number and Y position are 5. The Z number and Z position are 1.5. The R number and clear Z are 2.8. Old Z is 3. The following moves take place.
Example 2. Suppose the current position is (1, 2, 3) and the XY-plane has been selected, and the following line of NC code is interpreted.
G91 G81 G98 X4 Y5 Z-0.6 R1.8 L3
This calls for incremental distance mode (G91) and OLD_Z retract mode (G98) and calls for the G81 drilling cycle to be repeated three times. The X number is 4, the Y number is 5, the Z number is -0.6 and the R number is 1.8. The initial X position is 5 (=1+4), the initial Y position is 7 (=2+5), the clear Z position is 4.8 (=1.8+3), and the Z position is 4.2 (=4.8-0.6). Old Z is 3.
The first move is a traverse along the Z-axis to (1,2,4.8), since old Z < clear Z.
The first repeat consists of 3 moves.
The second repeat consists of 3 moves. The X position is reset to 9 (=5+4) and the Y position to 12 (=7+5).
The third repeat consists of 3 moves. The X position is reset to 13 (=9+4) and the Y position to 17 (=12+5).
The G82 cycle is intended for drilling. Program G82 X- Y- Z- A- B- C- R- L- P-
The G83 cycle (often called peck drilling) is intended for deep drilling or milling with chip breaking. The retracts in this cycle clear the hole of chips and 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 G83 X- Y- Z- A- B- C- R- L- Q-
It is an error if:
This code is currently unimplemented in EMC2. It is accepted, but the behavior is undefined. See section[.]
The G85 cycle is intended for boring or reaming, but could be used for drilling or milling. Program G85 X- Y- Z- A- B- C- R- L-
The G86 cycle is intended for boring. This cycle uses a P number for the number of seconds to dwell. Program G86 X- Y- Z- A- B- C- R- L- P-
The spindle must be turning before this cycle is used. It is an error if:
This code is currently unimplemented in EMC2. It is accepted, but the behavior is undefined.
This code is currently unimplemented in EMC2. It is accepted, but the behavior is undefined.
The G89 cycle is intended for boring. This cycle uses a P number, where P specifies the number of seconds to dwell. program G89 X- Y- Z- A- B- C- R- L- P-
Interpretation of RS274/NGC code can be in one of two distance modes: absolute or incremental.
To go into absolute distance mode, program G90. In absolute distance mode, axis numbers (X, Y, Z, A, B, C) usually represent positions in terms of the currently active coordinate system. Any exceptions to that rule are described explicitly in this Section [.].
To go into incremental distance mode, program G91. In incremental distance mode, axis numbers (X, Y, Z, A, B, C) usually represent increments from the current values of the numbers.
I and J numbers always represent increments, regardless of the distance mode setting. K numbers represent increments in all but one usage (see Section [.]), where the meaning changes with distance mode.
See Section [->] for an overview of coordinate systems.
See Section [->] for more information on Offsets.
To make the current point have the coordinates you want (without motion), program G92 X- Y- Z- A- B- C- , where the axis words contain the axis numbers you want. All axis words are optional, except that at least one must be used. If an axis word is not used for a given axis, the coordinate on that axis of the current point is not changed. It is an error if:
When G92 is executed, the origin of the currently active coordinate system moves. To do this, origin offsets are calculated so that the coordinates of the current point with respect to the moved origin are as specified on the line containing the G92. In addition, parameters 5211 to 5216 are set to the X, Y, Z, A, B, and C-axis offsets. The offset for an axis is the amount the origin must be moved so that the coordinate of the controlled point on the axis has the specified value.
Here is an example. Suppose the current point is at X=4 in the currently specified coordinate system and the current X-axis offset is zero, then G92 x7 sets the X-axis offset to -3, sets parameter 5211 to -3, and causes the X-coordinate of the current point to be 7.
The axis offsets are always used when motion is specified in absolute distance mode using any of the nine coordinate systems (those designated by G54 - G59.3). Thus all nine coordinate systems are affected by G92.
Being in incremental distance mode has no effect on the action of G92.
Non-zero offsets may be already be in effect when the G92 is called. If this is the case, the new value of each offset is A+B, where A is what the offset would be if the old offset were zero, and B is the old offset. For example, after the previous example, the X-value of the current point is 7. If G92 x9 is then programmed, the new X-axis offset is -5, which is calculated by [[7-9] + -3].
To reset axis offsets to zero, program G92.1 or G92.2. G92.1 sets parameters 5211 to 5216 to zero, whereas G92.2 leaves their current values alone.
To set the axis offset values to the values given in parameters 5211 to 5216, program G92.3.
You can set axis offsets in one program and use the same offsets in another program. Program G92 in the first program. This will set parameters 5211 to 5216. Do not use G92.1 in the remainder of the first program. The parameter values will be saved when the first program exits and restored when the second one starts up. Use G92.3 near the beginning of the second program. That will restore the offsets saved in the first program. If other programs are to run between the the program that sets the offsets and the one that restores them, make a copy of the parameter file written by the first program and use it as the parameter file for the second program.
Three feed rate modes are recognized: units per minute, inverse time, and units per revolution. Program G94 to start the units per minute mode. Program G93 to start the inverse time mode. Program G95 to start the units per revolution mode.
In units per minute feed rate mode, an F word is interpreted to mean the controlled point should move at a certain number of inches per minute, millimeters per minute, or degrees per minute, depending upon what length units are being used and which axis or axes are moving.
In units per revolution mode, an F word is interpreted to mean the controlled point should move a certain number of inches per revolution of the spindle, depending on what length units are being used and which axis or axes are moving. G95 is not suitable for threading, for threading use G33 or G76.
In inverse time feed rate mode, an F word means the move should be completed in [one divided by the F number] minutes. For example, if the F number is 2.0, the move should be completed in half a minute.
When the inverse time feed rate mode is active, an F word must appear on every line which has a G1, G2, or G3 motion, and an F word on a line that does not have G1, G2, or G3 is ignored. Being in inverse time feed rate mode does not affect G0 (rapid traverse) motions. It is an error if:
Two spindle control modes are recognized: revolutions per minute, and constant surface speed. Program G96 D- S- to select constant surface speed of S feet per minute (if G20 is in effect) or meters per minute (if G21 is in effect). The maximum spindle speed is set by the D- number in revolutions per minute.
Program G97 to select RPM mode.
It is an error if:
When the spindle retracts during canned cycles, there is a choice of how far it retracts: (1) retract perpendicular to the selected plane to the position indicated by the R word, or (2) retract perpendicular to the selected plane to the position that axis was in just before the canned cycle started (unless that position is lower than the position indicated by the R word, in which case use the R word position).
To use option (1), program G99. To use option (2), program G98. Remember that the R word has different meanings in absolute distance mode and incremental distance mode.
To pause a running program temporarily (regardless of the setting of the optional stop switch), program M0. EMC2 remains in Auto Mode so MDI and other manual actions are not enabled.
To pause a running program temporarily (but only if the optional stop switch is on), program M1. EMC2 remains in Auto Mode so MDI and other manual actions are not enabled.
It is OK to program M0 and M1 in MDI mode, but the effect will probably not be noticeable, because normal behavior in MDI mode is to stop after each line of input, anyway.
To exchange pallet shuttles and then stop a running program temporarily (regardless of the setting of the optional stop switch), program M60.
If a program is stopped by an M0, M1, or M60, pressing the cycle start button will restart the program at the following line.
To end a program, program M2. To exchange pallet shuttles and then end a program, program M30. Both of these commands have the following effects.
No more lines of code in an RS274/NGC file will be executed after the M2 or M30 command is executed. Pressing cycle start will start the program back at the beginning of the file.
To start the spindle turning clockwise at the currently programmed speed, program M3.
To start the spindle turning counterclockwise at the currently programmed speed, program M4.
To stop the spindle from turning, program M5.
It is OK to use M3 or M4 if the spindle speed is set to zero. If this is done (or if the speed override switch is enabled and set to zero), the spindle will not start turning. If, later, the spindle speed is set above zero (or the override switch is turned up), the spindle will start turning. It is OK to use M3 or M4 when the spindle is already turning or to use M5 when the spindle is already stopped.
If the hal component hal_manualtoolchange is loaded M6 will stop the spindle and prompt the user to change the tool. For more information on hal_manualtoolchange see Section ([->])
To change a tool in the spindle from the tool currently in the spindle to the tool most recently selected (using a T word - see Section [.]), program M6. When the tool change is complete:
The tool change may include axis motion. It is OK (but not useful) to program a change to the tool already in the spindle. It is OK if there is no tool in the selected slot; in that case, the spindle will be empty after the tool change. If slot zero was last selected, there will definitely be no tool in the spindle after a tool change.
To turn mist coolant on, program M7.
To turn flood coolant on, program M8.
To turn all coolant off, program M9.
It is always OK to use any of these commands, regardless of what coolant is on or off.
To enable the spindle speed and feed rate override switches, program M48. To disable both switches, program M49. See Section [->] for more details. It is OK to enable or disable the switches when they are already enabled or disabled. These switches can also be toggled individually using M50 and M51 as described in the sections [.] and [.].
To enable the feed rate override switch, program M50 or M50 P1. To disable the switch program M50 P0. While disabled the feed override will have no influence, and the motion will be executed at programmed feed rate. (unless there is an adaptive feed rate override active).
To enable the spindle speed override switch, program M51 or M51 P1. To disable the switch program M51 P0. While disabled the spindle speed override will have no influence, and the spindle speed will have the exact program specified value (using the S-word as described in [.]).
To use an adaptive feed, program M52 or M52 P1. To stop using adaptive feed, program M52 P0. When adaptive feed is enabled, some external input value is used together with the user interface feed override value and the commanded feed rate to set the actual feed rate. In EMC2, the HAL pin motion.adaptive-feed is used for this purpose. Values on motion.adaptive-feed should range from 0 (feed hold) to 1 (full speed).
To enable the feed stop switch, program M53 or M53 P1. To disable the switch program M53 P0. Enabling the feed stop switch will allow motion to be interrupted by means of the feedstop control. In EMC2, the HAL pin motion.feed-hold is used for this purpose. Values of 1 will cause the motion to stop (if M53 is active).
To control a digital output bit, program M- P-, where the M-word ranges from 62 to 65, and the P-word ranges from 0 to an implementation-defined maximum- currently this is 3 in EMC2. These outputs are not changed in realtime and thus should not be used for timing-critical applications.
To control a digital input bit, program M66 P- E- L- Q- , where the P-word and the E-word ranges from 0 to an implementation-defined maximum. Only one of the P or E words must be present. It is an error if they are both missing.
M66 wait on an input stops further execution of the program, until the selected event (or the programmed timeout) occurs. It is an error to program a timeout value of 0 with any mode different than mode 0.
It is also an error to program M66 with both a P-word and an E-word (thus selecting both an analog and a digital input).In EMC2 these inputs are not monitored in realtime and thus should not be used for timing-critical applications.
To invoke a user-defined command, program M1nn P- Q- where P- and Q- are both optional. The external program "M1nn" must be in the directory named in [DISPLAY]PROGRAM_PREFIX in the ini file and is executed with the P and Q values as its two arguments. Execution of the RS274NGC file pauses until the invoked program exits. Any valid executable file can be used.
The error "Unknown M code used" denotes one of the following
For example to open and close a collet closer that is controlled by a paraport pin using a bash script file using M101 and M102. Create two files called M101 and M102. Set them as executable files (typically right click/properties/permissions) before running EMC2.
M101
#!/bin/bash
# file to turn on paraport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out True
exit 0
M102
#!/bin/bash
# file to turn off paraport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out False
exit 0
O-codes provide for flow control in NC programs. Each block has an associated number, which is the number used after O. Care must be taken to properly match the O-numbers.
The behavior is undefined if
Subroutines extend from a O- sub to an O- endsub. The lines inside the subroutine (the “body”) are not executed in order; instead, they are executed each time the subroutine is called with O- call.
O100 sub (subroutine to move to machine home)
G0 X0 Y0 Z0
O100 endsub
(many intervening lines)
O100 call
Inside a subroutine, O- return can be executed. This immediately returns to the calling code, just as though O- endsub was encountered.
O- call takes up to 30 optional arguments, which are passed to the subroutine as #1, #2, ..., #N. Parameters from #N+1 to #30 have the same value as in the calling context. On return from the subroutine, the values of parameters #1 through #30 (regardless of the number of arguments) will be restored to the values they had before the call.
Because “1 2 3” is parsed as the number 123, the parameters must be enclosed in square brackets. The following calls a subroutine with 3 arguments:
O200 call [1] [2] [3]
Subroutine bodies may not be nested. They may only be called after they are defined. They may be called from other functions, and may call themselves recursively if it makes sense to do so. The maximum subroutine nesting level is 10.
Subroutines do not have “return values”, but they may change the value of parameters above #30 and those changes will be visible to the calling code. Subroutines may also change the value of global named parameters.
The “while loop” has two structures: while/endwhile, and do/while. In each case, the loop is exited when the “while” condition evaluates to false.
(draw a sawtooth shape)
F100
#1 = 0
O101 while [#1 lt 10]
G1 X0
G1 Y[#1/10] X1
#1 = [#1+1]
O101 endwhile
Inside a while loop, O- break immediately exits the loop, and O- continue immediately skips to the next evaluation of the while condition. If it is still true, the loop begins again at the top. If it is false, it exits the loop.
The “if” conditional executes one group of statements if a condition is true and another if it is false.
(Set feed rate depending on a variable)
O102 if [#2 GT 5]
F100
O102 else
F200
O102 endif
The O-number may be given by a parameter or calculation.
O[#101+2] call
In O-words, Parameters (section [.]), Expressions (section [.]), Binary Operators (section [.]) and Functions (table [.]) are particularly useful.
To set the feed rate, program F- . The application of the feed rate is as described in Section [->], unless inverse time feed rate mode is in effect, in which case the feed rate is as described in Section [.].
To set the speed in revolutions per minute (rpm) of the spindle, program S- . The spindle will turn at that speed when it has been programmed to start turning. It is OK to program an S word whether the spindle is turning or not. If the speed override switch is enabled and not set at 100%, the speed will be different from what is programmed. It is OK to program S0; the spindle will not turn if that is done. It is an error if:
As described in Section [.], if a G84 (tapping) canned cycle is active and the feed and speed override switches are enabled, the one set at the lower setting will take effect. The speed and feed rates will still be synchronized. In this case, the speed may differ from what is programmed, even if the speed override switch is set at 100%.
To select a tool, program T-, where the T number is the carousel slot for the tool. The tool is not changed until an M6 is programmed (see Section [.]). The T word may appear on the same line as the M6 or on a previous line. It is OK, but not normally useful, if T words appear on two or more lines with no tool change. The carousel may move a lot, but only the most recent T word will take effect at the next tool change. It is OK to program T0; no tool will be selected. This is useful if you want the spindle to be empty after a tool change. It is an error if:
On some machines, the carousel will move when a T word is programmed, at the same time machining is occurring. On such machines, programming the T word several lines before a tool change will save time. A common programming practice for such machines is to put the T word for the next tool to be used on the line after a tool change. This maximizes the time available for the carousel to move.
xxxx
In EMC2, the machine does not return to its original position after a tool change. This change was made because the new tool might be longer than the old tool, and the move to the original machine position could therefore leave the tool tip too low.
In EMC2, the values stored in parameters for the G28 and G30 home locations, the P1…P9 coordinate systems, and the G92 offset are in “inifile units”. This change was made because otherwise the meaning of a location changed depending on whether G20 or G21 was active when G28, G30, G10 L2, or G92.3 is programmed.
In EMC2, the tool lengths (offsets) and diameters in the tool table are specified in inifile units only. This change was made because otherwise the length of a tool and its diameter would change based on whether G20 or G21 was active when initiating G43, G41, G42 modes. This made it impossible to run gcode in the machine's non-native units, even when the gcode was simple and well-formed (starting with G20 or G21, and didn't change units throughout the program), without changing the tool table.
G84 and G87 are not currently implemented, but may be added to a future release of emc2.
When G28 or G30 is programmed with only some axis words present, EMC2 only moves the named axes. This is common on other machine controls. To move some axes to an intermediate point and then move all axes to the predefined point, write two lines of gcode:
G0 X- Y- (axes to move to intermediate point)
G28 (move all axes to predefined point)
M62 and M63 are not currently implemented, but may be added to a future release of emc2.
These codes are not defined in RS274NGC.
The probe tip is not retracted after a G38.2 movement. This retraction move may be added in a future release of emc2.
These codes are not defined in RS274NGC
These codes are not defined in RS274NGC
The RS274NGC spec says “it is expected that” all tool lengths will be positive. However, G43 works for negative tool lengths.
G43 tool length compensation can offset the tool in both the X and Z dimensions. This feature is primarily useful on lathes.
EMC2 allows specification of a computed tool length through G43.1 I K.
EMC2 allows specification of a tool diameter and, if in lathe mode, orientation in the gcode. The format is G41.1/G42.1 D L, where D is diameter and L (if specified) is the lathe tool orientation.
In ngc, this is not allowed. In EMC2, it sets length offsets for the currently loaded tool. If no tool is currently loaded, it is an error. This change was made so the user doesn't have to specify the tool number in two places for each tool change, and because it's consistent with the way G41/G42 work when the D word is not specified.
EMC2 allows machines with up to 9 axes by defining an additional set of 3 linear axes known as U, V and W
1 Actually, the movement continues beyond the “probe state changed” point due to machine acceleration constraints. back