G and M Programming For CNC Lathes
G and M Programming For CNC Lathes
G and M Programming For CNC Lathes
Denford Limited reserves the right to alter any specifications and documentation without prior notice. No part of this manual or its accompanying documents may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Denford Limited. All brands and products are trademarks or registered trademarks of their respective companies. Copyright Denford Limited - Version 1.05.01. All rights reserved. G and M Programming for CNC Lathes Section 1 - Introduction - 1
Contact Details
Address: Denford Limited, Birds Royd, Brighouse, West Yorkshire, HD6 1NB, UK. General Enquiries +44 (0) 1484 712264 Customer Services +44 (0) 1484 722733 +44 (0) 1484 722160 for customer services and technical support contact, [email protected]
2 - Section 1 - Introduction
Contents
Table of Contents
Preface.
Contact Details ............................................................................................. 2 About this Manual ........................................................................................ 2 Contents ....................................................................................................... 3
Section 1: Introduction.
Introduction to G & M Code Programming ................................................... 6 What is CNC? .............................................................................................. 7 Example CNC Manufacturing Process ......................................................... 8
Section 1 - Introduction - 3
Contents
Section 3: G Codes (Preparatory Functions).
G Codes (Preparatory Functions) - Introduction .......................................... 27 List of G Codes supported by Denford CNC Controls .................................. 29 G (Rapid Positioning/Traverse) .............................................................. 30 G1 (Linear Interpolation) ........................................................................... 34 G2 G3 (Circular Interpolation)................................................................. 37 G4 (Dwell) ................................................................................................. 41 G2 G21 (Inch/Metric Data Input) ............................................................... 42 G28 (Reference Point Return) ..................................................................... 43 G4 G41 G42 (Tool Nose Radius Compensation) ...................................... 46 G5 (Multiple Command Functions - 1. Clamping Max. Spindle Speed) .... 55 G5 (Multiple Command Functions - 2. Co-ordinate System Setting) ...... 56 G5 (Multiple Command Functions - 3. Co-ordinate System Shift). ............ 59 G7 (Finishing Cycle) .................................................................................. 60 G71 (Stock Removal in X Axis) .................................................................... 61 G72 (Stock Removal in Facing) ................................................................... 68 G73 (Pattern Repeating) .............................................................................. 72 G74 (End Face Peck Drilling Cycle) ............................................................. 74 G75 (Outer Diameter/Internal Diameter Drilling and Grooving Cycle) .......... 78 G76 (Multiple Thread Cutting Cycle) ............................................................ 80 G81 (Deep Hole Drilling Cycle) .................................................................... 84 G9 (Outer Diameter/Internal Diameter Cutting Cycle) ............................... 85 G92 (Thread Cutting Cycle) ......................................................................... 89 G94 (End Face Turning Cycle) ..................................................................... 91 G96 (Constant Surface Speed Control) ....................................................... 94 G97 (Spindle Speed in Rev/Minute) ............................................................. 95 G98 (Per Minute Feed) ................................................................................ 96 G99 (Per Revolution Feed) .......................................................................... 98
4 - Section 1 - Introduction
Contents
Section 4: M Codes (Miscellaneous Functions).
M Codes (Miscellaneous Functions) - Introduction ...................................... 99 List of M Codes supported by Denford CNC Controls .................................. 100 M (Program Stop) ................................................................................... 101 M1 (Optional Stop) .................................................................................... 101 M2 (End of Program) ................................................................................. 101 M3 (Spindle Forward) ................................................................................ 101 M4 (Spindle Reverse) ................................................................................ 101 M5 (Spindle Stop) ...................................................................................... 102 M6 (Automatic Tool Change) ..................................................................... 102 M8 (Coolant On) ........................................................................................ 102 M9 (Coolant Off) ........................................................................................ 102 M1 (Chuck Open) ...................................................................................... 102 M11 (Chuck Close) ....................................................................................... 102 M13 (Spindle Forward and Coolant On)....................................................... 103 M14 (Spindle Reverse and Coolant On) ...................................................... 103 M25 (Tailstock Quill Extend) ......................................................................... 103 M26 (Tailstock Quill Retract) ........................................................................ 103 M3 (Program Stop and Reset)................................................................... 104 M4 (Parts Catcher Extend) ........................................................................ 104 M41 (Parts Catcher Retract) ........................................................................ 104 M62, M63, M64, M65, M66, M76, M77 (Auxiliary Output Functions) ........... 104 M98 (Sub Program Call)............................................................................... 105 M99 (Sub Program End and Return)............................................................ 105
Section 1 - Introduction - 5
6 - Section 1 - Introduction
1: What is CNC?
CNC (Computer Numerical Control) is the general term used for a system which controls the functions of a machine tool using coded instructions processed by a computer.
The application of CNC to a manual machine allows its operation to become fully automated. Combining this with the use of a part program enhances the ability of the machine to perform repeat tasks with high degrees of accuracy.
Section 1 - Introduction - 7
G&M Codes.
Control Signals.
8 - Section 1 - Introduction
A Part Program is a list of coded instructions which describes how the designed component, or part, will be manufactured. These coded instructions are called data - a series of letters and numbers. The part program includes all the geometrical and technological data to perform the required machine functions and movements to manufacture the part. The part program can be further broken down into separate lines of data, each line describing a particular set of machining operations. These lines, which run in sequence, are called blocks. A block of data contains words, sometimes called codes. Each word refers to a specific cutting/movement command or machine function. The programming language recognised by the CNC, the machine controller, is an I.S.O. code, which includes the G and M code groups. Each program word is composed from a letter, called the address, along with a number.
Word example - G1
Address example - G
Addresses N refers to the block number. G refers to the G code (Preparatory function). X refers to the absolute distance travelled by the slide tool in the X axis direction. U refers to the incremental distance travelled by the slide tool in the X axis direction. Z refers to the absolute distance travelled by the slide tool in the Z axis direction. W refers to the incremental distance travelled by the slide tool in the Z axis direction. F refers to the feed rate. M refers to the M code (Miscellaneous function). S refers to the spindle speed. T refers to the tooling management. Each block, or program line, contains addresses which appear in this order : N , G , X (or U) , Z (or W) , F , M , S , T ; This order should be maintained throughout every block in the program, although individual blocks may not necessarily contain all these addresses.
Program end.
The above listing shows an example program using the Denford programming system. For the program to operate correctly on a genuine FANUC control, the CAD/CAM software information and billet size definitions must be removed from the listing.
G and M Programming for CNC Lathes Section 2 - Basic Programming - 11
Main Program.
O1 N1 G21; [BILLET X.... Y.... Z.... N2 ...... ; N3 ...... ; N4 ...... ; N5 ...... ; N6 ...... ; N7 ...... ; N8 M98 P1; N9 ...... ; N1 ...... ; N11 ...... ; N12 ...... ; N13 ...... ; N14 ...... ; N15 M3;
Sub Program 1.
O1 N1 ...... ; N2 ...... ; N3 ...... ; N4 ...... ; N5 ...... ; N6 ...... ; N7 ...... ; N8 ...... ; N9 ...... ; N1 ...... ; N11 M98 P2; N12 ...... ; N13 ...... ; N14 ...... ; N15 ...... ; N16 M99;
Sub Program 2.
O2 N1 ...... ; N2 ...... ; N3 ...... ; N4 ...... ; N5 ...... ; N6 ...... ; N7 ...... ; N8 ...... ; N9 ...... ; N1 ...... ; N11 ...... ; N12 ...... ; N13 ...... ; N14 ...... ; N15 ...... ; N16 M99;
One-Loop Nesting.
Two-Loop Nesting.
Note 2.
If cutter compensation is required on a tool and the co-ordinates for the tool are within the sub program, the cutter compensation must be applied and cancelled within the sub program.
Note 3.
To call a sub program the M98 code is used followed by P (the number of the sub program required). For example, M98 P2 This command is read call program number 2.
Note 4.
A sub program call command (M98 P) can be specified along with a move command in the same block. For example, G1 X42.5 M98 P1;
Note 5.
At the end of a sub program, the M99 code is entered. This returns control to the main program. The M99 code will return control to the next block after the M98 sub program call block in the main program. If the code M99 P is entered, control will pass to the main program at a block with the N number equal to that of the P number stated after the M99 code. For example, M99 P16 This command is read return to the main program at block number N16.
When the repetition is omitted, the sub program will be called once only. For example, M98 P11 This command is read call the sub program number 1 ten times.
2: Billet Definition
The Billet Definition is a feature which is only used in the Denford programming system. It defines the size of the workpiece billet for use in the simulation sections of the Denford machine software. The billet definition command has no outcome on the actual machining of the part. The billet definition command is written at the start of the main program. The previous block usually states the units of measurement to be applied to the billet dimensions, ie, G21 (Metric data input) or G2 (Imperial data input). For example, N1 G21; [BILLET X44.8 Z65.; These two commands are read. program line number 1 states that all units are to be measured in Metric, the billet is a bar with a diameter of 44.8mm and a length protruding from chuck/collet face of 65.mm.
Note 1.
A program that has been written on a Denford control (or using Denford CAD/ CAM post processor software) will not operate directly on a genuine FANUC machine. The simulation sections of the program are incompatible with the FANUC control. For the program to run successfully, lines referring to the CAD/CAM software (at the beginning of the program) and the billet definition block must be deleted.
Note 1.
Sub program numbers must be saved between the ranges 1 to 9999, ie, using a four digit number. It is recommended that all programs saved have filenames also between these numbers.
Note 2.
Before saving a program to disk or hard drive, check that the program name you wish to use has not been used on another file. If the program is saved using a name identical to an old program file, the old program file will be overwritten.
Note 3.
Programs that need to be used at a later date on genuine FANUC controls must have their program number stated on the first program block. The format for inserting a FANUC compatible program number line is as follows: O
Four digit program number. Address code O.
Note 1.
The block number must be written at the start of a program line when used.
Note 2.
It is recommended that all blocks are numbered using a four digit number which rises between each block in steps of 1. This allows the program to be edited at a later date, ie, new blocks can be inserted or deleted as required. For example, N 1 .... N 2 .... N 3 .... N 4 .... etc....
Note 3.
Even when block numbering is not a priority, it is useful to insert block numbers at important points in the program, such as tool change commands. This will help if a program search is used in the future.
2: Block Configuration
The sequence in which address codes appear in each block should remain consistent throughout the program. It is recommended that the order of these address codes follows the example shown below:
N G X. Z. F M S T ; U. W.
Block sequence number. Preparatory function. Interpolation function. Feedrate function. Miscellaneous function. Spindle function. Tool End of function. block signal.
Note 1.
Each block may not necessarily contain all these items.
2: Tool Movement
The tool moves along straight lines and arcs forming the workpiece shape.
+ X Axis Direction.
P3 P2 P1
2: Tool Movement
b) Taper Movement.
Program command format: G1 X _ _ _ _ Z _ _ _ _ ; (P1 - P2) Diagram: Taper Movement.
+ X Axis Direction.
+ Z Axis Direction. P2 P1
2: Tool Movement
c) Tool Movement along an arc.
Program command format: G2 X _ _ _ _ Z _ _ _ _ R _ _ _ _ ; (P1 - P2) or G3 X _ _ _ _ Z _ _ _ _ R _ _ _ _ ; (P1 - P2) The function of moving the tool along straight lines and arcs is called the Interpolation. Symbols of the programmed commands G1, G2 and G3 are called the Preparatory functions and specify the type of interpolation conducted in the control unit.
+ X Axis Direction.
+ Z Axis Direction. P2 P1
2: Thread Cutting
Thread cutting of equal lead straight threads can be cut using G76 or G92 commands. In G76 and G92, the lead is specified numerically following the address letter F.
2: Feed Function
The movement of the tool at a specified speed for cutting is called the Feedrate. The feedrate is defined using the address lettter F followed by a numerical value. The two types of feedrate used are G98 (feedrate per minute) and G99 (feedrate per revolution). In G2 Imperial units, the feedrate is defined by Inches per minute. In G21 Metric units, the feedrate is defined by Millimetres per minute. For example: (G2, G98) G1 X _ _ _ _ (G2, G99) G1 X _ _ _ _ (G21, G98) G1 X _ _ _ _ (G21, G99) G1 X _ _ _ _
Z _ _ _ _ F6 Inches per minute Z _ _ _ _ F.6 Inches per minute Z _ _ _ _ F15 Millimetres per minute Z _ _ _ _ F.15 Millimetres per minute
2: Tool Function
3 4 2
6 7
Tool profiles can be changed during a program using the tool function command for an automatic toolpost. By specifying a tool number, a signal is transmitted from the CNC to the machine tool, where upon the toolpost will index to the corresponding tool number. The tool number is defined using the address lettter T followed by a numerical value. An automatic tool change is defined using the M6 code, called a Miscellaneous function, followed by the new tool number required. For example, M6 T1 (Tool number 1 and offset number 1) M6 T1 (Tool number 1 and offset number 1) M6 T15 (Tool number 1 and offest number 5)
+ Z Axis Direction.
30 DIA.
50
The example above shows four different ways that can be used to write a block within a program that defines a taper: Absolute/Absolute G1 X3 Z-5 F.15 ; Incremental/Incremental G1 U1 W-52 F.15 ; Absolute/Incremental G1 X3 W-52 F.15 ; Incremental/Absolute G1 U1 Z-5 F.15 ;
20 DIA.
Note 1.
A "/" mark must be specified at the start of the block. If it is placed elsewhere in the block, the information from the "/" mark to the ";" mark (the end of block mark) will be ignored, whilst the information before the "/" mark will be effective.
Note 2.
It is not necessary to enter a modal G code in repetitive blocks within a program. For example: If all movements are G1 (linear cutting command) then G1 is entered on the first block and omitted from all subsequent blocks. This G code will remain active until an interpolation change is commanded (using G, G2 or G3).
Note 3.
The machine controller has the ability to interpret a maximum of four G codes in one single block of data. However, these G codes must be from separate modal groups. When two or more G codes from the same group are specified in the same block, the CNC will only make the last stated G code from that modal group effective.
Note 2.
G codes marked with an * are set at machine power up and when the machine is reset or the emergency stop button is activated.
Note 1.
The rate of movement is set by the manufacturer of the machine tool. The rate of movement can be reduced from 1% to %, but only in increments of 1%, by using the feed override controls (see specific machine operating manual).
Note 2.
On instruction to perform the G command, the two slides (the X and Z axes) move completely independant of each other at a maximum feedrate, along a non-vector (sometimes called a non-linear) type path.
In the above example, the G command will instruct both slides to begin moving, both at a maximum feedrate. When both slides begin moving the tool will appear to traverse diagonally, a composite movement of both axes moving together. When one axis reaches its finishing co-ordinate, the other axis will continue to move until it reaches its own finishing co-ordinate. This gives the impression that the tool "changes" direction. Working example: Program Block instructing a move to Position P1. G X3. Z2.
+ X Axis Direction. X 3. Diameter. 2. P1 Tool Movement. + Z Axis Direction.
Z . Datum Face.
X 16. Diameter.
Z . Datum Face.
Note 5.
The G code is modal and is therefore incompatible with G1, G2 and G3 codes in the same block.
Note 6.
A G code can be written into a program in two ways. G or G.
The feedrate value programmed into the G1 command is the actual feedrate along the proposed tool path, not the feedrate of the axis/slide. On single axis moves (ie, the tool moves exactly parallel to the X axis direction or the Z direction), the slide will feed at the rate stated in the G1 command. On two axis moves (ie, the tool is moving diagonally), both slides will have to operate exactly the same length of time in order to produce a single diagonal, or vector, move. The machine controller will calculate the separate feedrates for both the X and Z slides, enabling the actual vector feedrate to equal that stated in the G1 command. The axis co-ordinate moves following a G1 command can be programmed in absolute values (relative to a set datum point) as X and Z, or incremental values (relative to the last stated co-ordinate in the program) as U and W. It is also possible to program one axis with an absolute value and the other axis with an incremental value (U-Z or X-W).
Absolute.
Incremental.
In the above programs, both G1 and the F feedrate value are modal, ie, their commands continue onto the next block without having to be restated.
+ X Axis Direction.
P3 P2 P1 25. 25. 5. 4. Diameter. Datum (Zero) Position. G and M Programming for CNC Lathes Section 3 - G Code Programming - 35
Note 3.
If no feedrate is programmed on a G1 command, the machine controller will set a feedrate of F.1 mm per rev. on G99 mode (Feed per revolution), or F1 mm per min. on G98 mode (Feed per minute).
Note 4.
If a block containing G1 and a feedrate F_ is executed and the following block contains a G command, the machine controller will retain this F_ value in its memory. The G command will usually set the feedrate to its maximum value. On overriding the G command with a block containing G1, G2 or G3, the original F_ value will be released from memory and become active.
Note 5.
The G1 code is modal and is therefore incompatible with G, G2 and G3 codes in the same block.
Note 6.
A G1 code can be written into a program in two ways. G1 or G1.
The G2 code executes a cutting movement following a clockwise circular path, at a set feedrate. The G3 code executes a cutting movement following an anticlockwise circular path, at a set feedrate. The definitions of clockwise (G2) and anticlockwise (G3) are fixed according to the system of co-ordinates in the diagram below.
+X G3 G2 +Z
When programming arcs, the end point of the arc is specified by the address X, Z when stated as an absolute position, or U, W when stated as an incremental position. This arc end point is sometimes referred to as the target position. Using an absolute position (X, Z), the value is the dimension of the end point of the arc in relation to the datum position of the component. Using an incremental position (U, W), the co-ordinate of the end point is the distance the tool moves from the start position of the arc. This can either be a plus (+) value or a minus (-) value depending on the movement of the machine slides in relation to the start position.
I and K
To program an arc when only the arc centre is given (the radius is unknown) use the address letters I and K. I relates to the address X and is the incremental value and direction (+/-) from the start point of the arc in the X axis to the arc centre (see diagram below). K relates to the address Z and is the incremental value and direction (+/-) from the start point of the arc in the Z axis to the arc centre (see diagram below).
+ X Axis Direction. End Point (X,Z)
Z (+ve)
X (+ve)
Z (+ve)
Start Point
Z (+ve)
Note 1.
When programming arcs using the address R (arc radius), the value of R must be equal to, or greater than half the longest distance travelled by either axis.
Note 2.
For an arc greater than 18 degrees, two separate arcs have to be programmed.
Note 3.
A G2 code can be written into a program in two ways. G2 or G2. A G3 code can be written into a program in two ways. G3 or G3.
3: G Codes - G4 (Dwell)
The G4 code is used to enter a set time delay into the program. The dwell value is programmed using the address letters X (time in seconds), U (time in seconds) or P (time in 1/1 seconds), followed by a number indicating this dwell value. For example: G4 X1. ; This command is read perform a dwell of 1 second duration. G4 U1.5 ; This command is read perform a dwell of 1.5 seconds duration. G4 P2 ; This command is read perform a dwell of 2 seconds duration.
Note 1.
A decimal point cannot be used with the address P.
Note 2.
The dwell is performed at the start of the block in which it is programmed.
Note 3.
The dwell begins when the commanded feedrate of the previous block reaches zero. For the slides to remain motionless in terms of revolutions, the current r.p.m. must be known and the length of the dwell based upon that speed.
Note 4.
The maximum value of a dwell time is 9999 seconds.
Note 5.
G4 is a non-modal G code. It is only active in the block in which it is programmed.
Note 6.
A G4 code can be written into a program in two ways. G4 or G4.
Note 1.
The status of G2 or G21 in the machine controller is dependant on the option that is saved to the disc.
Note 2.
A G2 code must not be changed for a G21 code (or vice versa) during the program.
Note 3.
When switching between G2 and G21, the offsets must be set according to the units of measurement being used.
Note 4.
G 2 and G21 are both modal G codes within the same modal group.
P1
8mm Dia.
+ Z Axis Direction.
Zero Datum.
4mm
To avoid this collision, the tool is sent on a path which includes the additional, or intermediate, point P2. The intermediate point is used to allow the tool to move completely clear from the billet, before continuing onto the reference point, P3, shown below.
P2 Intermediate point P3 Reference point
P1
8mm Dia.
+ Z Axis Direction.
4mm
Working example: Block required to perform this operation would read, G28 X1. Z-4. ;
P1
+ Z Axis Direction.
Note 3.
G28 is a non-modal G code. It is only active in the block in which it is programmed.
Tool.
Tool Nose Radius. Software Reference Point (Imaginary Tool Nose) - This is the point used by the software to follow the programmed path line.
Tool nose radius compensation is not required if the tool cuts parallel to the X and Z axes, as shown below. The software reference point and the cutting edge of the tool both follow the same path.
X Axis Direction. + X Axis Direction. + Z Axis Direction. G and M Programming for CNC Lathes
Path followed by software reference point (dotted line) matches path followed by tool cutting edge (solid line) along X axis.
Z Axis Direction. Path followed by software reference point (dotted line) matches path followed by tool cutting edge (solid line) along Z axis. Software Reference Point. 46 - Section 3 - G Code Programming Tool Cutting Edge.
Direction of Travel.
Direction of Travel.
In the above tip code box, the amount in box number 7, translates to a radius of 1.2mm.
Tool 1 2 _ _ 15 16
R .4 .8 _ _ . .4
T 3 2 _ _ 4
Note
From the eight tool direction numbers available to indicate the orientation of the imaginary tool nose, the numbers 2, 3 and 4 correspond to: 2 - Boring bar cutting towards the chuck. 3 - Standard right hand knife tool cutting towards the chuck. 4 - Standard left hand knife tool cutting away from the chuck.
The two diagrams below illustrate the direction of compensation codes G41 and G42, in relation to your eye level.
Tool Direction
Eye Level
Part
Billet Chuck
Billet Chuck
+ X Axis Direction. + Z Axis Direction. G42 Programmed Path Direction G41 Programmed Path Direction G and M Programming for CNC Lathes
Billet Chuck
Billet Chuck
Note 1.
A G2 or G3 circular interpolation command cannot be specified in the start-up block.
Note 2.
In tool nose radius compensation start-up, two blocks are read into the CNC control. The first block is performed and the second block is entered and held in memory. In subsequent compensation moves, two blocks are read in advance, so the CNC control has the block currently being performed and the next two blocks in memory. This is because tool nose radius compensation always needs to know what happens in the move following the one being currently performed. The CNC control can plan ahead to calculate the correct end position for the current move, that will also be the correct start position allowing for cutter compensation, for the next move.
Note 3.
The codes G4, G41 and G42 are modal, belonging to the same modal family. They are incompatible with each other on the same block.
+X Axis
3 2 1
(,)
+Z Axis
Billet
In diagram 1, the zero datum is set at the face end of the billet, along its centreline, simply to make the diagrams and graphs easier to follow. Note that the zero datum may be set at another position on your machine. The tool is currently at the position Z=4, X=3. Position (,) is the zero datum.
3 2 1
(,)
+Z Axis
Billet
In diagram 2, a command is programmed instructing the entire co-ordinates grid (the graph paper) to shift so that the tool position will line up with the co-ordinates Z=1, X=1. Note that the command instructs the grid to move, not the tool. G5 X1 Z1 This command is read move the entire co-ordinates grid so that the position Z=1, X=1 is now at the current position of the tool.
(,)
+Z Axis
Billet
In diagram 3, the tool position now reads Z=1, X=1, even though the tool is still exactly the same distance away from the billet as it was in diagram 1. Recap : General G5 command layout for co-ordinate system setting using absolute values : G5 X..... Z..... where, X and Z values represent the required tool position co-ordinates. This command is read set the current tool position to the X..... and Z..... values. All future absolute dimensions are now relative to a "new" zero datum position.
Note 1.
The two functions feedrate, F, and spindle speed, S, commanded between the sequence numbers ns and nf will only be effective in the G7 operation.
Note2.
When the finishing pass is ended by reading the nf sequence number, the tool returns to the position it was originally at before the G7 was commanded.
Note 3.
In the blocks between the sequence numbers ns to nf, no sub programs can be called into operation.
Program Pathline F A U2
where, R = Rapid Traverse F = Feed U1 = Depth of cut in X axis U2 = Finishing allowance in X axis W = Finishing allowance in Z axis
Note 1. Any F (Feed rate) or S (Spindle speed, rpm) commands between ns to nf block numbers will only be effective on the finishing pass (G7). Note 2. Prior to writing the command G71 within the program, the tool is positioned at the start point.
Note 2.
Only G, G1, G2, G3 and G4 can be programmed between ns and nf blocks. Four cutting patterns can be used with G71: 1) Outside turning tool moving towards the spindle. 2) Outside turning tool moving away from the spindle. 3) Internal turning tool moving towards the spindle. 4) Internal turning tool moving away from the spindle. These 4 cutting patterns are illustrated opposite.
Note 1.
Only a steadily increasing, decreasing or parallel toolpath between A and B is permitted, depending on the cutting pattern.
A Start Point B
+ X Axis Direction.
+ Z Axis Direction. The plus and minus signs of U and W refer to the for the material that must be left on the billet to allow a clean finishing cut.
A A
Start Point
4 U (-) W (-) Both Linear and Circular Interpolation is Possible. Start Point G and M Programming for CNC Lathes B Section 3 - G Code Programming - 65
1 Rad. 3 Rad. 12 35 3
(Diameter Designation, Metric Input). N4 N5 N6 N7 N8 N9 N1 N11 N12 N13 N14 N15 N16 N17 N18 ....... ; G X38. Z2. ; (Start and Finish Position) G71 U1.5 R.5 ; G71 P8 Q17 U2. W.1 F.15 ; G1 X16. F.3 ; ( ns ) Z.5 ; X2. Z-1.5 F.5 ; Z-3. F.75 ; X23. ; G3 X25. Z-24. R1. ; G1 X3. Z-65. ; Z-74. ; G2 X36. Z-77. R3. ; G1 X38.5 ; ( nf ) G7 P8 Q17 ; (Finishing Pass)
15
15
15
(Diameter Designation, Metric Input). N6 N7 N8 N9 N1 N11 N12 N13 N14 N15 N16 N17 N18 .......... ; G X16. Z2. ; ( Start and Finish Position ) G71 U1.25 R.5 ; G71 P1 Q17 U-1.5 W.7 F.75 ; G1 X36. F.3 ; ( ns ) Z.5 ; X32. Z-1.5 F.5 ; Z-15. F.7 ; X2. Z-3. ; Z-43.5 ; G3 X17. Z-45 R1.5 F.5 ; G1 X15.8 ; ( nf ) G7 P1 Q17 ; (Finishing Pass)
R F
Programmed Pathline.
where, F = Feed. R = Rapid Traverse. W(1) = Depth of cut. W(2) = Finishing cut in Z axis. U = Finishing cut in X axis.
B W(2)
A G72 command is written in the following format : G72 W (1) R ; G72 P ns Q nf U W (2) F ; where, W (1) = Depth of cut in the Z axis. R = Escaping amount (Retract). ns = Sequence number of the first block of the programmed finished shape. nf = Sequence number of the last block of the programmed finished shape. U = Distance and direction of the finishing allowance in the X axis. W (2) = Distance and direction of the finishing allowance in the Z axis (Diameter value). F = Feedrate for Roughing.
Note 2.
If a finishing pass (ie, a single cut following the same pathline) is required, the block G7 P ns Q nf would be read into the CNC control after the G72 command has been completed. This method is similar to the finishing pass on a G71 command. Four cutting patterns can be used with G72: 1) Internal facing with the Z axis cut moving towards the spindle. 2) Internal facing with the Z axis cut moving away from the spindle. 3) External facing with the Z axis cut moving towards the spindle. 4) External facing with the Z axis cut moving away from the spindle. These 4 cutting patterns are illustrated on the next page.
Note 1.
Only a steadily increasing, decreasing or parallel toolpath between A and B is permitted, depending on the cutting pattern.
Start Point
2 + X Axis Direction. U (-) W (-) Both Linear and Circular Interpolation is Possible.
The plus and minus signs of U and W refer to the for the material that must be left on the billet to allow a clean finishing cut.
Start Point
Start Point
4 U (-) W (-) Both Linear and Circular Interpolation is Possible. G and M Programming for CNC Lathes
(Diameter Designation, Metric Input). N4 N5 N6 N7 N8 N9 N1 N11 N12 N13 N14 N15 N16 N17 .......... ; G X81. Z2. ; ( Start and Finish Position ) G72 W2. R.5 ; G72 P8 Q15 U.5 W1. F.1 ; G Z-6. ; ( ns ) G1 X8. F.2 ; X6. W1. F.75 ; W1. ; X4. W1. ; W2. ; X18. W11. ; W1. ; ( nf ) G7 P8 Q15 ; (Finishing Pass) .......... ;
(R) B
(F)
Programmed Pathline.
A where, W(2) F = Feed. R = Repeat patterns. U (1) = Distance and direction of relief in the X axis direction (Radius value). W (1) = Distance and direction of relief in the Z axis direction.
A G73 command is written in the following format : G73 U (1) W (1) R ; G73 P ns Q nf U (2) W (2) F ; where, U (1) = Depth of cut in the X axis (Radius value). W (1) = Depth of cut in the Z axis. R = Escaping amount (Retract). ns = Sequence number of the first block of the programmed finished shape. nf = Sequence number of the last block of the programmed finished shape. U (2) = Distance and direction of the finishing allowance in the X axis (Diameter value). W (2) = Distance and direction of the finishing allowance in the Z axis (Diameter value). F = Feedrate for Roughing.
U(2)
U(1) + U(2)
Note 2.
The four cutting patterns used by G71 can also be used by G73. Example of programming an external profile using a multiple repetitive cycle (G7, G71).
11 11 8 Dia 6 Dia 4 Dia 2 Dia + X Axis Direction. + Z Axis Direction. 2mm Chamfer. 1 4 35 3 Section 3 - G Code Programming - 73
(Diameter Designation, Metric Input). N5 N6 N7 N8 N9 N1 N11 N12 N13 N14 N15 N16 N17 .......... ; G X82. Z2. ; G73 U1. W1. R3. ; G73 P9 Q15 U2. W1. F.1 ; G X15. Z.5 ; ( ns ) G1 X2. Z-2. F.5 ; Z-3. F.75 ; X4. Z-65. ; Z-95. ; G2 X6. Z-15. R1. ; G1 X82. Z-116. ; ( nf ) G7 P9 Q15 ; .......... ;
P Q' Q Z(W) Q Q
A G74 command is written in the following format : G74 R (1) ; G74 X (U) Z (W) P Q R (2) F ; where, R(1) = Peck Return amount. X (U) = Diameter of the bore if stepover is used (ie, stepping along the X axis to repeat the peck cycle). Z (W) = Depth of the bore. P = Stepover in the X axis measured in micron's (without sign). Q = Pecking depth in the Z axis measured in micron's (without sign). F = Feedrate.
Note 1.
G74 is a chip break cycle (ie, peck drilling), not a deep hole drilling cycle where the drill retracts clear of the hole when it pecks.
Note 2.
In a G74, the absolute values of X and Z may be replaced with the incremental values U and W.
R(2)
X/2 (U/2)
2.
25 Dia. U-Drill.
(Diameter Designation, Metric Input). N7 N8 N9 N1 N11 .......... ; G X3. Z2. ; G74 R.5 ; G74 X35. Z-4. P4 Q1 R.5 F.2 ; .......... ;
In the above program, the drill is positioned at X3. Z2.. From this point, the G74 command is read into the CNC control. The drill moves forward 1mm (the Q value) and then retracts .5mm (the R(1) value). These movements are repeated until the full depth is reached (the Z (W) value). At this point, the drill moves in a minus direction along the X axis (towards the spindle centreline) .5mm (the R (2) value), then it retracts at a rapid traverse rate to the start position in the Z axis. From this point, the drill moves in a positive direction along the X axis 4mm (the P value) and the sequence of peck drilling moves is repeated until the X axis diameter and Z axis depth stop is reached. The tool will repeat this operation of peck drilling each cut-in section until the correct hole diameter is achieved. After all the moves have been completed, the drill is retracted back to the start position in the Z axis and the last cut-in section in the X axis.
(Diameter Designation, Metric Input). N7 N8 N9 N1 N11 .......... ; G X. Z2. ; G74 R.5 ; G74 Z-5. Q1 F.15 ; .......... ;
In the above program, the drill is positioned at a point in the X and Z axis and the G74 is read into the CNC control. The drill moves forward 1mm (the Q value) and then retracts back .5mm (the R (1) value). These moves are repeated until the Z axis depth is reached. The drill then moves back at a rapid traverse rate to the start position and the next block is read into the CNC control. The following terms do not apply to this example since no X axis stepover is required; X (U) ; P ; R (2).
Note 1.
The Q value does not have to divide into the total Z depth equally.
R (1) Z (W)
A G75 command is written in the following format : G75 R (1) ; G75 X (U) Z (W) P Q R (2) F ; where, the definitions of R (1) , X (U) , Z (W) , P , Q , R (2) and F are the same as G74.
Note 1.
When G75 is used for grooving, the retract move ( R(2) ) at the base of the groove may be impossible, unless a clearance amount has been provided. If no clearance amount has been left, the R(2) value must be zero or omitted from the block.
X (U)
5 4
(Diameter Designation, Metric Input). N5 N6 N7 N8 N9 N1 N11 N12 .......... ; G X52. Z-8. ; G1 X2. F.75 ; G X52. ; W-2.5 ; G75 R.5 ; G75 X2. Z-4. P5 Q25 R.5 F.75 ; .......... ;
A G76 command is written in the following format : G76 P (A) / (B) / (C) Q (Min) R ; G76 X(U) Z(W) P (DEP) Q (1st) F ; where, P (A) = Number of thread finishing passes (1 to 99). P (B) = The chamfer amount. This is the angle at which the tool leaves the billet, at the end of the thread cutting cycle. = The angle of the tool tip (8, 6, 55, 3, 29 and ). P (C) Note - (A), (B) and (C) are all specified at the same time by the address P, eg, P366 = number of cuts is 3, chamfer amount of 6 and tool angle of 6. Q (Min) = Minimum cutting depth (in microns). When the depth of the cut calculated by the CNC control becomes less than this limit, the cutting depth is clamped at this minimum value. R __ = Finishing allowance. This is the final, or finishing, cuts applied to the thread. The number of stages to complete this finishing allowance is determined by the value of P(A), ie, the value of R divided by the P(A) number of finishing passes equals the value of each finishing allowance stage. X(U) __ = The end position of the thread in the X axis (the core diameter). Z(W) __ = The end position of the thread in the Z axis. P (DEP) = The depth of the thread as a radius value (in microns). Q (1st) = The depth of the first pass as a radius value (in microns). F __ = The size of the thread pitch.
Note 2.
Four symmetrical patterns can be considered depending on the sign (plus or minus) of the X and Z axis movements.
Note 3.
It is possible to cut internal threads with the G76 command.
Note 4.
Thread cutting is repeated along the same tool path from rough cutting through to the final finishing cut, so the spindle speed must remain constant. The G96 command for constant surface speed must not be used when the thread cutting cycle is active, otherwise the pitch of thread could be incorrectly machined.
Note 5.
When possible, allow a 5mm run-in at the start of the thread pass, to allow for any lag in the machine drive system, etc... Without a sufficient run-in the start of the thread could be machined with an incorrect pitch.
Note 6.
The feedrate override on the CNC control panel will be ineffective, ie, it is set at a fixed value of 1% during the entire thread cutting cycle.
Note 7.
Although the spindle override feature is not disabled whilst a thread is being cut, it should not be activated since an incorrect thread pitch will be generated.
Note 9.
The machine can be set to read one block at a time by pressing the [SINGLE BLOCK] key on the CNC controller panel. When operating in single block mode, one press of the [CYCLE START] key will activate one complete threading pass (cut on, thread pass, cut off and rapid back). If single block mode is activated during a threading operation, the tool motion will stop at the beginning (cut on) of the next complete threading pass.
16 Dia. x 2. Pitch.
(Diameter Designation, Metric Input). N9 N1 N11 N12 N13 .......... ; G X16.25 Z5. ; G76 P36 Q15 R.3 ; G76 X13.546 Z-4. P1226 Q3 F2. ; .......... ;
(Diameter Designation, Metric Input). N9 N1 N11 N12 N13 .......... ; G X27.9 Z5. ; G76 P46 Q1 R.4 ; G76 X3. Z-4. P92 Q2 F1.5 ; .......... ;
1 5 15 2
(Diameter Designation, Metric Input). Absolute. N5 .......... ; N6 G X. Z2. ; N7 G81 Z-2. F.1 ; N8 Z-35. ; N9 Z-45. ; N1 Z-5. ; N11 G........ ;
(Diameter Designation, Metric Input). Incremental. N5 .......... ; N6 G X. Z2. ; N7 N8 N9 N1 N11 G81 W-22. F.1 ; W-37. ; W-47. ; W-52. ; G........ ;
In the above program, the drill is positioned at the start point and G81 Z-2. F.1 is read into the machine controller. The drill then cuts into the billet to the stated Z position (Z-2.) and then raid traverses back to the starting point. At this point, the next block is read into the machine controller (Z-35.). The drill rapid traverses forward to within 1mm of the previous cut (Z-19.) where cutting starts for this pass. These moves continue (cut-in, rapid out to start, rapid back to within 1mm), until the last block containing a Z axis block has been completed. The next block containing a different G code will cancel the G81 command.
P3(F)
P2(F)
P1(R)
A G9 command for straight line cutting is written in the following format: G9 X (U) __ Z (W) __ F __ ; where, F __ = Feedrate.
Note 1.
When programming using incremental dimensions (U, W), the direction of the tool movement along paths "P1" and "P2" will define the signs of U and W (plus or minus). In the above program, both U and W are minus.
Note 2.
The G9 straight cut command can be used for both internal and external cutting operations.
U/2
P4(R)
P3(F)
P1(R) R
A G9 command for taper cutting is written in the following format: G9 X (U) __ Z (W) __ R __ F __ ; where, R __ = Dimension defining taper angle. F __ = Feedrate.
Note 1.
The sign of R depends on the cutting direction of path "P1" - in the above program, R is entered as a minus value.
Note 2.
When programming using incremental dimensions (U, W), the direction of the tool movement along paths "P1" and "P2" will define the signs of U and W (plus or minus). In the above program, both U and W are minus.
Note 3.
The G9 taper cut command can be used for both internal and external cutting operations.
X/2
U/2
U/2
P3(F) c
P4(R) P2(F)
a P1(R)
The Four Diagrams opposite show the Relationship of the signs of the following values for G9 Taper cutting, U, W and R. + X Axis Direction.
Sign Designations for the Path shown below are: U=Plus sign ; W=Minus sign ; R=Plus sign.
+ Z Axis Direction. Co-ordinate Positions at the four points labelled on each Diagram are as follows: a= (X,Z) b= (X+U+R,Z) c= (X+U,Z+W) d= (X,Z+W)
Sign Designations for the Path shown below are: U=Minus sign ; W=Minus sign ; R=Plus sign.
U/2
Sign Designations for the Path shown below are: U=Plus sign ; W=Minus sign ; R=Minus sign.
R
Section 3 - G Code Programming - 87
R U/2
U/2
P4(R)
25
(Diameter Designation, Metric Input). N5 N6 N7 N8 N9 N1 N11 N12 .......... ; G X41. Z2. ; G9 X35. Z-45. F.1 ; X3. ; X25. Z-25. ; X2. ; X2. R-3.794 ; G........ ;
P3(R)
P1(R)
Note 1.
G92 can be used to cut both internal and external threads.
Note 2.
Plunge cutting is used with G92 to generate a thread, from the first pass to the last finishing pass. Plunge cutting involves the tool approaching the billet at 9 degrees to its surface, rather than approaching the billet at a run-in angle. Effectively, this means greater stresses are placed on the tool since both edges will be cutting. As the tool cuts further into the material, more surface area is in contact with the tool tip.
Note 3.
The same notes on thread cutting in G76 regarding speed, run-in, feed hold etc. are also relevant to G92.
U/2
(Diameter Designation, Metric Input). N4 N5 N6 N7 N8 N9 N1 N11 N12 N13 N14 N15 .......... ; G X16.25 Z5. ; G92 X15.6 Z-4. F2. ; X15.2 ; X14.8 ; X14.5 ; X14.2 ; X13.9 ; X13.9 ; X13.546 ; X13.546 ; G....... ;
(Spring Pass)
Note 1.
When operating in Single Block Mode, each move of the tool requires one press of the [CYCLE START] button.
Note 2.
G94 can be used for internal and external cutting.
Note 1.
When programming using incremental positioning, the signs (plus or minus) of U, W and R will depend on the directions of paths "P1" and "P2", in a similar way to the methods shown for the command G9. In the above example, U, W and R are all minus values.
6Dia.
1Dia. 5 5 5
(Diameter Designation, Metric Input). N5 N6 N7 N8 N9 N1 N11 N12 N13 N14 N15 N16 N17 N18 .......... ; G X61. Z2. ; G94 X2. Z-2.5 F.1 ; Z-5. ; Z-7.5 ; Z-1. ; Z-12.5 ; Z-15. ; G X2. Z5. ; G94 X1. Z2.5 R-2.5 ; Z. ; Z-2.5 ; Z-5. ; .......... ;
Note 1.
The programmed surface speed can be altered during the running of the program, using the spindle override control on the machine operating panel. The range of adjustment varies from 5% to 12%, with 1% being the programmed speed.
Note 2.
When constant surface speed control is used, the work co-ordinate system setting and co-ordinate system shift (ie, the software datum point) must be set so that the centre of rotation meets the Z axis (ie, at X=0.0).
Note 3.
The G50 code defining clamping of maximum spindle speed must be used in conjunction with G96, so as not to overrun the safe maximum spindle speed of the chuck.
Note 4.
The G96 code is modal. It will remain active until G97, M02 or M30 codes are programmed into the same block, or the Emergency Stop or Machine Reset is activated.
Note 1.
The programmed spindle speed can be altered during the running of the program, using the spindle override control on the machine operating panel. The range of adjustment varies from 5% to 12%, with 1% being the programmed speed.
Note 2.
The G97 code is modal. It will remain active until G96, M02 or M30 codes are programmed into the same block, or the Emergency Stop or Machine Reset is activated.
Note 3.
The machine controller will assume G97 is active, in the following situations: Initially, when the machine is switched on. After an M02 code is programmed. After an M30 code is programmed. After the Emergency Stop button is used. After the machine has been Reset.
Note 1.
The programmed feedrate can be altered during the running of the program, using the feedrate override control on the machine operating panel. The range of adjustment varies from % to 15%, with 1% being the programmed speed.
Note 2.
The G99 code is modal. It remains active until G98, M02, M30 Emergency Stop or Machine Reset is activated.
Note 2.
Only one M code can be programmed within each block. If more than one M code is programmed, the machine controller will only perform the last stated M code.
4: M Codes - M62, M63, M64, M65, M66, M76, M77 (Auxiliary Output Functions)
M62 - Auxiliary Output 1 On. M63 - Auxiliary Output 2 On. M64 - Auxiliary Output 1 Off. M65 - Auxiliary Output 2 Off. M66 - Wait for Auxiliary Output 1 On. M67 - Wait for Auxiliary Output 2 On. M76 - Wait for Auxiliary Output 1 Off. M77 - Wait for Auxiliary Output 2 Off. These codes allow a signal to be sent from the machine controller to a different device, such as a robot, then wait for a return signal instructing that the device has completed its function.
Notes