CNC Programming Examples

As a CNC operator and programmer, you choose CAM systems for NC programming. Most likely, you may feel afraid or have not been trained properly in following some specific rules in programming through the control of CNC machines.

These rules concern the correct structure and writing of a CNC program; they provide information that renders the utilization and intertemporal operation making the process easy and effective. The modern controllers (MCUs) of CNC machine tools - besides the possibilities that provisions regarding the programming - also give you the ability to make the process more effective, in terms of writing of numerical control programs and their operation, facilitating the flow of working in every company. If you need more information you can read our article NC G-code programming and management: 6 key rules.

Below we recommend some basic aspects that you can follow when it comes to the CNC milling and turning programming for typical prismatic components. In general, there are many approaches to follow when establishing a process plan and consequently a CNC program for a given part. However, success is rather achieved when adopting an organized philosophy when programming.

Based on our extensive experience and industrial know-how, we give you some tips to follow, in the form of typical CNC programming examples for some discrete operations that almost any part comprises.

 

Simple CNC milling programming examples for a typical prismatic part

Despite the simplicity of the part presented, it comprises most of the basic features usually found in actual industrial applications, such as contour milling, drilling, tapping, and circular pocket milling. For this part, we present the recommended G-code for program start, face milling/profile contouring, and contour finishing.

engineering drawing of a typical prismatic part

 

CNC Milling Example 1: Program start / stopper programming

Especially when we are to produce small or bigger batches, we need a quick reference point for our stock of material so that operator needs less time to clamp the part to the vice or the clamping fixture. In this milling example, the use of a simple X-axis positioning strategy is applied to orient the part at a fixed X-axis position. The CNC program starts by setting the work offset (G54) and determining the absolute coordinate system (G90).

The following table gives the NC program with comments, from block #1 (program name) to block #9 (retract the stopper at tool change position). In this case, we use a Ø8 mm tool.

Block

CNC program

1

O10001 (CNC-Training Part-3)

Program name

2

G90 G54

Work offset G54, Absolute coordinate system

3

T10 M06 (STOP 8mm)

Stopper selection to manually clamp the left side of the part at X0 location.

4

G00 X-7.5 Y12.5

Stopper motion in X, Y and downward shit towards safe Z height with tool length compensation active. Downward shift towards Ζ-8.

5

G00 G43 H10 Z20.

6

G00 Z-8.

7

M00

Optional stop to clamp the part in X0 position that the stopper determines.

8

G00 Z20.

Upward shift of the stopper in safe Z height.

9

G00 Z100.

Retract at tool change position

 

CNC Milling Example 2: Face milling and profile contouring

In this milling example, the top face of the part is machined in a single X-Y pass using a face mill, 50mm in diameter, with five cutting inserts. In addition, a profile contouring operation is executed in four passes to machine the “25mm x 65mm” profile.

The following table gives the NC program corresponding to the face milling operation. The code starts from block #10 (Ø50 face-mill selection) to block #54 (retract at tool change position). In first, a pass is executed to prepare the “20mm x 60mm” contour with 2mm height on the top surface of the part.

3d model after face milling and profile contouring

 

10

T1 M06 (FACEMILL 50)

Ø50 face-mill selection.

11

S5000 M03

Spindle clockwise, 5000 rpm

12

G00 X-40. Y12.5

Initial X,Y positioning, while staying in safe Z height (Ζ100)

13

G00 G43 H01 Z20. M08

Rapid downward shift in safe Z height with active tool length compensation. Coolant on.

14

G00 Z0.

Positioning at Z0. (Note that Z0 is not necessarily the top surface of the part. It can be programmed to be below the part’s surface to travel a pass and define Z0 onto a clean surface)

15

G01 X95. F1000.

Face milling from Χ-40 to Χ95

16

G00 Z20.

Tool retract at Ζ20

17

G00 X-30. Y-30.

Rapid shift towards a safe position Χ-30, Υ-30 at the left side of the part.

18

G00 Z-3.

Programming of the first depth at Ζ = -3mm for contour milling.

19

G01 G41 D01 X0. Y-25. F1000.

The face mill shifts at X-30, Y-30 to allow for activating left cutter radius compensation (G41).

20

G01 Y25. ,C0.5

Machining of the left side of the part with simultaneous chamfer, using “C” parameter.

21

G01 X65. ,C0.5

Machining of the top surface of the part with simultaneous chamfer, using “C” parameter.

22

G01 Y0. ,C0.5

Machining of the right side of the part with simultaneous chamfer, using “C” parameter.

23

G01 X0. ,C0.5

Machining of the bottom side of the part with simultaneous chamfer, using “C” parameter.

24

G01 Y50.

Shift towards the left side of the part once again for cancelling tool radius compensation and reposition for the next milling pass in new Z depth. 

25

G01 G40 X-30. Y55.

Tool radius compensation cancellation with linear / diagonal shift in Χ,Υ axes.

26

G00 X-30. Y-30.

Return to safe position X-30, Υ-30.

27

G00 Z-6.

Programming of the second depth at Ζ = -6mm for contour milling.

28

G01 G41 D01 X0. Y-25. F1000.

Same sequence of commands, as for Ζ-3 depth.

29

G01 Y25. ,C0.5

30

G01 X65. ,C0.5

31

G01 Y0. ,C0.5

32

G01 X0. ,C0.5

33

G01 Y50.

34

G01 G40 X-30. Y55.

35

G00 X-30. Y-30.

36

G00 Z-9.

Programming of the third depth at Ζ = -9mm for contour milling.

37

G01 G41 D01 X0. Y-25. F1000.

Same sequence of commands, as for Ζ-3 and Z-6 depths.

38

G01 Y25. ,C0.5

39

G01 X65. ,C0.5

40

G01 Y0. ,C0.5

41

G01 X0. ,C0.5

42

G01 Y50.

43

G01 G40 X-30. Y55.

44

G00 X-30. Y-30.

45

G00 Z-12.5

Programming of the fourth and last depth at Ζ = -12.5mm for contour milling. (Instead of Z-12, Z-12.5 is given, to deburr and clean the bottom side of the part).

46

G01 G41 D01 X0. Y-25. F1000.

Same sequence of commands, as for Ζ-3, Z-6 and Z-9 depths.

47

G01 Y25. ,C0.5

48

G01 X65. ,C0.5

49

G01 Y0. ,C0.5

50

G01 X0. ,C0.5

51

G01 Y50.

52

G01 G40 X-30. Y55.

53

G00 Z20. M09

Tool retract at Ζ20. Coolant off.

54

G00 Z100.

Retract to tool change position.

 

CNC Milling Example 3: Contour finishing

In this milling example, the part’s “20mm x 60mm” peripheral contour is finished in a single X-Y pass using a 2-flute, Ø6 end-mill. This tool finishes the 3mm radius, as well. The code for this operation continues from block #55 (Ø6 end-mill selection) to block #69 (retract at tool change position).

3d model after contour finishing

 

55

T2 M06 (ENDMILL 6)

Ø6 end-mill selection.

56

S5000 M03

Spindle clockwise, 5000 rpm

57

G00 X-6. Y-6.

Initial X,Y positioning

58

G00 G43 Z20. H02 M08

Rapid downward shift in safe Z height with active tool length compensation. Coolant on.

59

G00 Z-2.

Positioning at depth Ζ-2

60

G01 G41 D02 X2.5 Y-3. F700.

Linear shift to facilitate the activation of G41 for finishing the fillet that the face mill cannot machine owing to its large diameter.

61

G01 Y22.5 ,R3.

Sequence of commands for contour finishing.

62

G01 X59.5

63

G03 X62.5 Y19.5 R3.

64

G01 Y2.5 ,C3.

65

G01 X2.5 ,C0.5

66

G01 Y28.

67

G01 G40 X-6. Y31.

68

G00 Z20. M09

Tool retract at Ζ20. Coolant off.

69

G00 Z100.

Retract to tool change position.

 

Simple CNC turning programming examples for a typical part

Turning parts are very popular and 2-axis CNC turning programming can be easy for CNC operators and programmers, as the basic operations for completing a part, such as roughing, finishing, drilling, tapping, and threading are less than in CNC milling programming.

For this simple part, we present the recommended G-code for Program start/bar feeder adjustment, roughing operation to remove material from the outer contour, and center drilling in the part’s face.

engineering drawing of a typical turning part

 

CNC turning example 1: Program start/bar feeder adjustment

In this example, the CNC program starts by setting the bar feeder to a proper position to orient the stock length needed for machining the part.  In addition, the first tool which is a roughing tool is selected for the first machining operation, so we are ready for the second operation without changing tool and gain some time.

Tip: Consider your approaching and retracting positioning to be both safe and quick.

The NC blocks are shown and commented from block #1 (program name) to block #7 (program pause to adjust the bar feeder).

Block number

NC Program

1

O12346 (TRAINING 102 Lathe)

Program name

2

G54

Work offset definition

3

G50 S1800

Constant spindle speed limit to 1800 rpm.

4

T101 

Tool change Τ1 (rough machining insert-external tool holder) with tool offsets registered to 01.

5

G96 S220 M3

Clockwise spindle rotation with constant cutting speed (Vc) 220m/min.

6

G00 X30. Z.5

Rapid shift above the part, 0.5mm in front to the part’s face.

7

M00

Program pause to adjust the bar feeder to proper stock length for machining.

 

CNC turning example 2: Roughing operation to remove material from the outer contour

In this example, the part’s contour is programmed with the commands starting with Ν1 (appeared in block #15) up to Ν3 (block #24). The canned cycle responsible for rough machining in turning, is activated by G71 accompanied by its corresponding parameters. The NC blocks are shown and commented from block #8 (Tool change T1) to block #25 (Tool retract).

8

T101 

Tool change Τ1 (rough machining insert-external tool holder) with tool offsets registered to 01.

9

G00 X62. Z2. Μ08

Rapid shift above the part’s diameter (2mm), and 2mm in front to the face – coolant on.

10

G96 S220 M3

Clockwise spindle rotation with constant cutting speed (Vc) 220m/min.

11

G00 Z0

Rapid shift towards the part’s face

12

G01 X-2. F.2

Vertical cut until Χ-2 owing to the 0.8mm rounded tool tip with feed rate equal to 0.2mm/rev

13

G00 X60. Z2.

Rapid shift to the exact part diameter (X60) and 2mm in front of the part’s face. Preparation for executing the G71 roughing cycle.

14

G71 P1 Q3 D2. U.4 W.05 F.2

G71 roughing canned cycle. The part’s contour is programmed with the commands starting with Ν1 up to Ν3. Radial depth of cut 2mm, material left for finishing equal to 0.4mm in diameter (X-axis) and 0.05mm in Z-axis. Feed rate equal to 0.2mm/rev.

15

N1 G00 X31. Z2.

N1 to N3 nested group of commands for contour roughing using the G71 canned cycle.

16

G01 Z0

17

G01 Χ35. Ζ-2.

18

G01 Z-23.

19

G01 X33.5 Z-23.75

20

G01 Z-29.

21

G01 X39.1

22

G01 Z-35.

23

G01 X60. Z-55.

24

N3 G01 Z-90.

25

G00 X100. Z180. M9

Tool retract at Χ100 and return to safe Z distance away from the part’s face.

 

CNC turning example 3: Center drilling in the part’s face

In this example, a center drilling is performed in the part’s face for preparing the drilling operation that follows next. Simple drilling operation is activated by G81 canned cycle accompanied by its corresponding parameters. The NC blocks are shown and commented from block #26 (Tool change T7) to block #33 (Tool retract).

26

T707

Tool change Τ7 (center drill) with tool offsets registered to 07.

27

G97 S800 M3

Clockwise spindle rotation with constant spindle speed (n) 800rpm

28

G00 Z20.

Preparation for center drilling (centering) – tool positioning 20mm away from the part’s face.

29

G00 X0 Z2. M8

Rapid shift 2mm away from the face at the center of the part (X0)– coolant on.

30

G81 Z-2. R2. F.08

Simple drilling operation with G81 canned cycle, final depth equal to 2mm, tool retract (R) 2mm.

31

G80

G81 cycle cancellation.

32

G00 Z2. M9

Tool retract at 2mm away from the face – coolant off.

33

G00 Z130.

Tool retract at a safe Z distance to facilitate tool change.