Professional Documents
Culture Documents
NC Programming
NC Programming
Programming
For the Fanuc 0T controller
Axes convention
X Axis
Z Axis
20 0,0 30 50
N1
Absolute traverse to N1, then to N2 X20.0 Z50.0 X50.0 Z30.0 Absolute traverse to N1, incremental to N2 X20.0 Z50.0 U30.0 W-20.0
CNC Turning
Programming
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.
+ Z + X -X + -Y -Z +X +Z +Y
Y -
CNC Milling
Programming
+ Y X + Z +
CNC Milling
Programming
List of G-codes
G-code G00 G01 G02 G03 G04 G20 G21 G28 G30 G40 G41 G42 G43 G52 G54 G55 G56 G57 G58 G59 G74 G76 G80 G81 G82 G83 G84 G85 G86 G87 G90 G91 G94 G95 G98 G99 Function Positioning rapid traverse Linear interpolation (feed) Circular interpolation CW Circular interpolation CCW Dwell Inch unit Metric unit Automatic zero return 2nd reference point return Tool nose radius compensation cancel Tool nose radius compensation left Tool nose radius compensation right Tool length compensation Local co-ordinate system Work co-ordinate system 1 selection Work co-ordinate system 2 selection Work co-ordinate system 3 selection Work co-ordinate system 4 selection Work co-ordinate system 5 selection Work co-ordinate system 6 selection Left hand tapping cycle Fine boring cycle Canned cycle cancel Drilling cycle Drilling cycle with dwell Peck drilling cycle / deep drill Tapping cycle Boring / Reaming cycle Boring cycle Back boring cycle
CNC Milling
Programming
List of M codes
M codes vary from machine to machine depending on the functions available on it. They are decided by the manufacturer of the machine. The M codes listed below are the common ones.
M-codes M00 M01 M02 M03 M04 M05 M06 M07 M08 M09 M19 M30 M98 M99 Function Optional program stop automatic Optional program stop request Program end Spindle ON clock wise (CW) Spindle ON counter clock wise (CCW) Spindle stop Tool change Mist coolant ON (coolant 1 ON) Flood coolant ON (coolant 2 ON) Coolant OFF Spindle orientation End of program, Reset to start Sub program call Sub program end
There are other M-codes for functions like gear change, pallet change, pallet clamp / unclamp, door open / close etc.
Y 50
N2
20 0,0
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
N1
30
50
CNC Milling
Programming
Feed
Feed
Part Part
CNC Milling
Programming
Format
N__ G02/03 X__ Y__Z__ I__ J__K__ F__ OR N__ G02/03 X__ Y__Z__ R__ F__ G02 moves along a CW arc G03 moves along a CCW arc using the arc center using the arc radius
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.
Y
Arc start Arc end -I -J Arc center
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.
Arc radius
CNC Milling
Programming
Arc end
Arc radius
Arc center
Block format
N__ G02 X__Y__ Z__ R__ F__ N__ G03 X__Y__ Z__ R__ F__
G41
G41
G42
G42
Block format
CNC Milling
Programming
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
Program Zero
CNC Milling
Programming
Gauge line
Length offset
Length offset
Length offset
Length offset
Boring tool
Part
CNC Milling
Programming
10
Machine table
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. G81 G82 G83 G84 G85 G86 G87 G74 G76 Drilling cycle Drilling cycle with dwell (Counter bore cycle) Peck drilling cycle / deep drill Right hand tapping cycle Boring / Reaming cycle Boring cycle Back boring cycle Left hand tapping cycle Fine boring cycle
CNC Milling
Programming
11
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
CNC Milling
Programming
12
Dwell at bottom
Dwell at bottom
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
CNC Milling
Programming
13
Final depth
Final depth
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
CNC Milling
Programming
14
R point / Safe height Spindle CW Retract feed rate equals infeed feed rate Final depth Spindle CCW
R point / Safe height Spindle CW Retract feed rate equals infeed feed rate Final depth Spindle CCW
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
CNC Milling
Programming
15
Final depth
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
CNC Milling
Programming
16
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
CNC Milling
Programming
17
Lateral shift
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
CNC Milling
Programming
18
R point / Safe height Spindle CCW Retract feed rate equals infeed feed rate Final depth Spindle CW
R point / Safe height Spindle CCW Retract feed rate equals infeed feed rate Final depth Spindle CW
Format
N__ G98/99 G74 R__ Z__ F__ Infeed / retract feed rate mm/min Final depth Safe height / R point Left hand tapping cycle code Return position code Block number
CNC Milling
Programming
19
Lateral shift
Lateral shift
Final depth Dwell at bottom Lateral shift Spindle Orientation Dwell at bottom
Final depth
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
CNC Milling
Programming
20
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
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.
CNC Milling
Programming
21
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.
CNC Milling
Programming
CNC Turning
Programming
List of G-codes
G-code G00 G01 G02 G03 G04 G20 G21 G28 G30 G32 / G33 G40 G41 G42 G50 / G92 G70 G71 G72 G73 G74 G75 G76 G94 / G98 G95 / G99 G96 G97 Function Positioning rapid traverse Linear interpolation (feed) Circular interpolation CW Circular interpolation CCW Dwell Inch unit Metric unit Automatic zero return 2nd reference point return Thread cutting (single motion) Tool nose radius compensation cancel Tool nose radius compensation left Tool nose radius compensation right Local co-ordinate system setting, max. spindle speed setting Finishing cycle Stock removal in turning Stock removal in facing Pattern repeating Peck drilling on Z axis / Face grooving Peck drilling on X axis / Int-Ext grooving Multiple threading cycle Feed per minute Feed per revolution Constant surface speed control Constant surface speed control cancel
List of M codes
M codes vary from machine to machine depending on the functions available on it and the manufacturer of the machine decides them. The M codes listed below are the common ones.
M-codes M00 M01 M02 M03 M04 M05 M06 M07 M08 M09 M30 M98 M99 Function Optional program stop automatic Optional program stop request Program end Spindle ON clock wise (CW) Spindle ON counter clock wise (CCW) Spindle stop Tool change Mist coolant ON (coolant 1 ON) Flood coolant ON (coolant 2 ON) Coolant OFF End of program, Reset to start Sub program call Sub program end
There are other M-codes for functions like gear change, tail stock quill in/out, chuck clamp/unclamp, chip conveyor forward/backward, door open / close etc.
CNC Turning
Programming
Rapid traverse
Feed motion
CNC Turning
Programming
CW arc
CCW arc
Format
N__ G02/03 X__ Z__ I__ K__ F__ OR N__ G02/03 X__ Z__ R__ F__ G02 moves along a CW arc G03 moves along a CCW arc using the arc center using the arc radius
Arc center
The arc center is specified by addresses I and K. I and K are the X and Z co-ordinates of the arc center with reference to the arc start point. X
Arc start Arc end -K -I Arc center
Z I =(X coord. of center - X coord. of start point)/2 K = Z coord. of center - Z coord. of start point I and K must be written with their signs.
CNC Turning
Programming
Arc radius
The radius is specified with address R.
Arc start
Arc end
Arc radius
Arc center
N__ G02 X__ Z__ R__ F__ N__ G03 X__ Z__ R__ F__ If the radius is used, only arcs of less than 180 deg. can be programmed in a block. An arc with included angle greater than 180 deg. must be specified in two blocks.
X axis
Z axis
CNC Turning
Programming
2. If tool nose radius compensation is not used for motion from P2 to P3, material is left out as shown in the figure.
CNC Turning
Programming
Type No. 1
Type No. 2
Type No. 3
Type No. 4
Z Z X Z X X
Type No. 5
X Z
Type No. 6
Z X
Type No. 7
Z
Type No. 8
CNC Turning
Programming
The direction of the imaginary tool nose viewed from the tool nose center is determined by the direction of the tool during cutting.
3
Neutral tools
CNC Turning
Programming
10
G32
Thread cutting is done by moving the tool along the thread repeatedly at different depths tiil the final thread profile is formed. Each cut must start at the same angular position on the part. The spindle has an encoder, which generates a pulse at exactly the same angular position in every revolution. When a threading motion is programmed, the linear motion of the tool starts when this pulse is detected. This ensures that every cut starts at the same angular position. Thread cutting must be done at constant spindle speed. Block format N__ G32 X__ Z__ F__ X, Z are the end point of the thread and F is the pitch of the thread. The controller calculates feed rate through the following relationship Feed rate = Pitch x Spindle speed Each threading cut involves 4 motions: 1 threading motion and 3 rapid traverse motions. Since a thread normally requires multiple cuts, G32 results in a long program and is not normally used. The G76 canned cycle is normally used for threading.
CNC Turning
Programming
11
Canned cycles
A canned cycle simplifies a program by using a few blocks containing G-codes functions to specify the machining operations usually specified in several blocks.
CNC Turning
Programming
12
CNC Turning
Programming
13
CNC Turning
Programming
14
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 This prevents 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
CNC Turning
Programming
15
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.
CNC Turning