Unit 4: CNC Language And Structure – Manufacturing Processes 4-5
After completing this unit, you should be able to:
- Identify the programs list instructions.
- Understand the Program Format
- Describe Letter Address Commands codes
- Describe Special Character Code Definitions.
- Understand the G & M Codes.
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.
The blocks are arranged in the following order:
- Program Start
- Load Tool
- Spindle On
- Coolant On
- Rapid to position above part
- Machining operation
- Coolant Off
- Spindle Off
- Move to safe position
- End program
The steps listed above represent the simplest type of CNC program, where only one tool is used and one operation performed. Programs that use multiple tools repeat steps two through nine for each.
Table 3 and Table 4 in section G & M Codes show the most common G and M codes that should be memorized if possible.
Like any language, the G-code language has rules. For example, some codes are modal, meaning they do not have to be repeated if they do not change between blocks. Some codes have different meanings depending on how and where there are used.
While these rules are covered in this chapter, do not concern yourself with learning every nuance of the language. It is the job of the job of the CAD/CAM software Post Processor to properly format and write the CNC program.
Program FormatThe program in Table 1: below machines a square contour and drills a hole.
Block | Description | Purpose |
% O1234 (T1 0.25 END MILL) 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 |
T1 M6 S9200 M3 | Load Tool #1. Spindle Speed 9200 RPM, On CW. | Change Tool |
G54 M8 G00 X-0.025 Y-0.275 G43 Z1.H1 Z0.1 G01 Z-0.1 F18. | 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. | Move to Position |
G41 Y0.1 D1 F36. Y2.025 X2.025 Y-0.025 X-0.025 G40 X-0.4 G00 Z1. | 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. | Machine Contour |
M5 M9 (T2 0.25 DRILL) T2 M6 S3820 M3 | Spindle Off. Coolant Off. Tool description for operator. Load Tool #2. Spindle Speed 3820 RPM, On CW. | Change Tool |
M8 X1. Y1. G43 Z1.H2 Z0.25 | Coolant On. Rapid above hole. Rapid to safe plane, use Tool Length Offset 2. Rapid to feed plane. | Move to Position |
G98 G81 Z-0.325 R0.1 F12. G80 Z1. | Drill hole (canned) cycle, Depth Z-.325, F12. Cancel drill cycle. Rapid to safe plane. | Drill Hole |
M5 M9 G91 G28 Z0 G91 G28 X0 Y0 G90 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 |
The command block controls the machine tool through the use of letter address commands. Some are used more than once, and their meaning changes based on which G-code appears in the same block.
Codes are either modal, which means they remain in effect until cancelled or changed, or non-modal, which means they are effective only in the current block. As you can see, many of the letter addresses are chosen in a logical manner (T for tool, S for spindle, F for feed rate, etc.).
The table below lists the most common Letter Address Commands codes.
Table 2: Letter Address Commands Codes
Variable | Description | Definitions |
A | Absolute or incremental position ofAaxis (rotational axis around X axis) | A,B,C – 4th/5th Axis Rotary Motion Rotation about the X, Y or Z-axis respectively.The angle is in degrees and up to three decimal places precision. G01 A45.325B90. |
B | Absolute or incremental position of B axis (rotational axis around Y axis) | Same as A |
C | Absolute or incremental position of C axis (rotational axis around Z axis) | Same as B |
D | Defines diameter or radial offset used for cutter compensation | Used to compensate for tool diameter wear and deflection.D is accompanied by an integer that isthe same as the tool number (T5 uses D5,etc). No decimal point is used. Itis always usedin 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. G01 G41 X2.D1 |
E | Precision feed rate for threading on lathes | |
F | Defines 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 placesaccuracy (for tap cycles) and require a decimal point. G01 X2.Y0. F30. |
G | Address for preparatory commands | G commands often tell the control what kind of motion is wanted (e.g., rapid positioning, linear feed, circular feed, fixed cycle) or what offset value to use. G02 X2.Y2.I.50J0. |
H | Defines tool length offset; Incremental axis corresponding to C axis (e.g., on a turn-mill) | This code calls a tool length offset (TLO) register on the control. The control 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 Z2. |
I | Defines arc size inX axisfor G02 or G03 arc commands. Also used as a parameter within some fixed cycles. | For arc moves (G2/G3), this is the incremental X-distance from the arc start point to the arc center. Certain drill cycles also use I as an optional parameter. G02 X.5 Y2.500I0.J0.250 |
J | Defines arc size inY axisfor G02 or G03 arc commands. Also used as a parameter within some fixed cycles. | For arc moves (G2/G3), this is the incremental Y-distance from the arc start point to the arc center. Certain drill cycles also use J as an optional parameter. G02 X.5 Y2.500 I0.J0.250 |
K | Defines arc size inZ axisfor G02 or G03 arc commands. Also used as a parameter within some fixed cycles, equal to L address. | For anarcmove (G2/G3) this is the incremental Z-distance from the arc start point 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 G03 X.3 Z2.500 I0.K0.250 |
L | Fixed cycle loop count; Specification of what register to edit using G10 | Fixed cycle loop count: Defines number of repetitions (“loops”) of a fixed cycle at each position.Assumed to be 1 unless programmed with another integer.Sometimes the K addressis usedinstead of L. With incremental positioning (G91), a series of equally spaced holes can be programmed as a loop rather than as individual positions.G10 use:Specificationof what register to edit (work offsets, tool radius offsets, tool length offsets, etc.). |
M | Miscellaneous function | Always accompanied by an integer that determines its meaning.Only one M-codeis allowedin each block of code. Expanded definitions of M-codes appear later in this chapter. M08 |
N | Line (block) number in program; System parameter number to be changed using G10 | 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 controlmemorymost 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 T02 M06 |
O | Program name | Programs are stored on the control by their program number. Thisis an integer thatis preceded by the letter O and has no decimal places. O1234 (Exercise 1) |
P | Serves as parameter address for various G and M codes | Dwell (delay) in seconds.Accompanied by G4 unless used within certain drill cycles. G4 P.1 |
Q | Peck increment in canned cycles | The incremental feed distance per pass in a peck drill cycle. G83 X2.000 Y2.000 Z-.625 F20.R.2 Q.2 P9. |
R | Defines size of arc radius or defines retract height in canned cycles | Arcs can be defined using the arc radius R or I,J,Kvectors. IJK’s are more reliable than R’s so itis recommendedto use them instead. Ris also usedby drill cycles as the return plane Z value. G83 Z-.625 F20.R.2 Q.2 P9. |
S | Defines speed, either spindle speed or surface speed depending on mode | Spindle speed in revolutions per minute (RPM). It is an integer value with no decimal, and always used in conjunction with M03 (Spindle on CW) or M04 (Spindle on CCW). S2500M03 |
T | Tool selection | Selects tool. It is an integer value always accompanied by M6 (tool change code). T01 M06 |
U | Incremental axis corresponding to X axis (typically only lathe group A controls) Also defines dwell time on some machines. | In these controls, X and U obviate G90 and G91, respectively. On these lathes, G90 is instead a fixed cycle address for roughing. |
V | Incremental axis corresponding to Y axis | Until the 2000s, the V address was very rarely used, because most lathes that used U andWdidn’thave a Y-axis, so they didn’t use V. (Green et al 1996 did not even list V in their table of addresses.) That is still often the case, although the proliferation of live lathe tooling and turn-mill machining has made V address usage less rare than it used to be (Smid2008 shows an example). |
W | Incremental axis corresponding to Z axis (typically only lathe group A controls) | In these controls, Z and W obviate G90 and G91, respectively. On these lathes, G90 is instead a fixed cycle address for roughing. |
X | Absolute or incremental position ofX axis. | Coordinate data for the X-axis. Up to four places after the decimalare allowedand trailing zeros are not used. Coordinates are modal, so there is no need to repeat them in subsequent blocks if they do not change. G01 X2.250F20. |
Y | Absolute or incremental position of Y axis | Coordinate data for the Y-axis. G01 Y2.250 F20. |
Z | Absolute or incremental position of Z axis | Coordinate data for the Z-axis. |
The following is a list of commonly used special characters, their meaning, use, and restrictions.
% – Program Start or End
All programs begin and end with % on a block by itself. This code is called tape rewind character (a holdover from the days when programs were loaded using paper tapes).
( ) – Comments
Comments to the operator must be all caps and enclosed within brackets. The maximum length of a comment is 40 characters and all characters are capitalized. (T02: 5/8 END MILL)
/ – Block Delete
Codes after this character are ignored if the Block Delete switch on the control is on. / M00
; – 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. N8 Z0.750 ;
G & M CodesG&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.
G-Codes
Codes that begin with G are called preparatory words because they prepare the machine for a certain type of motion.
Table 3: G-Code
Code | Description |
G00 | Rapid motion.Used to position the machine for non-milling moves. |
G01 | Line motion at a specified feed rate. |
G02 | Clockwise arc. |
G03 | Counterclockwise arc. |
G04 | Dwell. |
G28 | Return to machine home position. |
G40 | Cutter Diameter Compensation (CDC) off. |
G41 | Cutter Diameter Compensation (CDC) left. |
G42 | Cutter Diameter Compensation (CDC) right. |
G43 | Tool length offset (TLO). |
G54 | Fixture Offset #1. |
G55 | Fixture Offset #2. |
G56 | Fixture Offset #3. |
G57 | Fixture Offset #4. |
G58 | Fixture Offset #5. |
G59 | Fixture Offset #6. |
G80 | Cancel drill cycle. |
G81 | Simple drill cycle. |
G82 | Simple drill cycle with dwell. |
G83 | Peck drill cycle. |
G84 | Tap cycle. |
G90 | Absolute coordinate programming mode. |
G91 | Incremental coordinate programming mode. |
G98 | Drill cycle return to Initial point (R). |
G99 | Drill cycle return to Reference plane (last Z Height) |
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.
Table 4: M-Codes
Code | Description |
M00 | Program stop.Press Cycle Start button to continue. |
M01 | Optional stop. |
M02 | End of program. |
M03 | Spindle on Clockwise. |
M04 | Spindle on Counterclockwise. |
M05 | Spindle stop. |
M06 | Change tool. |
M08 | Coolant on. |
M09 | Coolant off. |
M30 | End program and press Cycle Start to run it again. |
Select G-Code Definitions (Expanded)
G00 – Rapid Move
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 G01, G00 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 motion as shown in Figure 18, below.
G00 X0. Y0.
Figure 1. G00 Motion Caution: The rapid speed of some machines can exceed 1. An incorrect offset or coordinate move can crash the machine faster than the operator can hit the emergency stop. Use the rapid feed override on the machine when running a program for the first time. Linear Motion is Straight Line Motion:G-Code is about motion, and the most common kind of motion found in part programs is straight line or linear motion. Motion is another one of those things in G-Code that is modal. You tell the controller what kind of motion you’d like with a G-Code and it remembers to always make that kind of motion until you tell it to change using another G-Code.
G00 for Fast Positioning ; Rapids Motion as fast as your machine will go. Used to move the cutter through air to the next position it will be cutting.
G01 for Slower Cutting Motion; Feed Motion slower, for cutting. Feedrate set by “F” G-Code.
F-word = “F” as in “Feedrate”.
S-word = “S” as in “Spindle Speed”, address is rpm.
Specifying Linear Motion With X, Y, and Z:
Specifying G00 or G01 does not cause any motion to happen–they merely tell the controller what type of motion is expected when you finally tell it where to move to. For actual motion you need to specify a destination using the X, Y, and Z words. To move to the part zero, we might issue a command like this:
G00 X0 Y0 Z0 Or use G01 if you want to go slower G01 X0 Y0 Z0 F40.
Interpolated motion or an interpolated move, When we specify multiple coordinates on a line, means more than one axis of the machine is moving at the same time. In fact, the controller will move them all at exactly the right speed relative to one another so that the cutter follows a straight line to the destination and moves at the feedrate.
If we specify the same destination, but spread the coordinates over multiple lines, each line is a separate move:
G00 X0 Y0 (Move to X0 Y0 in one move, keeping Z constant)
Z0 (Move to Z0 in one move, keeping X and Y constant)
G00 and G01 are modal, so we only have to specify them when we want to change modes.
Z Axis:
The concept of interpolated moves raises an interesting issue for the Z axis. It’s often a good idea to move the depth-of-cut-axis on its own, rather than as coordinated motion with other axes(X and Y). Whether you’re going to have a problem (collision) as the cutter gets close to the workpiece and fixturing. First moving in X and Y and then moving in Z , it’s much easier to judge whether an accidental collision is about to take place. You’re also much less likely to hit some random object sticking up, like a clamp, if you keep the cutter high until you’re directly over where you want to start cutting.
G02 and G03 Circular Motion is a Mode Initiated:
G02 establishes a mode for clockwise circular arcs.
G03 establishes a mode for counter-clockwise circular arcs.
The G02 or G03 mode is established, arcs are defined in G-Code by identifying their 2 endpoints and the center which must be equi-distant from each endpoint. The endpoints are easy. The current control point, or location when the block is begun establishes one endpoint. The other may be established by XYZ coordinates. The center is most commonly identified by using I, J, or K to establish relative offsets from the starting point of the arc to the center.
EXAMPLE OF CLOCKWISE ARC:
Figure 2. An Arc’s center with IJK
This arc starts at X0Y2. and finishes at X2.Y0. It’s center is at X0Y0. We could specify it in G-code like this:
G02 (Set up the clockwise arc mode)
X2Y0 I0J-2.0
The Center Using Radius “R”.
The center just by specifying the radius of the circle. Circle has a radius of 2, so the G-Code might be simply:
G02 X2Y0 R2
G17/G18/G19 – Plane Designation
Arcs must exist on a plane designated by the command G17 (XY), G18 (XZ) or G19 (YZ). G17 is the machine default.
Figure 3. Plane Designation
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 register can be thought of like a table that the control refers to with every move.
Table 5: Diameter Offset Register
Tool Diameter Offset | Value |
D1 | 0.0125 |
D2 | 0.0000 |
D3 | 0.0000 |
D4 | 0.0000 |
D5 | 0.0000 |
D6 | 0.0000 |
The value in the D-register is calculated by the machine tool operator, who monitors the finished size of part features, compares them with the print, and enters the difference in the register as needed to keep the part within specifications. If there is no deviation, the register is set to zero.
G01 G41 D1 X1.0 Y.25 F40.
G43 – Tool Length Compensation
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 like a table on the control:
Table 6: Work Offsets
Tool Length Resister | Z |
H1 | 10.236 |
H2 | 4.7510 |
H3 | 6.9652 |
H4 | 7.6841 |
H5 | 12.4483 |
H6 | 8.2250 |
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.
G43 H1 Z1.
G54 – Work Offset
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 the control:
Table 7: Work Offset
Work Offset | X | Y | Z |
G54 | 14.2567 | 6.6597 | 0.0000 |
G55 | 0.0000 | 0.0000 | 0.0000 |
G56 | 0.0000 | 0.0000 | 0.0000 |
G57 | 0.0000 | 0.0000 | 0.0000 |
G58 | 0.0000 | 0.0000 | 0.0000 |
G59 | 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 top of a 1-2-3 block) and the part Z-datum.
G54 X0. Y0.
UNIT TEST1. Please describe the CNC program list instruction.
2. All CNC program start and end with what?
3. Describe letter address Commands codes.
4. Please lists three special character codes.
5. Describe G and M codes.
6. Please describe G00 G90 G54 X0 Y0.
7. Please describe G00 G90 G43 H1 Z1.
8. What is the different between G00 and G01?
9. Explain the different between G02 and G03.
10. Please Describe the F and S word.
Previous: Unit 3: Vertical Milling Center Machine Motion Next: Unit 5: CNC Operation Back to topLicense
Manufacturing Processes 4-5 Copyright © by LamNgeun Virasak is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.
Share This Book
Share on TwitterTừ khóa » G91 G28 X0 Y0 Z0
-
Learn G28 X0. Y0. Z0. G-code - With Examples - Cnc Philosophy
-
G28 G-Code
-
G91 G28 X0 Y0 Z0 - YouTube
-
G28 G-Code: CNC Return To Reference [ Easy Tutorial & Guide ]
-
G28 Return To Machine Zero Point (Group 00) - Haas Automation Inc.
-
How The Heck Does G28 Work? - CNC Concepts, Inc.
-
G91 G28 Z0 - Narkive
-
G28 G-code: All You Need To Know About Homing - All3DP
-
Official Home G91 G28 X0 Y0 Z0 Shirt - Pinterest
-
G28 Versus G53 | Modern Machine Shop
-
G Codes G28 & G30: CNC Home And Reference Points
-
Official Home G91 G28 X0 Y0 Z0 Shirt - Premiumtstore