g & m codes © 2013 project lead the way, inc.computer integrated manufacturing
TRANSCRIPT
G & M Codes
© 2013 Project Lead The Way, Inc.Computer Integrated Manufacturing
What Are G & M Codes?
• Operate CNC machines
• Began in the form of punch tape
• Developed into computer chips in the 1970s
G & M Today
• Translates human language to machine language
• Typed into computer or generated by a program
Sample Program Block
N1 M06 T1 ; Change to tool #1
Block Sequence #Miscellaneous code: Tool change
Tool Number
Comment
Comment separator
Sample Program Block
N02 M03 S1500
Line Number
Miscellaneous code: Turn spindle on
Spindle Speed: 1500 rpm
Sample Program Block
N03 G90 G01 X.5 Y.5 Z0 F1
Line NumberPrep Code – Absolute
Prep Code – SL Interpol
Y Coordinate
X Coordinate
Z Coordinate
Feed Rate (in./min)
More Terminology
Address Character – A letter used in G & M code programming to designate a class of functions
Parameter – Attribute of a feature, such as a dimension, that can be modified
N00 G90 G01 X.5 Y.5 Z0 F1
TerminologyWord – The programming expression formed when a letter (address) is combined with a number
Block – A single line of code in an NC part program
N00 G90 G01 X.5 Y.5 Z0 F1
G Codes – Preparatory
G90 Absolute CoordinatesG91 Relative CoordinatesG00 Rapid Traverse (non-cutting move)G01 Straight Line Interpolation (cutting move)G02 Circular Interpolation (clockwise)G03 Circular Interpolation (c-clockwise)G04 Dwell (wait) – Pause measured in seconds on all
axes between motions (i.e., G04F2.3 is a pause for 2.3 s)
G05 Pause – Wait for user intervention
G Codes – Arcs
Absolute coordinatesExample
N0 G90 ; Absolute coordN5 G01 X1 Y2 ; startN10 G02 X2 Y1 I1 J1
X2Y1
Relative coordinatesExample
N0 G91; Relative coordN05 G01 X1 Y2 ; startN10 G02 X1 Y-1 I0 J-1
X1Y2
I1J1
X1Y-1
X1Y2
I0 J-1
Method 1: Arc with I & J( I & J are center point coordinates )
G Codes – Arcs
Absolute coordinatesExample
N0 G90 ; Absolute coordN5 G01 X1 Y2 ; startN10 G02 X2 Y1 R1
Relative coordinatesExample
N0 G91; Relative coordN05 G01 X1 Y2 ; startN10 G02 X1 Y-1 R1
X1Y-1
X1Y2
R1
X2Y1
X1Y2
R1
Method 2: Arc with R(R is arc radius)
Other Common G Codes
G20 Inch programming units
G21 Millimeter programming units
G80 Canned cycle cancel
G81 Drilling cycle
G82 Drilling cycle with dwell
M Codes – Miscellaneous
M00 Pause M01 Optional stopM02 End of programM03 Spindle onM05 Spindle offM06 Tool changeM08 / M09 Accessory # 1 on / offM10 / M11 Accessory # 2 on / offM30 Program end and resetM47 Rewind (used for handshaking operations)
Code Suggestions• Same code not required to be repeated every
block– Machine will use same code until changed– Called modal
• Tab remarks away from code to facilitate troubleshooting program
• Specify absolute or relative coordinates and inch or metric modes at beginning of program
• Always use a tool change command to move tool to safe position away from material; change tool if necessary
• Indicate spindle speed each time turned on
Code Suggestions
• Move tool to start position in two lines– First line moves in X-Y plane, then moves in Z
axis– Prevents ramping or inadvertently cutting a
part• Raise tool out of the stock at end of program• Always move table to safe unload position and
turn spindle off at end of program• Use M02 command to end program
Sample Part – Absolute
A 0.5 0.5B 0.5 1.5C 0.875 1D 1.25 1.5E 1.25 0.5F 1.75 1.5H 1.75 0.5I 1.75 1
AbsoluteCoordinates
Origin
Sample ProgramAbsolute
N1 G90 G20 ; ABSOLUTE COORD & INCH MODEN2 M06 T1 ; TOOL CHANGE – LOAD TOOL 1N3 M03 S3000 ; TURN SPINDLE ON CW TO 3000 RPMN4 G00 X.5 Y.5 ; RAPID TO POINT AN5 G00 Z.1 ; RAPID TO .1 ABOVE PARTN6 G01 Z-.0625 F9 ; PLUNGE 1/16 AT 9 IN./MINN7 G01 X.5 Y1.5 F18 ; STRAIGHT LINE INTERP TO BN8 G01 X.875 Y1 ; STRAIGNT LINE INTERP TO
CN9 G01 X1.25 Y1.5 ; STRAIGHT LINE INTERP TO
DN10 G01 X1.25 Y.5 ; STRAIGHT LINE INTERP TO
E
Sample ProgramAbsolute
N11 G01 Z.1 ; RETRACT CUTTING TOOLN12 G00 X1.75 Y1.5 ; RAPID TO POINT FN13 G01 Z-.0625 F9 ; PLUNGE AT 9 IN./MINN14 G01 X1.75 Y.5 F18 ; STRAIGHT LINE INTERP TO HN15 G03 X1.75 Y1.5 I1.75 J1 ; CCW CIRCLE INTERPN16 G01 Z.1 ; RETRACT CUTTING TOOLN17 M05 ; TURN OFF SPINDLEN18 G00 Z2 ; RAPID Z TO SAFE POSITIONN19 G00 X4 Y3 ; MOVE TABLE TO UNLOAD POSITIONN20 M02 ; END OF PROGRAM
Sample Part – Incremental
LABEL X YA 0.5 0.5B 0 1C 0.375 -0.5D 0.375 0.5E 0 -1F 0 1H 0 -1I 0 0.5
IncrementalCoordinates
Origin
Sample ProgramIncremental / Relative
N1 G90 G20 ; ABSOLUTE COORD & INCH MODEN2 M06 T1 ; TOOL CHANGE – LOAD TOOL 1 N3 M03 S3000 ; TURN SPINDLE ON CW TO 3000 RPMN4 G00 X.5 Y.5 ; RAPID TO POINT AN5 G00 Z.1 ; RAPID TO .1 ABOVE POINT AN6 G91 ; INCREMENTAL COORD & INCH MODEN7 G01 Z-.1625 F9 ; PLUNGE 1/16 AT 9 IN./MINN8 G01 X0 Y1 F16 ; STRAIGHT LINE INTERP TO BN9 G01 X.375 Y-.5 ; STRAIGHT LINE INTERP TO CN10 G01 X.375 Y.5 ; STRAIGHT LINE INTERP TO DN11 G01 X0 Y-1 ; STRAIGHT LINE INTERP TO E
N12 G01 Z.1625 ; RETRACT CUTTING TOOLN13 G00 X.5 Y1 ; RAPID TO POINT FN14 G01 Z-.1625 F9 ; PLUNGE AT 9 IN./MINN15 G01 X0 Y-1 F16 ; STRAIGHT LINE INTERP TO HN16 G03 X0 Y1 I0 J.5 ; CCW CIRCLE INTERPN17 G01 Z.1625 ; RETRACT CUTTING TOOLN18 M05 ; TURN OFF SPINDLEN19 G90 ; CHANGE TO ABSOLUTE COORD N20 G00 Z2 ; RAPID Z TO SAFE POSITIONN21 G00 X4 Y3 ; MOVE TABLE TO UNLOAD POSITIONN22 M02 ; END OF PROGRAM
Sample ProgramIncremental / Relative
Your Turn
What line in the last example uses the arc command?
N16
Change the arc command in the last example into the format with R (radius).
N16 G03 X0 Y1 R.5 ; CCW CIRCLE INTERP
See next slide for change in program.
Solution
N12 G01 Z.1625 ; RETRACT CUTTING TOOLN13 G00 X.5 Y1 ; RAPID TO POINT FN14 G01 Z-.1625 F9 ; PLUNGE AT 9 IN./MINN15 G01 X0 Y-1 F16 ; STRAIGHT LINE INTERP TO HN16 G03 X0 Y1 R.5 ; CCW CIRCLE INTERPN17 G01 Z.1625 ; RETRACT CUTTING TOOLN18 M05 ; TURN OFF SPINDLEN19 G90 ; CHANGE TO ABSOLUTE COORD N20 G00 Z2 ; RAPID Z TO SAFE POSITIONN21 G00 X4 Y3 ; MOVE TABLE TO UNLOAD POSITIONN22 M02 ; END OF PROGRAM
Explain the Code
N2 G1 X2.5 Y3 F2
N2G1X2.5Y3F2
Block twoLinear interpolation
2.5 on the X axis
3 on the Y axis
Feed rate = 2 IPM
What’s Wrong with These?1. N1G01G90X2X2; 2. N1G00G01X2Y2; 3. N3G01X.5Y2F1;
N4G01X.5Y3.5F1;4. Changing N6G00X0.500Y1.500; to N6G0X.5Y1.5;5. Changing N2G90Z0.05M00; to N2G9Z.5M;
References
Mattson, M. (2010). CNC programming principles and applications. Oregon City, OR: Delmar.