MOULDLKnowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Machining Processes › CNC Programming
HomeModels
Table of contents

On this page

Knowledge Base Home

📐 Standard Data

🧮 Calculators

📖 Selection Guides

🏭 Material Grades

❓ Engineer FAQ

🗂 Quick-Reference Categories

❌ Error Case Studies

📚 Technical Articles

Machining Processes · CNC Programming (Quick Reference)

CNC Machining Center Programming Basics

【Characteristics of a Machining Center】

① Multiple operations concentrated (milling / drilling / boring / tapping)

② Automatic tool change (ATC)

③ High accuracy (±0.005~0.01)

④ High efficiency

【Coordinate Systems】

1. Machine coordinate system (the machine origin)

The positive direction of each axis: the tool moves away from the workpiece

X: right+

Y: up+ (vertical) / front+ (horizontal)

Z: up+

C/A/B: the rotary axes

2. Workpiece coordinate system (G54~G59)

The programming origin (the workpiece origin)

Set by tool setting

3. Local coordinate system (G52)

A temporary coordinate shift

【Tool Setting Methods】

1. Trial cutting method

The tool touches the end face / the side face of the workpiece

Record the machine coordinates → set G54

2. Edge finder

A mechanical / optical edge finder finds the workpiece origin

3. Z axis tool setter

Sets the Z axis zero

4. Automatic tool length measurement

Built into the machine, measures the tool length automatically

5. Touch probe (RENISHAW)

Measures the workpiece position on the machine

Automatic compensation

【Tool Compensation】

1. Tool length compensation (G43/G44)

G43 H01 Z100 (Z axis positive compensation)

H01 — the tool length compensation number

The corresponding compensation is called automatically after the tool change

2. Cutter radius compensation (G41/G42/G40)

G41 — left compensation (to the left of the feed direction)

G42 — right compensation

G40 — cancel the compensation

D01 — the radius compensation number

Application scenarios:

- Milling a contour (program to the drawing dimensions, the compensation offsets automatically)

- Sharing one program between roughing and finishing (change the compensation value)

- Adjusting after the tool has worn

【Typical Program Structure (Vertical Machining Center)】

O0001 (main program)

G91 G28 Z0 (Z axis back to the reference point)

G90 G54 G40 G80 (initialisation)

T01 M06 (change to tool 1)

G00 X0 Y0 S2000 M03 (positioning + spindle rotation)

G43 H01 Z50 (tool length compensation)

G00 Z5 (approach the workpiece)

G01 Z-5 F100 (plunge)

G41 D01 X10 Y10 F200 (radius compensation + start of the contour)

Y30

X40

Y10

X0

G40 X0 Y0 (cancel the compensation)

G00 Z50 (retract)

M05 (spindle stop)

M01 (pause)

T02 M06 (change the tool)

...

M30 (end)

【Canned Cycles (Hole Machining)】

G81 — drilling (normal)

G82 — drilling (dwell at the bottom)

G83 — deep hole drilling (peck drilling)

G73 — high speed deep hole drilling (small retract)

G84 — tapping

G85 — reaming

G86 — boring (the spindle stops at the bottom)

G87 — back boring

G88 — boring (dwell at the bottom with a manual retract)

G89 — reaming (dwell at the bottom)

G80 — cancel the canned cycle

Format:

G81 X10 Y10 Z-15 R2 F50

X — Y — the hole position

Z — the hole depth

R — the clearance plane (the R plane)

F — the feed

【Subprogram Calls】

M98 P1000 L5

P1000 — the subprogram number

L5 — called 5 times

Example (a matrix of holes):

Main program:

G90 G54 G00 X0 Y0

G81 Z-10 R2 F50

M98 P1000 L5 (the subprogram is called 5 times)

G80

M30

Subprogram O1000:

G91 X20 (incremental move)

M99

【Programming Recommendations】

1. Simulate the program to verify it

2. Dry run before the first cut

3. Single block execution (for the first piece)

4. Set a safe height

5. Optimise the tool path (avoid air cuts)

6. Sensible cutting parameters

7. Adequate cooling

8. Reliable workpiece clamping

Tool Path Strategies for CNC Machining

【Roughing Strategies】

1. Parallel milling (bidirectional / Z direction)

Simple, general purpose

Suited to planes / gently varying surfaces

2. Contour milling (constant Z level)

Cuts inwards ring by ring

Stable cutting forces

Suited to cavities / steps

3. Trochoidal milling

The tool feeds in an arc oscillation

The chip thickness is constant

Suited to narrow slots / difficult to machine materials

Extends the tool life

4. Plunge milling

The tool feeds in the Z direction (like drilling)

Suited to deep cavities / high ribs

Good rigidity (the load is axial)

5. Adaptive roughing (Volume Clear)

The CAM software optimises the tool path

A constant chip load

Suited to complex surfaces

【Finishing Strategies】

1. Parallel finishing

Cuts along the X or Y direction

Suited to gently varying surfaces

Disadvantage: poor quality on steep walls

2. Z-level finishing

Layered by the Z height

Suited to steep wall surfaces

Disadvantage: poor quality on flat surfaces

3. 3D offset finishing

Equidistant offset tool paths

Suited to free form surfaces

Uniform stepover

4. Projected finishing

The tool path is projected onto the surface

Suited to complex surfaces

5. Streamline finishing

Follows the parameter lines of the surface

Suited to surfaces with a clear U/V direction

6. Corner clearing finishing

Specifically machines the corners (the residue from the previous pass)

Uses a small tool to clear the corners

7. Pencil finishing

Follows the intersection line of two surfaces

A single tool clears the corner

【Combined Strategy (Complex Parts)】

1. Roughing: trochoidal milling (removes the bulk allowance)

2. Semi-finishing: Z-level (leaves 0.3mm)

3. Finishing the flat surfaces: parallel (stepover 0.2mm)

4. Finishing the steep walls: Z-level (layer height 0.2mm)

5. Corner clearing: a small tool clears the corners

6. Pencil finishing: removes the residue

【Stepover and Residual Height】

Residual height h:

h = R - √(R² - (s/2)²) ≈ s²/(8R) (approximation for a small h)

R — the ball nose radius

s — the stepover

Example: R=3, h<0.001 required

s = √(8R·h) = √(8×3×0.001) = 0.155mm

【Optimising the Cutting Parameters】

1. Spindle speed

According to the tool material and the workpiece material

Reference: carbide on steel vc=100~200m/min

2. Feed rate

vf = fz·z·n

fz is the feed per tooth (0.02~0.2mm)

3. Depth of cut

ap (axial) + ae (radial)

A large depth of cut when roughing, a small one when finishing

4. Optimisation objectives

The shortest time (roughing)

The highest accuracy (finishing)

The longest tool life (cost)

【Tool Path Simulation and Verification】

1. Machine motion simulation (collision prevention)

2. Material removal simulation (verify)

3. Cutting force simulation (finite element)

4. Vibration simulation (chatter prediction)

5. An actual trial cut (first piece verification)

【CAM Software Functions】

1. Tool path generation (a strategy library)

2. Post processing (G-code)

3. Tool path simulation

4. Material residue analysis

5. Tool library management

6. Process templates

Mainstream CAM: Mastercam / UG NX / PowerMill / HyperMill / Cimatron

CNC Machine Accuracy and Error Compensation

【Classification of CNC Machine Accuracy】

1. Geometric accuracy

The manufacturing / assembly accuracy of the machine

Guideway straightness / perpendicularity / parallelism

Spindle runout / axial play

2. Positioning accuracy

The difference between the actual position of each axis and the commanded position

Includes: backlash / lead error / repeatability

3. Working accuracy (machining accuracy)

The accuracy reflected by the actual machined part

A combination of the geometric, positioning, thermal and force deformation

【Positioning Accuracy Indicators】

1. Backlash

A sudden jump in position when the axis reverses

Comes from the leadscrew / nut clearance and the coupling clearance

Standard: 0.02~0.05mm

Precision: 0.005~0.01mm

Ultra precision: <0.003mm

2. Lead error

The positioning error caused by the manufacturing error of the leadscrew

The error differs at different positions along the axis

Compensation is required

3. Repeatability

The scatter of repeated positioning to the same position

±3σ (statistical)

Standard: ±0.01mm

Precision: ±0.003mm

4. Positioning accuracy

The maximum position error (over the whole travel)

Standard: 0.02~0.05mm

Precision: 0.005~0.01mm

【Error Compensation Methods】

1. Backlash compensation

Measure the reversal gap B

Set the backlash value in the CNC parameters

The machine automatically moves an extra B/2 on reversal

Compensates 80~90%

2. Lead error compensation

Measure the error at each point with a laser interferometer

Enter it in the CNC compensation table

Each position is corrected automatically

Number of compensation points: 100~500 per axis

The accuracy after compensation can reach ±0.003mm

3. Thermal error compensation

The error caused by the thermal expansion of the machine (30~50% of the total)

Measure the temperature at the key points → model it → compensate

Reduces the thermal error by 70~90%

4. Straightness / perpendicularity compensation

The straightness error of the guideways

Compensated by software (not a hardware correction)

The effect after compensation is limited

5. Force deformation compensation

The spindle / table deformation caused by the cutting force

Limited force measurement + model compensation

High real time requirements

【Laser Interferometer Measurement】

1. Lead error

Measure a point every 20~50mm along the axis

Measure once in each direction

Derive the compensation table

2. Backlash

Measure the reversal gap at several positions

Take the average

3. Straightness

Use an optical straightness accessory

4. Perpendicularity

Use an optical square

【Accuracy Acceptance Standards】

GB/T 17421.1-1998 (General rules for the inspection of CNC machine tools)

VDI/DGQ 3441 (German standard)

ISO 230-2 (positioning accuracy)

【Accuracy Grades】

Economy: positioning 0.05, repeatability 0.01

Standard: positioning 0.02, repeatability 0.005

Precision: positioning 0.005, repeatability 0.003

Ultra precision: positioning 0.001, repeatability 0.0005

【Factors Influencing the Accuracy】

1. Machine rigidity (cutting force deformation)

2. Thermal deformation (spindle / leadscrew)

3. Clearances (leadscrew / guideways)

4. Vibration

5. Workpiece / tool rigidity

6. The clamping method

7. The programming strategy

8. The operator skill level

【Measures to Improve the Accuracy】

1. Regular accuracy checks and compensation

2. Machine thermal balancing (a 30min warm-up)

3. A temperature controlled workshop (20±2℃)

4. A vibration damping foundation

5. Rigid clamping

6. Optimising the tool paths

7. Multiple finishing passes

8. On-machine measurement + compensation

Five-Axis Machining and Multi-Axis Programming

【Concept of Five-Axis Machining】

Three linear axes (X/Y/Z) + two rotary axes (A/B/C)

Common configurations:

1. 3+2 positioning (a five-sided body)

The rotary axes are positioned and the three axes do the machining

Multiple faces machined in one setup

Simple, most five-axis machines support it

2. Five-axis simultaneous

All five axes are interpolated at the same time

Complex surface machining

The tool attitude changes continuously

【Definition of the Rotary Axes】

A: rotation about X

B: rotation about Y

C: rotation about Z

Common five-axis configurations:

1. Two tables (AC/BC)

The workpiece rotates

Suited to small parts

2. A table + a swivel head (B+C or A+C)

The workpiece rotates + the tool swivels

Medium sized parts

3. Two swivel heads (AB)

The tool swivels

Suited to large parts (aerospace structures)

【Advantages of Five-Axis Machining】

1. Multiple faces machined in one setup (reduces the accumulated error)

2. Complex surfaces (impellers / blades / propellers)

3. Optimised tool attitude (avoids interference)

4. Short tools (high rigidity, suited to deep cavities)

5. Improved cutting conditions (the best angle for a ball nose)

6. Fewer setups (improves the accuracy)

【RTCP (Rotational Tool Center Point)】

A key five-axis function

When the rotary axes move, the tool tip position shifts

RTCP automatically compensates the tool tip position

It guarantees a correct tool tip path

Advantages:

① The programming only has to consider the tool tip path

② The machine structure does not have to be known

③ The post processing is simplified

④ The program is portable

【Tool Axis Control】

1. Fixed direction

The tool axis direction does not change (similar to three axis)

2. Perpendicular to the surface

The tool axis is always perpendicular to the machined surface

Suited to planes / gently varying surfaces

3. Inclined relative to the surface

The ball nose is tilted forward by 10~15°

Avoids zero velocity cutting (at the center)

Improves the surface quality

4. Towards a point / away from a point

The tool axis points at a fixed point

Suited to spheres / concave cavities

5. Towards a line / away from a line

The tool axis points at a line

Suited to cylindrical surfaces

6. Interpolated direction

A custom change of the tool axis

Suited to complex parts

【Typical Five-Axis Applications】

1. Impellers (compressors / turbines)

The blades are twisted, five-axis simultaneous is needed

Slotting / finish milling the blades

2. Propellers

A variable pitch and a variable section

3. Blades (steam turbines / gas turbines)

Free form surfaces

High profile accuracy requirements

4. Moulds (deep cavities / steep walls)

A short tool has high rigidity

5. Artificial joints

Complex surfaces

Titanium alloys

6. Complex housings

Multiple faces machined in one setup

【Precautions for Five-Axis Programming】

1. Tool interference checking (the rotation may hit the workpiece)

2. The rotary axis limits (avoid over travel)

3. The rotary axis speed limits (it may be slower than the linear axes)

4. Post processing (a five-axis specific post processor is needed)

5. The machine structure (two tables / a swivel head / a hybrid)

6. Program simulation (essential!)

【Five-Axis CAM】

The mainstream CAM:

- Mastercam (the multi-axis module)

- UG NX (advanced machining)

- PowerMill (a five-axis specialist)

- HyperMill (a five-axis expert)

- CATIA (aerospace)

- Cimatron (moulds)

【Five-Axis vs Three-Axis】

Advantages of five-axis:

① Complex surfaces are formed in one setup

② Multiple faces machined in one setup

③ Short tools with high rigidity

④ Optimised cutting conditions

Disadvantages of five-axis:

① The machine is expensive (3~5 times)

② The programming is complex

③ It is difficult to commission

④ It depends on the post processor

⑤ A high skill level is required of the operator

【When to Use Five-Axis】

1. Complex surfaces (impellers / blades / moulds)

2. Multi-face machining with high accuracy requirements

3. Difficult to machine materials (rigidity)

4. Reducing the number of operations / setups

5. High value parts

CNC Machine Tool Maintenance and Fault Diagnosis

【Daily Maintenance】

1. Before starting up

- Air pressure (0.5~0.7MPa)

- The oil levels (the guideway oil / the hydraulic oil)

- The emergency stop buttons

- The appearance (no looseness / no leakage)

2. After starting up

- Warm up (the spindle / the feed idle for 10~20min)

- Check for abnormal noise

- The lubrication system is working

- The coolant flow rate

3. During machining

- Listen for abnormal sounds

- Watch the vibration

- Monitor the temperature

4. Before shutting down

- Clean the machine (chips / oil)

- Return the table to the zero position

- Switch off the power / the air supply

- Apply rust preventive oil (if it will not be used for a long time)

【Periodic Maintenance】

1. Weekly

- Check / clean the filter

- Check the tool clamping

- Guideway lubrication

2. Monthly

- Check the electrical cabinet (dust / temperature)

- Check the coolant concentration / pH

- Check the air pressure filter

- Check the spindle end face runout

3. Quarterly

- Replace the coolant

- Check / replace the guideway oil

- Check the leadscrew / guideway wear

- Check the cables (wear / ageing)

4. Annually

- Accuracy testing (a laser interferometer)

- Backlash / lead error compensation

- Replace the hydraulic oil / the lubricating oil

- Check the machine level

- Clean the electrical cabinet

- Spindle maintenance (bearing lubrication)

【Classification of Faults】

1. Mechanical faults

- The spindle (bearings / belts / couplings)

- The feed (leadscrew / guideways / couplings)

- The tool change (the magazine / the manipulator)

- Hydraulic / pneumatic

2. Electrical faults

- The power supply (voltage / phase sequence)

- The motors (the spindle / the feed)

- The encoder / the linear scale

- The limit switches

- The contactors / relays

3. System faults

- The CNC system (a crash / an alarm)

- The servo drive (overcurrent / overvoltage)

- The PLC (an I/O fault)

- The network (the communication is interrupted)

4. Programming / operation

- A program error

- A tool setting error

- Parameter settings

【Fault Diagnosis Methods】

1. Read the alarm message (shown on the CNC)

2. Listen for abnormal sounds

3. Feel the temperature / the vibration

4. Smell for a burnt odour

5. Check the program / the parameters

6. Swap the components (the substitution method)

7. Measure (the voltage / the resistance)

8. Section by section (isolation)

【Common Faults and Their Handling】

1. The spindle does not rotate

- Check the spindle enable signal

- Check the inverter / the servo drive

- Check the spindle motor

- Check for a mechanical lock-up

2. The feed does not move

- Check the emergency stop / the limits

- Check the servo enable

- Check the leadscrew / the guideways

- Check the motor / the encoder

3. The machined dimensions are out of tolerance

- Check the tool wear

- Check the compensation values

- Check the thermal deformation of the workpiece

- Check the machine accuracy

4. Chatter marks on the surface

- Check the rigidity of the tool / the clamping

- Change the cutting parameters (avoid the resonance)

- Check the rigidity of the machine

5. Tool change faults

- Check the magazine position

- Check the manipulator

- Check the sensors

【Principles of Repair】

1. Safety first (disconnect the power / a lock out tag)

2. From simple to complex (start with the simple)

3. From outside to inside (external → internal)

4. Electrical before mechanical (electrical → mechanical)

5. Record the repair (so it can be traced)

6. Find the root cause (do not only fix the symptom)

【Preventive Maintenance】

1. A regular maintenance plan

2. Spare part stock (the easily worn parts)

3. Train the operators

4. Monitor the machine condition (vibration / temperature)

5. An overhaul cycle (8~10 years)

CNC Post Processing and Program Optimisation

【Concept of Post Processing】

The tool paths generated by the CAM software (a universal format)

→ The post processor converts them into the G-code of a specific machine

Different machines need different post processors:

FANUC / Siemens / Mitsubishi / Brother / Haas

The syntax differs

【Contents of the Post Processor】

1. The program header / footer

O0001 (the program number)

G21 G40 G80 (initialisation)

M30 (end)

2. The coordinate transformations

The machine coordinate system definition

The workpiece coordinate system

The rotary axis handling

3. The tool calls

T01 M06 (tool change)

G43 H01 (tool length compensation)

4. The canned cycles

The machine specific commands

5. The circular interpolation

The IJK vs the R format

6. The feed / speed

G94/G95 (per minute / per revolution)

G96/G97 (constant surface speed)

【Program Optimisation】

1. Reducing the air moves

- Optimise the rapid path

- Raise the rapid speed (G00)

- Reduce the retracts

2. Smooth transitions

- Round the corners (the CAM does it automatically)

- NURBS interpolation (replaces the small straight segments)

- Reduces the acceleration and deceleration shock

3. Optimising the cutting parameters

- Different parameters in different areas

- Adjust the feed when the cutting width changes

- Slow down at the corners

4. Merging the tool paths

- Connect the adjacent tool paths

- Reduce the retracts

- A helical plunge instead of a straight plunge

5. Optimising the levels

- A large depth of cut when roughing

- A small depth of cut at a high speed when finishing

【Program Verification】

1. CAM simulation (visualising the tool paths)

2. Machine simulation (prevents collisions)

3. Material removal simulation (verify)

4. A dry run (the machine runs without the workpiece)

5. Single block execution (the first piece)

6. A trial cut (wax / plastic / aluminium)

【DNC (Direct Numerical Control)】

The program is transferred to the machine over a network cable / a serial port

Advantages:

① Large programs do not need a CF card

② Several machines can share them

③ Program management

④ Version control

⑤ Online transfer

【Networked Manufacturing】

1. A program server

2. The machines connected to the network

3. MES system integration

4. Tooling / fixture management

5. Program access rights

6. Traceability of the modifications

【Program Management】

1. The naming convention

Part number - operation number - version

Example: P001-OP10-V1.2

2. Version control

A record of the changes

A backup of the old versions

3. Access rights management

Programming / review / execution

4. The supporting documents

The process card

The tool list

The fixture list

The program list

DNC Program Transfer and Shop Floor Management

【Concept of DNC】

Distributed Numerical Control

The computer transfers the programs directly to the CNC machine tools

【DNC Functions】

1. Program transfer (upload / download)

2. Program storage management

3. Connecting several machines at the same time

4. Program version control

5. Machining parameter management

6. Tool data management

7. Remote monitoring

8. Data collection (SCADA)

【Transfer Methods】

1. Serial port (RS-232)

Traditional, a short distance (<15m)

Requires a server relay

2. Network ethernet

The modern mainstream

The TCP/IP protocol

A long distance

3. Wireless (WiFi/5G)

Flexible

Suited to retrofitting an old shop floor

4. USB/CF card

Manual copying

Suited to a small shop floor

【DNC Architecture】

1. The server (the program library)

2. The network switch

3. The machine terminal (embedded / PC)

4. The software (DNC management)

【DNC Software Functions】

1. Program management

- The naming convention

- Version control

- Access rights management

- A record of the modifications

2. Transfer management

- Automatic / manual transfer

- Resume from a breakpoint

- A large program is machined while it is still transferring

3. Tool management

- The tool data

- Life monitoring

- The tool library

4. Fixture management

- The fixture drawings

- The clamping photographs

5. The process documents

- The process card

- The tool list

- The inspection requirements

6. Production management

- The work order release

- Progress feedback

- The labour time statistics

【Integration of DNC with MES】

MES (Manufacturing Execution System):

- Work order management

- Process release

- Quality records

- Equipment status

- Material traceability

DNC is one of the data sources for the MES

【Shop Floor Information Architecture】

ERP (planning) → MES (execution) → DNC (equipment)

↑ ↑

orders/materials programs/data

【Benefits of Implementing DNC】

1. Fewer program errors (version control)

2. Higher efficiency (no CF card needed)

3. Quality traceability

4. Data driven decisions

5. Remote support

6. Program standardisation

【Implementation Steps】

1. Assess the current situation (the machines / the network)

2. Select the DNC software

3. Retrofit the machines onto the network

4. Establish the program library

5. Train the staff

6. Define the procedures

7. Roll it out gradually

【Common Problems】

1. Machine compatibility (old machines need retrofitting)

2. Network security (viruses / hackers)

3. Operator acceptance

4. Confusing program naming

5. Version control is not enforced strictly

6. Data backup

【Network Security】

1. Physical isolation (if necessary)

2. A firewall

3. Access rights management

4. An operation log

5. Regular backups

6. Virus protection

Related quick references: Machining FundamentalsCutting Tool MaterialsTool GeometryTurning ProcessMilling ProcessDrilling ProcessBoring ProcessGrinding ProcessMachining AllowanceProcess SequencingTypical ProcessesFixture DesignSpecial Machining Processes

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Mechanical Engineering Knowledge Base · free self-study reference for machine designers, 3D CAD models at MOULDL