CNC Programming Tutorials Examples G M Codes G M Programming Tutorial Example
CNC Programming Tutorials Examples G M Codes G M Programming Tutorial Example
com
C NC Progr amming Tutor ials E xamples G & M C odes
***
TA B L E OF C ONT E NT S:
1. A dvanced L evel
2. B eginner L evel
3. B olt Hole Circle
4. B oring CNC L athe
5. Chamfer R adius
6. CNC L athe Machine
7. CNC Milling Machine
8. Drilling
9. G02 G03 I J K
10. G02 G03 R
11. G40 G41 G42
12. G81 Drilling Cycle
13. G91 Incremental Programming
14. Grooving
15. Intermediate L evel
16. Pattern Drilling
17. Peck Drilling L athe
18. Peck Drilling-Mill
19. Peck Milling
20. R amping Milling
21. Slot Milling
22. Step Turning CNC L athe
23. Subprogram
24. Taper T hreading
25. Tapping
26. T hreading
http://www.education-techniques.com
C NC Progr am E xamples *
http://www.education-techniques.com
Advanced Level
Fanuc G72.1 G72.2 Figure Copy Program Example
(Bolt Hole Circle)
This CNC program example shows how both G72.1 and G72.2 figure copy
functions can call one-another in one part program, read Programming
Notes below carefully.
Programming
Fanuc G72.1 Rotational Copy
Using G72.1 Rotational Copy G-code a figure specified by a subprogram
can be repeatedly produced with Rotational movement.
Read G72.1 definition with program example Fanuc G72.1 Rotational
Copy (Figure Copy Function CNC Mill)
Fanuc G72.2 Linear Copy
Using G72.2 Linear Copy G-code a figure specified by a subprogram can
be repeatedly produced with Linear movement.
Read G72.2 definition with program example Fanuc G72.2 Linear Copy
(Figure Copy Function CNC Mill)
Fanuc G81 Drilling Cycle
G81 drilling cycle is used for simple drilling/spot drilling operations.
Read G81 drilling cycle definition with program examples Fanuc G81
Drilling Cycle
Programming Notes
Specifying two or more commands to copy a figure
G72.1 cannot be specified more than once in a subprogram for making a
rotational copy (If this is attempted, alarm PS0900 will occur).
G72.2 cannot be specified more than once in a subprogram for making a
linear copy (If this is attempted, alarm PS0901 will occur).
In a subprogram that specifies rotational copy, however, linear copy can be
specified. Similarly, in a subprogram that specifies linear copy, rotational
copy can be specified.
Fanuc G71.2 G72.2 Program Example
Main program
O4000 ;
N10 G90 G00 G17 X240. Y230. Z100. ; (P0)
N20 G72.1 P4100 X120. Y120. L8 R45. ;
N30 G80 G00 X240. Y230. ; (P0)
N40 M30 ;
Sub program_ Rotation copy_ (G72.1)
O4100 N100 G72.2 P4200 I0 J20. L3 ;
N200 M99 ;
Sub program_ Linear copy (G72.2_)
O4200 N110 G90 G81 X120. Y180. R60. Z10. F200. ; (P1)
N210 M99 ;
****************
Main program
O3000 ;
N10 G90 G00 X-30. Y0 ;
N20 X0 ;
N30 G01 G17 G41 X30. D01 F100 ; (P0)
N40 Y20. ; (P1)
N50 X40. ; (P2)
N60 G72.2 P3100 L3 I90.0 J0 ;
N70 G90 X310. Y0 ; (P8)
N80 X0 ;
N90 G40 G00 X-30.0 ;
N100 M30 ;
Sub program
O3100 G91 G01 X20. ; (P3)
N100 Y30. ; (P4)
N200 G02 X40. I20. ; (P5)
N300 G01 Y-30. ; (P6)
N400 X30. ; (P7)
N500 M99 ;
****************
T1 M6
G0 G90 G40 G21 G17 G94 G80
G54 X20 Y0 S1500 M3
G43 Z100 H1
Z5
G81 R3 Z-20 F? M8
X30
X45
G68 X0 Y0 R120
X20 Y0
X30
X45
G68 X0 Y0 R240
X20 Y0
X30
X45
G69 G80
G0 G90 Z100 M30
Beginner Level
CNC Program
N40 G90 G00 X0 Y0
N50 G01 X-10 Y-20 R8 (P1)
N60 G01 X-50 R10 (P2)
N70 Y10 (P3)
N80 X-19.97 Y25.01 (P4)
N90 G03 X7.97 Y38.99 R18 (P5)
N100 G01 X30 Y50 (P6)
N110 G91 X10.1 Y-10.1(P7)
N120 G90 G02 X59.9 Y20.1 R14 (P8)
N130 G01 X70 Y10 (P9)
N140 Y-20 R10(P10)
N150 X50 (P11)
N160 G03 X30 R10 (P12)
N170 G01 X10 R8 (P13)
N180 X0 Y0
G M S T Codes Explanation
Code Description
G00 Rapid traverse
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G90 Absolute command
G91 Increment command
*************
G02 G03 Example CNC Mill
CNC Part Program
G0 X30 Y-30 (P1)
G1 Y22.67 (P2)
G3 X24.07 Y26.18 R4 (P3)
G2 X-18.27 Y23.46 R50 (P4)
G3 X-23.46 Y18.27 R4(P5)
G2 X-23.46 Y-18.27 R50 (P6)
G3 X-18.27 Y-23.46 R4 (P7)
G2 X24.07 Y-26.18 R50 (P8)
G3 X30 Y-24.67 R4 (P9)
G1 X33
G M S T Codes Explanation
Code Description
G0 Rapid traverse
G1 Linear interpolation
G2 Circular interpolation CW
G3 Circular interpolation CCW
M30 End of program (Reset)
*************
CNC Part Program
N10 M6 T1 G43 H1 M3
N15 S500 F120
N20 G0 X0 Y0 (P1)
N25 G1 Y20(P2)
N30 G3 X-15 Y35 I-15 J0 (P3)
N35 G2 X-45 Y35 I-15 J0 (P4)
N40 G3 X-60 Y20 I0 J-15 (P5)
N45 G1 Y0 (P6)
N50 G1 X0 (P1)
N55 M30
G M S T Codes Explanation
Code Description
G0 Rapid traverse
G1 Linear interpolation
G2 Circular interpolation CW
G3 Circular interpolation CCW
G43 Tool length compensation + direction
M3 Spindle start forward CW
M6 Tool change
M30 End of program (Reset)
T Tool
S Speed
F Feed
*************
CNC Mill Subprogram Example
Joining Multiple Arcs G02 G03 G41
CNC milling program to describe how two or more radii can be joint together in
a cnc mill program.
CNC Mill Subprogram Example
CNC Part Program
N10 T1 H1 M6 G43 M3
N20 F150 S250
N30 G0 X-21 Y50 Z0.5
N40 G0 Z0
N50 M98 P040050
N60 G49
N70 G0 Z50
N80 M30
Subprogram
O0050
N10 F160 S400
N20 G0 Z-2.5 G91
N30 G1 G90 X5 Y50 G41 (P1)
N40 G2 X22 Y85.23 I45 J0 (P2)
N50 G3 X78 Y85.23 R45 (P3)
N60 G2 X78 Y14.77 R45 (P4)
N70 G3 X22 Y14.77 R45 (P5)
N80 G2 X5 Y50 R45 (P1)
N90 G0 G40 X-21
N100 M99
G M S T Codes Explanation
Code Description
G00 Rapid traverse
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G40 Cutter compensation cancel
G41 Tool nose radius compensation left
G43 Tool length compensation + direction
G49 Tool length compensation cancel
G90 Absolute command
G91 Increment command
M03 Spindle start forward CW
M06 Tool change
M30 End of program (Reset)
M98 Subprogram call
M99 End of subprogram
T Tool
S Speed
F Feed
*************
*************
http://www.education-techniques.com
Main Program
Milling cutter diameter: 10mm
N05 G55
N10 M6 T2 H3 G43 M3
N15 S1000 F60
N20 G0 X9 Y9 Z1
N25 G1 Z0
N30 M98 P030035
N35 G0 Z1 G90
N40 X42 Y38
N45 G1 Z-2 F30
N50 X47 F300
N55 G3 X47 Y38 I-5 J0
N60 G0 Z100
N65 G49
N70 M30
Subprogram
O0035
N05 G1 Z-2 G91 F30
N10 X10 F100
N15 Y36
N20 X-10
N25 Y-36
N30 M99
Explanation
Although this cnc mill program is self explanatory
M98 P030035
*************
Wire EDM cutting can provide high dimensional accuracy for close fitting parts.
The process can make sharp inside corners.
Wire EDM Programming Example
Wire EDM Programming Example
G92 X0. Y0.
G01 Y1.25 (P1)
G02 X.5 I.25 J0.(P2)
G01 Y.75(P3)
G03 X1. I.25 J0.(P4)
G01 Y1.25 (P5)
G02 X1.5 I.25 J0. (P6)
G01 Y0. (P7)
X0. (P8)
M02
G92 command is used to assign program zero. You will include the distances and
directions from the program zero point to the wire start point in your G92
command.
*************
CNC Lathe Example Turning Boring
O0000
N10 (ø30 DRILL)
G50 T0200
G97 S250 M03
G00 X0 Z5.0 T0202 M08
G01 Z-5.0 F0.07
W1.0
Z-40.0 F0.25
G00 Z5.0
Z-39.0
G01 Z-60.0
G00 Z10.0
X200.0 Z200.0 T0200
M01
N20 (Outside diameter stock removal)
G50 S1500 T0100
G96 S180 M03
G00 X94.0 Z5.0 T0101 M08
G01 Z-14.8 F0.27
G00 U2.0 Z0.5
G01 X28.0 F0.23
G00 X87.0 W1.0
G01 Z-14.8 F0.27
G00 U2.0 Z1.0
X80.5
G01 Z-14.1
G02 X81.9 Z-14.8 R0.7
G00 X100.5 W1.0
G01 Z-29.8
G00 U2.0 Z-1.0
G01 X60.5 F0.23
G00 X82.0 W1.0
Z-2.4
G01 X60.5
X72.9
G03 X80.5 Z-6.2 R3.8
G00 U2.0 Z5.0
X200.0 Z200.0 T0100
M01
N30 (Inside diameter stock removal)
G50 S1500 T0400
G96 S180 M03
G00 X34.5 Z3.0 T0404 M08
G01 Z-41.8 F0.27
G00 U-0.5 Z1.0
X39.5
G01 Z-15.0
X34.5 Z-24.3
G00 Z10.0
X200.0 Z200.0 T0400
M01
N40 (Out diameter finishing)
G50 S1800 T0500
G96 S200 M03
G00 X63.0 Z5.0 T0505 M08
Z0
G01 X38.0 F0.2
G00 X60.0 Z3.0
G42 Z1.0
G01 Z-2.5 F0.2
X74.0
G03 X80.0 Z-5.5 R3.0
G01 Z-13.5
G02 X83.0 Z-15.0 R1.5
G01 X100.0
Z-30.0
X102.0
G40 G00 U2.0 W1.0
G00 Z10.0
X200.0 Z200.0 T0500
M01
N50 (Inside diameter finishing)
G50 S1800 T0600
G96 S200 M03
G00 X40.0 Z5.0 T0606 M08
G41 Z1.0
G01 Z-15.0 F0.2
X35.0 Z-24.33
Z-42.0
X29.0
G40 G00 Z10.0
X200.0 Z200.0 T0600 M09
M30
***********
CNC Mill Programming Exercise
using G91 Incremental Programming
This CNC mill programming exercise will give you more idea to understand
drawing and how to find exact coordinate of each drawing point.
Completely based on G91 Incremental Dimensioning System, so cnc
programmers/machinists can learn and understand how G91 Incremental
Programming works.
This program is written for 4-axis CNC mill, where C-axis is used for rotary
table.
3-axis CNC mill can also run this program, so for this just remove program
block no. N15.
CNC Mill Programming Exercise
G91 Incremental Programming CNC Mill Exercise
N5 G00 G54 G64 G90 G17 X-20 Y-20 Z50 ;Point 1
N10 S450 M03 F250 D01 (12.5 MM DIA)
N15 C0
N20 Z5
N25 G01 Z0
N30 Z-5
N35 G42 G91 X20 Y20 ;Point 2
N40 X10 Y10 ;Point 3
N45 X70 Y-10 ;Point 4
N50 X20 Y20 ;Point 5
N55 X-40 Y60 ;Point 6
N60 X-20 ;Point 7
N65 X-10 Y-25;Point 8
N70 X-30 Y-15;Point 9
N80 X0 Y-40 ;Point 10
N85 G40 G90 X-20 Y-20;Point 11
N90 G00 Z50
N95 Y100
N100 M30
Finished Part
After completing the machining process, your job will look like this in 3D view,
Complete Machined Part in 3D
Explanation of CNC G-Code
G00 : Rapid traverse.
G54 : Zero Offset no. 1.
G64 : Continuous-path mode.
G90 : Absolute dimensioning system.
G91 : Incremental dimensioning system.
G17 : X-Y plan selection.
G42 : Cutter radius compensation activation (right hand side movement)
G40 : Cutter radius compensation de-active
S : Spindle speed
F : Axises motion feed
M : Cutter motion (3=clockwise, 4=anti-clockwise)
D : Tool no
**********
Vertical Machining Center Programming Example
N10 T1
N20 S1000 M3
N30 G00 G40 G90 G17 X-30 Y60
N40 G43 Z50 H1
N50 Z-5
N60 G01 G41 X10 Y60 D1 F200
N70 Y80
N80 G02 X20 Y90 R10
N90 G01 X50
N100 X90 Y50
N110 Y20
N120 G02 X80 Y10 R10
N130 G01 X50
N140 X10 Y50
N150 Y65
N160 G40 X-30 Y60
N170 G00 Z200 M02
**********
G41 G40 Cutter Radius Compensation Example
N5 G00 G54 G64 G90 G17 X20 Y-20 Z50
N10 S450 M03 F250 D01 (12.5 MM DIA)
N15 C0
N20 Z5
N25 G01 Z0
N30 Z-5
N35 G41 X0 Y0
N40 X-48
N45 X-68 Y72
N50 X-28
N55 Y44
N60 X12 Y32
N65 X0 Y0
N70 G40 X20 Y-20
N75 G00 Z50
N80 Y100
N85 M30
Finished Part
After machining process completion, component will look like
Sinumerik Mill Programming Example
N5 G00 G54 G64 G90 G17 X-20 Y-20 Z50
N10 S450 M03 F250 D01 (12.5 MM DIA)
N15 C0
N20 Z5
N25 G01 Z0
N30 Z-5
N35 G42 X0 Y0
N40 X30
N45 Y30
N50 X0
N55 Y0
N60 G40 X-20 Y-20
N65 G00 Z50
N70 Y100
N75 M30
Finished Part
After the machining is complete, this finished part will look like this
Finished Part
Explanation of G-Code
G00 – Rapid traverse.
G54 – Zero Offset no 1.
G64 – Continuous-path mode.
G90 – Absolute dimensioning system.
G17 – X-Y plan selection.
G42 – Cutter radius compensation activation
G40 – Cutter radius compensation cancel
M03 – Cutter rotation clockwise
S – Spindle speed
F – Axis motion feed
D – Tool no
*********
G Code Example Mill
O1000
T1 M6
G0 G90 G40 G21 G17 G94 G80
G54 X-75 Y-25 S500 M3 (Start Point)
G43 Z100 H1
Z5
G1 Z-20 F100
X-50 M8 (Position 1)
Y0(Position 2)
X0 Y50(Position 3)
X50 Y0(Position 4)
X0 Y-50 (Position 5)
X-50 Y0 (Position 6)
Y25 (Position 7)
X-75 (Position 8)
G0 Z100
M30
*****************
Simple G Code Example Mill – G
code Programming for Beginners
G code Programming for Beginners
Learning G code programming is not that difficult.
Read and learn about a G code.
Understand how that G code work.
Then make a simple G code example drawing.
Make program for that example.
Run the program on your cnc machine (Safety first, keep a professional
around).
Or you can simply run a cnc program Simulation (but this always doesn’t
substitute the actual cnc machining process.)
The last thing is the most crucial which is Just practice practice and
practice.
This is a very simple G code example for beginner level cnc programmers
/ cnc machinists.
This G code program example don’t use Tool radius compensation
G40/G41/G42 G code.
Simple G Code Example Mill
Simple G Code Example
O1000
T1 M6
(Linear / Feed - Absolute)
G0 G90 G40 G21 G17 G94 G80
G54 X-75 Y-75 S500 M3 (Position 6)
G43 Z100 H1
Z5
G1 Z-20 F100
X-40 (Position 1)
Y40 M8 (Position 2)
X40(Position 3)
Y-40 (Position 4)
X-75 (Position 5)
Y-75 (Position 6)
G0 Z100
M30
Bolt Hole Circle
Main program
O4000 ;
N10 G90 G00 G17 X240. Y230. Z100. ; (P0)
N20 G72.1 P4100 X120. Y120. L8 R45. ;
N30 G80 G00 X240. Y230. ; (P0)
N40 M30 ;
Sub program_ Rotation copy_ (G72.1)
O4100 N100 G72.2 P4200 I0 J20. L3 ;
N200 M99 ;
Sub progr am_ L inear copy (G 72.2_)
O4200 N110 G90 G81 X 120. Y 180. R 60. Z10. F200. ; (P1)
N210 M99 ;
http://www.education-techniques.com
Boring CNC Lathe
CNC Lathe Basic Programming
Example ID/OD Turning/Boring
Operations (No Canned Cycle Used)
A full CNC programming example with ID/OD (Turning/Boring operations) for
cnc machinists who work on a cnc lathe machine. A must to learn/practice for
those who are learning cnc programming.
The added benefit of this programming example is that no cnc lathe canned
cycle is used in this programming example.
CNC Lathe Basic Programming Example (Turning
Boring Operations)
CNC Lathe Example Turning Boring
O0000
N10 (ø30 DRILL)
G50 T0200
G97 S250 M03
G00 X0 Z5.0 T0202 M08
G01 Z-5.0 F0.07
W1.0
Z-40.0 F0.25
G00 Z5.0
Z-39.0
G01 Z-60.0
G00 Z10.0
X200.0 Z200.0 T0200
M01
N20 (Outside diameter stock removal)
G50 S1500 T0100
G96 S180 M03
G00 X94.0 Z5.0 T0101 M08
G01 Z-14.8 F0.27
G00 U2.0 Z0.5
G01 X28.0 F0.23
G00 X87.0 W1.0
G01 Z-14.8 F0.27
G00 U2.0 Z1.0
X80.5
G01 Z-14.1
G02 X81.9 Z-14.8 R0.7
G00 X100.5 W1.0
G01 Z-29.8
G00 U2.0 Z-1.0
G01 X60.5 F0.23
G00 X82.0 W1.0
Z-2.4
G01 X60.5
X72.9
G03 X80.5 Z-6.2 R3.8
G00 U2.0 Z5.0
X200.0 Z200.0 T0100
M01
N30 (Inside diameter stock removal)
G50 S1500 T0400
G96 S180 M03
G00 X34.5 Z3.0 T0404 M08
G01 Z-41.8 F0.27
G00 U-0.5 Z1.0
X39.5
G01 Z-15.0
X34.5 Z-24.3
G00 Z10.0
X200.0 Z200.0 T0400
M01
N40 (Out diameter finishing)
G50 S1800 T0500
G96 S200 M03
G00 X63.0 Z5.0 T0505 M08
Z0
G01 X38.0 F0.2
G00 X60.0 Z3.0
G42 Z1.0
G01 Z-2.5 F0.2
X74.0
G03 X80.0 Z-5.5 R3.0
G01 Z-13.5
G02 X83.0 Z-15.0 R1.5
G01 X100.0
Z-30.0
X102.0
G40 G00 U2.0 W1.0
G00 Z10.0
X200.0 Z200.0 T0500
M01
N50 (Inside diameter finishing)
G50 S1800 T0600
G96 S200 M03
G00 X40.0 Z5.0 T0606 M08
G41 Z1.0
G01 Z-15.0 F0.2
X35.0 Z-24.33
Z-42.0
X29.0
G40 G00 Z10.0
X200.0 Z200.0 T0600 M09
M30
*****************
Fanuc Lathe Programming Example
Using G70, G71, G74 for ID
Machining
Fanuc lathe programming example which uses Fanuc canned cycle
• G71 Turning Cycle
• G70 Finish Cycle
• G74 Peck Drilling Cycle
This Fanuc lathe programming example illustrates who to use G71 Turning
cycle, G70 Finish cycle, G74 Peck drilling cycle for ID machining (Inside
machining, boring operations)
Fanuc Lathe Programming Example
Fanuc Lathe Programming Example Using G71, G70 for ID Machining
N10 G40 G00
N20 G99
N30 M5
N40 M9
N60 T0101
N70 G50 S3500
N80 G96 S0240 M4
N90 G00 X102. Z0.
N100 G01 X-2. F0.15 M7
N110 G00 X150. Z150.
N120 M9
N130 T0707
N140 G97 S0950 M3
N150 G00 Z3.
N160 G00 X0.
N170 G74 R1.0
N171 G74 X0.0 Z-59.0 Q12000 R0.0 F0.2
N350 G00 X150. Z150.
N360 T0505
N370 G50 S3500
N380 G96 S0200 M4
N390 G00 X23. Z2.
N400 G71 U3. R1
N410 G71 P420 Q530 U-0.5 W0.2 F0.3
N420 G41 G00 X72.
N440 G01 Z-21.
N450 G03 X66. Z-24. I-3. K0.
N460 G01 X54.
N470 G02 X48. Z-27. I0. K-3.
N480 G01 Z-41.
N490 G03 X42. Z-44. I-3. K0.
N500 G01 X30.
N510 G02 X24. Z-47. I0. K-3.
N520 G01 Z-59.
N530 G01 X23.
N540 G40
N550 G00 X150. Z150. F0.3
N560 T1111
N570 G50 S4500
N580 G96 S0380 M4
N590 G41 G00 X72. Z2.
N600 G70 P420 Q530
N610 G40
N620 G00 X23. Z2.
N630 G00 X200. Z150.
N640 M5
N650 M30
Tools & Oprations
T0101 Turning Tool – Facing Operation
T0707 Tip Drill Tool – Drilling
T0505 Boring Bar – Internal machining (ID machining)
T1111 Boring Bar – Internal finish machining
***************
CNC Lathe Programming Exercise Fanuc G71, G74 Cycles
N10 G40 G00
N20 G99
N60 T0101
N70 G50 S3500
N80 G96 S0240 M4
N90 G00 X72. Z0.1
N100 G01 X-1.6 F0.12 M7
N110 G00 X150. Z150.
N120 M5
N130 M9
N140 T0303
N150 G97 S2500 M3
N160 G00 X0. Z3.
N170 G01 Z-6. F0.1 M7
N180 G00 Z2.
N190 G00 X150. Z150.
N210 T0707 M7
N220 G97 S0884 M3
N230 G00 Z3.
N240 G00 X0.
N250 G74 R1.0
N260 G74 X0.0 Z-68.326 Q18000 F0.22
N380 G00 X200.
N400 G00 Z100.
N500 T0404 M7
N510 G50 S3500
N520 G96 S0240 M4
N530 G00 Z1.
N540 G00 X70.
N550 G71 U4. R1
N560 G71 P570 Q650 U0.6 W0.2 F0.35
N570 G42 G00 X24.
N580 G01 Z0.
N590 G01 X28. Z-2.
N600 G01 Z-72.
N610 G02 X32. Z-74. I2. K0.
N620 G01 X62.
N630 G01 X68. Z-77.
N640 G01 Z-90.
N650 G40
N660 G00 X150.
N680 G00 Z70.
N690 T0202 M7
N700 G50 S4500
N710 G96 S0380 M4
N720 G00 X16. Z3.
N730 G42 G01 Z0. F0.1
N740 G01 X24.
N750 G01 X28. Z-2.
N760 G01 Z-72.
N770 G02 X32. Z-74. I2. K0.
N780 G01 X62.
N790 G01 X68. Z-77.
N800 G01 Z-90.
N810 G40
N820 G00 X150. Z150.
N830 M5
N840 M9
N850 M30
Used Tools & Operations
• T0101 Turning Tool – Rough Facing
• T0303 Center Drill – Center Drilling
• T0707 Twist Drill – Drilling
• T0404 Turning Tool – Rough Turning
• T0202 Turning Tool – Finish Contour Cutting
Chamfer Radius
CNC Program
N40 G90 G00 X0 Y0
N50 G01 X-10 Y-20 R8 (P1)
N60 G01 X-50 R10 (P2)
N70 Y10 (P3)
N80 X-19.97 Y25.01 (P4)
N90 G03 X7.97 Y38.99 R18 (P5)
N100 G01 X30 Y50 (P6)
N110 G91 X10.1 Y-10.1(P7)
N120 G90 G02 X59.9 Y20.1 R14 (P8)
N130 G01 X70 Y10 (P9)
N140 Y-20 R10(P10)
N150 X50(P11)
N160 G03 X30 R10 (P12)
N170 G01 X10 R8(P13)
N180 X0 Y0
G M S T Codes Explanation
Code Description
G00 Rapid traverse
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G90 Absolute command
G91 Increment command
**************
Haas CNC Program
O1234 (Corner Rounding and Chamfering Example);
T1 M6;
G00 G90 G54 X0. Y0. S3000 M3; (P1)
G43 H01 Z0.1 M08;
G01 Z-0.5 F20.;
Y40. ,R10.;(P2)
X50. ,C5.; (P3)
Y0.;(P4)
G00 Z0.1 M09;
G53 G49 Z0.;
G53 Y0.;
M30;
Haas G M S T Codes
Code Description
G00 Rapid Motion
G01 Linear Interpolation Motion
G43 Tool Length Compensation +
G49 G43/G44 Cancel
G53 Non-Modal Machine Coordinate Selection
G54 Select Work Coordinate System l
G90 Incremental Programming
M3 Spindle On, Clockwise (S)
M6 Tool Change (T)
M08 Coolant On
M09 Coolant Off
M30 Program End and Reset
S Spindle speed
T Tool
****************
CNC Programming Example of Chamfer and Corner Rounding with G01 G
Code
N5 ……
N6 G00 X0 Z3
N7 G01 Z0 F0.2
N8 X35 C2
N9 Z-40 R4
N10 X55 Z-52 F0.1
N11 X75 C2
N12 Z-76
N13 G00 X100 Z50
N14 ……
***********************
CNC Lathe Simple G Code Example
– G code Programming for Beginners
CNC lathe simple g code example for CNC machinists/CNC programmers who
just started their journey to learn CNC programming.
Simple G Code Example CNC Lathe
Fanuc G73 Pattern Repeating Canned Cycle Basic CNC Sample Program
N10 G50 S2000 T0300
G96 S200 M03
G00 X35.0 Z5.0 T0303
Z0
G01 X-1.6 F0.2
G00 X70.0 Z10.0
G73 U3.0 W2.0 R2
G73 P12 Q16 U0.5 W0.1 F0.25
N12 G00 G42 X20.0 Z2.0
G01 Z-10.0 F0.15
G02 X40.0 Z-20.0 R10.0
G01 Z-30.0
X60.0 Z-50.0
N16 G40 U1.0
G70 P12 Q16
G00 X200.0 Z200.0 T0300
M30
***************
**************
G71 Longitudinal Roughing Cycle
Mazak CNC Basic Programming
Example
CNC basic programming exmaple for cnc programmers/machinists who work on
Mazak / Fanuc cnc controls. This cnc code example shows the use of G71
Longitudinal Roughing Cycle.
G71 Turning Cycle
For complete parameter explanation for G71 canned cycle read
CNC Fanuc G71 Turning Cycle or Stock Removal Canned Cycle
you might like G71 Rough Turning Cycle One-line Format.
Other such programming examples are here
CNC Programming Example with Fanuc G71 Rough Turning Cycle and G70
Fanuc G70 G71 Rough and Finish Turning Cycle Program Example
Programming Example
External Thread Cutting with G76 Threading Cycle on Fanuc 21i 18i 16i CNC
N17 T101
N18 G54
N19 G97 S800 M3
N20 G0 X32 Z6 M8
N21 G76 P010060 Q100 R0.02
N22 G76 X28.161 Z-50 P919 Q250 F1.5
N23 G0 X150 Z100
*******************
CNC Program
N40 G90 G00 X0 Y0
N50 G01 X-10 Y-20 R8 (P1)
N60 G01 X-50 R10 (P2)
N70 Y10 (P3)
N80 X-19.97 Y25.01 (P4)
N90 G03 X7.97 Y38.99 R18 (P5)
N100 G01 X30 Y50 (P6)
N110 G91 X10.1 Y-10.1(P7)
N120 G90 G02 X59.9 Y20.1 R14 (P8)
N130 G01 X70 Y10 (P9)
N140 Y-20 R10(P10)
N150 X50 (P11)
N160 G03 X30 R10 (P12)
N170 G01 X10 R8 (P13)
N180 X0 Y0
G M S T Codes Explanation
Code Description
G00 Rapid traverse
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G90 Absolute command
G91 Increment command
----------------
G02 G03 Example CNC Mill
CNC Part Program
G0 X30 Y-30 (P1)
G1 Y22.67 (P2)
G3 X24.07 Y26.18 R4 (P3)
G2 X-18.27 Y23.46 R50 (P4)
G3 X-23.46 Y18.27 R4(P5)
G2 X-23.46 Y-18.27 R50 (P6)
G3 X-18.27 Y-23.46 R4 (P7)
G2 X24.07 Y-26.18 R50 (P8)
G3 X30 Y-24.67 R4 (P9)
G1 X33
G M S T Codes Explanation
Code Description
G0 Rapid traverse
G1 Linear interpolation
G2 Circular interpolation CW
G3 Circular interpolation CCW
M30 End of program (Reset)
-------------
CNC Part Program
N05 G54
N10 M6 T1 G43 H1 M3
N15 S500 F120
N20 G0 X-22 Y-22
N25 Z-3
N30 G1 X3 Y6 G41 H2 (P1)
N35 G91 X0 Y24(P2)
N40 X12 Y9(P3)
N45 X36 (P4)
N50 Y-24 (P5)
N55 X-21 (P6)
N60 G90 X3 Y6 (P1)
N65 G0 X-21 G40
G M S T Codes Explanation
Code Description
G00 Rapid traverse
G01 Linear interpolation
G40 Cutter compensation cancel
G41 Tool nose radius compensation left
G43 Tool length compensation + direction
G54 Workpiece coordinate system 1 selection
G90 Absolute command
G91 Incremental command
M06 Tool change
T Tool
S Speed
F Feed
---------------
--------------
Fanuc G72.1 G72.2 Figure Copy
Program Example (Bolt Hole Circle)
This CNC program example shows how both G72.1 and G72.2 figure copy
functions can call one-another in one part program, read Programming
Notes below carefully.
Programming
Fanuc G72.1 Rotational Copy
Using G72.1 Rotational Copy G-code a figure specified by a subprogram can be
repeatedly produced with Rotational movement.
Read G72.1 definition with program example Fanuc G72.1 Rotational Copy
(Figure Copy Function CNC Mill)
Fanuc G72.2 Linear Copy
Using G72.2 Linear Copy G-code a figure specified by a subprogram can be
repeatedly produced with Linear movement.
Read G72.2 definition with program example Fanuc G72.2 Linear Copy (Figure
Copy Function CNC Mill)
Fanuc G81 Drilling Cycle
G81 drilling cycle is used for simple drilling/spot drilling operations.
Read G81 drilling cycle definition with program examples Fanuc G81 Drilling
Cycle
Programming Notes
Specifying two or more commands to copy a figure
• G72.1 cannot be specified more than once in a subprogram for making a
rotational copy (If this is attempted, alarm PS0900 will occur).
• G72.2 cannot be specified more than once in a subprogram for making a
linear copy (If this is attempted, alarm PS0901 will occur).
• In a subprogram that specifies rotational copy, however, linear copy can be
specified. Similarly, in a subprogram that specifies linear copy, rotational
copy can be specified.
Fanuc G71.2 G72.2 Program Example
Main program
O4000 ;
N10 G90 G00 G17 X240. Y230. Z100. ; (P0)
N20 G72.1 P4100 X120. Y120. L8 R45. ;
N30 G80 G00 X240. Y230. ; (P0)
N40 M30 ;
Sub program_ Rotation copy_ (G72.1)
O4100 N100 G72.2 P4200 I0 J20. L3 ;
N200 M99 ;
Sub program_ Linear copy (G72.2_)
O4200 N110 G90 G81 X120. Y180. R60. Z10. F200. ; (P1)
N210 M99 ;
------------------
G82 Drilling Canned Cycle with Dwell CNC Milling Example Program
O10076
N10 T11 M06
N20 G90 G54 G00 X0.5 Y-0.5
N30 S1200 M03
N40 G43 H11 Z1. M08
N50 G82 G99 Z-0.375 P1 R0.1 F7.5
N60 X1.5
N70 Y-1.5
N80 X0.5
N90 G80 G00 Z1. M09
N100 G53 G49 Z0. M05
N110 M30
Note N50 – CNC machines with Fanuc cnc control will use P1000 instead of P1
which is used for Haas CNC machines
----------------
Main program
O4000 ;
N10 G90 G00 G17 X240. Y230. Z100. ; (P0)
N20 G72.1 P4100 X120. Y120. L8 R45. ;
N30 G80 G00 X240. Y230. ; (P0)
N40 M30 ;
Sub program_ Rotation copy_ (G72.1)
O4100 N100 G72.2 P4200 I0 J20. L3 ;
N200 M99 ;
Sub program_ Linear copy (G72.2_)
O4200 N110 G90 G81 X120. Y180. R60. Z10. F200. ; (P1)
N210 M99 ;
--------------------
Fanuc G81 Drilling Cycle
G81 drilling cycle is used for simple drilling/spot drilling operations.
Contents
• Syntax
• Usage
• Working
• G98 G99 Modes
◦ Example
• Repeat Drilling
• Working Examples
• G98 G99 Example
• Repeat Drilling Example
Syntax
G81 X... Y... Z... R... K... F...
Parameter Description
X Hole position in x-axis.
Y Hole position in y-axis.
Depth, tool will travel with feed to Z-depth starting from
Z
R plane.
R Position of the R plane.
Number of cycle repetitions (if
K
required)__________________.
F Feedrate.
Once G81 drilling cycle is defined, the canned cycle is repeated at every X-Y
position in sequential blocks. So G81 drilling cycle must be cancelled with G80.
Usage
N30 G81 X10 Y30 Z-17 R2 F75
N40 Y10
N50 X30
N60 Y30
N70 X90
N80 Y10
N90 G80
In the above example drilling will start with G81 drilling cycle at X10 Y30, so
first drill will be at X10 Y30, then second at Y10, third at X30, fourth at Y30,
fifth at X90 and the last one at Y10, because next block have G80 code, so
drilling cycle will no more be repeated.
Working
Here is briefly described how G81 drilling cycle operates,
1- Rapid traverse to the specified x,y axis position (drilling position).
2- Rapid traverse to the R plane position.
3- Drilling with specified Feed from R-plane position to Z-depth position.
4- Rapid traverse to Initial level or R-plane depends on G98, G99 modes.
T1 M6
G0 G90 G40 G21 G17 G94 G80
G54 X20 Y0 S1500 M3
G43 Z100 H1
Z5
G81 R3 Z-20 F? M8
X30
X45
G68 X0 Y0 R120
X20 Y0
X30
X45
G68 X0 Y0 R240
X20 Y0
X30
X45
G69 G80
G0 G90 Z100 M30
-------------------------
Contents
1 CNC Mill Programming Example
CNC Program
G M S T Codes Explanation
Main program
O3000 ;
N10 G90 G00 X-30. Y0 ;
N20 X0 ;
N30 G01 G17 G41 X30. D01 F100 ; (P0)
N40 Y20. ; (P1)
N50 X40. ; (P2)
N60 G72.2 P3100 L3 I90.0 J0 ;
N70 G90 X310. Y0 ; (P8)
N80 X0 ;
N90 G40 G00 X-30.0 ;
N100 M30 ;
Sub program
O3100 G91 G01 X20. ; (P3)
N100 Y30. ; (P4)
N200 G02 X40. I20. ; (P5)
N300 G01 Y-30. ; (P6)
N400 X30. ; (P7)
N500 M99 ;
-----------
CNC Program
N40 G90 G00 X0 Y0
N50 G01 X-10 Y-20 R8 (P1)
N60 G01 X-50 R10 (P2)
N70 Y10 (P3)
N80 X-19.97 Y25.01 (P4)
N90 G03 X7.97 Y38.99 R18 (P5)
N100 G01 X30 Y50 (P6)
N110 G91 X10.1 Y-10.1(P7)
N120 G90 G02 X59.9 Y20.1 R14 (P8)
N130 G01 X70 Y10 (P9)
N140 Y-20 R10(P10)
N150 X50 (P11)
N160 G03 X30 R10 (P12)
N170 G01 X10 R8 (P13)
N180 X0 Y0
G M S T Codes Explanation
Code Description
G00 Rapid traverse
G01 Linear interpolation
G02 Circular interpolation CW
G03 Circular interpolation CCW
G90 Absolute command
G91 Increment command
-----------------
Fanuc G73 Pattern Repeating Canned Cycle Basic CNC Sample Program
N10 G50 S2000 T0300
G96 S200 M03
G00 X35.0 Z5.0 T0303
Z0
G01 X-1.6 F0.2
G00 X70.0 Z10.0
G73 U3.0 W2.0 R2
G73 P12 Q16 U0.5 W0.1 F0.25
N12 G00 G42 X20.0 Z2.0
G01 Z-10.0 F0.15
G02 X40.0 Z-20.0 R10.0
G01 Z-30.0
X60.0 Z-50.0
N16 G40 U1.0
G70 P12 Q16
G00 X200.0 Z200.0 T0300
M30
------------
Main program
O4000 ;
N10 G90 G00 G17 X240. Y230. Z100. ; (P0)
N20 G72.1 P4100 X120. Y120. L8 R45. ;
N30 G80 G00 X240. Y230. ; (P0)
N40 M30 ;
Sub program_ Rotation copy_ (G72.1)
O4100 N100 G72.2 P4200 I0 J20. L3 ;
N200 M99 ;
Sub program_ Linear copy (G72.2_)
O4200 N110 G90 G81 X120. Y180. R60. Z10. F200. ; (P1)
N210 M99 ;
-------------
Main program
O2000 ;
N10 G90 G00 G17 X250. Y100. Z100. ; (P0)
N20 G72.1 P2100 L6 X100. Y50. R60. ;
N30 G80 G00 X250. Y100. ; (P0)
N40 M30 ;
Sub program
O2100 N100 G90 G81 X100. Y150. R60. Z10. F200. ; (P1)
N200 M99 ;
---------------
T1 M6
G0 G90 G40 G21 G17 G94 G80
G54 X20 Y0 S1500 M3
G43 Z100 H1
Z5
G81 R3 Z-20 F? M8
X30
X45
G68 X0 Y0 R120
X20 Y0
X30
X45
G68 X0 Y0 R240
X20 Y0
X30
X45
G69 G80
G0 G90 Z100 M30
-----------------
----------
Drilling Grid Plate with G81 Drilling
Cycle – Sample CNC Program
CNC machine workshops deal with variety of components, of course cnc
machinists program and machine them.
But a cnc machinists also should understand and practice new and economical
ways to machine a component.
The following cnc programming example can be programmed in variety of
ways, the method of cnc programming used in this cnc program sample uses
G81 drilling cycle with G91 Incremental Programming mode, which makes
programming easy.
Fanuc cnc control uses K with G81 drilling cycle to repeat drilling cycle.
Haas cnc controls use L to repeat G81 drilling cycle.
Following cnc program is written for haas cnc machine but can easily be
converted for Fanuc cnc controls.
You might read other cnc programming example which shows the same
technique for Fanuc cnc controls
G81 Drilling Cycle – Repeat Drilling in G91 Incremental Mode Example
Code
Repeat Drilling with G81 Drilling Cycle and G91 Example Program
CNC Program of Drilling Grid Plate
Drilling Grid Plate with G81 Drilling Cycle
03400 (Drilling grid plate)
T1 M06
G00 G90 G54 X1.0 Y-1.0 S2500 M03
G43 H01 Z.1 M08
G81 Z-1.5 F15. R.1
G91 X1.0 L9
G90 Y-2.0 (Or stay in G91 and repeat Y-1.0)
G91 X-1.0 L9
G90 Y-3.0
G91 X1.0 L9
G90 Y-4.0
G91 X-1.0 L9
G90 Y-5.0
G91 X1.0 L9
G90 Y-6.0
G91 X-1.0 L9
G90 Y-7.0
G91 X1.0 L9
G90 Y-8.0
G91 X-1.0 L9
G90 Y-9.0
G91 X1.0 L9
G90 Y-10.0
G91 X-1.0 L9
G00 G90 G80 Z1.0 M09
G28 G91 Y0 Z0
M30
In above cnc program G90 Absolute programming mode is used while starting a
new row for drilling. Although G91 Incremen0tal programming can be used but
using G90 there makes this program easy to read understand and debug (if
anything goes wrong).
-----------
Simple CNC Lathe Drilling with Fanuc G74 Peck Drilling Cycle
N10 T5
N20 G97 S500 M03
N30 G00 X0 Z2
N40 G74 R1
N50 G74 Z-60 Q30000 F0.1
N60 G00 X100 Z100
N70 M30
The above cnc program code shows that the tool no.5 which is a drill, will drill
the component with the peck drilling cycle G74.
The R in first block shows the amount ( 1mm) the drill will get back after it
drills 30 mm every time.
Peck Drilling Lathe
Parameter Description
X Hole position in x-axis.
Y Hole position in y-axis.
Depth, tool will travel with feed to Z-depth starting
Z
from R plane.
R Position of the R plane.
Q Depth of cut for each cutting feed (Peck).
Number of cycle repetitions (if
K
required)__________________.
F Feedrate.
Once given in program G83 peck drilling cycle is repeated at every axis
movement until G80 is given in program to end peck drilling cycle.
Usage
N150 M06 T02
N160 G90 G00 X60 Y28 Z12 S750 M03
N170 G99 G83 X60 Y28 Z-17 Q6 R2 F60
N180 G98 Y12
N190 G91 G80 G28 X0 Y0 Z0 M05
N200 M30
In the above example code first drill is done at X60 Y28 and second at Y12 and
then peck drilling is cycle is ended with G80.
6mm pecks are taken to complete total drilling depth of 17mm.
Working
Here is briefly described how G83 peck drilling cycle works,
1- Rapid traverse to X, Y drilling position.
2- Rapid traverse to R-plane.
3- Drilling with feed Q deep.
4- Retraction with Rapid traverse to R-plane.
5- Rapid traverse to Q-d deep (d value is specified in parameters).
6- Drilling with feed Q+d deep.
7- Retraction with Rapid traverse to R-plane
– this whole procedure is repeated until drill reaches Z-depth position,
– then drill is retracted to R-plane or Initial-level depends on G99 or G98 which
one is given in program.
Main Program
Milling cutter diameter: 10mm
N05 G55
N10 M6 T2 H3 G43 M3
N15 S1000 F60
N20 G0 X9 Y9 Z1
N25 G1 Z0
N30 M98 P030035
N35 G0 Z1 G90
N40 X42 Y38
N45 G1 Z-2 F30
N50 X47 F300
N55 G3 X47 Y38 I-5 J0
N60 G0 Z100
N65 G49
N70 M30
Subprogram
O0035
N05 G1 Z-2 G91 F30
N10 X10 F100
N15 Y36
N20 X-10
N25 Y-36
N30 M99
Explanation
Although this cnc mill program is self explanatory
M98 P030035
this code mean call Subprogram No. 0035 three times.
-------------
CNC Programming Example with Fanuc G71 Rough Turning Cycle and G70
N10 G00 G90 X142 Z171
N20 G71 U4 R1
N30 G71 P40 Q110 U4 W2 F0.3
N40 G00 X40
N50 G01 Z140 F0.2
N60 G01 X60 Z110
N70 G01 Z90
N80 G01 X100 Z80
N90 G01 Z60
N110 G01 X140 Z40
N120 G70 P40 Q110
N130 G00 X200 Z220
N140 M30
Step Turning CNC Lathe
Main Program
Milling cutter diameter: 10mm
N05 G55
N10 M6 T2 H3 G43 M3
N15 S1000 F60
N20 G0 X9 Y9 Z1
N25 G1 Z0
N30 M98 P030035
N35 G0 Z1 G90
N40 X42 Y38
N45 G1 Z-2 F30
N50 X47 F300
N55 G3 X47 Y38 I-5 J0
N60 G0 Z100
N65 G49
N70 M30
Subprogram
O0035
N05 G1 Z-2 G91 F30
N10 X10 F100
N15 Y36
N20 X-10
N25 Y-36
N30 M99
Explanation
Although this cnc mill program is self explanatory
M98 P030035
this code mean call Subprogram No. 0035 three times.
------------
http://www.education-techniques.com