G AND M CODES

G-codes are also called preparatory codes, and are any word in a CNC program that begins with the letter "G". Generally it is a code telling the machine tool what type of action to perform, such as:
• • •

rapid move controlled feed move in a straight line or arc series of controlled feed moves that would result in a hole being bored, a workpiece cut (routed) to a specific dimension, or a decorative profile shape added to the edge of a workpiece. set tool information such as offset.

Letter addresses
Some letter addresses are used only in milling or only in turning; most are used in both. Bold below are the letters seen most frequently throughout a program. Variable Description Corollary info A Absolute or incremental position of A axis (rotational axis around X axis) B Absolute or incremental position of B axis (rotational axis around Y axis) C Absolute or incremental position of C axis (rotational axis around Z axis) D Defines diameter or radial offset used for cutter compensation E Precision feedrate for threading on lathes F Defines feed rate G G commands often tell the control what kind of motion Address for is wanted (e.g., rapid positioning, linear feed, circular preparatory commands feed, fixed cycle) or what offset value to use. H Defines tool length offset; Incremental axis

tool length offsets. Also used as a parameter within some fixed cycles. Action code. Fixed cycle loop count: Defines number of repetitions ("loops") of a fixed cycle at each position. Sometimes the K address is used instead of L. 20. Line (block) number in Line (block) numbers: Optional. although it was not intended to. G10 use: Specification of what register to edit (work offsets. With Specification of what incremental positioning (G91). Also used as a parameter within some fixed cycles. or 1000) and can be used on every block or only in certain spots throughout a program.. equal to L address. N numbering need not increment by 1 (for example. tool radius offsets.g. which is why Miscellaneous function people often say that the "M" stands for "machine". Defines arc size in Z axis for G02 or G03 arc commands. Defines arc size in Y axis for G02 or G03 arc commands.). Also used as a parameter within some fixed cycles. such as M99 P address (to System parameter tell the control which block of the program to return to if number to be changed not the default one) or GoTo statements (if the control using G10 supports those). System parameter number: G10 allows changing of L M N . it can increment by 10. etc.I J K corresponding to C axis (e. Many M-codes call for machine functions. Assumed to be 1 unless programmed with another integer. Fixed cycle loop count. Necessary for certain tasks. on a turnmill) Defines arc size in X axis for G02 or G03 arc commands. so often omitted. a series of equally spaced register to edit using holes can be programmed as a loop rather than as G10 individual positions. auxiliary command. program. descriptions vary.

On multifunction depending on mode (turn-mill or mill-turn) machines. See also Speeds and feeds. although the proliferation of live lathe tooling and turn-mill machining has made V address usage less . O4501. In G96 mode (CSS). lathe group A controls) respectively.O P Program name Serves as parameter address for various G and M codes system parameters under program control. • Also serves as a parameter in some canned cycles. and empty tools. In G97 mode (which is usually the default). which spindle gets the input (main spindle or subspindles) is determined by other M codes. an integer after S is interpreted as a number of Defines speed. • Also used in the calling and termination of subprograms. defines dwell time value. For example. the concept of "next tool waiting". G83 (peck drilling cycles) canned cycles Defines size of arc radius or defines retract height in canned cycles Data type = integer. so they didn't use V. it specifies which block number of the main program to return to. time on some machines (instead of "P" or "X"). the V address was very rarely used. either rev/min (rpm). On these lathes. To understand how the T address works and how it interacts (or not) with M06. G90 is instead a fixed Also defines dwell cycle address for roughing. (With M98. ATC random memory tool selection.) That is still often the case. an integer after S is spindle speed or interpreted as surface speed—sfm (G20) or m/min surface speed (G21). G73. (Green et al 1996[2] did not even list V in their table of addresses. with M99. • With G04.) Q R S T U V Peck increment in For example. X and U obviate G90 and G91. one must study the various methods. Incremental axis corresponding to X axis (typically only In these controls. representing dwell times or other variables. Programming on any particular machine tool requires knowing which method that machine uses. ATC fixed Tool selection tool selection. it specifies which subprogram to call. such as lathe turret programming. Incremental axis Until the 2000s. corresponding to Y because most lathes that used U and W didn't have a Yaxis axis.

Absolute or incremental position of Y axis Absolute or The main spindle's axis of rotation often determines incremental position of which axis of a machine tool is labeled as Z. The most common workhorse code for feeding during a cut. group A controls) Absolute or incremental position of X axis. Shorter vector usually finishes first (given similar axis speeds). Some machines offer interpolated rapids as a feature for ease of programming (safe to assume a straight line). to avoid a crash. corresponding to Z axis respectively. and the control automatically calculates (interpolates) the intermediate points to pass through that will yield a straight line (hence "linear"). W Incremental axis In these controls. Also defines dwell time on some machines (instead of "P" or "U"). Z and W obviate G90 and G91.or 3-axis moves.rare than it used to be (Smid 2008[1] shows an example). On these lathes. Rapid positioning M T G01 Linear interpolation M T . The program specs the start and end points. G00 (unlike G01) traditionally does not necessarily move in a single straight line between start point and end point. G90 is instead a fixed (typically only lathe cycle address for roughing. Z axis X Y Z • List of G-codes commonly found on Fanuc and similarly designed controls Code G00 Description Milling Turning (M) (T) Corollary info On 2. It moves each axis at its max speed until its vector is achieved. See also G18. This matters because it may yield a dog-leg or hockeystick motion. which the programmer needs to consider depending on what obstacles are nearby.

so no G17 to G19 codes are used. U. Not standard on Fanuc controls. counterclockwise XY plane selection ZX plane selection M M The control then calculates the angular velocities at which to turn the axis leadscrews. ZX is the only available plane. and G13 M M M G17 G18 . counterclockwise Dwell M T M M T T G04 G05 High-precision P10000 contour control (HPCC) G05. Fixed cycle for ease of programming 360° circular interpolation with blendradius lead-in and lead-out. multitask/multifunction. Not standard on Fanuc controls. or P) Uses a deep look-ahead buffer and simulation processing to provide better axis movement acceleration and deceleration during contour milling Uses a deep look-ahead buffer and simulation processing to provide better axis movement acceleration and deceleration during contour milling G07 G09 G10 G11 G12 M M M M M T T T Fixed cycle for ease of programming 360° circular interpolation with blendradius lead-in and lead-out. This is now changing as the era begins in which live tooling. clockwise Circular interpolation. Cannot start G41 or G42 in G02 or G03 modes. T On most CNC lathes (built 1960s to 2000s). Must already be compensated in earlier G01 block. Takes an address for dwell period (may be X. Ai Nano contour control Imaginary axis designation Exact stop check Programmable data input Data write cancel Full-circle interpolation. The computer performs thousands of calculations per second. Actual machining takes place with given feed on linear path.G02 G03 Circular interpolation. clockwise Full-circle interpolation. Cannot start G41 or G42 in G02 or G03 modes.1 Q1. Must already be compensated in earlier G01 block.

in the global marketplace. longhand T Similar to G01 linear interpolation. But the simpler. They are in terms of part zero (aka program zero). if the machine has several secondary points (P1 to P4). However. Programming in inches M T G21 Programming in millimeters (mm) G28 Return to home position (machine zero. This physical difference sometimes favors G21 programming. that is.0001"). Takes a P address specifying which machine zero point is desired.mill-turn/turn-mill gradually become the "new normal". G19 G20 YZ plane selection M Somewhat uncommon except in USA and (to lesser extent) Canada and UK. However. . Takes X Y Z addresses which define the intermediate point that the tool tip will pass through on its way home to machine zero.001 mm. See also V address. NOT machine zero. competence with both G20 and G21 always stands some chance of being necessary at any time. traditional form factor will probably not disappear—just move over to make room for the newer configurations. The usual minimum increment in G20 is one tenthousandth of an inch (0. competence with both G20 and G21 always stands some chance of being necessary at any time. except with automatic spindle . aka machine reference point) M T M T G30 Return to secondary home position (machine zero. Takes X Y Z addresses which define the intermediate point that the tool tip will pass through on its way home to machine zero. which is a larger distance than the usual minimum increment in G21 (one thousandth of a millimeter. in the global marketplace. Prevalent worldwide. They are in terms of part zero (aka program zero). one micrometre). aka M machine reference point) T G31 G32 Skip function (used for probes and tool M length measurement systems) Single-point threading. NOT machine zero.

The value is negative because it will be added to the gauge line position. because whatever tool is active automatically calls its geometry offsets with it. to call the tool length offset register value. e.. G43 is the commonly used version (vs G44). longhand style (if not using a cycle. Takes an address. Takes an address.) Similar corollary info as for G41.g. The value is positive because it will be subtracted from the gauge line position. T Cancels G41 or G42. usually H. (Each turret station is bound to its geometry offset register. G42 corresponds to conventional milling (up milling). Tool radius compensation left M T G42 Tool radius compensation right G43 Tool height offset compensation negative G44 Tool height offset compensation positive G45 G46 G47 Axis offset single increase Axis offset single decrease Axis offset double increase M M M T M M M . G76) Constant-pitch M threading Single-point threading. G41 corresponds to climb milling (down milling). Turning: Often needs no D or H address on lathes.g. Given righthand-helix cutter and M03 spindle direction. Milling: Given righthand-helix cutter and M03 spindle direction. to call the tool length offset register value.. G76) Variable-pitch M threading Tool radius M compensation off synchronization for single-point threading. T Some lathe controls assign this mode to G33 rather than G32. e. G44 is the seldom-used version (vs G43). usually H. Takes an address (D or H) that calls an offset register value for radius.G33 G33 G34 G40 G41 style (if not using a cycle.

which indirectly relates it to the machine coordinate system.G48 G49 G50 Axis offset double M decrease Tool length offset M compensation cancel Define the maximum spindle speed Scaling function cancel Cancels G43 or G44. T G50 M Position register is one of the original methods to relate the part (program) coordinate system to the tool position. the only position the control really "knows". Can be helpful for tool changes.A.1 P1 to P48. newer method.B.Z.Y. Each tuple of axis offsets relates program zero directly to machine zero. Called via G50 for turning. Temporarily shifts program zero to a new location. Note floating-point extension of G-code data type (formerly all integers). Standard is 6 tuples (G54 to G59).1 P1 to P48 Extended work coordinate systems M T . Not commonly programmed anymore because G54 to G59 (WCSs) are a better.C) with reference to machine zero rather than program zero. Without this feature. G92 for milling. G96 mode (CSS) would rev the spindle to "wide open throttle" when closely approaching the axis of rotation. Other G50 Position register (programming of vector from part zero to tool tip) T G52 Local coordinate system (LCS) M G53 Machine coordinate M system T G54 to G59 Work coordinate systems (WCSs) M T G54. Position register can still be useful for datum shift programming. Takes absolute coordinates (X. Nonmodal and absolute only. Those G addresses also have alternate meanings (which see). Subsequent blocks are interpreted as "back to G54" even if it is not explicitly programmed. Up to 48 more WCSs besides the 6 provided as standard by G54 to G59. with optional extensibility to 48 more via G54. Takes an S address integer which is interpreted as rpm. Have largely replaced position register (G50 and G92). This simplifies programming in some cases.

multiple repetitive cycle. multiple repetitive cycle. Modern controls have the hardware to handle it. Z-axis returns either to Zinitial level or R-level.g. for roughing (X-axis emphasis) Fixed cycle. G84. G88. lefthand M thread. Turning: Usually not needed on lathes. M04 spindle direction Peck grooving cycle for turning Fine boring cycle for M milling Threading cycle for turning. multiple repetitive cycle Cancel canned cycle M T G71 T G72 T G73 T G73 Retracts only as far as a clearance increment (system parameter). multiple repetitive cycle. multiple repetitive cycle.. etc.2). T G74 G74 G75 G76 T G76 G80 T T Milling: Cancels all cycles such as G73. for finishing (including contours) Fixed cycle. for roughing (Z-axis emphasis) Fixed cycle. For when chipbreaking is the main concern.examples have also evolved (e. with pattern repetition Peck drilling cycle for milling . for roughing. as programmed (G98 or G99. G70 Fixed cycle. because a new group-1 G address (G00 to . respectively). G83. but chip clogging of flutes is not.highspeed (NO full M retraction from pecks) Peck drilling cycle for turning Tapping cycle for milling.

for roughing (Z-axis emphasis) Incremental M programming T (A) T (B) . On these lathes. rigid toolholder G90 Absolute programming M T (B) Positioning defined with reference to part zero. No dwell built in Dwells at hole bottom (Z-depth) for the number of milliseconds specified by the P address. Turning: Sometimes as above (Fanuc group type B and similarly designed). Milling: Always as above. M M03 spindle direction Tapping cycle. but on most lathes (Fanuc group type A and similarly designed). Instead. Good for clearing flutes of chips. G90 is a fixed G90 G91 Fixed cycle. Returns to R-level after each peck. G83 G84 G84. righthand thread. simple cycle. Turning: Sometimes as above (Fanuc group type B and similarly designed). G90/G91 are not used for absolute/incremental modes. Instead. U and W are the incremental addresses and X and Z are the absolute addresses.G81 G82 Simple drilling cycle M Drilling cycle with dwell M G03) cancels whatever cycle was active. but on most lathes (Fanuc group type A and similarly designed). M03 spindle M direction.2 Peck drilling cycle (full retraction from M pecks) Tapping cycle. G90 is instead a fixed cycle address for roughing. Good for when hole bottom finish matters. When not serving for absolute programming (above) Positioning defined with reference to previous position. Milling: Always as above. On these lathes. G90/G91 are not used for absolute/incremental modes. U and W are the incremental addresses and X and Z are the absolute addresses. righthand thread.

which is interpreted as sfm in G20 mode or as m/min in G21 mode. Takes an S address integer. G94 G95 G96 T G97 Constant spindle speed G98 G98 G99 M T G99 Return to initial Z M level in canned cycle Feedrate per minute (group type A) Return to R level in M canned cycle Feedrate per revolution (group type A) T (A) Feedrate per minute is G94 on group type B. but on most lathes (Fanuc group type A and similarly designed). Turning: Sometimes as above (Fanuc group type B and similarly designed). position register is G50. • List of M-codes commonly found on Fanuc and similarly designed controls Code M00 Description Compulsory stop Milling Turning Corollary info (M) (T) M T Non-optional—machine will always stop . feedrate per minute is G98. When not serving for feedrate per minute (above) On group type A lathes. Varies spindle speed automatically to achieve a constant surface speed. G92 G94 Threading cycle. T (A) Feedrate per revolution is G95 on group type B. The default speed mode per system parameter if no mode is programmed. which is interpreted as rev/min (rpm). Milling: Always as above. Same corollary info as at G50 position register. simple cycle Feedrate per minute M Fixed cycle. for roughing (X-axis emphasis) Feedrate per M revolution Constant surface speed (CSS) T (A) T (B) T (A) T (B) On group type A lathes. Takes an S address integer. See speeds and feeds. feedrate per revolution is G99.G92 Position register (programming of M vector from part zero to tool tip) T (B) cycle address for roughing. simple cycle.

How to objectively define "clockwise" or "counterclockwise" (CW or CCW) when the same rotating cylinder can be viewed as either CW or CCW. and empty tools. depending on which end of it the viewer is looking from? The answer links back to the righthand rule. See comment above at M03. the concept of "next tool waiting". M04 M05 M06 Spindle on (counterclockwise rotation) Spindle stop M M T T Automatic tool change (ATC) M M07 M08 M09 M10 M11 Coolant on (mist) Coolant on (flood) Coolant off Pallet clamp on Pallet clamp off M M M M M Many lathes do not use M06 because the T address itself indexes the turret. To understand how the T address works and how it interacts (or not) with M06.M01 M02 M03 Optional stop End of program M M T T Spindle on M (clockwise rotation) T upon reaching M00 in the program execution. ATC fixed times) tool selection. one must study the various methods. Right-hand-helix screws moving in the tightening direction (and right-hand-helix flutes spinning in the cutting direction) are defined as moving in the M03 direction. Programming on any particular machine tool requires knowing which method that machine uses. Machine will only stop at M01 if operator has pushed the optional stop button. No return to program top. may or may not reset register values. such T (someas lathe turret programming. and are labeled "clockwise" by convention. The M03 direction is always M03 regardless of local vantage point and local CW/CCW distinction. T T T For machining centers with pallet changers For machining centers with pallet changers . ATC random memory tool selection.

Spindle orientation is more often called within cycles (automatically) or during setup (manually). but it is also available under program control via M19. Usually placed at end of subprogram.gear 2 Gear select . where feed is precisely correlated to speed.gear 1 Gear select . "M98 P8979" calls subprogram O8979. X-axis M Tailstock forward Mirror.gear 3 Gear select .gear 4 Feedrate override M allowed Feedrate override NOT allowed T T T T T T T T T T This rule is also called (automatically) within tapping cycles or single-point threading cycles.M13 Spindle on (clockwise rotation) M and coolant on (flood) M19 Spindle orientation M T This one M-code does the work of both M03 and M08. more quickly written programs. It is not unusual for specific machine models to have such combined commands. M21 M21 M22 M22 M23 M23 M24 M30 M41 M42 M43 M44 M48 M49 Mirror. Same with spindle speed override and feed hold button. where it returns execution control to the M T M60 M98 Automatic pallet change (APC) Subprogram call M M M T T M99 Subprogram end . For machining centers with pallet changers Takes an address P to specify which subprogram to call. for example. Y-axis M Tailstock backward Mirror OFF M Thread gradual pullout ON Thread gradual pullout OFF End of program with M return to program top Gear select . which make for shorter. The abbreviation OSS (oriented spindle stop) may be seen in reference to an oriented stop within cycles.

M99 can also be used in main program with block skip for endless loop of main program on bar work on lathes (until operator toggles block skip). . The default is that control returns to the block following the M98 call in the main program. Return to a different block number can be specified by a P address.main program.

Sign up to vote on this title
UsefulNot useful