CNC Programming and Operation
CNC Programming and Operation
BLOCK ->
PROGRAMMING FORMATS
WORD ADDRESS FORMAT based on a combinations of one letter and one or more digits, can be supplements by a symbol , such as a minus sign or a decimal point. Each letter, digit or symbol represents one character in the program and in the control memory.. This unique alpha-numerical arrangement creates a word where the letter is the address followed by a numerical data with or without symbols.
CNC Language and Structure CNC programs list instructions to be performed in the order
they are written. They read like a book, left to right and top-down. Each sentence in a CNC program is written on a separate line, called a Block. Blocks are arranged in a specific sequence that promotes safety, predictability and readability, so it is important to adhere to a standard program structure. Typically, blocks are arranged in the following order:
Program Start Load Tool Spindle On Coolant On
CNC Language and Structure CNC programs list instructions to be performed in the order
they are written. They read like a book, left to right and top-down. Each sentence in a CNC program is written on a separate line, called a Block. Blocks are arranged in a specific sequence that promotes safety, predictability and readability, so it is important to adhere to a standard program structure. Typically, blocks are arranged in the following order:
Program Start Load Tool Spindle On Coolant On
Block
Description
Purpose
% O0001 (PROJECT1) (T1 0.25 END MILL) N1 G17 G20 G40 G49 G80 G90
Start of program. Program number (Program Name). Tool description for operator. Safety block to ensure machine is in safe mode.
Start Program
N2 T1 M6 N3 S9200 M3
Change Tool
N4 G54 N5 M8 N6 G00 X-0.025 Y-0.275 N7 G43 Z1. H1 N8 Z0.1 N9 G01 Z-0.1 F18. N10 G41 Y0.1 D1 F36. N11 Y2.025 N12 X2.025 N13 Y-0.025 N14 X-0.025 N15 G40 X-0.4 N16 G00 Z1. N17 M5 N18 M9 (T2 0.25 DRILL) N19 T2 M6 N20 S3820 M3
Use Fixture Offset #1. Coolant On. Rapid above part. Rapid to safe plane, use Tool Length Offset #1. Rapid to feed plane. Line move to cutting depth at 18 IPM. CDC Left, Lead in line, Dia. Offset #1, 36 IPM. Line move. Line move. Line move. Line move. Turn CDC off with lead-out move. Rapid to safe plane. Spindle Off. Coolant Off. Tool description for operator. Load Tool #2. Spindle Speed 3820 RPM, On CW.
Move to Position
Machine Contour
Change Tool
Coolant On. Rapid above hole. Rapid to safe plane, use Tool Length Offset 2. Rapid to feed plane.
Move to Position
N25 G98 G81 Z-0.325 R0.1 F12. N26 G80 N27 Z1.
Drill hole (canned) cycle, Depth Z-.325, F12. Cancel drill cycle. Rapid to safe plane.
Drill Hole
N28 M5 N29 M9 N30 G91 G28 Z0 N31 G91 G28 X0 Y0 N32 G90 N33 M30 %
Spindle Off. Coolant Off. Return to machine Home position in Z. Return to machine Home position in XY. Reset to absolute positioning mode (for safety). Reset program to beginning. End Program.
End Program
integer that is the same as the tool number (T1 uses D1, etc). No decimal point is used. It is always used in conjunction with G41 or G42 and a XY move (never an arc). When called, the control reads the register and offsets the tool path left (G41) or right (G42) by the value in the register. G1 G41 X1. D1
F - Feed Rate
Sets the feed rate when machining lines, arcs or drill cycles. Feed rate can be in
Inches per Minute (G94 mode) or Inverse Time (G93 mode). Feed rates can be up to three decimal places accuracy (for tap cycles) and require a decimal point. G1 X1. Y0. F18.
G - Preparatory Code
Always accompanied by an integer that determines its meaning. Most G-codes are
modal. Expanded definitions of G-codes appear in the next section of this chapter. G2 X1. Y1. I.25 J0.
combines the TLO and Fixture Offset Z values to know where the tool is in relation to the part datum. It is always accompanied by an integer (H1, H2, etc), G43, and Z coordinate. G43 H1 Z1.
to the arc center. Certain drill cycles also use I as an optional parameter. G2 X.1 Y2.025 I0. J0.125
the arc center. Certain drill cycles also use J as an optional parameter. G2 X.1 Y2.025 I0. J0.125
to the arc center. In the G17 plane, this is the incremental Z-distance for helical moves. Certain drill cycles also use J as an optional parameter. G18 G3 X.1 Z2.025 I0. K0.125
is allowed in each block of code. Expanded definitions of M-codes appear later in this chapter. M8
N - Block Number
Block numbers can make the CNC program easier to read. They are seldom
required for CAD/CAM generated programs with no subprograms. Because they take up control memory most 3D programs do not use block numbers. Block numbers are integers up to five characters long with no decimal point. They cannot appear before the tape start/end character (%) and usually do not appear before a comment only block. N100 T2 M6
O - Program Number
Programs are stored on the control by their program number. This is an integer that
P - Delay
Dwell (delay) in seconds. Accompanied by G4 unless used within certain drill
cycles. G4 P.1
than R's so it is recommended to use them instead. R is also used by drill cycles as the return plane Z value. G83 Z-.5 F12. R.1 Q.1 P5.
S - Spindle Speed
Spindle speed in revolutions per minute (RPM). It is an integer value with no
decimal, and always used in conjunction with M3 (Spindle on CW) or M4 (Spindle on CCW). S3820 M3
T - Tool number
Selects tool. It is an integer value always accompanied by M6 (tool change code).
T1 M6
X - X-Coordinate
Coordinate data for the X-axis. Up to four places after the decimal are allowed and
trailing zeros are not used. Coordinates are modal, so there is no need to repeat them in subsequent blocks if they do not change. G1 X1.1252
Code
K M
Meaning
Arc center Z-vector, also used in drill cycles. M-Code (miscellaneous code).
N
O
Cutter diameter compensation (CDC) offset address. Feed rate. G-Code (preparatory code). Tool length offset (TLO). Arc center X-vector, also used in drill cycles. Arc center Y-vector, also used in drill cycles.
Block Number.
Program Number. Dwell time. Used in drill cycles. Arc radius, also used in drill cycles. Spindle speed in RPM. Tool number. X-coordinate. Y-coordinate. Z-coordinate.
P Q R S T X Y Z
/ - Block Delete
Codes after this character are ignored if the Block Delete switch on the control is on. Ex. / M0
; - End of Block
This character is not visible when the CNC program is read in a text editor (carriage return), but does appear at the end of every block of code when the program is displayed on the machine control. Ex. N8 Z0.1 ;
G & M Codes
G&M Codes make up the most of the contents of the CNC program. The definition of each class of code and specific meanings of the most important codes are covered next.
Table 5.3: Common G-Codes Code G0 G1 Meaning Rapid motion. Used to position the machine for non-milling moves. Line motion at a specified feed rate.
G2
G3 G4 G28 G40 G41 G42 G43
Clockwise arc.
Counterclockwise arc. Dwell. Return to machine home position. Cutter Diameter Compensation (CDC) off. Cutter Diameter Compensation (CDC) left. Cutter Diameter Compensation (CDC) right. Tool length offset (TLO).
G54
G55 G56 G57 G58 G59 G80 G81 G82 G83 G84 G90 G91 G98 G99
M-Codes
Codes that begin with M are called miscellaneous words. They control machine auxiliary options like coolant and spindle direction. Only one M-code can appear in each block of code.
Meaning Program stop. Press Cycle Start button to continue. Optional stop. Only executed if Op Stop switch on the CNC control is turned ON. End of program. Spindle on Clockwise.
M4
M5 M6
Spindle on Counterclockwise.
Spindle stop. Change tool.
M8
M9 M30
Coolant on.
Coolant off. End program and press Cycle Start to run it again.
This code commands the machine to move as fast as it can to a specified point. It is always used with a coordinate position and is modal. Unlike G1, G0 does not coordinate the axes to move in a straight line. Rather, each axis moves at its maximum speed until it is satisfied. This results in "dogleg" motion as shown in Figure 5.1, below. Ex. G0 X0. Y0.
G1 - Linear Move
This command moves the tool in a straight line at a programmed feed rate. Ex. G1 X1. Y1.1255 F32 G2/G3 - CW/CCW Arc G2 commands clockwise arcs. G3 commands counterclockwise arcs. Arcs must exist on a plane (G17/G18/G19) and include the coordinates of the arc end point and IJK vectors indicating the arc center location.
Arcs must exist on a plane designated by the command G17 (XY), G18 (XZ) or G19 (YZ). G17 is the machine default.
G40/G41/G42
Cutter
Diameter
Compensation
(CDC)
CDC is a key to precision CNC machining, allowing the operator to compensate for tool wear and deflection by commanding the machine to veer left (G41) or right (G42) from the programmed path. G40 cancels cutter compensation. The amount of offset is entered in a CNC control D-register. The wear registerDiameter can be thought ofRegister like a table that the control refers to with Table: Offset every move.
G43 activates tool length compensation. It is always accompanied by an H-code and Z-move, where H is the tool length offset (TLO) register to read, and Z is the height to go to in reference to the part datum. The (TLO) can be thought of Offsets like a table on the control: Table: Work
Tool Length Resister H1 H2 H3 H4 H5 H6 Z 12.6280 6.3582 9.7852 6.8943 10.5673 7.1258
The TLO is combined with the active fixture offset on the control so
the machine knows where the tip of the tool is in relation to the part datum. Ex. G43 H1 Z1.
Work offsets are data registers in the CNC control that hold the distance from the machine home X, Y, Z position to the part datum. These offsets can be thought of like a Table: on Work Offsets table the control.
Work Offset G54 G55 G56 G57 G58 G59 X 14.2567 0.0000 0.0000 0.0000 0.0000 0.0000 Y 6.6597 0.0000 0.0000 0.0000 0.0000 0.0000 Z 2.0183 0.0000 0.0000 0.0000 0.0000 0.0000
The X and Y values represent the distance from the machine home to part datum XY. The Z value is the distance from the tool reference point (for example, the
Canned Cycles
Canned cycles are special codes that act like a macro. They are used for hole making and allow one compact block of code to command many moves. For example, a hole can be created using a peck drill cycle with two lines of code (left column) whereas the same move would require maybe twenty or more lines of code if each motion was commanded separately (right column).
Table: Canned Cycle vs. Expanded Code Canned Cycle Equivalent Motion: Expanded Code N70 G98 G83 X1. Y1. Z-1.04 R0.06 N70 Z0.06 Q0.15 P0 F9. N75 Z0.04 N75 G80 N80 G01 Z-0.19 F9. N85 G00 Z0.06 N90 Z-0.11 N95 G01 Z-0.34 N100 G00 Z0.06 N105 Z-0.26 N110 G01 Z-0.49. N115 G00 Z0.06 N120 Z-0.41 N125 G01 Z-0.64. N130 G00 Z0.06 N135 Z-0.56 N140 G01 Z-0.79 N145 G00 Z0.06 N150 Z-0.71 N155 G01 Z-0.94. N160 G00 Z0.06 N165 Z-0.86 N170 G01 Z-1.04. N175 G00 Z0.25
This cycle makes holes by feeding to depth at a programmed feed rate and then retracting at rapid rate. It is accompanied by G98 or G99, XYZ coordinates, feed rate, and R. R is the feed plane and Z is final depth of the tool tip. All drill cycles are accompanied by G98 or G99 that determine how high the tool retracts between holes. Ex. G0 Z1. G43 H1 G98 G81 X.5 Y.5 Z-1. R.1 F9.5
This cycle is identical to G81 except it includes a dwell value, P (in seconds). P is used to pause the tool feed rate at the final depth to create a clean countersink or counterbore finish. Ex. G0 Z1. G43 H1 G98 G82 X.5 Y.5 Z-.0925 P.1 R0.1 F9.5 G83 - Peck Drill A peck drill cycle is used on deep holes. The tool drills an incremental distance (Q) and then fully retracts from the hole. This breaks the chip, clears material out of the hole, and allows coolant to cool the drill and flush out the hole, reducing the chance of the tool breaking and producing a better quality hole. The simplest form of this cycle is shown in Figure 5.5. Another version of this cycle, called a deep drill cycle , uses I,J,K parameters to reduce the amount of peck as the hole gets deeper. Ex. G0 Z1. G43 H1 G83 X.5 Y.5 Z-1. R0.1 Q.25 F9.
Most modern machines support rigid tapping, which eliminates the need to use special tapping attachments. Rigid tapping precisely coordinates the spindle speed and feed to match the lead of the thread. It then stops and reverses the spindle at the bottom of the cycle to retract the tap. The parameters for the tap cycle are identical to simple drilling (G81). Ex. G0 Z1. G43 H1
G84 X.5 Y.5 Z-1.5 R0.1 F20.
G90 - Absolute Positioning
This code commands the machine to interpret coordinates as absolute position moves in the active Work Coordinate System. All programs are written in absolute coordinates.
This code commands the machine to interpret coordinates as incremental position moves. G91 is used by subprograms but most programming done with CAD/CAM software and does not use subprograms. The only common use of G91 is in combination with G28 to send the machine back to its home position at the end of the program. The machine must be set back to G90 mode in the next block as a safety measure. Ex. G91 G28 Z0 G90 G98 - Return to Initial Rapid Height This code is used in drill cycles to retract the tool to the clearance plane (set in the next previous block) between holes to avoid clamps. Ex. G0 Z1. G43 H1 G98 G81 Z-0.325 R0.1 F12.
This code is used in drill cycles to retract the tool to the rapid plane (R) between holes. G99 mode is the machine default and is used when clamp clearance between holes is not an issue. Ex. G0 Z1. G43 H1 G99 G81 Z-0.325 R0.1 F12.