Notes about G codes for CNC Programming.
The following is taken from 7 Easy Steps to CNC Programming Book II, Beyond the Beginning.
There are two types of G codes, modal and non-modal. Modal G codes remain in effect until canceled or changed by another G code. For example G0 / G00, which initiates rapid travel, is modal. So once programmed, the machine will remain in rapid travel mode until a G1 / G01, G2 / G02, G3 / G03 is commanded. By contrast, G4 / G04, which causes the machine to dwell for a specified time is non-modal. When a G4 / G04 is commanded, the machine suspends machine motions code, dwells for the programmed time, then returns to normal movements.
There is some degree of variation in the use of G and M codes. The 1980 ANSI/EIA standard RS-274-D left several ranges of G and M codes unassigned. These unassigned codes give machine tool builders more flexibility to build custom features into their machines and controls.
G codes belong to several groups. Early NC controls did not allow combining G codes on the same line of a program. More recent CNC controls do allow combining G codes on the same line providing the G codes are from different groups.
If two G codes from the same group are put on the same line, the machine will only act on the last G code of the group. For example, if a line read G01 X0 Y0 F3.0 G00, the control would tell the machine to rapid travel to point X0, Y0 rather than feed to the point at the programmed F3.0 feed rate.
The parameter column in the following table shows the required / necessary codes that may be needed to complete the command.
The following pages provide a list of the common turning G codes.
Most Common Turning G Codes
G Code |
G Code Group |
G Code Parameters |
What the G CODE does / How to Use the G Code |
G0 / G00 |
01 |
Modal. Initiates rapid travel. Causes the machine to move the tool to the programmed coordinate at the machines maximum speed. |
|
G1 / G01 |
01 |
F |
Modal. Initiates linear feed. Moves the tool in a straight line at the programmed feed rate as specified by F. |
G2 / G02 |
01 |
I, K, R, F |
Modal. Initiates clockwise interpolation. Moves the tool to a specified endpoint in a clockwise direction. The parameters I, J ,K and R define the size of the arc. I, J ,K define the center of the arc and are generally used together. These parameters allow programming of arcs from 0-360 degrees. The R command is a shortcut for defining the arc radius and is never used on the same line with I, J, or K. The R command can be used to program arcs up to 360 degrees but not including 360 degrees. |
G3 / G03 |
01 |
I, K, R, F |
Modal. Initiates counterclockwise interpolation. Moves the tool to a specified endpoint in a counterclockwise direction. The parameters I, J ,K and R define the size of the arc. I, J ,K define the center of the arc and are generally used together. These parameters allow programming of arcs from 0-360 degrees. The R command is a shortcut for defining the arc radius and is never used on the same line with I, J, or K. The R command can be used to program arcs up to 360 degrees but not including 360 degrees. |
G4 / G04 |
00 |
X, P |
Non-modal. Commands the machine to dwell or sit still for X seconds or P miliseconds. For example G04 X3 would cause the machine to dwell for 3 seconds. This is useful for having the machine sit idle while coolant comes on or the spindle gets up to speed, etc. |
G17 |
16 |
Modal. Sets active plane to the X, Y plane. |
|
G18 |
16 |
Modal. Sets active plane to the X, Z plane (most common plane for turning). |
|
G19 |
16 |
Modal. Sets active plane to the Y, Z plane |
|
G20 / G94 |
06 |
Modal. Sets the machine to operate in inch mode. |
|
G21 / G95 |
06 |
Modal. Sets the machine to operate in metric mode. |
|
G28 |
00 |
Non-Modal. Commands the machine to move to the machine zero-reference point through an intermediate point. |
|
G32 / G33 |
01 |
F |
Modal. Single pass Threading. This command causes the machine to make one threading pass that ends at the X, Z coordinates specified in the G33 line. The F or feed rate parameter controls the pitch of the thread. For older machines that cannot feed in inches per revolution you need to calculate the feed rate using the following formula 1/TPI x RPM. For example, the feed rate for a 12 pitch thread at 100 RPM would be 1/12 x 100 or 8.3333. The F command on a machine with decimal point programming would be F8.333. |
G40 |
07 |
Modal. Cancels cuter compensation. |
|
G41 |
07 |
D |
Modal. Cutter compensation left. This command tells the machine to move the cutter to the left of the programmed path by the amount specified in the offset identified by the D word. For example G41 X-3.000 D23 commands the machine to move to X-3 but to keep the tool to the left of the programmed path by amount in offset register 23. Left and Right are determined by looking down the tool path from start point to end point. As you imagine looking down that path, the compensation will be to the left. |
G42 |
07 |
D |
Modal. Cutter compensation Right. This command tells the machine to move the cutter to the right of the programmed path by the amount specified in the offset identified by the D word. For example G41 X-3.000 D23 commands the machine to move to X-3 but to keep the tool to the right of the programmed path by amount in offset register 23. Left and Right are determined by looking down the tool path from start point to end point. As you imagine looking down that path, the compensation will be to the right. |
G50 / G92 |
00 |
X, Z, S |
Modal. Used to program the absolute zero. Additionally the G50 is used to establish the maximum spindle speed when using Constant Surface Speed spindle control. On some machines these functions are handled by the G92 command. The X and Z would be programmed as the distance and direction from the desired absolute zero point to the current tool position. The S would be programmed as direct RPM in a manner similar to this: G50 S350 The example command would insure the spindle speed never exceeded 350 RPM. |
G70 |
00 |
Modal. The ANSI/EIA RS-274-D standard command for inch programming. |
|
G70 |
00 |
P, Q |
Non-Modal. Finishing Cycle. This is a different use of the G70 command. On the controls that use this version of G70, this command is used in conjunction with a G71, G72 or G73 command. The part is first roughed with a G71, G72 or G73 command. Once the roughing cycle is completed, the G70 is used to perform the finish pass. G70 P100 Q125; |
G71 |
00 |
Modal. The ANSI/EIA RS-274-D standard command for metric programming. |
|
G71 |
00 |
P, Q, R, U, W |
Non-Modal Turning stock removal. This command simplifies roughing by allowing you to describe the finish turn in a series of commands and defining how much stock is to be removed. This is a linear roughing command that removes stock off the diameter by cutting parallel to the center line of the part. The command takes 2 lines. The first line defines the depth of cut to take per pass and the amount to retract the tool for clearance. The second line of the command defines: * the starting block of the finish pass (P), A typical G71 command set might look like: G71 U.125 R.03; G71 P100 Q125 U.015 W.015; This command would tell the control to look ahead to blocks 100-125, rough turn at .125 per pass, retract the tool by .031, and leave .015 stock on the X and Z axis for finishing. |
G72 |
00 |
P, Q, R, U, W |
Non-Modal Facing stock removal. This command simplifies roughing by allowing you to describe the finish part in a series of commands and defining how much stock is to be removed. This is a linear roughing command that removes stock off the faces by cutting perpendicular to the center line of the part. The command and parameters are used as described in the G71 command. The notable exception is that the first G72 line is a W and an R because the depth of cut is along the face rather than the diameter. |
G73 |
00 |
D, I, K, P, |
Non-Modal Contour roughing / pattern repeating. This cycle is similar to the previous G71 and G72 in that it removes stock based on the finish profile as defined by the P and Q parameters. The command is different in that it removes the stock in cuts parallel to the finish pass rather than in straight lines. |
G73
|
00 |
D, I, K, |
The P, Q, U and W parameters are the same as described above. D specifies depth of cut per side, I specifies total displacement along the X axis, and K specifies total displacement along the Z axis. A typical G73 command might look like: G73 P185 Q205 U.015 W.015 I.3 K.25 D.1; |
G90 |
03 |
Modal. The ANSI/EIA RS-274-D standard command for absolute programming. On some controls, the use of X and Z coordinate commands implies absolute programming and the use of U and W coordinate commands implies incremental programming. |
|
G91 |
03 |
Modal. The ANSI/EIA RS-274-D standard command for incremental programming. On some controls, the use of U and W coordinate commands implies incremental programming and the use of X and Z coordinate commands implies absolute programming. |
|
G96 |
02 |
S, U, X |
Modal. Constant Surface speed control. As you know when turning a piece on lathe, as you face to the center, the surface speed of the cutting drops. The G96 command insures that the cutting surface speed (CSS) remains constant as set by the parameter S. For example, an S350 parameter setting on the G96 command line tells the machine to keep the machine cutting at a constant 350 surface feet per minute. The other important parameters to include are the U or X. For the machine to calculate the proper spindle speed to maintain the programmed CSS, you must tell the machine the current tool location with respect to the centerline of the part. A couple of notes about G96 programming: Clearly, as the tool moves closer to the center of the part you reach a theoretical infinite spindle speed. Programming CSS will not enable the machine to reach a spindle speed greater than the machine’s limitations. |
G96
|
02 |
S, U, X |
Depending on the rigidity of your set up, the condition of your machine or any safety considerations, you may not want the spindle speed to exceed a particular RPM. On a separate line, you can program a maximum allowable RPM while in CSS mode. Depending on your machine control, the command to control the maximum RPM will either be a G50 or a G92. For example, if you program a G50 S200. The spindle speed would never exceed 200 RPM while in G96 mode, even if towards the center of the part, the surface speed drops below the programmed CSS. Another point to remember. If you are programming a roughing cycle and the tool is quickly and frequently moving from a cutting diameter to a clearance diameter, the spindle RPM will rise and fall with each move. This is not good for the machine. So, in a situation like this, it is best to program a G97 on the retract, then reprogram the G96 on the block prior to engaging the part. |
G97 |
02 |
Modal. CSS cancel. Returns the machine to direct RPM spindle speed programming. |
|
G98 |
10 |
Modal. Instructs the control to interpret the feed rate commands in inches/mm per minute. |
|
G99 |
10 |
Modal. Instructs the control to interpret the feed rate commands in inches/mm per revolution. |
Look to future posts that will list some Common Milling G Codes for CNC Programming excerpted from 7 Easy Steps to CNC Programming . . . A Beginner’s Guide.
[…] For the list of CNC Programming G codes for turning applications see previous post. […]
By: Most Common Turning M Codes for CNC Programming « The CNC Project on March 1, 2012
at 5:40 am
[…] Most Common G Codes for CNC Milling Applications This is the thrid post in a series about common G & M codes that started with the common G codes for CNC turning / CNC lathe work. […]
By: Most Common G Codes for CNC Milling Applications « The CNC Project on March 3, 2012
at 5:41 am
[…] Most Common M Codes for Programming CNC Mills This is the fourth post in a series about common G & M codes that started with the common G codes for CNC turning / CNC lathe work. […]
By: Most Common M Codes for Programming CNC Mills « The CNC Project on March 7, 2012
at 1:01 pm
thanks for the tuto
By: nichm on September 5, 2012
at 7:10 am
It is very useful for who have doubts on G Codes and very very useful.Thank you
By: DASHARATH.Y on November 25, 2013
at 9:34 am
Can you provide the service,by using that list of the codes can be downloaded?
i think it should be available for download.
thank you…
By: vivek on March 23, 2014
at 12:58 am
I emailed you a copy of the more common G & M codes. I hope that helps.
By: davidhayden on March 23, 2014
at 12:00 pm
this is good http://www.portablecnc.com/content/main-difference-between-g-codes-and-m-codes-cnc
By: jithincv on January 5, 2015
at 7:45 am
I don’t even know how I stopped up right here, however I believed this post used to
be great. I do not know who you are but certainly you are going to a well-known blogger if you happen to are
not already. Cheers!
By: accustic guitar tuner on November 23, 2015
at 2:45 pm