G Codes Topics
Typical CNC Machine Codes
Coordinate system
Axes
Introduction go G-Code
G-Code Basics
Safe Startup Line - ensure all the commands are cancelled before starting a program
Examples include
G80 to cancel all canned cycles
“There is also one case where the Group 01 G codes will cancel the Group 9 (canned cycles) codes. If a canned cycle is active (G81 through G89), the use os G00 or G01 will cancel the canned cycle.” [Haas p. 20]
G00 - Linear Rapid Position Command (moving the tool)
G00 X2.2 Z-3.0 (say the tool is at home, then will move 3.0“ to the left and 2.2” towards the operator)
“This G code is modal so that all following blocks will be in rapid motion until another Group 01 G code is specified” (Haas p. 32)
G01 - Linear Feed/Interpolation Command (cutting with tool)
G02 - Circular Clockwise (CW) Interpolation Command
G03 - Circular Counterclockwise (CCW) Interpolation Command
G18 - Circular Motion ZX Plane Selection (G02, G03)
G20 - Inch Coordinate Positioning
“The G codes G20 and G21 are used to select between inch and metric. In the Haas control, the G20 (inch) and G21 (mm) codes can only be used to make sure that the inch/metric setting is set correctly for that program.”
“Selecting between inch and metric programming can only be done from the Setting page, Setting 9. Changing the setting from inches to metric or back again will interpret the content of any program listed in memory. You must load in a program with metric values after changing this setting to MM.” [Haas p. 47]
G21 - Metric (mm) Coordinate Positioning
G28 - Reference Point Return Command (rapid traverse)
G40 - Tool Nose Compensation - Cancel
G41 - Tool Nose Compensation
G42 - Tool Nose Compensation
G51 - Reference Point Return Command
G52 - Set Local
G53 - Non-Modal Machine Coordinate Selection (Work Coordinate System Command)
G54 - Work Offset Positioning Coordinate #1
“Work offsets on a CNC lathe, are not used like they are on a CNC mill. Many lathe users don't even have values in their work offsets, because all the offsets that are needed on a lathe, for most users, are entered in the Tool Geometry display. The only time someone might use a work offset on a lathe, is to shift all the tools in the Z axis the same distance.” [Haas p. 16]
G70 - Finishing Cycle
G71
G76
G80 thru G89 Canned Cycles
G80 - turns off the canned cycles (typically done at the end of the cuts)
G81 - basic drill
G82 - peck drill (drill down, bring back up to clear chips, drill a little deeper, bring back up to clear chips, and so on)
G83 - counter bore
G84 - tapping (used to create internal threads)
G97 - Constant Non-Varying Spindle Speed,
CSS Off
G99 - Feed Per Revolution
Coordinate System
Machine Home
Absolute Position
X - absolute X-axis motion command. Moving towards me is positive, away from me is negative
Z - absolute Z-axis motion command. Moving right is positive, left is negative
Incremental Position
M Codes
Miscellaneous Function 'M' Codes
All M codes are activated or cause an action to occur after everything else on a block has been completed. Only one M code is allowed per block in a program.
If there is a (setting number) listed next to an M code, that setting will in some way relate to that M code.
M00 - Program Stop
M01 - Optional Program Stop
M02 - end of program
M03 - spindle on clockwise/forward. Must have a spindle speed defined.
M04 - spindle on counterclockwise/reverse. Must have a spindle speed defined.
M05 - spindle stop
M08 - Coolant On
M09 - Coolant Off
M30 - Program End / Return to start
M97 - local subroutine call
M98 - subprogram call
M99 - subprogram return
Sequence Numbers
Address Codes
F Feed Rate
S Spindle Speed
Revolutions Per Minute (RPM) is default
S command does not turn the spindle on or off, it only sets the desired speed
Surface Feet per Minute (SFM) if constant, then RPM will increase as Diameter is decreased
G97 cancels constant surface speed along a spindle speed defines a constant speed
SFM is same as surface speed
RPM is same as spindle speed
Program Structure
Line 1: Programs must begin and end with a percent (%) sign
Line 2: o2000
Line 3: G18 G20 G40 G80 G97 G99
Line 4: G54
Line 5: G28 (go home);
Line 6: T1 (select roughing cutting tool);
Line 7: S1000 (select the RPM);
Line 8: M03 (turn spindle on);
Line 9: G0 X1.1 Z0.1 (rapid movement to face of part);
Line 10: M08 (turn on coolant unless cutting plastic);
Line 11: G1 Z0. F.005 (Haas gives error is G1 called without F.005);
Line 12: x-.01
Line 13: z.1
Line 14: x.9 (part is 1.0 diameter, taking off 0.100“)
Line 15: z-1.7 (turning part from 0 to 1.7”)
Line 16: g0 x1.1 (move back to clearance position/start before selecting a tool);
Line 17: z.1;
Blocks or line of text are always terminated by the semicolon (;) to designate the end of block (EOB)
Comment statement between parenthesis “(” and “)”
G-Code Sample File
%
o2000 (program name);
%
Software
Haas Control Pendant Keyboard
Return Home
ZERO RET (Zero Return)
Selects Zero Return mode, which displays axis location in four different categories, they are; Operator, Work G54, Machine and Dist (distance) to go. You can page up or down to view each category in a larger format by itself
HOME G28
-
Reference
GWizard Editor by CNC Cookbook
Tutorials
References
-
Lathe Operator's Manual (
pdf)
Programming of CNC Machines, 4th by Ken Evans, published by Industrial Press \$42.67
CNC G Code Programming for Beginners by Mike Mattera (mike.mattera@autodesk.com)
Forums