cnc turning basic program

1. Basic Cognition: Core Composition of CNC Turning Programs

A CNC turning program is a “digital instruction set” that controls the machine tool to complete cutting operations. It follows a fixed logical structure (taking the mainstream FANUC system as an example) and consists of 4 core components:
  1. Program Header: Starts with O followed by a 4-digit number (e.g., O0001). It is used to identify the program for easy machine tool calling.
  1. Preparatory Instructions: Mainly G-codes (e.g., G50 for setting the coordinate system, G99 for setting the feed rate unit), which define the machine tool’s movement mode.
  1. Execution Instructions: Include M-codes (for spindle/coolant control), S (spindle speed), F (feed rate), and T (tool/tool offset). These directly drive the machine tool’s actions.
  1. Program End: Ends with M30 (resets and returns to the start of the program) or M02 (only ends the program) to ensure a closed program loop.
Industry data shows that a standardized program structure can reduce debugging time by 70%. For example, an automotive parts factory unified its program format, reducing the trial cutting time after programming new parts from 2.5 hours to 45 minutes (Source: 2025 CNC Machining Operation Guide).

2. Core Codes: Must-Master Instructions for Beginners

For basic CNC turning programming, there’s no need to memorize all codes. Mastering the following 10 core instruction types allows handling 80% of simple part machining tasks (taking the FANUC 0i-TC system as an example):
Instruction Type
Code
Function Description
Practical Parameter Example
Rapid Traverse
G00
Moves the tool to the target position quickly (non-cutting state)
G00 X50 Z2 (Moves to X=50mm, Z=2mm)
Linear Interpolation
G01
Uniform linear cutting (core cutting instruction)
G01 X30 Z-50 F0.2 (Feed rate: 0.2mm/rev)
Rough Turning Cycle
G71
Automatically completes rough turning (removes most material allowance)
G71 U2 R1 (Depth of cut: 2mm, retract amount: 1mm)
Finish Turning Cycle
G70
Completes finish turning based on the rough turning contour (ensures precision)
G70 P10 Q20 (Calls the finish turning contour from N10 to N20)
Coordinate System Setting
G50
Sets the workpiece coordinate system origin
G50 S2000 (Limits the maximum spindle speed to 2000r/min)
Spindle Control
M03
Spindle forward rotation (essential for cutting)
M03 S1500 (Spindle speed: 1500r/min)
Coolant Control
M08
Turns on coolant (prevents tool overheating)
M08 (Used independently, no parameters)
Tool Selection
Txxyy
Selects tool + tool offset (xx=tool number, yy=offset number)
T0101 (Tool 1: external turning tool + Offset 1)
Feed Unit
G99
Sets feed rate to “millimeters per revolution” (common for turning)
G99 F0.15 (Feed rate: 0.15mm/rev)
Program End
M30
Program ends + resets + returns to start
M30 (Last line of the program)
Critical Reminder: G00 is a non-cutting instruction—ensure no obstacles in the movement path. A novice at a machinery factory failed to check the path of G00 X30 Z0, causing the tool to collide with the workpiece and resulting in over $2,000 in tool replacement costs (Source: CNC Turning Safety Case Study 2025).

3. Programming Process: 5-Step Practical Method (From Drawing to Machine Tool)

Taking “machining a φ30×50mm shaft part” as an example, the complete programming process is as follows:

Step 1: Drawing Analysis

Confirm key dimensions: Outer diameter φ30 (tolerance IT7, i.e., φ29.952-30) and length 50mm. Required machining processes: Rough turning → Finish turning → Chamfering (C1) → Cutting-off.

Step 2: Coordinate System Setting

Select the “center of the workpiece’s right end face” as the origin (Z=0, X=0), and set it via G50 or G54:
  • Manually move the tool to the right end face, record X0 Z0 after contact, and input the values into the machine tool’s coordinate system parameters.

Step 3: Process Planning

Process
Tool
Spindle Speed (S)
Feed Rate (F)
Instruction Selection
Rough Turning (Outer Diameter)
T0101 (External Turning Tool)
1500r/min
0.2mm/rev
G71
Finish Turning (Outer Diameter)
T0101
2000r/min
0.1mm/rev
G70
Cutting-off
T0202 (Cut-off Tool)
800r/min
0.15mm/rev
G01

Step 4: Program Writing

Write the program following the structure “Header → Preparation → Execution → End” (see the next section for the complete program example).

Step 5: Simulation & Verification

  • Machine Dry Run: Turn off the spindle, execute the program to check the tool path.
  • Trial Cutting Verification: Use scrap material for trial machining, and measure dimensions to ensure compliance (e.g., adjust the tool offset if the φ30 dimension exceeds the tolerance).
After adopting this process, a small hardware factory increased the first-pass qualification rate of newly programmed parts from 65% to 92%, reducing material waste (Source: Small Batch CNC Production Efficiency Report).

4. Practical Case: Complete Program for a φ30×50mm Shaft

Below is a complete program for the FANUC system, with function explanations for each line
O0001 (Shaft Part Machining Program)
G99 G50 S2000 (Sets feed unit to mm/rev; max spindle speed: 2000r/min)
T0101 M03 S1500 (Selects Tool 1 + Offset 1; spindle forward rotation at 1500r/min)
M08 (Turns on coolant)
G00 X35 Z2 (Rapidly moves to outside the blank (X35) and safe distance (Z2))
G71 U2 R1 (Rough turning cycle: depth of cut 2mm, retract amount 1mm)
G71 P10 Q20 U0.2 W0.1 F0.2 (Finish turning allowance: X=0.2mm, Z=0.1mm; rough turning feed rate 0.2)
N10 G00 X28 Z0 (Start point of finish turning contour: near right end face (Z0), X=28)
G01 X30 Z-1 F0.1 (Chamfer C1: from X28Z0 to X30Z-1; finish turning feed rate 0.1)
Z-50 (Turns outer diameter to Z-50 (length 50mm))
N20 G00 X35 Z2 (End point of finish turning contour: returns to safe position)
G70 P10 Q20 (Finish turning cycle: follows the contour from N10 to Q20)
G00 X100 Z100 (Rapidly returns to machine tool origin)
T0202 M03 S800 (Switches to Tool 2 (cut-off tool) + Offset 2; spindle speed 800r/min)
G00 X32 Z-48 (Moves to cutting-off position: Z-48 (2mm safety allowance), X32)
G01 X-1 F0.15 (Cutting-off: cuts to center (X-1); feed rate 0.15)
G00 X100 Z100 (Returns to origin)
M05 M09 (Stops spindle; turns off coolant)
M30 (Program ends and resets)
Key Explanations:
  • In G71 P10 Q20, P10-Q20 defines the finish turning contour, and the machine tool automatically completes rough turning along this path.
  • During cutting-off, Z-48 (instead of Z-50) is used to avoid the cut-off tool colliding with the chuck (2mm safety allowance).

5. Common Problems & Pitfall Avoidance Guide

  1. Tool Collision
    • Cause: The G00 path does not avoid the workpiece/chuck, or the tool offset value is set incorrectly.
    • Solution: Use the “machine simulation” function to check the path before programming. Reduce the G00 speed by 50% (parameter G00 F1500) during the first trial cutting.
  1. Dimensional Deviation
    • Cause: The finish turning allowance U/W is too small (e.g., U0.1 makes error correction impossible), or the tool offset is not updated.
    • Solution: Measure dimensions after rough turning and adjust the U/W values in G71 (it is recommended to leave U0.2-W0.1). If deviation occurs, modify the tool offset (e.g., if φ30 is 0.05mm too small, add +0.05 to the X-direction offset).
  1. Uneven Rough Turning
    • Cause: The U value (depth of cut) in G71 exceeds the tool’s maximum load capacity (e.g., U > 3mm for carbide tools).
    • Solution: Adjust the U value based on tool material (2-3mm for carbide tools, 1-1.5mm for high-speed steel tools).

6. Q&A: High-Frequency Questions for Beginners

Q1: How to remember G-codes efficiently?

There’s no need to memorize them by rote. Prioritize mastering “high-frequency codes” (e.g., G00/G01/G71/G70), and practice with real cases (e.g., write one simple part program per day). Proficiency can be achieved in 1-2 weeks. The “categorization memory method” is recommended: positioning codes (e.g., G00), cutting codes (e.g., G01), and cycle codes (e.g., G71).

Q2: What if the machine uses a different system (e.g., SINUMERIK)?

The core instruction logic of mainstream systems is consistent—only some format differences exist. For example, G71 in FANUC corresponds to CYCLE95 in SIEMENS, and M30 corresponds to M02. It is recommended to refer to the machine tool manual before programming, or use a “universal program template” (e.g., replace G71 with CYCLE95 and adjust parameters to match the format).

Q3: Do small factories need CAD/CAM software (e.g., Mastercam)?

Manual programming is sufficient for small-batch production (e.g., <50 pieces per batch). For mass production or complex parts (e.g., shafts with arcs or grooves), entry-level CAD/CAM software (e.g., Mastercam X9) is recommended. The software can automatically generate programs, reducing programming time by 60% and minimizing manual calculation errors.

Final Thought

The core of basic CNC turning programming is not “memorizing codes” but “understanding logic + repeated practice.” Start with simple shaft parts, and gradually master parameter adjustment and problem-solving skills through the cycle of “writing → simulating → trial cutting → modifying.”
Have you encountered dimensional deviation or tool collision issues when programming? Or do you need program analysis for specific parts (e.g., grooved shafts, stepped shafts)? Feel free to share in the comments—I’ll provide targeted answers!

Recommended Reading