Programming 77
Programming
For the Fanuc 0M controller
Axes convention
The tool can be moved to any position in a 3 dimensional cartesian co-ordinate system.
The Z axis is along the spindle axis. The X and Y axes are perpendicular to Z.
VMC (Vertical Machining Center)
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 78
HMC (Horizontal Machining Center)
-
X
-
+ - Z
+
Y
Z
Part
X
Machine table
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 79
List of G-codes
G-code Function Format
G00 Positioning rapid traverse G0 X Y Z
G01 Linear interpolation (feed) G01 X Y Z F
G02 Circular interpolation CW (feed) G02 X Y I J F or G02 X Y R F
G03 Circular interpolation CCW (feed) G02 X Y I J F or G02 X Y R F
G04 Dwell G4 X1.0 (one sec)
G4 P1000 (1000 milli sec)
G10 Data setting Changing work offset
G10 G90 L2 P1 X163.684 Y-391.934 Z-693.344
L2 = Load work offset
P= 0 External work zero offset (G53)
P= 1 to 6 Work coordinate system 54 to G59
Changing tool length offset value
P= offset number
R= Tool offset value
Tool length compensation value (H code)
G10 G90 L10 P1 R100.0
Tool length wear compensation value (H code)
G10 G90 L11 P1 R-0.02
Changing cutter radius offset value
Cutter radius compensation value (D code)
G10 G90 L12 P1 R10.0
Cutter radius wear compensation value (D code)
G10 G90 L13 P1 R-0.03
G15 Polar coordinate command cancel G90 G16 (polar coordinate system on)
G16 Polar coordinate command G98 G81 X134.938 Y15.0 R3.0 Z-44.0 F104.
Y45.0
Y75.0
Y105.0 X= PCR
Y135.0 Y= Angular pitch
Y165.0
Y195.0 If
Y225.0 G90 G16 (Absolute)
Y255.0 G91 G16 (incremental)
Y285.0
Y315.0
Y345.0
G80 G15 (polar coordinate system cancel)
G17 XY plane Must be commanded bigining of the program or wherever
G18 ZX plane changes required
%
G19 YZ plane O1234
G20 Inch unit G21
G21 Metric unit G91 G30 Z0.
M60
M84
G40 G80 G49 G17
G28 Automatic zero return G91 G28 X0 Y0 Z0
Note: G91 must be used with G28 if not machine zero will shift to
part zero
G30 2nd reference point return G91 G30 X0 Y0 Z0
Note: G91 must be used with G30 if not machine zero will shift to
part zero
G40 Cutter radius compensation (CRC) cancel G40 X Y
X and Y are cutter center coordinates
G40 must be with G0 or G1 mode
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 80
G41 Cutter radius compensation (CRC) left G41 X Y D
G42 Cutter radius compensation (CRC) right X and Y are tangential coordinates
G41 or G42 must be with G0 or G1 mode
G43 Tool length compensation G43 Z H
After each tool change G43 must be used along with first Z motion
and with H code
G49 Tool length compensation cancel Used before every tool change
G52 Local co-ordinate system G90 G52 X Y Z
1. X Y Z along with G52 are not coordinate valves
2. X Y Z along with G52 are work zero shift values with
direction (G54 – G59)
G54 Work co-ordinate system 1 selection
G55 Work co-ordinate system 2 selection
G56 Work co-ordinate system 3 selection G0 G90 G54 X0. Y0. S1200 M3 T02
G57 Work co-ordinate system 4 selection G43 H01 Z150. M8
G58 Work co-ordinate system 5 selection
G59 Work co-ordinate system 6 selection
G73 Peck drilling G73 R Z Q F
XY
G80
G74 Left hand tapping cycle M29 S
G74 R Z F P
XY
G80 M28
G76 Fine boring cycle G76 R Z Q F
XY
G80
G80 Canned cycle cancel
G81 Drilling cycle G81 R Z F
XY
G80
G82 Drilling cycle with dwell G82 R Z F P
XY
G80
G83 Peck drilling cycle / deep drill G83 R Z Q F
XY
G80
G84 Tapping cycle M29 S
G84 R Z F P
XY
G80 M28
G85 Boring / Reaming cycle G85 R Z F
XY
G80
G86 Boring cycle G86 R Z F
XY
G80
G87 Back boring cycle G87 R Z Q F
XY
G80
G90 Absolute command
G91 Incremental command
G94 Feed per minute
G95 Feed per revolution
G98 Return to initial point in canned cycle G98 G81 R Z F
G99 Return to R point in canned cycle G99 G81 R Z F
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 81
List of M codes
M codes vary from machine to machine depending on the functions available on it. The machine tool
manufacturer decides them. The M codes listed below are the common ones.
M-codes Function
M00 Optional program stop automatic
M01 Optional program stop request
M02 Program end
M03 Spindle ON clock wise (CW)
M04 Spindle ON counter clock wise (CCW)
M05 Spindle stop
M06 Tool change
M07 Mist coolant ON (coolant 1 ON)
M08 Flood coolant ON (coolant 2 ON)
M09 Coolant OFF
M28 Rigid tapping cycle cancel
M29 Rigid tapping cycle enable
M19 Spindle orientation
M30 End of program, Reset to start
M98 Sub program call
M99 Sub program end
There are other M-codes for functions like gear change, pallet change, pallet clamp / unclamp, door open /
close etc.
Absolute and Incremental co-ordinates
In the absolute programming , the end point of a motion is programmed with reference to the program zero
point. In incremental programming, the end point is specified with reference to the current tool position.
N2
50
20 N1
X
0,0 30 50
Absolute traverse to N1, then to N2
G90 X20.0 Z50.0
X50.0 Z30.0
Absolute traverse to N1, incremental to N2
G90 X20.0 Z50.0
G91 X-20. Y30
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 82
G00 Rapid traverse
When the tool being positioned at a point preparatory to a cutting motion, to save time it is moved along a
straight line at Rapid traverse, at a fixed traverse rate which is pre-programmed into the machine's
control system. Typical rapid traverse rates are 10 to 25 m /min., but can be as high as 80 m/min.
Format
G0 X__
G0 Y__
G0 Z__
G0 X__ Y__Z__
G01 Linear interpolation (feed traverse)
The tool moves along a straight line in one or two axis simultaneously at a programmed linear speed, the
feed rate.
Format
G01 X__ F__
G01 Y__ F__
G01 Z__ F__
G01 X__ Y__Z__ F__
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 83
G02/03 Circular interpolation
Format
G02/03 X__ Y__Z__ I__ J__K__ F__ using the arc center
OR
G02/03 X__ Y__Z__ R__ F__ using the arc radius
G02 moves along a CW arc
G03 moves along a CCW arc
Arc center
The arc center is specified by addresses I, J and K. I, J and K are the X, Y and Z co-ordinates of the arc
center with reference to the arc start point.
I = X coord. of center - X coord. of start point
J = Y coord. of center - Y coord. of start point
K = Z coord. of center - Z coord. of start point
I, J and K must be written with their signs.
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 84
Arc radius
The radius is specified with address R.
Arc start
Y Arc end Arc radius
Arc center
X
Block format
N__ G02 X__Y__ Z__ R__ F__
N__ G03 X__Y__ Z__ R__ F__
Cutter radius compensation (CRC)
G40 Tool nose radius compensation Cancel
G41 Tool nose radius compensation Left
G42 Tool nose radius compensation Right
G42 G42
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 85
Block format
N__ G01 G41/42 X__ Y__ D__ F__
Feed rate mm/min
CRC offset number
CRC start co-ordinates absolute
CRC command code
Linear interpolation command code
Necessity of using CRC
Difficult to calculate cutter center co-ordinates
If cutter center co-ordinates are used
Same diameter of cutter is required to be used
Cutter wear can not compensated
Program Zero
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 86
Tool length compensation (G43)
Different tools of different lengths are used in machining any part. The lengths of the tools are not
considered in the part program. They are entered in the machine’s memory, and are considered
automatically for each motion in the program depending on the tool that is being used. The tool lengths in
the Z direction are called the Tool length offsets.
Gauge line
Length offset Length offset
Length offset
Length offset
Face milling cutter
T-slot milling cutter
Boring tool
Back boring tool
Part
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 87
Setting work co-ordinate system (G54 - G59)
G54 Work co-ordinate system 1 selection
G55 Work co-ordinate system 2 selection
G56 Work co-ordinate system 3 selection
G57 Work co-ordinate system 4 selection
G58 Work co-ordinate system 5 selection
G59 Work co-ordinate system 6 selection
Work co-ordinate system 3
selection
Work co-ordinate
system 1 selection
Work co-ordinate
system 2 selection Machine table
Work co-ordinate system 6
Work co-ordinate system 4 selection
selection
Work co-ordinate system 5
selection
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 88
Canned cycles
Canned or fixed cycles are programming aids that simplify programming. Canned cycles combine many
programming operations and are designed to shorten the program length, minimize mathematical
calculations, and use minimal tool motions.
Examples: drilling, peck drilling, tapping, boring, back spot facing.
Canned cycle Axis movement Operation at Retraction
Application
G-code (Z- direction) bottom of the hole (Z+ direction)
G73 Peck High speed peck
Intermittent feed Rapid traverse
drilling cycle drilling
Spindle stop
G74 Left hand
Feed Dwell Feed Left hand tapping
tapping cycle
Spindle CW
Spindle stop, Spindle
G76 Fine
Feed orientation Lateral Rapid traverse Fine boring
boring cycle
shift in X or Y axis
G81 Drilling
Centring, Drilling
cycle Feed Rapid traverse
and spot facing
Centring, Drilling,
G82 Drilling
Feed Dwell Rapid traverse C-bore and spot
cycle with dwell
facing
G83 Peck
Feed Rapid traverse Peck drilling
drilling cycle
Spindle stop
G84 Right hand
Feed Dwell Feed Right hand tapping
tapping cycle
Spindle CCW
G85 Boring / Reaming and
Feed Feed
Reaming cycle boring
G86 Boring
Feed Spindle stop Rapid traverse Boring
cycle
Spindle stop, Spindle
G87 Back
Feed orientation Lateral Rapid traverse Back spot facing
boring cycle
shift in X or Y axis
Dwell
G88 Boring cycle Feed Spindle stop Rapid traverse Boring
G89 Boring cycle Feed Dwell Feed Boring
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 89
High speed peck drill cycle (G73)
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 90
Tapping cycle (G74)
Left hand tapping
With G98 return initial point With G99 return R point
Initial Rapid Feed Initial Rapid Feed
point point
R point / Safe height R point / Safe height
Spindle CCW Spindle CCW
Retract feed rate Retract feed rate
equals infeed feed equals infeed feed
rate rate
Final depth Final depth
Spindle CW Spindle CW
Feedrate = Spindle RPM x Pitch
Spindle direction in RH tapping
CCW during infeed
CW during outfeed
Ex:
M29 S1000
G98 G74 R3.0 Z-20.0 F1000.0 P100
XY
XY
M28
G0 G80
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 91
Fine boring cycle (G76)
With G99 return to R point
Rapid Feed
Initial
point
Lateral shift
Spindle CW
R point / Safe height
Final depth
Dwell at
bottom
Lateral shift
Spindle Orientation
Format
N__ G98 G76 R__ Z__ Q__ F__
Infeed feed rate mm/min
Lateral shift
Final depth
Safe height / R point
Fine boring cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 92
Drilling cycle (G81)
Format
N__ G98/99 G81 R__ Z__ F__
Infeed feed rate mm/min
Final depth
Safe height / R point
Drilling cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 93
Counter bore cycle (G82)
Format
N__ G98/99 G82 R__ Z__ P__ F__
Infeed feed rate mm/min
Dwell at bottom
Final depth
Safe height / R point
Counter bore drilling cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 94
Peck drill cycle (G83)
Format
N__ G98/99 G83 R__ Z__ Q__ F__
Infeed feed rate mm/min
Peck depth
Final depth
Safe height / R point
Peck drilling cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 95
Tapping cycle (G84)
Right hand tapping
With G98 return to initial point With G99 return to R point
Initial Rapid Feed Initial Rapid Feed
point point
R point / Safe height R point / Safe height
Spindle CW Spindle CW
Retract feed rate Retract feed rate
equals infeed feed equals infeed feed
rate rate
Final depth Final depth
Spindle CCW Spindle CCW
Feedrate = Spindle RPM x Pitch
Format
N__ G98/99 G84 R__ Z__ F__
Infeed / retract feed rate mm/min
Final depth
Safe height / R point
Right hand tapping cycle code
Return position code
Block number
Spindle direction in RH tapping
CW during infeed
CCW during outfeed
Ex:
M29 S1000
G98 G84 R3.0 Z-20.0 F1000.0 P100
XY
XY
M28
G0 G80
Reaming cycle (G85)
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 96
With G98 return to R point
Rapid Feed
Initial
point
R point / Safe height
Final depth
Format
N__ G98/99 G85 R__ Z__ F__
Infeed / retract feed rate mm/min
Final depth
Safe height / R point
Reaming cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 97
Boring cycle (G86)
With G98 return to initial point With G99 return to R point
Rapid Feed Rapid Feed
Initial
point
Spindle CW Spindle CW
R point / Safe height R point / Safe height
Final depth Final depth
Spindle stop Spindle stop
Format
N__ G98/99 G86 R__ Z__ F__
Infeed feed rate mm/min
Final depth
Safe height / R point
Boring cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 98
Back boring cycle (G87)
Spindle orientation
Initial point
Bore axis
Lateral shift
Final depth
Spindle CW Safe height / R point
Format
N__ G98 G87 R__ Z__ Q__ F__
Infeed feed rate mm/min
Lateral shift
Final depth
Safe height / R point
Back boring cycle code
Return position code
Block number
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 99
Verifying NC programs
Safety priorities
Safety priorities must be followed when verifying programs.
Operator safety - priority 1
Safety of the person operating the machine
Machine tool safety - priority 2
Prevention of damage to the machine
Workpiece safety - priority 3
Prevention of part rejection
Typical errors
Syntax errors
Errors which prevent the machine controller from executing a command. E.g., writing G101 instead of G01
Motion errors
Machine does not generate an error, so these are difficult to diagnose.
E.g., Writing X instead of Z; wrong co-ordinates; reversing CW and CCW commands; improper
incremental/absolute mode selection.
Omission errors
Omitting decimal points, forgetting to program feed rates, forgetting to turn on the coolant
Setup errors
Wrongly measured work offset and tool offsets, or correct measurement and wrong entry
Program verification procedures
A new program is checked by executing it in some or all of the verification modes.
Dry run with Machine lock
Used for checking syntax errors. Motion errors are not checked.
Set Machine lock ON and Dry run ON.
Set feed rate override switch to maximum to execute the cycle fast.
The spindle rotates, the turret indexes and the display changes as per program, but axes do not move.
Tool and work offsets need not be set.
AceMicromatic-LPM CNC Technology Center Machining Center
Programming 100
Dry run with air cutting
Used for checking motion errors and correctness of spindle direction. Since execution is at dry run feed,
difference between rapid and feed motions is not known. Collisions cannot be checked.
Set the tool offsets. Set the work offset so that all motions occur away from work holding devices like
the chuck.. Do not load a part.
Set Machine lock OFF and Dry run ON. All machine functions and motions are active.
Set feed rate override switch to minimum for safety.
Normal cycle with air cutting
Used for checking collisions.
Set the tool offsets. Set the work offset so that all motions occur away from work holding devices like
the chuck.. Do not load a part.
Set all functions for normal machine execution.
For safety, when in doubt set the feed rate override switch to minimum.
Carefully watch for motions which result in tool colliding with the part or work holding device.
Single block execution
Used for checking motion errors and part dimensional accuracy.
Set the work offset normally, and load a part.
Set the tool offsets to leave excess stock on the part.
Set all functions for normal machine execution.
For safety, when in doubt set the feed rate override switch to minimum.
Check the Distance to go value to detect potential motion errors.
Check all dimensions. For critical dimensions alter the tool offsets and rerun the tool again to check
whether the dimension is within tolerance. Repeat till tolerance is achieved.
AceMicromatic-LPM CNC Technology Center Machining Center