Machining Technology at HCC

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 for school projects will relate most closely to Fanuc-type controllers specifically Haas and Doosan; however, the principles may be applied to any manufacturer's programming format (see the specific machine's programming manual).

Free download from Haas:

    1. Haas Lathe Programming Workbook
    2. Haas CNC Lathe Operator's Manual
    3. Live Tool for Haas Lathe

Free download from Doosan:

    1. Doosan NC Programming Manual for Turning Centers Fanuc 30 Series Controls
    2. Doosan Programming Manual Fanuc Controls
    3. DOOSAN CNC Turning Center Programming Manual
    4. Fanuc Manual Guide i Operator's Manual

Free download from Mori Seiki:

    1. Mori Seiki Operating Manual ZL-153 ZL-253SMC
    2. Mori Seiki Programming Manual

Free download from Romi:

    1. ROMI G GL GLM Fanuc 0I-TD Programming Operation Manual

Free download from Okuma:

    1. Okuma OSP P200L Simple Manual
    2. OKUMA OSP100 Programing Training

I have several projects per semester. By the end of the semester, I have created many programs and machined the entire things and that really is inspirational. Here are some of the projects I have done in the shop.

Rough & Finish

CNC Lathe Project 1

Lathe Simulator

Lathe Simulator

The G71 Roughing cycle will rough out material on a part defining the finished part shap. The G70 Finishing cycle can be used to finish cut paths that are defined and roughed out with stock removal cycles G71. After execution of the Q block, a rapid (G00) is executed returning the machine to the start position that was saved earlier during G70 initialization. The program then returns to the block following the G70 call.

Groove & Thread

Turning Operation

Turning Operation

Lathe Simulator

The G75 canned cycle can be used for grooving an outside diameter with a chip break. The G76 canned cycle can be used for threading both straight or tappered (pipe) threads.

For Haas CNC Lathe Machines

%
O00021
(PROGRAMMER: FRANCIS NGUYEN)
(VERSION: 2020)
(STOCK 2.5" O.D.)
(T0101 O.D. ROUGH TOOL x 1/32 TNR)
(T0202 O.D. FINISH TOOL x 1/64 TNR)
(T0303 GROOVING TOOL x 0.118")
(T0404 O.D. THREADING TOOL)
(T0505 PARTING TOOL x 0.118")
(T0606 STOP BAR)
(T0707 CENTER DRILL #2)

(BAR STOP)
G53 G00 X0.0 Z0.0 T0 (SENDING HOME FOR A TOOL CHANGE)
T0606
G55 G00 X0.0 Z0.02
M00
Z0.1
X5.0 Z1.0
G28 U0.0
M01

T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G96 S500 M03 (CSS ON, AT 500 SURFACE SPEED, SPINDLE ON FORWARD)
G55 G00 X2.6 Z0.1 M08 (RAPID X2.6, Z0.1 TO START POINT, COOLANT ON)
G01 Z0.0 F0.01
X-0.063 (FEED DOWN X-0.063 TO FACE END OF PART)
Z0.1
G00 X5.0 Z1.0 M09 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART, COOLANT OFF)
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M05 (SPINDLE STOP)
M01 (OPTIONAL STOP COMMAND)

(CENTER DRILL USING LIVE TOOL)
T0707 (Tool 5 Offset 5)
G98 (Feed per minute)
M154 (Engage C-Axis)
G97 M133 P1000 (Live Tool Drive Forward/Live Tool Spindle Speed)
G55 G00 X0. C0. Z0.25 M08 (Rapid to Initial Start Point)

G81 Z-0.125 R-0.15 F1.0 (G81 Drilling Cycle)
G80 G00 Z0.25 M09

M155 (Disengage C-Axis)
M135 (Live Tool Drive Stop)
G28 H0 (Return C-Axis to Home Position)
G00 X5. Z1.0
G99 (Feed per revolution)
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M01

(BAR STOP)
T0606
G54 G00 X0.0 Z0.0
M00
Z0.1
X5.0 Z1.0
G28 U0.0
M01

(ROUGH PART PROFILE USING TAILSTOCK)
M21 (TAILSTOCK ADVANCE)
T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G96 S500 M03 (TURN ON CSS TO 500)
G54 G00 X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)

(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 D0.05 F0.01 (G71 ROUGH CYCLE)
N100 G42 G00 X0.72 (PNN START #100, RAPID X0.72, CUTTER COMP. ON)
G01 Z0.0 F0.005 (G71 PART GEOMETRY)
X0.82 (POINT 1)
X1. Z-0.09 (POINT 2)
Z-1.5 (POINT 3)
X1.45 (POINT 4)
Z-3. (POINT 5)
X1.7 (POINT 6)
Z-3.5 (POINT 7)
X1.95 (POINT 8)
Z-4.425 (POINT 9 EXTEND 0.125)
N200 G40 G00 X2.6 M09 (QNN END #200, CANCEL CUTTER COMP., FEED X TO 2.6, COOLANT OFF)
G00 X5.0 Z1.0
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(FINISH PART PROFILE)
T0202 (TOOL #2 AND OFFSET #2)
G50 S1200 (SPINDLE SPEED CLAMP AT 1200 RPM)
G96 S600 M03 (TURN ON CSS TO 600)
G54 G00 X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G70 P100 Q200 (DEFINE A G70 FINISH PASS OF PART GEOMETRY)
G00 X5.0 Z1.0
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(GROOVING CYCLE)
T0303
G97 S400 M03
G54 G00 X1.6 Z0.1 M08
Z-1.418 (1.30 + 0.118 GROOVING TOOL = 1.418)

(I - X AXIS PECKING DEPTH INCREMENT, RADIUS VALUE)
(K - Z AXIS SHIFT INCREMENT BETWEEN PECKING CYCLES)

G75 X0.750 Z-1.5 I0.05 K0.1 F0.005
G00 X1.8
Z-2.918 (2.800 + 0.118 GROOVING TOOL = 2.918)
G75 X1.250 Z-3.0 I0.05 K0.1 F0.005

G00 X2.6 M09
X5.0 Z1.0
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M01

(THREADING CYCLE)
T0404
G97 S400 M03

(SINGLE DEPTH = 0.61343 / TPI)
(SINGLE DEPTH = 0.61343 / 8 = 0.0767)
(X START POINT = MAJOR DIA. + 2 X SINGLE DEPTH)
(X START POINT = 0.9905 + 2 X 0.0767 = 1.1439)
(PITCH = 1/ TPI)
(PITCH = 1/ 8 = 0.125)

G54 G00 X1.1439 Z0.25 M08 (X START POINT, Z START POINT)
(K - THREAD HEIGHT, RADIUS VALUE)
(# OF THREADING PASSES = [72 X PITCH] + 7)
(D - FIRST PASS CUTTING DEPTH)
(D = SINGLE DEPTH / OF THREADING PASSES)
(D = 0.0767 / SQRT OF 16 = 0.0192)
(F - 1/TPI)
(F = 1/ 8 = 0.125)
(X - MIN MINOR DIAMETER)
(Z - THREAD LENGHT)

G76 X0.8206 Z-1.3 K0.0767 D0.0192 F0.125 (16 PASSES)

G00 X5.0 Z1.0 M09
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M01

(PARTING PART)
M22 (TAILSTOCK RETRACT)
T0505
G50 S800 (SPINDLE SPEED CLAMP AT 800 RPM)
G96 S400 M03 (TURN ON CSS TO 400)
G54 G00 X2.6 Z-4.418 M08 (4.30 + 0.118 PARTING TOOL = 4.418)
G01 X-.02 F0.002 M36 (PARTS CATCHER ON)
G00 X2.6 M09
M00
X5.0 Z1.0 M37 (PARTS CATCHER OFF)
G28 U0. (SENDING HOME FOR A TOOL CHANGE)
M05 (SPINDLE STOP)
M30 (END OF PROGRAM AND RESET)
%

CNC Lathe Machine

For Doosan CNC Lathe Machines

%
O0001
(PROGRAMMER: FRANCIS NGUYEN)
(VERSION: 2021)
(STOCK 2.5" O.D.)
(T0101 O.D. ROUGH TOOL x 1/32 TNR)
(T0202 O.D. FINISH TOOL x 1/64 TNR)
(T0303 GROOVING TOOL x 0.118")
(T0404 O.D. THREADING TOOL)
(T0505 PARTING TOOL x 0.118")
(T0606 STOP BAR)
(T0707 CENTER DRILL #2)

#100 = 4.300 (PART LENGTH)
#101 = 2.500 (STOCK DIA)
#102 = #101 + 0.1(STOCK DIA + 0.1)
#103 = #100 + 0.118 (PART LENGTH CUTOFF)
#5222 = #100 (G54)
#5242 = 0.5 (G55)

(BAR STOP)
T0606
G55 G00 Z0.02 X0.0
M00
Z0.1
X5.0 Z1.0
G28 U0.0
M01

T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G96 S500 P11 M03 (CSS ON, AT 500 SURFACE SPEED, MAIN SPINDLE ON)
G55 G00 X#102 Z0.1 M08 (RAPID X2.6, Z0.1 TO START POINT, COOLANT ON)
G01 Z0.0 F0.01
X-0.063 (FEED DOWN X-0.063 TO FACE END OF PART)
G00 X#102 Z0.1 M09 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART, COOLANT OFF)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M05 P11 (SPINDLE STOP)
M01 (OPTIONAL STOP COMMAND)

(CENTER DRILL USING LIVE TOOL)
T0707 (Tool 7 Offset 7)
G98 (Feed per minute)
M35 (SPINDLE STOP C-Axis)
G97 S1000 M03 P12(Live Tool Spindle Speed/Live Tool Drive Forward)
G55 G00 X0. C0. Z0.25 M08 (Rapid to Initial Start Point)

G83 Z-0.125 R-0.15 F1.0 (G83 Drilling Cycle)
G80 G00 Z0.25 M09

M05 P12 (LIVE TOOL SPINDLE STOP)
M34 (SPINDLE REVERSE C-Axis)
G28 H0 (Return C-Axis to Home Position)
G00 X5. Z1.
G99 (Feed per revolution)
G28 U0.
M01

(BAR STOP)
T0606
G54 G00 Z0.0 X0.0
M00
Z0.1
X5.0 Z1.0
G28 U0.0
M01

(ROUGH PART PROFILE USING TAILSTOCK)
M78 (QUILL ADVANCE)
T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 P11 (SPINDLE SPEED CLAMP AT 1000 RPM)
G96 S500 P11 M03 (TURN ON CSS TO 500, SPINDLE ON)
G54 G00 X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)

(U - SETS THE DEPTH OF THE ROUGHING PASSES)
(R - SETS THE DISTANCE THE TOOL WILL RETRACT FROM EACH ROUGHING PASS)
(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)
(TOOL NOSE RADIUS COMPENSATION CANNOT BE APPLIED TO G71, G72, G73, G74, G75, G76, OR G78 FOR DOOSAN)

G71 U0.050 R0.050
G71 P100 Q200 U0.010 W0.005 F0.010
N100 G42 G00 X0.72 (PNN START #100, CUTTER COMP. ON FOR G70, RAPID X0.72)
G01 Z0.0 F0.005 (G71 PART GEOMETRY)
X0.82 (POINT 1)
X1. Z-0.09 (POINT 2)
Z-1.5 (POINT 3)
X1.45 (POINT 4)
Z-3. (POINT 5)
X1.7 (POINT 6)
Z-3.5 (POINT 7)
X1.95 (POINT 8)
Z-#103 (POINT 9)
N200 G40 G00 X#102 M09 (QNN END #200, CANCEL CUTTER COMP. FOR G70, FEED X TO 2.6)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(FINISH PART PROFILE)
(SET R IN TOOL GEOM TO 0.0156)
T0202 (TOOL #2 AND OFFSET #2)
G50 S1200 (SPINDLE SPEED CLAMP AT 1200 RPM)
G96 S600 P11 M03 (TURN ON CSS TO 900, MAIN SPINDLE ON)
G54 G00 X#102 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G70 P100 Q200 (DEFINE A G70 FINISH PASS OF PART GEOMETRY)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(GROOVING CYCLE)
T0303
G97 S400 M03 P11
G54 G00 X1.6 Z0.1 M08
Z-1.418 (1.30 + 0.118 GROOVING TOOL = 1.418)

(R - RETRACTION AMOUNT)
(P - X AXIS PECKING DEPTH INCREMENT, RADIUS VALUE)
(Q - Z AXIS SHIFT INCREMENT BETWEEN PECKING CYCLES)

G75 R0.05
G75 X0.750 Z-1.5 P0500 Q1000 F0.005
G00 X1.8
Z-2.918 (2.800 + 0.118 GROOVING TOOL = 2.918)
G75 X1.250 Z-3.0 P0500 Q1000 F0.005

G00 X#102 M09
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(THREADING CYCLE)
T0404
G97 S400 M03 P11 (MAIN SPINDLE)

(SINGLE DEPTH = 0.61343 / TPI)
(SINGLE DEPTH = 0.61343 / 8 = 0.0767)
(X START POINT = MAJOR DIA. + 2 X SINGLE DEPTH)
(X START POINT = 0.9905 + 2 X 0.0767 = 1.1439)
(PITCH = 1/ TPI)
(PITCH = 1/ 8 = 0.125)

G54 G00 X1.1439 Z0.25 M08 (X START POINT, Z START POINT)

(P - SETS THE NUMBER OF SPRING PASSES)
(THE FIRST NUMERICAL VALUE CONTROLS HOW QUICKLY THE TOOL RETRACTS.)
(THE SECOND NUMERICAL VALUE CONTROLS THE TOOL INFEED ANGLE SUCH AS: 80°, 60°, 55°, 30°, 29° or 0° )
(Q - SETS THE MINIMUM CUT DEPTH)
(A value of 0040 will set the minimum depth to 0.004)
(R - SETS THE DEPTH OF THE FINAL PATH)

(X - MIN MINOR DIAMETER)
(Z - THREAD LENGHT)
(P - SINGLE DEPTH, THREAD HEIGHT, RADIUS VALUE)
(# OF THREADING PASSES = [72 X PITCH] + 7)
(Q - FIRST PASS CUTTING DEPTH)
(Q = SINGLE DEPTH / OF THREADING PASSES)
(Q = 0.0767 / SQRT OF 16 = 0.0192)
(R - DIFFERENCE OF THREAD RADIUS)
(If R = 0, ordinary straight thread cutting can be made.)
(R-: Taper thread to X+)
(R+: Taper thread to X-)
(F - 1/TPI)
(F = 1/ 8 = 0.125)

G76 P030060 Q40 R0.001
G76 X0.8206 Z-1.3 R0.0 P767 Q192 F0.125

G00 X5.0 Z1.0 M09
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01

M79 (QUILL RETRACT)
M54 (PART COUNT)
(0.118 CUT OFF)
T0505
G50 S800 (SPINDLE SPEED CLAMP AT 800 RPM)
G96 S400 P11 M03 (TURN ON CSS TO 400)
G54 G00 X#102 Z-#103 M08 (4.30 + 0.118 PARTING TOOL = 4.418)
G01 X-0.03 F0.002 M10 (PARTS CATCHER RECEIVE ADVANCE)
G00 X2.6 M09
M00
X5.0 Z1.0 M11 (PARTS CATCHER RECEIVE RETURN)
G28 U0.0
M05 (SPINDLE STOP)
M30

%

For Mori Seiki CNC Lathe Machines

%
O0001
(PROGRAMMER: FRANCIS NGUYEN)
(VERSION: 2022)
(STOCK 2.5" O.D.)
(T0101 O.D. ROUGH TOOL x 1/32 TNR)
(T0202 O.D. FINISH TOOL x 1/64 TNR)
(T0303 GROOVING TOOL x 0.118")
(T0404 O.D. THREADING TOOL)
(T0505 PARTING TOOL x 0.118")
(T0606 STOP BAR)
(T0707 CENTER DRILL #2)

(BAR STOP)
T0606
G55 G00 Z0.02 X0.0
M00
Z0.1
X5.0 Z1.0
G28 U0.0
M01

T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G55 G00 X2.6 Z0.1 M08 (RAPID X2.6, Z0.1 TO START POINT, COOLANT ON)
G96 S500 (CSS ON, AT 500 SURFACE SPEED)
G01 Z0.0 F0.01
X-0.063 (FEED DOWN X-0.063 TO FACE END OF PART)
G00 X2.6 Z0.1 M09 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M05 (SPINDLE STOP)
M01 (OPTIONAL STOP COMMAND)

(CENTER DRILL USING LIVE TOOL)
T0707 (Selecting the Tool 7)
G98 (Feed per minute)
M45 (Connecting the spindle as the C-Axis)
G28 H0 (Return the C-Axis to the machine zero point)
G97 S1000 M13 (Starting the rotary tool spindle in the normal direction at 1000)
G55 G00 X0. C0. Z0.25 M08 (Rapid to Initial Start Point)

G83 Z-0.125 R-0.15 F1.0 (G83 Drilling Cycle)
G80 G00 Z0.25 M05 (Stopping the rotary tool spindle)

M46 (Canceling the C-Axis connection)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
G99 (Feed per revolution)
M01

(BAR STOP)
T0606
G54 G00 Z0.0 X0.0
M00
Z0.1
X5.0 Z1.0
G28 U0.0
M01

(ROUGH PART PROFILE USING TAILSTOCK)
M25 (TAILSTOCK SPINDLE IN)
T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G54 G00 X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G96 S500 (TURN ON CSS TO 500)

(U - SETS THE DEPTH OF THE ROUGHING PASSES)
(R - SETS THE DISTANCE THE TOOL WILL RETRACT FROM EACH ROUGHING PASS)
(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 U0.050 R0.050
G71 P100 Q200 U0.010 W0.005 F0.010
N100 G42 G00 X0.72 (PNN START #100, CUTTER COMP. ON FOR G70, RAPID X0.72)
G01 Z0.0 F0.005 (G71 PART GEOMETRY)
X0.82 (POINT 1)
X1. Z-0.09 (POINT 2)
Z-1.5 (POINT 3)
X1.45 (POINT 4)
Z-3. (POINT 5)
X1.7 (POINT 6)
Z-3.5 (POINT 7)
X1.95 (POINT 8)
Z-4.425 (POINT 9)
N200 G40 G00 X2.6 (QNN END #200, CANCEL CUTTER COMP. FOR G70, FEED X TO 2.6)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(FINISH PART PROFILE)
(SET R IN TOOL GEOM TO 0.0156)
T0202 (TOOL #2 AND OFFSET #2)
G50 S1200 (SPINDLE SPEED CLAMP AT 1200 RPM)
G54 G00 X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G96 S800 (TURN ON CSS TO 800)
G70 P100 Q200 (DEFINE A G70 FINISH PASS OF PART GEOMETRY)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(GROOVING CYCLE)
T0303
G97 S400 M03
G54 G00 X1.6 Z0.1 M08
Z-1.418 (1.30 + 0.118 GROOVING TOOL = 1.418)

(R - RETRACTION AMOUNT)
(P - X AXIS PECKING DEPTH INCREMENT, RADIUS VALUE)
(Q - Z AXIS SHIFT INCREMENT BETWEEN PECKING CYCLES)

G75 R0.05
G75 X0.750 Z-1.5 P0500 Q1000 F0.005
G00 X1.8
Z-2.918 (2.800 + 0.118 GROOVING TOOL = 2.918)
G75 X1.250 Z-3.0 P0500 Q1000 F0.005

G00 X2.6 M09
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01 (OPTIONAL STOP COMMAND)

(THREADING CYCLE)
T0404
G97 S400 M03

(SINGLE DEPTH = 0.61343 / TPI)
(SINGLE DEPTH = 0.61343 / 8 = 0.0767)
(X START POINT = MAJOR DIA. + 2 X SINGLE DEPTH)
(X START POINT = 0.9905 + 2 X 0.0767 = 1.1439)
(PITCH = 1/ TPI)
(PITCH = 1/ 8 = 0.125)

G54 G00 X1.1439 Z0.5 M08 (X START POINT, Z START POINT)

(P - SETS THE NUMBER OF SPRING PASSES)
(THE FIRST NUMERICAL VALUE CONTROLS HOW QUICKLY THE TOOL RETRACTS.)
(THE SECOND NUMERICAL VALUE CONTROLS THE TOOL INFEED ANGLE SUCH AS: 80°, 60°, 55°, 30°, 29° or 0° )
(Q - SETS THE MINIMUM CUT DEPTH)
(A value of 0040 will set the minimum depth to 0.004)
(R - SETS THE DEPTH OF THE FINAL PATH)

(X - MIN MINOR DIAMETER)
(Z - THREAD LENGHT)
(P - SINGLE DEPTH, THREAD HEIGHT, RADIUS VALUE)
(# OF THREADING PASSES = [72 X PITCH] + 7)
(Q - FIRST PASS CUTTING DEPTH)
(Q = SINGLE DEPTH / OF THREADING PASSES)
(Q = 0.0767 / SQRT OF 16 = 0.0192)
(R - DIFFERENCE OF THREAD RADIUS)
(If R = 0, ordinary straight thread cutting can be made.)
(R-: Taper thread to X+)
(R+: Taper thread to X-)
(F - 1/TPI)
(F = 1/ 8 = 0.125)

G76 P030060 Q40 R0.001
G76 X0.8206 Z-1.3 R0.0 P767 Q192 F0.125

G00 X5.0 Z1.0 M09
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M01

M26 (TAILSTOCK SPINDLE OUT)
(PARTING)
T0505
G50 S800 (SPINDLE SPEED CLAMP AT 800 RPM)
G96 S400 M03 (TURN ON CSS TO 400)
G54 G00 X2.6 Z-4.418 M08
G01 X-0.02 F0.002 M73 (PARTS CATCHER IN)
G00 X2.6 M09
M00
X5.0 Z1.0 M74 (PARTS CATCHER OUT)
G28 U0.0
M05 (SPINDLE STOP)
M30
%

For Romi CNC Lathe Machines

%
O0001
(PROGRAMMER: FRANCIS NGUYEN)
(VERSION: 2022)
(STOCK 2.5" O.D.)
(T0101 O.D. ROUGH TOOL x 1/32 TNR)
(T0202 O.D. FINISH TOOL x 1/64 TNR)
(T0303 GROOVING TOOL x 0.118")
(T0404 O.D. THREADING TOOL)
(T0505 PARTING TOOL x 0.118")
(T0606 STOP BAR)
(T0707 CENTER DRILL #2)

(BAR STOP)
G55 G00 Z5.0 T00
T0606
X0.0 Z0.02
M00
Z0.1
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
T00
M01

G55 G00 X5.0 Z5.0 T00
T0101 (TOOL #1 AND OFFSET #1)
G96 S500 (TURN ON CSS TO 500)
G92 S1000 M03 (SPINDLE SPEED CLAMP AT 1000 RPM)
X2.6 Z0.1 M08 (RAPID X2.6, Z0.1 TO START POINT, COOLANT ON)
G01 Z0.0 F0.01
X-0.063 (FEED DOWN X-0.063 TO FACE END OF PART)
G00 X2.6 Z0.1 M09 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M05 (SPINDLE STOP)
T00
M01 (OPTIONAL STOP COMMAND)

(CENTER DRILL USING LIVE TOOL)
G55 G00 Z5.0 T00
T0707 (Tool 7 Offset 7)
G97 S1000 M15 (Turn on the driven tool in clockwise direction)
M19 (LEFT SPINDLE ORIENTATION)
G28 C0
G00 C0
G94 M86 (Feed per min/Turn on left spindle low torque brake)
G54 G00 X0. Z0.25 M08 (Rapid to Initial Start Point)

G83 Z-0.125 R-0.15 F1.0 (G83 Drilling Cycle)
G80 G00 Z0.25 M09

M18 (TURN OFF THE SPINDLE DIRECTION)
M17 (TURN OFF THE DRIVEN TOOL)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
G95 (FEED PER REVOLUTION)
T00
M01

(BAR STOP)
G54 G00 Z5.0 T00
T0606
X0.0 Z0.0
M00
Z0.1
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
T00
M01

(ROUGH PART PROFILE USING TAILSTOCK)
G54 G00 Z5.0 T00
T0101 (TOOL #1 AND OFFSET #1)
G96 S500 (TURN ON CSS TO 500)
G92 S1000 M03 (SPINDLE SPEED CLAMP AT 1000 RPM)
X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)

(U - SETS THE DEPTH OF THE ROUGHING PASSES)
(R - SETS THE DISTANCE THE TOOL WILL RETRACT FROM EACH ROUGHING PASS)
(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 U0.050 R0.050
G71 P100 Q200 U0.010 W0.005 F0.010
N100 G00 X0.72 (PNN START #100, CUTTER COMP. ON FOR G70, RAPID X0.72)
G01 Z0.0 F0.005 (G71 PART GEOMETRY)
X0.82 (POINT 1)
X1. Z-0.09 (POINT 2)
Z-1.5 (POINT 3)
X1.45 (POINT 4)
Z-3. (POINT 5)
X1.7 (POINT 6)
Z-3.5 (POINT 7)
X1.95 (POINT 8)
Z-4.418 (POINT 9)
N200 G00 X2.6 M09 (QNN END #200, CANCEL CUTTER COMP. FOR G70, FEED X TO 2.6)
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
T00
M01 (OPTIONAL STOP COMMAND)

(FINISH PART PROFILE)
(SET R IN TOOL GEOM TO 0.0156)
G54 G00 Z5.0 T00
T0202 (TOOL #2 AND OFFSET #2)
G96 S800 (TURN ON CSS TO 800, MAIN SPINDLE)
G92 S1200 M03 (SPINDLE SPEED CLAMP AT 1200 RPM)
X2.6 Z0.1 M08 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G42
G70 P100 Q200 (DEFINE A G70 FINISH PASS OF PART GEOMETRY)
G40
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
T00
M01 (OPTIONAL STOP COMMAND)

(GROOVING CYCLE)
G54 G00 Z5.0 T00
T0303
G96 S400
G92 S800 M03 (SPINDLE SPEED CLAMP AT 800 RPM)
X1.6 Z0.1 M08
Z-1.418 (1.30 + 0.118 GROOVING TOOL = 1.418)

(R - RETRACTION AMOUNT)
(P - X AXIS PECKING DEPTH INCREMENT, RADIUS VALUE)
(Q - Z AXIS SHIFT INCREMENT BETWEEN PECKING CYCLES)

G75 R0.05
G75 X0.750 Z-1.5 P0500 Q1000 F0.005
G00 X1.8
Z-2.918 (2.800 + 0.118 GROOVING TOOL = 2.918)
G75 X1.250 Z-3.0 P0500 Q1000 F0.005

G00 X2.6 M09
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
T00
M01 (OPTIONAL STOP COMMAND)

(THREADING CYCLE)
G54 G00 Z5.0 T00
T0404
G97 S400 M03 (MAIN SPINDLE)
(SINGLE DEPTH = 0.61343 / TPI)
(SINGLE DEPTH = 0.61343 / 8 = 0.0767)
(X START POINT = MAJOR DIA. + 2 X SINGLE DEPTH)
(X START POINT = 0.9905 + 2 X 0.0767 = 1.1439)
(PITCH = 1/ TPI)
(PITCH = 1/ 8 = 0.125)

G54 G00 X1.1439 Z0.5 M08 (X START POINT, Z START POINT)

(P - SETS THE NUMBER OF SPRING PASSES)
(THE FIRST NUMERICAL VALUE CONTROLS HOW QUICKLY THE TOOL RETRACTS.)
(THE SECOND NUMERICAL VALUE CONTROLS THE TOOL INFEED ANGLE SUCH AS: 80°, 60°, 55°, 30°, 29° or 0° )
(Q - SETS THE MINIMUM CUT DEPTH)
(A value of 0040 will set the minimum depth to 0.004)
(R - SETS THE DEPTH OF THE FINAL PATH)

(X - MIN MINOR DIAMETER)
(Z - THREAD LENGHT)
(P - SINGLE DEPTH, THREAD HEIGHT, RADIUS VALUE)
(# OF THREADING PASSES = [72 X PITCH] + 7)
(Q - FIRST PASS CUTTING DEPTH)
(Q = SINGLE DEPTH / OF THREADING PASSES)
(Q = 0.0767 / SQRT OF 16 = 0.0192)
(R - DIFFERENCE OF THREAD RADIUS)
(If R = 0, ordinary straight thread cutting can be made.)
(R-: Taper thread to X+)
(R+: Taper thread to X-)
(F - 1/TPI)
(F = 1/ 8 = 0.125)

G76 P030060 Q40 R0.001
G76 X0.8206 Z-1.3 R0.0 P767 Q192 F0.125

G00 X2.6 M09
X5.0 Z1.0
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
T00
M01

M76 (PART COUNT)
(0.118 CUT OFF)
G54 G00 Z5.0 T00
T0505
G96 S400
G92 S800 M03 (SPINDLE SPEED CLAMP AT 800 RPM)
X2.6 Z-4.418 M08 (4.30 + 0.118 PARTING TOOL = 4.418)
G01 X-0.02 F0.002 M38 (FORWARD PART CATCHER)
G00 X2.6 M09
M00
X5.0 Z1.0 M39 (PULL BACK PART CATCHER)
G28 U0.0 (SENDING HOME FOR A TOOL CHANGE)
M05 (SPINDLE STOP)
T00
M30
%

For Okuma CNC Lathe Machines

%
O0001
(PROGRAMMER: FRANCIS NGUYEN)
(VERSION: 2023)
(STOCK 2.5" O.D.)
(T0101 O.D. ROUGH TOOL x 1/32 TNR)
(T0202 O.D. FINISH TOOL x 1/64 TNR)
(T0303 GROOVING TOOL x 0.118")
(T0404 O.D. THREADING TOOL)
(T0505 PARTING TOOL x 0.118")
(T0606 STOP BAR)
(T0707 CENTER DRILL #2)

(BAR STOP)
T0606
G00 Z0 X0
M00

Z0.1
X5 Z5
M01

T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G00 X2.6 Z0.1 (RAPID X2.6, Z0.1 TO START POINT)
G96 S500 M03 M08 (AT 500 SURFACE SPEED, MAIN SPINDLE, COOLANT ON )
G01 Z0 F0.01
X-0.063 (FEED DOWN X-0.063 TO FACE END OF PART)
G00 X2.6 Z0.1 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
X5 Z5
M01 (OPTIONAL STOP COMMAND)

(CENTER DRILL)
T0707 (Tool 7 Offset 7)
G50 S1200
G97 S1000 M03 M42 M08 (High/middle-high range)
G00 X0 Z0.25 (Rapid to Initial Start Point)

(D - Depth of cut per peck feed)
(L - Total infeed amount to the cutting start point)
(E - Dwell time)

G74 X0 Z-0.125 D0 L1.5 E0 F0.001 (G74 Drilling Cycle)
G00 Z0.25 M09
X5 Z5
M01

(ROUGH PART PROFILE USING TAILSTOCK)
T0101 (TOOL #1 AND OFFSET #1)
G50 S1000 (SPINDLE SPEED CLAMP AT 1000 RPM)
G00 X2.6 Z0.1 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G96 S500 M03 M08 (TURN ON CSS TO 500)

(D - Cutting depth in diameter)
(U - Stock removal in X)
(W - Stock removal in Z)

G85 NAP1 D0.05 U0.01 W0.005 F0.01
NAP1 G81 (Cutting direction in Z - axis)
G00 X0.72
G01 Z0
X0.82 (POINT 1)
X1. Z-0.09 (POINT 2)
Z-1.5 (POINT 3)
X1.45 (POINT 4)
Z-3. (POINT 5)
X1.7 (POINT 6)
Z-3.5 (POINT 7)
X1.95 (POINT 8)
Z-4.418 (POINT 9)
G00 X2.6
G80
X5 Z5 M09
M01 (OPTIONAL STOP COMMAND)

(FINISH PART PROFILE)
(SET R IN TOOL GEOM TO 0.0156)
T0202 (TOOL #2 AND OFFSET #2)
G50 S1200 (SPINDLE SPEED CLAMP AT 1200 RPM)
G00 X2.6 Z0.1 (RAPID TO X2.6, Z0.1 START POINT ABOVE PART)
G96 S600 M03 M08 (TURN ON CSS TO 600, MAIN SPINDLE)
G87 NAP1
X5 Z5 M09
M01 (OPTIONAL STOP COMMAND)

(GROOVING CYCLE)
T0303
G50 S1000
G96 S500 M03 M42 M08 (High/middle-high range)
G00 X1.6 Z0.1
Z-1.418 (1.30 + 0.118 GROOVING TOOL = 1.418)

(K - Shift amount to the start point)
(D - Depth of cut per peck feed)
(L - Total infeed amount to the cutting start point)
(E - Dwell time)

G73 X0.750 Z-1.5 K0.1 D0.05 L0.4 E0 F0.005
G00 X1.8
Z-2.918 (2.800 + 0.118 GROOVING TOOL = 2.918)
G73 X1.250 Z-3.0 K0.1 D0.05 L0.4 E0 F0.005

G00 X2.6 M09
X5 Z5
M01 (OPTIONAL STOP COMMAND)

(THREADING CYCLE)
T0404
G50 S1000
G96 S500 M03 M08 (MAIN SPINDLE)
G00 X1.1439 Z0.6 (X START POINT)
Z0.5 (Z START POINT)

(H - Thread height)
(D - First cutting depth)
(U - Stock removal)
(B - Infeed angle)
(F - Pitch)
(M73 - Infeed pattern)
(M33 - Thread cutting mode)

G71 X0.8206 Z-1.3 H0.0767 D0.0192 U0.004 B60 F0.125 M73 M33

G00 X5 Z5 M09
M01

(0.118 CUT OFF)
T0505
G50 S1000
G96 S500 M03 M08 (MAIN SPINDLE)
G00 X2.6 Z4.418 (4.30 + 0.118 PARTING TOOL = 4.418)
G01 X-0.02 F0.002
G00 2.6 M09
X5 Z5
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 mill the hex nut on the lathe using live tooling.

Lathe Simulator

Lathe Simulator

%
O0996
(PROGRAMMER: FRANCIS NGUYEN)
(VERSION: 2023)
(HEX MILLING WITH MACROS)
(T6 2" FACEMILL)

G54 G18 G20
G28 U0.
G00 Z5.
M35 (SPINDLE STOP C-Axis)
G40 G98 T0606 (Feed per minute)

(MILL ALL 6 SIDES OF HEX)
#100 = 0.
WHILE [#100 LE 300.] DO1 (WHILE LOOP TERMINATES WHEN #100 > 300)
G00 C#100
G00 X2.9 Z.125 M08
G97 S460 M03 P12 (Live Tool Spindle Speed/Live Tool Drive Forward)
G71 U.05 R.1 (0.1 DEPTH OF CUT)
G71 P51 Q52 U0. W0. F6.15
N51 G00 X2.53
G01 Z-2.
N52 X2.9
G00 Z.125
#100 = #100 + 60. (INCREMENT BY 60)
END1

G28 U0. M09
G00 Z5.0
M05 P12 (LIVE TOOL SPINDLE STOP)
M34 (SPINDLE REVERSE C-Axis)
T0600
M30
%

C-Axis Turning and Live Tooling

cnc_lathe_live_tools

The C-axis machine tool combines the best elements of a lathe and a milling machine to turn out complex parts quickly that would be much less productive if done as multiple ops across different machines. First, it has the ability to treat the spindle as another axis, called the C-Axis. This allows positioning the part with great position to any angle. Second, it has live tooling. Instead of an ordinary lathe tool in a turret position, there’s a miniature motorized spindle that can hold endmills, twist drills, saws, or whatever else is needed.

B-Axis Turn/Mills

B-axis

The B-axis machine tool combines the turning capabilities of a horizontal/vertical turning machine with the milling and machining capabilities of a five-axis machining center. Like traditional turn/mill machines, B-axis machine tools provide control over the Z-X (turning) and C (rotary milling) axes. The B-axis head is used as a milling spindle or a turning/boring toolholder, thus enabling the machine to complete all milling and turning with one setup. These machine tools also give users control over the Y-axis for off-center milling operations. However, it is B-axis capability that sets these machines apart. The B axis is defined as rotation about the Y axis, and this fifth axis positioning makes cuts with compound angles possible. B-axis capability gives a machine full support for five-axis index milling and 3D/five-axis simultaneous freeform milling. The B-axis machine is literally one machine doing the work of two because it supports the entire range of milling and turning operations possible, with the advantage of doing it in one setup. With these machines a finished part can be produced from raw material without ever leaving the machine.

Swiss-Type Turning Center

Swiss crew machines were developed in Switzerland for producing small parts using in watches. Today, these turning machines have full CNC controls and make all sorts of small parts for medical, electronics. defense, and other industries. Swiss machines are unique because the workpiece is supported at all times by guide bushing and stabilize it and prevent it from deflecting and vibrating. Instead of moving the tool, the entire part moves in the Z-axis direction while supported by the guide bushing. Many Swiss machines such as Citizen hold the tools in a side-by-side arrangement on multiple machine slides that can be moved separately from one another to increase productivity.

Five-Axis Programming

Most five-axis programs are rather complex and should be written using a CAD/CAM software package such as SolidWorks/MasterCam. It is necessary to determine the pivot length and gauge length of the machine, and input them in these programs.

Create the CAD drawing is the first step in computer aided manufacturing so that its geometry may later be used for creating the machining operations. After a drawing has been created, the next step in CAM is to define the toolpath, or the path that the tool will follow in order to machine the part.

Three-dimensional surface milling is an area where the CAM software really begins to demonstrate its potential. Without CAM software, all but the simplest surface toolpaths would be virtually impossible. The final step in CAM programming is to take all of the defined toolpath data and allow the CAM software to write a CNC program.

Machining simulation that works perfectly in the virtual environment may not work physically without careful planning and consideration. Some of the major factors include choosing adequate fixtures to firmly hold the stock to the jig table, checking to ensure that cutters would not collide with fixtures and jig table, and verifying that the syntax and semantics of the G-code are compatible with the CNC machine at the shop floor.

Conversational-Type Programming

Not all CNC machines must be programmed with G- and M-codes. Some machines have a special type of MCU that allows conversational programming. Conversational programming was developed to simplify the machine programming process. There are many different types of conversational MCU brands, including Southwest Industry's Proto-TRAK machines, Bridgeport's EZ-Trak, Fanuc's FAPT and CAP, and Mazak's Mazatrol controls.

The advantages are that it requires much less programming knowledge, can often be faster for simple features, and can easily be performed at the machine on the shop floor. The disadvantages revolve mostly around the lack of flexibility: the only operations that can be performed are those provided by the manufacturer. It is for these reasons that conversational controls are usually most useful for repair work, prototyping, or low-volume production machines. When high production quantities require highly efficient programs or complex machining scenarios, the versatility of a G- and M-code programming method is usually more suitable.

SOLIDWORKS vs Mastercam

Both Mastercam and SOLIDWORKS can create model geometry and generate NC code. For 3D modeling, SOLIDWORKS is the world’s most widely used design software for a reason. It has a clear advantage for anyone routinely performing the design of products or fixtures.

For CNC programming, Mastercam is the World’s #1 CNC Programming software for a reason. It is powerful and easy to use and supports a wide range of machines and technologies.

SOLIDWORKS CAM is a low-cost option for users whose primary needs are design rather than manufacturing, but Mastercam offers a breadth and depth of features that cannot be matched for machine shops and programmers.