Machining Technology

There is no standardized format for writing a CNC program that is compatible with all machine control models. Each MCU manufacturer has developed its own unique programming format. Each one has minor differences, but the principles contained in the context of a program are the same among them all. These programs that I have written will relate most closely to Fanuc-type controllers; however, the principles may be applied to any manufacturer's programming format (see the specific machine's programming manual).

CNC Lathe Programming

Lathe Print Lathe Simulator

%

O00020
(T101 O.D. ROUGH TOOL x 1/32" TNR)
(T202 O.D. FINISH TOOL x 1/64" TNR)
(T303 GROOVE TOOL x 0.118")

G53 G00 X0.0 Z0.0 T0 (SENDING HOME FOR A TOOL CHANGE)
T101 (TOOL #1 AND OFFSET #1)
G50 S1528 (SPINDLE SPEED CLAMP AT 1528 RPM)
G97 S414 M03 (CANCEL CSS, 500 RPM, SPINDLE ON FORWARD)
G54 G00 X2.35 Z0.1 M08 (RAPID X2.35, Z0.1 TO START POINT, COOLANT ON)
G96 S390 (CSS ON, AT 390 SURFACE SPEED)
Z0.005 (POSITION 0.005 FROM END OF PART)
G01 X-0.063 F0.005 (FEED DOWN X-0.063 TO FACE END OF PART)
G00 X2.35 Z0.1 (RAPID TO X2.35, Z0.1 START POINT ABOVE PART)
M01

(ROUGH PART PROFILE)
(D - DEPTH OF ROUGHING PASSES)
(P - STARTING BLOCK NUMBER OF PATH TO ROUGH)
(Q - ENDING BLOCK NUMBER OF PATH TO ROUGH)
(U - AMOUNT OF MATERIAL TO BE LEFT ON DIA)
(W - AMOUNT OF MATERIAL TO BE LEFT ON FACES)
G71 P100 Q200 U0.01 W0.005 F0.012 D0.0375 (G71 ROUGH CYCLE)
N100 G42 G00 X0.53 F.003 (PNN START #100, RAPID X0.53, CUTTER COMP. ON)
G01 Z0.0 F0.006 (G71 PART GEOMETRY)
X0.63 (POINT 1)
X0.75 Z-0.06 (POINT 2)
Z-0.625 (POINT 3)
X1.25 Z-0.875 (POINT 4)
Z-1.875 (POINT 5)
X1.35 (POINT 6)
G03 X1.75 Z-2.075 R0.2 (POINT 7)
G01 Z-2.875 F0.004 (POINT 8)
X2.25 (POINT 9)
Z-4.725 (POINT 10)
N200 G40 G00 X2.35 F0.02 (QNN END #200, CANCEL CUTTER COMP. FFED X TO 2.35)
G97 S414 M09 (CANCEL CSS, 414 RPM, COOLANT OFF)
G53 G00 X0.0 Z0.0 T0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(FINISH PART PROFILE)
T202 (TOOL #2 AND OFFSET #2)
G50 S1528 (SPINDLE SPEED CLAMP AT 1528 RPM)
G97 S1354 M03 (CANCEL CSS, 1354 RPM, SPINDLE ON)
G54 G00 X1.13 Z0.1 M08 (RAPID, X1.13, Z0.1 LOCATION, COOLANT ON)
G96 S390 (TURN ON CSS TO 390)
Z0.0 (POSITION TO Z0.0 END OF PART)
G01 X-0.031 F0.005 (FEED DOWN FACE OF PART)
G00 X2.35 Z0.1 (RAPID TO X3.2, Z0.1 START POINT ABOVE PART)
G70 P100 Q200 (DEFINE A G70 FINISH PASS OF PART GEOMETRY)
G97 S600 M03 (CANCEL CSS, BACK TO RPM MODE)
G00 G53 X0.0 Z0.0
M01 (OPTIONAL STOP COMMAND)

(PARTING PART)
T303
G50 S2000 (SPINDLE SPEED CLAMP AT 2000 RPM)
G54 G00 X2.35 Z-4.843 M08 (4.725 + 0.118 GROOVE TOOL = 4.843)
G96 S300 (FINISH CYCLE SPEED)
G75 X0.0 I0.05 F0.005
G97 S500 M09 (CANCEL CSS, DEFINE 500 RPM, COOLANT OFF)
G53 G00 X0.0 Z0.0 T0 (SENDING HOME FOR A TOOL CHANGE)
M30 (END OF PROGRAM AND RESET)

%

We also can use G72 for facing and parting the part as well.

(FACING PART)
T101 (TOOL #1 AND OFFSET #1)
G50 S1528 (SPINDLE SPEED CLAMP AT 1528 RPM)
G97 S414 M03 (CANCEL CSS, 414 RPM, SPINDLE ON FORWARD)
G54 G00 X2.35 Z0.1 M08 (RAPID X2.35, Z0.1 TO START POINT, COOLANT ON)
G96 S390 (CSS ON, AT 390 SURFACE SPEED)
G72 P10 Q20 U0.02 W0.01 D0.03 F0.012 (G72 ROUGHING CYCLE)
N10 G41 G00 X2.35 Z0.0 (PROFILE START, APPROACH, TYPE II)
G01 X0.0
N20 G40 G00 Z0.1 M09 (END OF GEOMETRY, TNR COMP OFF)
G70 P10 Q20 F0.006 (FINISH CYCLE)

(PARTING PART)
T101 (TOOL #1 AND OFFSET #1)
G50 S1528 (SPINDLE SPEED CLAMP AT 1528 RPM)
G97 S414 M03 (CANCEL CSS, 414 RPM, SPINDLE ON FORWARD)
G54 G00 X2.35 Z0.1 M08 (RAPID X2.35, Z0.1 TO START POINT, COOLANT ON)
G96 S390 (CSS ON, AT 390 SURFACE SPEED)
G72 P10 Q20 U0.02 W0.01 D0.03 F0.012 (G72 ROUGHING CYCLE)
N10 G41 G00 X2.35 Z-4.725 (PROFILE START, APPROACH, TYPE II)
G01 X0.0
N20 G40 G00 Z0.1 M09 (END OF GEOMETRY, TNR COMP OFF)
G70 P10 Q20 F0.006 (FINISH CYCLE)

CNC Mill Programming

Lathe
Lathe

%

O00010
(MILL PROJECT)
(STOCK 4.6" X 2.5" X 0.75")
(4TH QUADRANT)
(T1 3" FACEMILL)
(T2 1/2" FLAT ENDMILL 0.500" dia)
(T3 3/4" CENTER DRILL 0.750" dia)
(T4 #7 DRILL 0.201" dia)
(T5 1/4-20 UNC TAP 0.250" dia)

(FACE TOP CLEAN)
(T1 3" FACEMILL)
G00 G40 G49 G80 G90
T1 M06 (T1 3" FACEMILL)
S2500 M03 (SET SPINDLE SPEED TO 2500 RPM)
G54 X-2.0 Y-1.25
G43 H01 Z1.0 (RAPID TO 1.0 ABOVE PART)
G01 Z0.1 F25. M08 (COOLANT ON)
Z-0.001
X5.0 F60.
G00 Z1. M09
M05
G91 G28 Z0.0
G28 G49 X0. Y0.
M01

(MILL INNER EDGES)
(T2 1/2" FLAT ENDMILL 0.500" dia)
G00 G40 G49 G80 G90
T2 M06 (T2 1/2" FLAT ENDMILL 0.500" dia)
S6500 M03 (SET SPINDLE SPEED TO 6500 RPM)

(1ST PASS ROUGHING)
G54 X-1. Y-.15 (STARTING X Y 0.3/2 = 0.15)
G43 H02 Z1.
G01 Z.1 F25. M08 (COOLANT ON)
Z-0.25 (FEED TO FINAL DEPTH)
G41 D02 G01 X-.5 F50. (START TOP LEFT)
X4.35 (POINT 12 ROUGHING)
Y-2.35 (POINT 14 ROUGHING)
X.15 (POINT 21 ROUGHING)
Y.5 (POINT 5)
M01

(2ND PASS FINISH INNER EDGES)
G00 Z1.
X-2.0 Y-0.3 (START TOP LEFT)
G01 Z-0.25 F50.
X3.7 (POINT 11 FINISH)
X4.2 Y-0.8 (POINT 12 FINISH)
Y-1.7 (POINT 13 FINISH)
X3.911 Y-2.2 (POINT 14 FINISH)
X0.6 (POINT 20 FINISH)
G02 X0.3 Y-1.9 R0.3 (POINT 21 FINISH)
G01 Y.5 (POINT 5 FINISH)
M01

(3RD PASS ROUGHING BIG RADIUS ALONG THE TOP EDGE)
G00 Z1.
X-2.0 Y-0.3 (START TOP LEFT)
G01 Z-0.25 F50.
X1.95 (POINT 7 ROUGHING)
G03 X2.55 Y-0.3 R0.3 (POINT 9 ROUGHING)
G01 X5.0
M01

(4TH PASS FINISH SMALL AND BIG RADIUS ALONG THE TOP EDGE)
G00 Z1.
X-2.0 Y-0.3 (START TOP LEFT)
G01 Z-0.25 F50.
X1.85 (POINT 6 FINISH)
G02 X1.95 Y-0.4 R0.1 (POINT 7 FINISH)
G03 X2.55 Y-0.4 R0.3 (POINT 9 FINISH)
G02 X2.65 Y-0.3 R0.1 (POINT 10 FINISH)
G01 X5.0
M01

(5TH PASS ROUGHING BIG RADIUS ALONG THE BOTTOM EDGE)
G00 Z1.
X5.0 Y-2.2 (START BOTTOM RIGHT)
G01 Z-0.25 F50.
X2.55 (POINT 16 ROUGHING)
G03 X1.95 Y-2.2 R0.3 (POINT 18 ROUGHING)
G01 X-0.1
M01

(6TH PASS FINISH SMALL AND BIG RADIUS ALONG THE BOTTOM EDGE)
G00 Z1.
X5.0 Y-2.2 (START BOTTOM RIGHT)
G01 Z-0.25 F50.
X2.65 (POINT 15 FINISH)
G02 X2.55 Y-2.1 R0.1 (POINT 16 FINISH)
G03 X1.95 Y-2.1 R0.3 (POINT 18 FINISH)
G02 X1.85 Y-2.2 R0.1 (POINT 19 FINISH)
G01 X-1.0
G40 Y1.
Z.1 M09
G00 Z1. M05
G91 G28 Z0.0
G28 G49 X0. Y0.
M01

(DRILL TWO 1.25" CIRCULAR POCKET MILLINGS)
(T2 1/2" FLAT ENDMILL 0.500" dia)
G00 G40 G49 G80 G90
T2 M06 (T2 1/2" FLAT ENDMILL 0.500" dia)
S1500 M03 (TURN SPINDLE ON, CLOCKWISE DIRECTION)
G54 X1.125 Y-1.25 (XY POSITION TO CENTER OF CPM1)
G43 Z0.1 H02 M08 (RAPID TO 0.1 ABOVE PART)
G1 Z0.0 F30.0

(I - Radius of the first circle and must be greater than Tool Radius)
(K - Radius of finished circle)
(L - Loop count for repeating deeper cuts)
(Q - Radius increment must be used with K)
(Z - Depth of cut or increment)

(Z = 0.855 depth / 5)
(K = 1.25 dia / 2)
(Q = K - I = 0.325 x 2 = 0.65 / L = 0.13)
(0.855 - 0.75 depth = 0.105 below the bottom part)

G13 G91 Z-0.171 I0.3 K0.625 Q0.13 D02 F15.0 L5 (I, K, Q & G91)
G90 G00 Z1.0 (SWITCH TO ABSOLUTE, RAPID 1.0 ABOVE PART, COOLANT OFF)
X3.375 Y-1.258 (XY POSITION TO CENTER OF CPM2)
G01 Z0.0 F30.0
G13 G91 Z-0.15 I0.3 K0.625 Q0.13 D02 F15.0 L5 (I, K, Q & G91)
G90 G00 Z0.1 M09 (SWITCH TO ABSOLUTE, RAPID 1.0 ABOVE PART, COOLANT OFF)
G53 G49 Z0. M05
M01

(CENTER DRILL HOLES)
(T3 3/4" CENTER DRILL 0.750" dia)
G00 G40 G49 G80 G90
T3 M06 (T3 3/4" CENTER DRILL 0.750" dia)
S2000 M03 (SET SPINDLE SPEED TO 2000 RPM)
G54 X1.95 Y-0.75
G43 H03 Z1.
G01 Z.1 F25. M08
G81 X1.95 Y-0.75 Z-.125 R.1 F4.
X2.55
Y-1.75
X1.95
G80 M09
G00 Z1. M05
G91 G28 Z0.0
G28 G49 X0. Y0.
M01

(DRILL 1/4-20 HOLES)
(T4 #7 DRILL 0.201")
G00 G40 G49 G80 G90
T4 M06 (T4 #7 DRILL 0.201")
S3000 M03
G54 X1.95 Y-0.75
G43 H04 Z1.
G01 Z.1 F25. M08

(Q - PECKING EQUAL INCREMENTAL DEPTH AMOUNT)
(0.855 - 0.75 depth = 0.105 below the bottom part)
G83 Z-0.855 R.1 Q0.075 F3.
X2.55
Y-1.75
X1.95
G80 M09
G00 Z1. M05
G91 G28 Z0.0
G28 G49 X0. Y0.
M01

(TAPPING 1/4-20 HOLES)
(T5 1/4-20 UNC TAP 0.250" dia)
G00 G40 G49 G80 G90
T5 M06 (T5 1/4-20 UNC TAP 0.250" dia)
S200 M03 (SET SPINDLE SPEED TO 200 RPM)
G54 X1.95 Y-0.75
G43 H05 Z1.
G01 Z.1 F25. M08

(1 / 20 X 200 RPM = 10 IPM)
(0.855 - 0.75 depth = 0.105 below the bottom part)
G84 Z-0.855 R.1 F10.
X2.55
Y-1.75
X1.95
G80 M09
G00 Z1. M05
G91 G28 Z0.0
G28 G49 X0. Y0.
M30

Macros

Macros add capabilities and flexibility to the control that are not possible with standard G-code. Some possible uses are: families of parts, custom canned cycles, complex motions, and driving optional devices. The possibilities are almost endless.

A Macro is any routine/subprogram that you can run multiple times. A macro statement can assign a value to a variable, read a value from a variable, evaluate an expression, conditionally or unconditionally branch to another point within a program, or conditionally repeat some section of a program.

Here is an example that I want to face both ends of the part from 4.8" to 4.5".

Mill Simulator

%

O00011
(FACING WITH MACROS)
(4TH QUADRANT)
(T2 1/2" FLAT ENDMILL 0.500" dia)

G00 G40 G49 G80 G90
T2 M06 (T2 1/2" FLAT ENDMILL 0.500" dia)
S6500 M03 (SET SPINDLE SPEED TO 6500 RPM)
G54 X5.0 Y-3.0
G43 H02 Z1. (RAPID TO 1.0 ABOVE PART)
G01 Z.1 F25. M08 (COOLANT ON)
Z-0.855

(NUMBERS STORED IN VARIABLE CAN BE OFF BY 1 LEAST SIGNIFICANT DIGIT)
#100 = 4.8

(FACE PART TO 4.5)
WHILE [#100 GT 4.49] DO1 (WHILE LOOP TERMINATES WHEN #100 = 4.48 OR < 4.5)
G41 D02 G01 X#100 F50. (LEFT AT POINT 3)
Y0.5 (POINT 2 conventional)
Y-3.0 (POINT 3 climbing)
#100 = #100 - 0.02 (DECREMENT BY 0.02)
(IF X = 4.7 OR 4.6 THEN OPTIONAL STOP)
IF [ [[#100 LT 4.71] AND [#100 GT 4.69]] OR [[#100 LT 4.61] AND [#100 GT 4.59]] ] THEN M01
END1

G40 X5.0
M09 (TURN OFF CC)
G00 Z1. M05
G91 G28 Z0.0
G28 G49 X0. Y0.
M30

%