G Codes Topics

  • Typical CNC Machine Codes
    • N#### G## X## Y## Z## F## S#### T## M##
      • G## generally defines motion
      • X## Y## Z## declare a position
      • F# set a value - feedrate
      • S### set a value - spindle speed
      • T## select an item - tool selection
      • M# switch something on/off - miscellaneous functions
    • Modality - if it's on, it stays on till you turn it off
      • Only 1 function can be active at any given time (what about flood coolant and cutting and moving the tool while the spindle is rotating, all on at the same time)
      • Select a new function to deactivate the previous function
      • Modal Groups
        • Group 1 = Motion (G00, G01, G02, G03, G80, G81, G82, G84, G85, G86, G87, G88, G89)
        • Group 2 = Plane Selection (G17, G18, G19) XY, YZ, ZX
        • Group 3 = absolute/incremental mode (G90, G91)
        • Group 5 = feed rate mode (G93, G94)
        • Group 6 = units (G20, G21) inches/millimeters
        • Group 7 = cutter radius compensation (G40, G41, G42)
        • Group 8 = tool length offset (G43, G49)
        • Group 10 = return mode in canned cycles (G98, G99)
        • Group 12 = work coordinate system selection (G54, G55, G56, G57, G58, G59, G59.xxx)
  • Coordinate system
    • CNC Lathe - Machine Zero
  • 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
    • U - incremental X-axis motion command
    • W - incremental Z-axis motion command

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

  • N1 thru N99999 in a program are only used to locate and identify a line or block and its relative position within a CNC program. A program can be with or without sequence numbers. The only function of sequence numbers is to locate a certain block or line within a CNC program. [Haas Lathe, p. 13]

Address Codes

  • F Feed Rate
    • inches per revolution is default G99
    • [Haas p. 24]
  • 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);
%

Program Header

  • CNC Program header - recommended items to include
    • Program file name
    • Program author
    • version date
    • modification history
    • machine and control the program is intended for
    • units: inches or mm
    • setup information: what stock material is expected, what size, etc.
    • work coordinates - what's expected by way of work coordinates? Where is Part Zero?
    • customer info: job shops will want information about what customer and job number the program is part of
    • see [CNC Cookbook basics]
  • Reference

Software

Haas Control Pendant Keyboard

  • Haas Lathe Control Pendant Keyboard
  • Haas Control Pendant Photo

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
    • returns all axes to machine zero in rapid motion. Home G28 will also home a single axis in the same manner if you enter an axis letter and press the home G28 button
  • Return Home
  • Reference
    • [Haas Lathe Operation, p. 16]

GWizard Editor by CNC Cookbook

Tutorials

References

  • [Haas Lathe] - Haas Automation, Inc. Lathe Series Programming Workbook (pdf)
    • Lathe Operator's Manual (pdf)
  • Programming of CNC Machines, 4th by Ken Evans, published by Industrial Press \$42.67
    • The Student Workbook for Programming of CNC Machines, 4th Edition from Industrial Press \$29.95
  • CNC G Code Programming for Beginners by Mike Mattera (mike.mattera@autodesk.com)

Forums

Navigation

Civil Engineering Engineering - Computer Engineering - Electrical Mechanical Engineering

Print/export
QR Code
QR Code engineer-mechanical:cnc (generated for current page)