# Mach3 Gcode Manual

### 1 Definitions

1.1 Linear Axes

The X, Y, and Z axes form a standard right-handed coordinate system of orthogonal linear axes. Positions of the three linear motion mechanisms are expressed using coordinates on these axes.

1.2 Rotational Axes

The rotational axes are measured in degrees as wrapped linear axes in which the direction of positive rotation is counterclockwise when viewed from the positive end of the corresponding X, Y, or Z-axis. By "wrapped linear axis," we mean one on which the angular position increases without limit (goes towards plus infinity) as the axis turns counterclockwise and decreases without limit (goes towards minus infinity) as the axis turns clockwise. Wrapped linear axes are used regardless of whether or not there is a mechanical limit on rotation.

Clockwise or counterclockwise is from the point of view of the work piece. If the work piece is fastened to a turntable which turns on a rotational axis, a counterclockwise turn from the point of view of the work piece is accomplished by turning the turntable in a direction that (for most common machine configurations) looks clockwise from the point of view of someone standing next to the machine.

1.3 Scaling Input

It is possible to set up scaling factors for each axis. These will be applied to the values of X, Y, Z, A, B, C, I, J and R words whenever these are entered. This allows the size of features machined to be altered and mirror images to be created - by use of negative scale factors. The scaling is the first thing done with the values and things like feed rate are always based on the scaled values.

The offsets stored in tool and fixture tables are not scaled before use. Scaling may, of course, have been applied at the time the values were entered (say using G10).

1.4 Controlled Point

The controlled point is the point whose position and rate of motion are controlled. When the tool length offset is zero (the default value), this is a point on the spindle axis (often called the gauge point) that is some fixed distance beyond the end of the spindle, usually near the end of a tool holder that fits into the spindle. The location of the controlled point can be moved out along the spindle axis by specifying some positive amount for the tool length offset. This amount is normally the length of the cutting tool in use, so that the controlled point is at the end of the cutting tool. G and M-code reference

1.5 Co-ordinated Linear Motion

To drive a tool along a specified path, a machining system must often co-ordinate the motion of several axes. We use the term "coordinated linear motion" to describe the situation in which, nominally, each axis moves at constant speed and all axes move from their starting positions to their end positions at the same time. If only the X, Y, and Z axes (or any one or two of them) move, this produces motion in a straight line, hence the word "linear" in the term. In actual motions, it is often not possible to maintain constant speed because acceleration or deceleration is required at the beginning and/or end of the motion. It is feasible, however, to control the axes so that, at all times, each axis has completed the same fraction of its required motion as the other axes. This moves the tool along the same path, and we also call this kind of motion coordinated linear motion.

Co-ordinated linear motion can be performed either at the prevailing feed rate, or at rapid traverse rate. If physical limits on axis speed make the desired rate unobtainable, all axes are slowed to maintain the desired path.

1.6 Feed Rate

The rate at which the controlled point or the axes move is nominally a steady rate which may be set by the user. In the Interpreter, the interpretation of the feed rate is as follows unless inverse time feed rate (G93) mode is being used:

• For motion involving one or more of the linear axes (X, Y, Z and optionally A, B, C), without simultaneous rotational axis motion, the feed rate means length units per minute along the programmed linear XYZ(ABC) path
• For motion involving one or more of the linear axes (X, Y, Z and optionally A, B, C), with simultaneous rotational axis motion, the feed rate means length units per minute along the programmed linear XYZ(ABC) path combined with the angular velocity of the rotary axes multiplied by the appropriate axis Correction Diameter multiplied by pi (p = 3.14152...); i.e. the declared "circumference" of the part
• For motion of one rotational axis with X, Y, and Z axes not moving, the feed rate means degrees per minute rotation of the rotational axis.
• For motion of two or three rotational axes with X, Y, and Z axes not moving, the rate is applied as follows. Let dA, dB, and dC be the angles in degrees through which the A, B, and C axes, respectively, must move. Let D = sqrt (dA2+ dB2+ dC2). Conceptually, D is a measure of total angular motion, using the usual Euclidean metric. Let T be the amount of time required to move through D degrees at the current feed rate in degrees per minute. The rotational axes should be moved in coordinated linear motion so that the elapsed time from the start to the end of the motion is T plus any time required for acceleration or deceleration.

1.7 Arc Motion

Any pair of the linear axes (XY, YZ, and XZ) can be controlled to move in a circular arc in the plane of that pair of axes. While this is occurring, the third linear axis and the rotational axes can be controlled to move simultaneously at effectively a constant rate. As in coordinated linear motion, the motions can be coordinated so that acceleration and deceleration do not affect the path.

If the rotational axes do not move, but the third linear axis does move, the trajectory of the controlled point is a helix.

The feed rate during arc motion is as described in Feed Rate above. In the case of helical motion, the rate is applied along the helix. Beware as other interpretations are used on other systems.

1.8 Coolant

Flood coolant and mist coolant may each be turned on independently. They are turned off together.

1.9 Dwell

A machining system may be commanded to dwell (i.e., keep all axes unmoving) for a specific amount of time. The most common use of dwell is to break and clear chips or for a spindle to get up to speed. The units in which you specify Dwell are either seconds or Milliseconds depending on the setting on Configure>Logic.

1.10 Units

Units used for distances along the X, Y, and Z axes may be measured in millimeters or inches. Units for all other quantities involved in machine control cannot be changed.

Different quantities use different specific units. Spindle speed is measured in revolutions per minute. The positions of rotational axes are measured in degrees. Feed rates are expressed in current length units per minute or in degrees per minute, as described above.

Carefully check the system's response to changing units while tool and fixture offsets are loaded into the tables, while these offsets are active and/or while a part program is executing

WARNING
Changing units during a file can cause the machine to move unexpectedly causing INJURY, PROPERTY DAMAGE, or DEATH

1.11 Current Position

The controlled point is always at some location called the "current position" and Mach3 always knows where that is. The numbers representing the current position are adjusted in the absence of any axis motion if any of several events take place:

• Length units are changed (but see Warning above)
• Tool length offset is changed
• Coordinate system offsets are changed.

1.12 Selected Plane

There is always a "selected plane", which must be the XY-plane, the YZ-plane, or the XZ-plane of the machining system. The Z-axis is, of course, perpendicular to the XY-plane, the X-axis to the YZ-plane, and the Y-axis to the XZ-plane.

1.13 Tool Table

Zero or one tool is assigned to each slot in the tool table.

1.14 Tool Change

Mach3 allows you to implement a procedure for implementing automatic tool changes using macros or to change the tools by hand when required.

1.15 Pallet Shuttle

Mach3 allows you to implement a procedure for implementing pallet shuttle using macros.

1.16 Path Control Modes

The machining system may be put into any one of two path control modes:

(1) Exact stop mode, (2) constant velocity mode. In exact stop mode, the machine stops briefly at the end of each programmed move. In constant velocity mode, sharp corners of the path may be rounded slightly so that the feed rate may be kept up. These modes are to allow the user to control the compromise involved in turning corners because a real machine has a finite acceleration due to the inertia of its mechanism.

Exact Stop does what it says. The machine will come to rest at each change of direction and the tool will therefore precisely follow the commanded path.

Constant Velocity will overlap acceleration in the new direction with deceleration in the current one in order to keep the commanded feedrate. This implies a rounding of any corner but faster and smoother cutting. This is particularly important in routing and plasma cutting. G and M-code reference

The lower the acceleration of the machine axes, the greater will be the radius of the rounded corner.

In Plasma mode (set on Configure Logic dialog) the system uses a proprietary algorithm to optimize motion around corners for plasma cutting.

It is also possible to define a limiting angle so that changes in direction of more than this angle will always be treated as Exact Stop even though Constant Velocity is selected. This allows gentle corners to be smoother but avoids excessive rounding of sharp corners even on machines with low acceleration on one or more axes. This feature is enabled in the Configure Logic dialog and the limiting angle is set by a DRO. This setting will probably need to be chosen experimentally depending on the characteristics of the machine tool and, perhaps, the tool path of an individual job.

### 2 Interpreter Interaction with Controls

2.1 Feed and Speed Override Controls

Mach3 commands which enable (M48) or disable (M49) the feed and speed override switches. It is useful to be able to override these switches for some machining operations. The idea is that optimal settings have been included in the program, and the operator should not change them.

2.2 Block Delete control

If the block delete control is ON, lines of code which start with a slash (the block delete character) are not executed. If the switch is off, such lines are executed.

2.3 Optional Program Stop Control

The optional program stop control (see Configure>Logic) works as follows. If this control is ON and an input line contains an M1 code, program execution is stopped at the end on the commands on that line until the Cycle Start button is pushed.

### 3 Tool File

Mach3 maintains a tool file for each of the 254 tools which can be used.

Each data line of the file contains the data for one tool. This allows the definition of the tool length (Z axis), tool diameter (for milling) and tool tip radius (for turning).

### 4 The Language of Part Programs

4.1 Overview

The language is based on lines of code. Each line (also called a "block") may include commands to the machining system 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 commands start with either G or M (for General and Miscellaneous). The words for these commands are called "G codes" and "M codes."

The 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 in the normal flow so will generally be parts of subroutines.

 ParameterNumber Meaning ParameterNumber Meaning 5161 G28 home X 5264 Work offset 3 A 5162 G28 home Y 5265 Work offset 3 B 5163 G28 home Z 5266 Work offset 3 C 5164 G28 home A 5281 Work offset 4 X 5165 G28 home B 5282 Work offset 4 Y 5166 G28 home C 5283 Work offset 4 Z 5181 G30 home X 5284 Work offset 4 A 5182 G30 home Y 5285 Work offset 4 B 5183 G30 home Z 5286 Work offset 4 C 5184 G30 home A 5301 Work offset 5 X 5185 G30 home B 5302 Work offset 5 Y 5186 G30 home C 5303 Work offset 5 Z 5211 G92 offset X 5304 Work offset 5 A 5212 G92 offset Y 5305 Work offset 5 B 5213 G92 offset Z 5306 Work offset 5 C 5214 G92 offset A 5321 Work offset 6 X 5215 G92 offset B 5322 Work offset 6 Y 5216 G92 offset C 5323 Work offset 6 Z 5220 Current Work Offset Number 5324 Work offset 6 A 5221 Work offset 1 X 5325 Work offset 6 B 5222 Work offset 1 Y 5326 Work offset 6 C 5223 Work offset 1 Z And so on every 20 values until 5224 Work offset 1 A 10281 Work offset 254 X 5225 Work offset 1 B 10282 Work offset 254 Y 5226 Work offset 1 C 10283 Work offset 254 Z 5241 Work offset 2 X 10284 Work offset 254 A 5242 Work offset 2 Y 10285 Work offset 254 B 5243 Work offset 2 Z 10286 Work offset 254 C 5244 Work offset 2 A 10301 Work offset 255 X 5245 Work offset 2 B 10302 Work offset 255 Y 5246 Work offset 2 C 10303 Work offset 255 Z 5261 Work offset 3 X 10304 Work offset 255 A 5262 Work offset 3 Y 10305 Work offset 255 B 5263 Work offset 3 Z 10306 Work offset 255 C

4.2 Parameters

A Mach3 machining system maintains an array of 10,320 numerical parameters. Many of them have specific uses. The parameters which are associated with fixtures are persistent over time. Other parameters will be undefined when Mach3 is loaded. The parameters are preserved when the interpreter is reset. The parameters with meanings defined by Mach3 are given in figure 10.1

Figure 10.1 - System defined parameters G and M-code reference

4.3 Coordinate Systems

The machining system has an absolute coordinate system and 254 work offset (fixture) systems.

You can set the offsets of tools by G10 L1 P~ X~ Z~. The P word defines the tool offset number to be set.

You can set the offsets of the fixture systems using G10 L2 P~ X~ Y~ Z~ A~ B~ C~.

The P word defines the fixture to be set. The X, Y, Z etc. words are the coordinates for the origin of for the axes in terms of the absolute coordinate system.

You can select one of the first seven work offsets by using G54, G55, G56, G57, G58, and G59.

Any of the 255 work offsets can be selected by G59 P~ (e.g. G59 P23 would select fixture 23). The absolute coordinate system can be selected by G59 P0.

You can offset the current coordinate system using G92 or G92.3. This offset will then be applied on top of work offset coordinate systems. This offset may be cancelled with G92.1 or G92.2.

You can make straight moves in the absolute machine coordinate system by using G53 with either G0 or G1.

 Letter Meaning A A-axis of machine B B-axis of machine C C-axis of machine D Tool Radius Compensation Number F Feedrate G General Function H Tool Length Offset Index I X-Axis Offset for Arcs X Offset in G87 Canned Cycle J Y-Axis Offset for Arcs Y Offset in G87 Canned Cycle K Z-Axis Offset for Arcs Z Offset in G87 Canned Cycle L Number of Repetitions in Canned Cycles/Sub-Routines Key Used with G10 M Miscellaneous Function N Line Number O Subroutine Label Number P Dwell Time in Canned Cycles Dwell Time with G4Key Used with G10 Q Feed Increment in G83 Canned Cycle Repetitions of Sub-Routine Call R Arc RadiusCanned Cycle Retract Level S Spindle Speed T Tool Selection U Synonymous with A V Synonymous with B W Synonymous with C X X-Axis of Machine Y Y-Axis of Machine Z Z-Axis of Machine

Figure 1 - Word Initial Letters for G-Codes

### 5 Format of a Line

A permissible line of input 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.

• An optional block delete character ("/”).
• An optional line number.
• Any number of words, parameter settings, and comments.
• An end of line marker (carriage return or line feed or both).

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

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. For example, the line “G0 X+0.1234 Y7” is equivalent to “G0 X+0.1234 Y7”.

Blank lines are allowed in the input. They will 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.

5.1 Line Number

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

5.2 Subroutine Labels

A subroutine label is the letter O followed by an integer (with no sign) between 0 and 99999 written with no more than five digits (000009 is not permitted, for example).

Subroutine labels may be used in any order but must be unique in a program although violation of this rule may not be flagged as an error. Nothing else except a comment should appear on the same line after a subroutine label.

5.3 Word

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

Words may begin with any of the letters shown in figure 11.2. The table includes N and O for completeness, even though, as defined above, line numbers are not words. Several letters (I, J, K, L, P, and R) may have different meanings in different contexts.

A real value is some collection of characters that can be processed to come up with a number. A real value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression, or a unary operation value. Definitions of these follow immediately.

Processing characters to come up with a number is called "evaluating". An explicit number evaluates to itself.

5.3.1 Number

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

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

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

Numbers used for specific purposes by Mach3 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.

5.3.2 Parameter Value

A parameter value is the hash character # followed by a real value. The real value must evaluate to an integer between 1 and 10320. The integer is a parameter number, and the value of the parameter value is whatever number is stored in the numbered parameter.

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.

5.3.3 Expressions and Binary Operations

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 may be 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-[#3**[4.0/2]]]

Binary operations appear only inside expressions. Nine binary operations are defined. 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 binary operations are divided into three groups. The first group is: power. The second group is: multiplication, division, and modulus. The third group is: addition, subtraction, logical non-exclusive or, logical exclusive or, and logical and. If operations are strung together (for example in the expression [2.0/3*1.5-5.5/11.0]), operations in the first group are to be performed before operations in the second group and operations in the second group before operations in the third 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 simplifies 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.

5.3.4 Unary Operation Value

A unary operation value is either "ATAN" followed by one expression divided by another expression (for example ATAN/[1+3]) or any other unary operation name followed by an expression (for example SIN). The unary operations are: ABS (absolute value), ACOS (arc cosine), ASIN (arc sine), ATAN (arc tangent), COS (cosine), EXP (e raised to the given power), FIX (round down), FUP (round up), LN (natural logarithm), ROUND (round to the nearest whole number), SIN (sine), SQRT (square root), and TAN (tangent). 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.

5.4 Parameter Setting

A parameter setting is the following four items one after the other:

• A pound character #
• A real value which evaluates to an integer between 1 and 10320,
• An equal sign = , and
• A real value. For example "#3 = 15" is a parameter setting meaning "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.

A line that starts with the percent character, %, is treated as a comment and not interpreted in any way.

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)

An alternative form of comment is to use the two characters.

// This is treated as a comment

Comments do not cause the machining system to do anything.

A comment that is included in parentheses, 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. Note that the comma which is required. The rest of the characters before the right parenthesis are considered to be a message to the operator. Messages are displayed on screen in the "Error" intelligent label.

5.6 Item Repeats

A line may have any number of G words, but two G words from the same modal group 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.

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.

5.7 Item Order

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

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

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

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

If each group is kept in order or reordered without changing the meaning of the line, then the three groups may be interleaved in any way without changing the meaning of the line. For example:

g40 g1 #3=15 (so there!) #4=-7.0

This line 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 (so there!)

5.8 Commands and Machine Modes

Mach3 has many commands which cause a machining system 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.

### 6 Modal Groups

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

 The modal Groups for G codes are: ·         Group 1 = {G00, G01, G02, G03, G38.2, G80, G81, G82, G84, G85, G86, G87, G88, G89} motion ·         Group 2 = {G17, G18, G19} plane selection ·         Group 3 = {G90, G91} distance mode ·         Group 5 = {G93, G94} feed rate mode ·         Group 6 = {G20, G21} units ·         Group 7 = {G40, G41, G42} cutter radius compensation ·         Group 8 = {G43, G49} tool length offset ·         Group 10 = {G98, G99} return mode in canned cycles ·         Group 12 = {G54, G55, G56, G57, G58, G59, G59.xxx} coordinate system selection ·         Group 13 = {G61, G61.1, G64} path control mode In addition to the above modal groups, there is a group for non-modal G codes: ·         Group 0 = {G4, G10, G28, G30, G53, G92, G92.1, G92.2, G92.3}

Figure 2 - Modal Groups

For several modal groups, when a machining system 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 system 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. Mach3 displays the current mode at the top of each screen.

### 8 Macro M-Codes

8.1 Macro Overview

If any M-code is used which is not in the above list of built-in codes then Mach3 will attempt to find a file named "Mxx.M1S" in the Macros folder. If it finds the file then it will execute the VB script program it finds within it.

The Operator>Macros menu item displays a dialog which allows you to see the currently installed macros, to Load, Edit and Save or Save As the text. The dialog also has a Help button which will display the VB functions which can be called to control Mach3. For example you can interrogate the position of axes, move axes, interrogate input signals and control output signals.

New macros can be written using an external editor program like Notepad and saved in the Macros folder or you can load an existing macro within Mach3, totally rewrite it and save it with a different file name.

8.2 List of M-Codes

Mach3 supports the following M-Codes.

 M-Code Functions M0 Program stop M1 Optional program stop M3/M4 Rotate spindle clockwise/counterclockwise M5 Stop spindle rotation M6 Tool change (by two macros) M7 Mist on M8 Flood on M9 Mist & flood off M30 Program end and rewind M47 Repeat program from first line M48 Enable speed and feed override M98 Call subroutine M99 Return from subroutine/repeat

MachMotion has created the following custom M-Codes for controlling outputs.

 Custom M-Code Functions M200 Output 5 on M201 Output 5 off M202 Output 6 on M203 Output 6 off M204 Output 7 on M205 Output 7 off M206 Output 8 on M207 Output 8 off M208 Output 9 on M209 Output 9 off M210 Output 10 on M211 Output 10 off M212 Output 11 on M213 Output 11 off M214 Output 12 on M215 Output 12 off

### 9 Other Input Codes

9.1 Set Feed Rate – F

To set the feed rate, program F~.

Depending on the setting of the Feed Mode toggle the rate may be in units/minute or units/rev of the spindle.

The units are those defined by the G20/G21 mode.

Depending on the setting in Configure>Logic a revolution of the spindle may be defined as a pulse appearing on the Index input or be derived from the speed requested by the S word or Set Spindle speed DRO.

The feed rate may sometimes be overridden as described in M48 and M49 above.

9.2 Set Spindle Speed – S

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 the S number is negative.

9.3 Select Tool – T

To select a tool, program T~ where the T number is the slot number in the tool changer (of course a rack for manual changing) for the tool.

Even if you have an automatic tool changer, the tool is not changed automatically by the T word (to do this use M06). The T word just allows the changer to get the tool ready.

M06 (depending on the settings in Config>Logic) will operate the tool changer or stop execution of the part-program so you can change the tool by hand. The detailed execution of these changes is set in the M6Start and M6End macros. If you require anything special you will have to customize these.

The T word, itself, does not actually apply any offsets. Use G43 or G44, q.v., to do this. The H word in G43/G44 specifies which tool table entry to use to get the tool offset. Notice that this is different to the action when you type a tool slot number into the T DRO. In this case an implied G43 is performed so the length offset for the tool will be applied assuming that the slot number and the tool table entry number are the same.

It is OK, but not normally useful, if T words appear on two or more lines with no 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 a negative T number is used, or a T number larger than 255 is used.

### 10 Error Handling

This section describes error handling in Mach3.

If a command does not work as expected or does not do anything check that you have typed it correctly. Common mistakes are GO, instead of G0 i.e. letter O instead of zero) and too many decimal points in numbers. Mach3 does not check for axis over travel (unless software limits are in use) or excessively high feeds or speeds. Nor does it does not detect situations where a legal command does something unfortunate, such as machining a fixture.

### 11 Order of Execution

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

 Order Item 1 Comment (including message) 2 Set feed rate mode (G93, G94, G95) 3 Set feed rate (F) 4 Set spindle speed (S) 5 Select tool 6 Tool change (M6) and Execute M-code macros 7 Spindle On/Off (M3, M4, M5) 8 Coolant On/Off (M7, M8, M9) 9 Enable/disable overrides (M48, M49) 10 Dwell (G4) 11 Set active plane (G17, G18, G18) 12 Set length units (G20, G21) 13 Cutter radius compensation On/Off (G40, G41, G42) 14 Tool table offset On/Off (G43, G49) 15 Fixture table select (G54 - G58 & G59 P~) 16 Set path control mode (G61, G61.1, G64) 17 Set distance mode (G90, G91) 18 Set canned cycle return level mode (G98, G99) 19 Home, or change coordinate system data (G10), or set offsets (G92,G94) 20 Perform motion (G0 to G3, G12, G13, G80 to G89 as modified by G53 21 Stop or repeat (M0, M1, M2, M30, M47, M99)

Figure 3 - Order of Execution on a Line

### 12 G-Codes

G00 Rapid Move

• For rapid linear motion, program G0 X~ Y~ Z~ A~ B~ C~, 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.
• If G16 has been executed to set a Polar Origin then for rapid linear motion to a point described by a radius and angle G0 X~ Y~ can be used. X~ is the radius of the line from the G16 polar origin and Y~ is the angle in degrees measured with increasing values counterclockwise from the 3 o’clock direction (i.e. the conventional four quadrant conventions). Coordinates of the current point at the time of executing the G16 are the polar origin.

It is an error if:

• All axis words are omitted

If cutter radius compensation is active, the motion will differ from the above; see Cutter Compensation. If G53 is programmed on the same line, the motion will also differ.

G01 Linear Move

• For linear motion at feed rate (for cutting or not), program G1 X~ Y~ Z~ A~ B~ C~, 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 co-ordinated linear motion to the destination point at the current feed rate (or slower if the machine will not go that fast).
• If G16 has been executed to set a polar origin then linear motion at feed rate to a point described by a radius and angle G0 X~ Y~ can be used. X~ is the radius of the line from the G16 polar origin and Y~ is the angle in degrees measured with increasing values counterclockwise from the 3 o’clock direction (i.e. the conventional four quadrant conventions).

Coordinates of the current point at the time of executing the G16 are the polar origin.

It is an error if:

• All axis words are omitted

If cutter radius compensation is active, the motion will differ from the above; see Cutter Compensation. If G53 is programmed on the same line, the motion will also differ.

G02 & G03 Arc Move

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 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 the above.

Two formats are allowed for specifying an arc. We will call these the center format and the radius format. In both formats the G2 or G3 is optional if it is the current motion mode.

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 X~ Y~ Z~ A~ B~ C~ 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 180 degrees or less, while a negative radius indicates a turn of 180 degrees to 359.999 degrees. If the arc is helical, the value of the end point of the arc on the coordinate axis parallel to the axis of the helix is also specified.

It is an error if:

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

It is not good practice to program radius format arcs that are nearly full circles or are semicircles (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. Nearly full circles are outrageously bad, semicircles (and nearly so) are only very bad. 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 X10 Y15 R20 Z5

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.

Arc Center Format

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

It is an error if:

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

The center is specified using the I and J words. There are two ways of interpreting them. The usual way is that I and J are the center relative to the current point at the start of the arc. This is sometimes called Incremental IJ mode. The second way is that I and J specify the center as actual coordinates in the current system. This is rather misleadingly called Absolute IJ mode.

The IJ mode is set using the Configure>State… menu when Mach3 is set up. The choice of modes are to provide compatibility with commercial controllers. You will probably find Incremental to be best. In Absolute it will, of course usually be necessary to use both I and J words unless by chance the arc’s center is at the origin.

When the XY-plane is selected, program G2 X~ Y~ Z~ A~ B~ C~ 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 or coordinates - depending on IJ mode (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.

It is an error if:

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

When the XZ-plane is selected, program G2 X~ Y~ Z~ A~ B~ C~ 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 or coordinates - depending on IJ mode (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.

It is an error if:

• X and Z are both omitted
• I and K are both omitted

When the YZ-plane is selected, program G2 X~ Y~ Z~ A~ B~ C~ 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 or coordinates - depending on IJ mode (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.

It is an error if:

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

Here is an example of a center format command to mill an arc in Incremental IJ mode:

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.

The above arc in Absolute IJ mode would be:

G17 G2 X10 Y16 I10 J11 Z9

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.

G4 Dwell

For a dwell, program G4 P~. This will keep the axes unmoving for the period of time in seconds or milliseconds specified by the P number. The time unit to be used is set up on the Config>Logic dialog. For example, with units set to Seconds, G4 P0.5 will dwell for half a second.

It is an error if:

• The P number is negative

G10 Tool Offset and Work Offset Tables

To set the offset values of a tool, program G10 L1 P~ X~ Z~ A~, where the P number must evaluate to an integer in the range 0 to 255 - the tool number - Offsets of the tool specified by the P number are reset to the given. The A number will reset the tool tip radius. Only those values for which an axis word is included on the line will be reset. The Tool diameter cannot be set in this way.

To set the coordinate values for the origin of a fixture coordinate system, program G10 L2 P~ X~ Y~ Z~ A~ B~ C~, where the P number must evaluate to an integer in the range 1 to 255 - the fixture number - (Values 1 to 6 corresponding to G54 to G59) 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:

• The P number does not evaluate to an integer in the range 0 to 255

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. The values set will not be persistent unless the tool or fixture tables are saved using the buttons on Tables screen.

Example: G10 L2 P1 x3.5 y17.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.

G12 & G13 CW/CCW Circular Pocket

These circular pocket commands are a sort of canned cycle which can be used to produce a circular hole larger than the tool in use or with a suitable tool (like a woodruff key cutter) to cut internal grooves for “O” rings etc.

Program G12 I~ for a clockwise move and G13 I~ for a counterclockwise move.

The tool is moved in the X direction by the value if the I word and a circle cut in the direction specified with the original X and Y coordinates as the center. The tool is returned to the center.

Its effect is undefined if the current plane is not XY.

G15 & G16 Exit and Enter Polar Mode

It is possible for G0 and G1 moves in the X/Y plane only to specify coordinates as a radius and angle relative to a temporary center point. Use G16 to enter this mode. The current coordinates of the controlled point are the temporary center.

Use G15 to revert to normal Cartesian coordinates:

G0 X10 Y10 // Normal G0 move to 10, 10

G16        // Start of polar mode

G10 X10 Y45

(This will move to X 17.xxx, Y 17.xxx which is a spot on a circle)

(of radius 10 at 45 degrees from the initial coordinates of 10,10.)

This can be very useful, for example, for drilling a circle of holes. The code below moves to a circle of holes every 10 degrees on a circle of radius 50 mm center X = 10, Y = 5.5 and peck drills to Z = -0.6.

G21        // Metric

G00 X10 Y5.5

G16

G01 X50 Y0 // Polar move to a radius of 50 angle 0deg

G83 Z-0.6  // Peck drill

G01 Y10    // Ten degrees from original center...

G83 Z-0.6

G01 Y20    // 20 degrees....etc...

G01 Y30

G01 Y40

> ...etc....

G15        // Back to normal Cartesian

Notes:

1. You must not make X or Y moves other than by using G0 or G1 when G16 is active
2. This G16 is different to a Fanuc implementation in that it uses the current point as the polar center. The Fanuc version requires a lot of origin shifting to get the desired result for any circle not centered on 0, 0.

G17, G18 & G19 Plane Selection

Use 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 under G02/03 and canned cycles

G20 & G21 Unit Selection

Command G20 or G21 to use inches or millimeters respectively for length units. It is usually a good idea to command 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. See also G70/G71 which are synonymous.

A home position is defined by parameters 5161-5166 for G28 and 5181-5186 for G30. The parameter values are in terms of the absolute coordinate system, but are in unspecified length units.

To return to home position by way of the commanded position, program G28 X~ Y~ Z~ A~ B~ C~ (or use G30). All axis words are optional. The path is made by a traverse move from the current position to the programmed position, followed by a traverse move to the home position. If no axis words are commanded, the intermediate point is the current point, so only one move is made. Note: G28 / G30 should not be on the same line as a G90 or G91.

G28.1 Reference Axis

Program G28.1 X~ Y~ Z~ A~ B~ C~ to reference the given axes. The axes will move at the current feed rate towards the home switches, as defined by the Configuration. When the absolute machine coordinate reaches the value given by an axis word then the feed rate is set to that defined by Configure>Config Referencing. Provided the current absolute position is approximately correct, then this will give a soft stop onto the reference switches. Note: G28.1 should not be on the same line as a G90 or G91.

G31 Straight Probe

The Straight Probe Command

Program G31 X~ Y~ Z~ A~ B~ C~ to perform a straight probe operation. The rotational axis words are allowed, 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. The linear axis words are optional, except that at least one of them must be used. The tool in the spindle must be a probe.

It is an error if:

• The current point is less than 0.254 mm or 0.01 inches from the programmed point
• G31 is used in inverse time feed rate mode
• Any rotational axis is commanded to move
• No X, Y, or Z-axis word is used

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. If the probe trips, it is retracted slightly from the trip point at the end of command execution. If the probe does not trip even after overshooting the programmed point slightly, an error is signaled.

After successful probing, parameters 2000 to 2005 will be set to the coordinates of the location of the controlled point at the time the probe tripped and a triplet giving X, Y and Z at the trip will be written to the triplet file if it has been opened by the M40 macro/OpenDigFile() function (q.v.)

Using the Straight Probe Command

Using the straight probe command, if the probe shank is kept nominally parallel to the Z-axis (i.e., any rotational axes are at zero) and the tool length offset for the probe is used, so that the controlled point is at the end of the tip of the probe:

• Without additional knowledge about the probe, the parallelism of a face of a part to the XY-plane may, for example, be found.
• If the probe tip radius is known approximately, the parallelism of a face of a part to the YZ or XZ-plane may, for example, be found.
• If the shank of the probe is known to be well-aligned with the Z-Axis and the probe tip radius is known approximately, the center of a circular hole, may, for example, be found.
• If the shank of the probe is known to be well-aligned with the Z-Axis and the probe tip radius is known precisely, more uses may be made of the straight probe command, such as finding the diameter of a circular hole.

If the straightness of the probe shank cannot be adjusted to high accuracy, it is desirable to know the effective radii of the probe tip in at least the +X, -X, +Y, and -Y directions. These quantities can be stored in parameters either by being included in the parameter file or by being set in a Mach3 program.

Using the probe with rotational axes not set to zero is also feasible. Doing so is more complex than when rotational axes are at zero, and we do not deal with it here.

Example Code

As a usable example, the code for finding the center and diameter of a circular hole is shown below. For this code to yield accurate results, the probe shank must be well-aligned with the Z-Axis, the cross section of the probe tip at its widest point must be very circular, and the probe tip radius (i.e., the radius of the circular cross section) must be known precisely. If the probe tip radius is known only approximately (but the other conditions hold), the location of the hole center will still be accurate, but the hole diameter will not.

N010 (probe to find center and diameter of circular hole)

N020 (This program will not run as given here. You have to)

N030 (insert numbers in place of <description of number>.)

N040 (Delete lines N020, N030, and N040 when you do that)

N050 G0 Z <Z-value of retracted position> F <feed rate>

N060 #1001=<nominal X-value of hole center>

N070 #1002=<nominal Y-value of hole center>

N080 #1003=<some Z-value inside the hole>

N100 #1005=[<nominal hole diameter>/2.0 - #1004]

N110 G0 X#1001 Y#1002 (move above nominal hole center)

N120 G0 Z#1003 (move into hole - to be cautious, substitute G1 for

G0 here)

N130 G31 X[#1001 + #1005] (probe +X side of hole)

N140 #1011=#2000 (save results)

N150 G0 X#1001 Y#1002 (back to center of hole)

N160 G31 X[#1001 - #1005] (probe -X side of hole)

N170 #1021=[[#1011 + #2000] / 2.0] (find pretty good X-value of hole center)

N180 G0 X#1021 Y#1002 (back to center of hole)

N190 G31 Y[#1002 + #1005] (probe +Y side of hole)

N200 #1012=#2001 (save results)

N210 G0 X#1021 Y#1002 (back to center of hole)

N220 G31 Y[#1002 - #1005] (probe -Y side of hole)

N230 #1022=[[#1012 + #2001] / 2.0] (find very good Y-value of hole center)

N240 #1014=[#1012 - #2001 + [2 * #1004]] (find hole diameter in Y direction)

N250 G0 X#1021 Y#1022 (back to center of hole)

N260 G31 X[#1021 + #1005] (probe +X side of hole)

N270 #1031=#2000 (save results)

N280 G0 X#1021 Y#1022 (back to center of hole)

N290 G31 X[#1021 - #1005] (probe -X side of hole)

N300 #1041=[[#1031 + #2000] / 2.0] (find very good X-value of hole center)

N310 #1024=[#1031 - #2000 + [2 * #1004]] (find hole diameter in X direction)

N320 #1034=[[#1014 + #1024] / 2.0] (find average hole diameter)

N330 #1035=[#1024 - #1014] (find difference in hole diameters)

N340 G0 X#1041 Y#1022 (back to center of hole)

N350 M2 (that’s all, folks)

Figure 4 - Code to Probe Hole

In the above figure an entry of the form <description of number> is meant to be replaced by an actual number that matches the description of number. After this section of code has executed, the X-value of the center will be in parameter 1041, the Y-value of the center in parameter 1022, and the diameter in parameter 1034. In addition, the diameter parallel to the X-axis will be in parameter 1024, the diameter parallel to the Y-axis in parameter 1014, and the difference (an indicator of circularity) in parameter 1035. The probe tip will be in the hole at the XY center of the hole.

The example does not include a tool change to put a probe in the spindle. Add the tool change code at the beginning, if needed.

G40, G41 & G42 Cutter Comp

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.

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.

G41 and G42 can be qualified by a P-word. This will override the value of the diameter of the tool (if any) given in the current tool table entry.

It is an error if:

• The D number is not an integer, is negative or is larger than the number of carousel slots
• The XY-plane is not active
• Cutter radius compensation is commanded to turn on when it is already on

The behavior of the machining system when cutter radius compensation is ON is described in the chapter of Cutter Compensation. Notice the importance of programming valid entry and exit moves.

G43, G44 & G49 Tool Length Offsets

To use a tool length offset, program G43 H~, where the H number is the desired index in the tool table. It is expected that all entries in this table will be positive. The H number should 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. Omitting H has the same effect as a zero value.

G44 is provided for compatibility and is used if entries in the table give negative offsets.

It is an error if:

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

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.

G50 & G51 Scale Factor

To define a scale factor which will be applied to an X, Y, Z, A, B, C, I & J word before it is used program G51 X~ Y~ Z~ A~ B~ C~ where the X, Y, Z etc. words are the scale factors for the given axes. These values are, of course, never themselves scaled.

It is not permitted to use unequal scale factors to produce elliptical arcs with G2 or G3.

To reset the scale factors of all axes to 1.0 program G50

G52 Coordinate System Offset

To offset the current point by a given positive or negative distance (without motion), program G52 X~ Y~ Z~ A~ B~ C~, where the axis words contain the offsets you want to provide. 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:

• All axis words are omitted

G52 and G92 use common internal mechanisms in Mach3 and may not be used together.

When G52 is executed, the origin of the currently active coordinate system moves by the values given.

The effect of G52 is cancelled by programming G52 X0 Y0 etc.

Here is an example. Suppose the current point is at X=4 in the currently specified coordinate system,  hen G52 X7 sets the X-axis offset to 7, and so causes the X-coordinate of the current point to be -3.

The axis offsets are always used when motion is specified in absolute distance mode using any of the fixture coordinate systems. Thus all fixture coordinate systems are affected by G52.

G53 Move in ABS Coordinates

Absolute machine coordinates: G53 - move in” For linear motion to a point expressed in absolute coordinates, program G1 G53 X~ Y~ Z~ A~ B~ C~ (or similarly with 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 in 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 co-ordinated linear motion to the programmed point. If G1 is active, the speed of motion is the current feed rate (or slower if the machine will not go that fast). If G0 is active, the speed of motion is the current traverse rate (or slower if the machine will not go that fast).

It is an error if:

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

G54-G59 and G59 P1-254 Work Offsets

To select work offset #1, program G54, and similarly for the first six offsets. The system-number-G-code pairs are: (1-G54), (2-G55), (3-G56), (4-G57), (5-G58), (6-G59).

To access any of the 254 work offsets (1 - 254) program G59 P~ where the P word gives the required offset number. Thus G59 P5 is identical in effect to G58.

It is an error if:

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

G61 & G64 Path Control Mode

Command G61 or G64 to put the machining system into exact stop mode or constant velocity mode respectively. It is OK to program for the mode that is already active. These modes are described in detail above.

G68 & G69 Rotate Coordinate System

Program G68 A~ B~ I~ R~ to rotate the program coordinate system.

A~ is the X coordinate and B~ the Y coordinate of the center of rotation in the current coordinate system (i.e. including all work and tool offsets and G52/G92 offsets.)

R~ is the rotation angle in degrees (positive is CCW viewed from the positive Z direction).

I~ is optional and the value is not used. If I~ is present it causes the given R value to be added to any existing rotation set by G68.

E.g. G68 A12 B25 R45 causes the coordinate system to be rotated by 45 degrees about the point Z=12, Y=25.

Subsequently: G68 A12 B35 I1 R40 leaves the coordinate system rotated by 85 degrees about X = 12, Y=25.

Command G69 to cancel rotation.

Notes:

1. This code only allows rotation when the current plane is X-Y
2. The I word can be used even if the center point is different from that used before although, in this case, the results need careful planning. It could be useful when simulating engine turning.

G70 & G71 Units

Command G70 or G71 to use inches or millimeters respectively.

It is usually a good idea to program either G70 or G71 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. See also G20/G21 which are synonymous and preferred.

G73 High Speed Peck Drill

The G73 cycle is intended for deep drilling or milling with chip breaking. See also G83. The retracts in this cycle break the chip but do not totally retract the drill from the hole. It is suitable for tools with long flutes which will clear the broken chips from the hole. This cycle takes a Q number which represents a “delta” increment along the Z-axis. Command:

G73 X~ Y~ Z~ A~ B~ C~ R~ L~ Q~

1. Preliminary motion, as described in G81 to 89 canned cycles
2. Move the Z-axis only at the current feed rate downward by delta or to the Z position, whichever is less deep
3. Rapid back out by the distance defined in the G73 Pullback DRO on the Settings screen
4. Rapid back down to the current hole bottom, backed off a bit
5. Repeat steps 1, 2, and 3 until the Z position is reached at step 1
6. Retract the Z-axis at traverse rate to clear Z

It is an error if:

• The Q number is negative or zero.

G80 Cancel Canned Cycles

Program G80 to ensure no axis motion will occur. It is an error if:

• Axis words are programmed when G80 is active, unless a modal group 0 G code is programmed which uses axis words.

G81 - G89 Canned Cycles

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, or 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 numbers 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 number 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), or otherwise to the R position.

It is an error if:

• X, Y, and Z words are all missing during a canned cycle
• A P number is required and a negative P number is used
• An L number is used that does not evaluate to a positive integer
• Rotational axis motion is used during a canned cycle
• Inverse time feed rate is active during a canned cycle
• Cutter radius compensation is active during a canned cycle

When the XY plane is active, the Z number is sticky, and it is an error if:

• The Z number is missing and the same canned cycle was not already active
• The R number is less than the Z number

When the XZ plane is active, the Y number is sticky, and it is an error if:

• The Y number is missing and the same canned cycle was not already active
• The R number is less than the Y number

When the YZ plane is active, the X number is sticky, and it is an error if:

• The X number is missing and the same canned cycle was not already active
• The R number is less than the X number

Preliminary and In-Between Motion

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:

• A straight traverse parallel to the XY-plane to the given XY position
• A straight traverse of the Z-axis only to the R position, if it is not already at the R position

If the XZ or YZ plane is active, the preliminary and in-between motions are analogous.

G81 Drill Cycle

The G81 cycle is intended for drilling. Command G81 X~ Y~ Z~ A~ B~ C~ R~ L~

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate to the Z position
• Retract the Z-axis at traverse rate to clear Z

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), 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

1. The Z number and Z position are 1.5. The R number and clear Z are 2.8. The following moves take place.
• A traverse parallel to the XY-plane to (4, 5, 3)
• A traverse parallel to the Z-axis to (4, 5, 2.8)
• A feed parallel to the Z-axis to (4, 5, 1.5)
• A traverse parallel to the Z-axis to (4, 5, 3)

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), old “Z” retract mode 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.0.

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.

• A traverse parallel to the XY-plane to (5, 7, 4.8)
• A feed parallel to the Z-axis to (5, 7, 4.2)
• A traverse parallel to the Z-axis to (5, 7, 4.8)

The second repeat consists of 3 moves. The X position is reset to 9 (=5+4) and the Y position to 12 (=7+5).

• A traverse parallel to the XY-plane to (9, 12, 4.8)
• A feed parallel to the Z-axis to (9, 12, 4.2)
• A traverse parallel to the Z-axis to (9, 12, 4.8)

The third repeat consists of 3 moves. The X position is reset to 13 (=9+4) and the Y position to 17 (=12+5).

• A traverse parallel to the XY-plane to (13, 17, 4.8)
• A feed parallel to the Z-axis to (13, 17, 4.2)
• A traverse parallel to the Z-axis to (13, 17, 4.8)

G82 Drill Cycle with Dwell

The G82 cycle is intended for drilling. Command G82 X~ Y~ Z~ A~ B~ C~ R~ L~ P~.

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate to the Z position
• Dwell for the P number of seconds
• Retract the Z-axis at traverse rate to clear Z

G83 Peck Drill Cycle

The G83 cycle (often called peck drilling) is intended for deep drilling or milling with chip breaking. See also G73. 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. Command G83 X~ Y~ Z~ A~ B~ C~ R~ L~ Q~

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate downward by delta or to the Z position, whichever is less deep
• Rapid back out to the clear Z
• Rapid back down to the current hole bottom, backed off a bit
• Repeat steps 1, 2, and 3 until the Z position is reached at step
• Retract the Z-axis at traverse rate to clear Z

It is an error if:

• The Q number is negative or zero

G85 Boring or Reaming Cycle

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~

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate to the Z position
• Retract the Z-axis at the current feed rate to clear Z

G86 Boring Cycle

The G86 cycle is intended for boring. This cycle uses a P number for the number of seconds to dwell. Command G86 X~ Y~ Z~ A~ B~ C~ R~ L~ P~

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate to the Z position
• Dwell for the P number of seconds
• Stop the spindle turning
• Retract the Z-axis at traverse rate to clear Z
• Restart the spindle in the direction it was going

The spindle must be turning before this cycle is used. It is an error if:

• The spindle is not turning before this cycle is executed.

G88 Boring Cycle

The G88 cycle is intended for boring. This cycle uses a P word, where P specifies the number of seconds to dwell. Program G88 X~ Y~ Z~ A- B~ C~ R~~ L~ P~

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate to the Z position
• Dwell for the P number of seconds
• Stop the spindle turning
• Stop the program so the operator can retract the spindle manually
• Restart the spindle in the direction it was going

G89 Boring Cycle

The G89 cycle is intended for boring. This cycle uses a P number, where P specifies the number of seconds to dwell. Command G89 X~ Y~ Z~ A~ B~ C~ R~ L~ P~

• Preliminary motion, as described above
• Move the Z-axis only at the current feed rate to the Z position
• Dwell for the P number of seconds
• Retract the Z-axis at the current feed rate to clear Z

G90 & G91 Distance Mode

Interpretation of Mach3 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, and C) usually represent positions in terms of the currently active coordinate system. Any exceptions to that rule are described explicitly in this section describing G-codes.

To go into incremental distance mode, program G91. In incremental distance mode, axis numbers (X, Y, Z, A, B, and 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 (the G87 boring cycle), where the meaning changes with distance mode.

G90.1 & G91.1 Set IJ Arc Mode

Interpretation of the IJK values in G02 and G03 codes can be in one of two distance modes: absolute or incremental.

To go into absolute IJ mode, program G90.1. In absolute distance mode, IJK numbers represent absolute positions in terms of the currently active coordinate system.

To go into incremental IJ mode, program G91.1. In incremental distance mode, IJK numbers usually represent increments from the current controlled point.

Incorrect settings of this mode will generally result in large incorrectly oriented arcs in the tool path display.

G92, G92.1, G92.2 & G92.3 Offsets

ATTENTION

It is strongly advised not to use this legacy feature on any axis where there is another offset applied including cutter comp.

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:

• All axis words are omitted

G52 and G92 use common internal mechanisms in Mach3 and may not be used together.

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 fixture coordinate systems. Thus all fixture 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. They are in effect discarded before the new value is applied. Mathematically 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]. Put another way the G92 X9 produces the same offset whatever G92 offset was already in place.

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. Command 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.

G93 Inverse Time

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.

G94 Units per Minute

In units per minute feed rate mode, an F word on the line 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.

G98 & G99 Canned Cycle Return

When the spindle retracts during canned cycles, there is a choice of how far it retracts:

• Retract perpendicular to the selected plane to the position indicated by the R word, or
• 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 the first option, program G99 To use the second option, program G98 Remember that the R word has different meanings in absolute distance mode and incremental distance mode.