Contents[hide] |
[edit]Specific codes
G-codes are also called preparatory codes, and are any word in a CNC program that begins with the letter "G". Generally it is a code telling the machine tool what type of action to perform, such as:
- rapid move
- controlled feed move in a straight line or arc
- series of controlled feed moves that would result in a hole being bored, a workpiece cut (routed) to a specific dimension, or a decorative profile shape added to the edge of a workpiece.
- set tool information such as offset.
There are other codes; the type codes can be thought of like registers in a computer.
[edit]Letter addresses
Some letter addresses are used only in milling or only in turning; most are used in both. Bold below are the letters seen most frequently throughout a program.
Variable | Description | Corollary info | |
---|---|---|---|
A | Absolute or incremental position of A axis (rotational axis around X axis) | ||
B | Absolute or incremental position of B axis (rotational axis around Y axis) | ||
C | Absolute or incremental position of C axis (rotational axis around Z axis) | ||
D | Defines diameter or radial offset used for cutter compensation | ||
E | Precision feedrate for threading on lathes | ||
F | Defines feed rate | ||
G | Address for preparatory commands | G commands often tell the control what kind of motion is wanted (eg, rapid positioning, linear feed, circular feed, fixed cycle) or what offset value to use. | |
H | Defines tool length offset | ||
I | Defines arc size in X axis for G02 or G03 arc commands. Also used as a parameter within some fixed cycles. | ||
J | Defines arc size in Y axis for G02 or G03 arc commands. Also used as a parameter within some fixed cycles. | ||
K | Defines arc size in Z axis for G02 or G03 arc commands. Also used as a parameter within some fixed cycles, equal to L address (which see). | ||
L | Defines number of repetitions ("loops") of a fixed cycle at each position. | Assumed to be 1 unless programmed with another integer. Sometimes the K address is used instead of L. With incremental positioning (G91), a series of equally spaced holes can be programmed as a loop rather than as individual positions. | |
M | Miscellaneous function | Action code, auxiliary command; descriptions vary. Many M-codes call for machine functions, which is why people often say that the "M" stands for "machine", although it was not intended to. | |
N | Line number in program | Optional, so often omitted. | |
O | Program name | For example, O4501. | |
P | With G04, defines dwell time value. Also serves as a variable in some canned cycles, representing dwell times or other variables. Also used to call subroutines. | ||
Q | Peck increment in canned cycles | For example, G73, G83 (peck drilling cycles) | |
R | Defines size of arc radius or defines retract height in canned cycles | ||
S | Defines speed, either spindle speed or surface speed depending on mode | Data type = integer. In G97 mode (which is usually the default), an integer after S is interpreted as a number of rev/min (rpm). In G96 mode (CSS), an integer after S is interpreted as surface speed—sfm (G20) or m/min (G21). See also Speeds and feeds. | |
T | Tool selection | To understand how the T address works and how it interacts (or not) with M06, one must study the various methods, such as lathe turret programming, ATC fixed tool selection, ATC random memory tool selection, the concept of "next tool waiting", and empty tools. Programming on any particular machine tool requires knowing which method that machine uses. | |
U | Incremental axis parallel to X axis (typically only lathe group A controls) | In these controls, X and U obviate G90 and G91, respectively. | |
V | Incremental axis parallel to Y axis | Very rarely used. Most lathes that use U and W don't have a Y-axis, so they don't use V. | |
W | Incremental axis parallel to Z axis (typically only lathe group A controls) | In these controls, Z and W obviate G90 and G91, respectively. | |
X | Absolute or incremental position of X axis. Also defines dwell time on some machines (instead of "P" or "U"). | ||
Y | Absolute or incremental position of Y axis | ||
Z | Absolute or incremental position of Z axis | The main spindle's axis of rotation often determines which axis of a machine tool is labeled as Z. |
[edit]List of G-codes for milling
Code | Description | Corollary info |
---|---|---|
G00 | Rapid positioning | |
G01 | Linear interpolation | |
G02 | CW circular interpolation | |
G03 | CCW circular interpolation | |
G04 | Dwell | Takes an address for dwell period (may be X, U, or P) |
G05.1 Q1. | Ai Nano contour control | |
G05 P10000 | HPCC | |
G07 | Imaginary axis designation | |
G09 | Exact stop check | |
G10/G11 | Programmable Data input/Data write cancel | |
G12 | CW full-circle interpolation | Fixed cycle for ease of programming 360° circular interpolation with blend-radius lead-in and lead-out. Not standard on Fanuc controls. |
G13 | CCW full-circle interpolation | Fixed cycle for ease of programming 360° circular interpolation with blend-radius lead-in and lead-out. Not standard on Fanuc controls. |
G17 | XY plane selection | |
G18 | ZX plane selection | |
G19 | YZ plane selection | |
G20 | Programming in inches | Somewhat uncommon except in USA and (to lesser extent) Canada and UK. However, in the global marketplace, competence with both G20 and G21 always stands some chance of being necessary at any time. The usual minimum increment in G20 is one ten-thousandth of an inch (0.0001"), which is a larger distance than the usual minimum increment in G21 (one thousandth of a millimeter, .001 mm, that is, one micrometre). This physical difference sometimes favors G21 programming. |
G21 | Programming in millimeters (mm) | Prevalent worldwide. However, in the global marketplace, competence with both G20 and G21 always stands some chance of being necessary at any time. |
G28 | Return to home position (machine zero, aka machine reference point) | Takes X Y Z addresses which define the intermediate point that the tool tip will pass through on its way home to machine zero. They are in terms of part zero (aka program zero), NOT machine zero. |
G30 | Return to secondary home position (machine zero, aka machine reference point) | Takes a P address specifying which machine zero point is desired, if the machine has several secondary points (P1 to P4). Takes X Y Z addresses which define the intermediate point that the tool tip will pass through on its way home to machine zero. They are in terms of part zero (aka program zero), NOT machine zero. |
G31 | Skip function (used for probes and tool length measurement systems) | |
G33 | Constant pitch threading | |
G34 | Variable pitch threading | |
G40 | Tool radius compensation off | Kills G41 or G42. |
G41 | Tool radius compensation left | Given righthand-helix cutter and M03 spindle direction, G41 corresponds to climb milling. Takes an address (D or H) that calls an offset register value for radius. |
G42 | Tool radius compensation right | Given righthand-helix cutter and M03 spindle direction, G42 corresponds to conventional milling. Takes an address (D or H) that calls an offset register value for radius. |
G43 | Tool height offset compensation negative | Takes an address, usually H, to call the tool length offset register value. The value is negative because it will be added to the gauge line position. G43 is the commonly used version (vs G44). |
G44 | Tool height offset compensation positive | Takes an address, usually H, to call the tool length offset register value. The value is positive because it will be subtracted from the gauge line position. G44 is the seldom-used version (vs G43). |
G45 | Axis offset single increase | |
G46 | Axis offset single decrease | |
G47 | Axis offset double increase | |
G48 | Axis offset double decrease | |
G49 | Tool length offset compensation cancel | Kills G43 or G44. |
G50 | Define the maximum spindle speed | |
G52 | Local coordinate system (LCS) | |
G53 | Machine coordinate system | |
G54 to G59 | Work coordinate systems (WCSs) | Have largely replaced position register (G92). |
G54.1 P1 to P48 | Extended work coordinate systems | Up to 48 more WCSs besides the 6 provided as standard by G54 to G59. Note floating-point extension of G-code data type (formerly all integers). Other examples have also evolved (e.g., G84.2). Modern controls have the hardware to handle it. |
G73 | Peck drilling cycle - high-speed (NO full retraction from pecks) | Retracts only as far as a clearance increment (system parameter). For when chipbreaking is the main concern, but chip clogging of flutes is not. |
G74 | Tapping cycle - lefthandthread, M04 spindle direction | |
G76 | Fine boring canned cycle | |
G80 | Cancel canned cycle | Kills all cycles such as G73, G83, G88, etc. Z-axis returns either to Z-initial level or R-level, as programmed (G98 or G99, respectively). |
G81 | Simple drilling cycle | No dwell |
G82 | Drilling cycle with dwell | Dwells at hole bottom (Z-depth) for the number of milliseconds specified by the P address. Good for when hole bottom finish matters. |
G83 | Peck drilling cycle (full retraction from pecks) | Returns to R-level after each peck. Good for clearing flutes of chips. |
G84 | Tapping cycle -righthand thread, M03 spindle direction | |
G84.2 | Tapping cycle -righthand thread, M03 spindle direction - rigid toolholder | |
G90 | Absolute programming | Positioning defined with reference to part zero |
G91 | Incremental programming | Positioning defined with reference to previous position |
G92 | Position register (programming of vector from part zero to tool tip) | If the operator was not allowed to overwrite G92 X Y Z values, then the programmer was effectively mandating that the part be placed on the table with perfect precision in a certain machine-referenced XYZ point. If programmer and/or management were ignorant of setup realities, this was very inefficient. WCSs (G54 et al) are a newer way to relate the part origin to the machine origin. |
G94 | Feedrate per minute | |
G95 | Feedrate per revolution | |
G96 | Constant surface speed | |
G97 | Constant spindle speed | |
G98 | Return to initial Z level in canned cycle | |
G99 | Return to R level in canned cycle |
[edit]List of G-codes for turning
Code | Description |
---|---|
G00 | Rapid positioning |
G01 | Linear interpolation |
G02 | CW circular interpolation |
G03 | CCW circular interpolation |
G04 | Dwell |
G09 | Exact stop check |
G10/G11 | Programmable Data input/Data write cancel |
G20 | Programming in inches |
G21 | Programming in mm |
G28 | Return to home position (machine zero, machine reference point) |
G30 | Return to secondary home position (machine zero, machine reference point) |
G40 | Tool radius compensation off |
G41 | Tool radius compensation left |
G42 | Tool radius compensation right |
G50 | Define the maximum spindle speed OR position register |
G53 | Machine coordinate system |
G54 to G59 | Work coordinate systems |
G54.1 P1 to P48 | Extended work coordinate systems |
G80 | Cancel canned cycle |
G90 | Absolute programming (type B and C systems; type A uses U/W address instead) |
G91 | Incremental programming (type B and C systems; type A uses U/W address instead) |
G92 | Position register (type B and C systems; type A uses G50) |
G96 | Constant surface speed (CSS) |
G97 | Constant spindle speed (that is, CSS cancel) |
G98 | Feedrate per minute (type A) |
G99 | Feedrate per revolution (type A) |
[edit]List of M-codes for milling
Code | Description | Corollary info |
---|---|---|
M00 | Compulsory stop | (non-optional—machine will always stop upon reaching M00 in the program execution) |
M01 | Optional stop | (machine will only stop at M01 if operator has pushed the optional stop button) |
M02 | End of program | (no return to program top; may or may not reset register values) |
M03 | Spindle on (CW rotation) | |
M04 | Spindle on (CCW rotation) | |
M05 | Spindle stop | |
M06 | Automatic tool change (ATC) | To understand how the T address works and how it interacts (or not) with M06, one must study the various methods, such as lathe turret programming, ATC fixed tool selection, ATC random memory tool selection, the concept of "next tool waiting", and empty tools. Programming on any particular machine tool requires knowing which method that machine uses. |
M07 | Coolant on (mist) | |
M08 | Coolant on (flood) | |
M09 | Coolant off | |
M10 | Pallet clamp on | |
M11 | Pallet clamp off | |
M19 | Spindle orientation | Spindle orientation is more often called within cycles (automatically) or during setup (manually), but it is also available under program control via M19. The abbreviation OSS (oriented spindle stop) may be seen in reference to an oriented stop within cycles. |
M21 | Mirror, X-axis | |
M22 | Mirror, Y-axis | |
M23 | Mirror OFF | |
M30 | End of program with return to program top | |
M48 | Feedrate override allowed | |
M49 | Feedrate override NOT allowed | This rule is also called (automatically) within tapping cycles, where feed is precisely correlated to speed. Same with spindle speed override and feed hold button. |
M60 | Automatic pallet change (APC) | |
M98 | Subprogram call | |
M99 | Subprogram end | Usually placed at end of subprogram, where it returns execution control to the M98 point of the main program. |
[edit]List of M-codes for turning
Code | Description | Corollary info |
---|---|---|
M00 | Compulsory stop | (non-optional—machine will always stop upon reaching M00 in the program execution) |
M01 | Optional stop | (machine will only stop at M01 if operator has pushed the optional stop button) |
M02 | End of program | (no return to program top; may or may not reset register values) |
M03 | Spindle on (CW rotation) | |
M04 | Spindle on (CCW rotation) | |
M05 | Spindle stop | |
M06 | Automatic tool change (ATC) | (many lathes do not use M06 because the T address itself indexes the turret) |
M07 | Coolant on (mist) | |
M08 | Coolant on (flood) | |
M09 | Coolant off | |
M19 | Spindle orientation | |
M21 | Tailstock forward | |
M22 | Tailstock backward | |
M23 | Thread gradual pullout ON | |
M24 | Thread gradual pullout OFF | |
M30 | End of program with return to program top | |
M41 | Gear select - gear 1 | |
M42 | Gear select - gear 2 | |
M43 | Gear select - gear 3 | |
M44 | Gear select - gear 4 | |
M48 | Feedrate override allowed | |
M49 | Feedrate override NOT allowed | This rule is also called (automatically) within tapping cycles, where feed is precisely correlated to speed. Same with spindle speed override and feed hold button. |
M98 | Subprogram call | |
M99 | Subprogram end | Usually placed at end of subprogram, where it returns execution control to the M98 point of the main program. Can also be used in main program with block skip for endless loop of main program on bar work (until operator toggles block skip) |
[edit]Example program
This is a generic program that demonstrates the use of G-Code to turn a 1" diameter X 1" long part. Assume that a bar of material is in the machine and that the bar is slightly oversized in length and diameter and that the bar protrudes by more than 1" from the face of the chuck. (Caution: This is generic, it might not work on any real machine! Pay particular attention to point 5 below.)
Line | Code | Description |
---|---|---|
O4968 | (Sample face and turn program) | |
N01 | M216 | (Turn on load monitor) |
N02 | G20 G90 G54 G40 | (Inch units. Absolute mode. Call work offset values. Cancel any existing tool radius offset.) |
N03 | G50 S2000 | (Set maximum spindle speed rev/min - preparing for G96 CSS coming soon) |
N04 | M01 | (Optional stop) |
N05 | T0303 M6 | (Select tool 3 from the carousel, use tool offset values located in line 3 of the program table, index the turret to select new tool) |
N06 | G96 S854 M42 M03 M08 | (Variable speed cutting, 854 sfm, select spindle gear, start spindle CW rotation, turn on the coolant flood) |
N07 | G41 G00 X1.1 Z1.1 | (Call tool radius offset. Rapid feed to a point 0.1" from the end of the bar and 0.05" from the side) |
N08 | G01 Z1.0 F.05 | (Feed in horizontally until the tool is standing 1" from the datum ie program Z-zero) |
N09 | X-0.002 | (Feed down until the tool is slightly past center, thus facing the end of the bar) |
N10 | G00 Z1.1 | (Rapid feed 0.1" away from the end of the bar - clear the part) |
N11 | X1.0 | (Rapid feed up until the tool is standing at the finished OD) |
N12 | G01 Z0.0 F.05 | (Feed in horizontally cutting the bar to 1" diameter all the way to the datum, feeding at 0.050" per revolution) |
N13 | G00 X1.1 M05 M09 | (Clear the part, stop the spindle, turn off the coolant) |
N14 | G91 G28 X0 | (Home X axis - return to machine X-zero passing through no intermediate X point [incremental X0]) |
N15 | G91 G28 Z0 | (Home Z axis - return to machine Z-zero passing through no intermediate Z point [incremental Z0]) |
N16 | G90 M215 | (Return to absolute mode. Turn off load monitor) |
N17 | M30 | (Program stop, rewind to beginning of program) |
% |
Several points to note:
- There is room for some programming style, even in this short program. The grouping of codes in line N06 could have been put on multiple lines. Doing so may have made it easier to follow program execution.
- Many codes are "modal", meaning that they stay in effect until they are cancelled or replaced by a contradictory code. For example, once variable speed cutting (CSS) had been selected (G96), it stayed in effect until the end of the program. In operation, the spindle speed would increase as the tool neared the center of the work in order to maintain a constant surface speed. Similarly, once rapid feed was selected (G00), all tool movements would be rapid until a feed rate code (G01, G02, G03) was selected.
- It is common practice to use a load monitor with CNC machinery. The load monitor will stop the machine if the spindle or feed loads exceed a preset value that is set during the set-up operation. The job of the load monitor is to prevent machine damage in the event of tool breakage or a programming mistake. On small or hobby machines, it can warn of a tool that is becoming dull and needs to be replaced or sharpened.
- It is common practice to bring the tool in rapidly to a "safe" point that is close to the part - in this case 0.1" away - and then start feeding the tool. How close that "safe" distance is, depends on the skill of the programmer and maximum material condition for the raw stock.
- If the program is wrong, there is a high probability that the machine will crash, or ram the tool into the part under high power. This can be costly, especially in newer machining centers. It is possible to intersperse the program with optional stops (M01 code) which allow the program to be run piecemeal for testing purposes. The optional stops remain in the program but they are skipped during the normal running of the machine. Thankfully, most CAD/CAM software ships with CNC simulators that will display the movement of the tool as the program executes. Many modern CNC machines also allow programmers to execute the program in a simulation mode and observe the operating parameters of the machine at a particular execution point. This enables programmers to discover semantic errors (as opposed to syntax errors) before losing material or tools to an incorrect program. Depending on the size of the part, wax blocks may be used for testing purposes as well.
- For pedagogical purposes, line numbers have been included in the program above. They are usually not necessary for operation of a machine, so they are seldom used in industry. However, if branching or looping statements are used in the code, then line numbers may well be included as the target of those statements (e.g. GOTO N99).
- Some machines do not allow multiple M codes in the same line.
[edit]Programming environments
G-code's programming environments have evolved in parallel with those of general programming—from the earliest environments (e.g., writing a program with a pencil, typing it into a tape puncher) to the latest environments that stack CAD, CAM, and richly featured G-code editors. (G-code editors are analogous to XML editors, using colors and indents semantically [plus other features] to aid the user in ways that basic text editors can't. CAM packages are analogous to IDEs in general programming.)
Two high-level paradigm shifts have been (1) abandoning "manual programming" (with nothing but a pencil or text editor and a human mind) for CAM software systems that generate G-code automatically via postprocessors (analogous to the development of visual techniques in general programming), and (2) abandoning hardcoded constructs for parametric ones (analogous to the difference in general programming between hardcoding a constant into an equation versus declaring it a variable and assigning new values to it at will). Macro (parametric) CNC programming uses human-friendly variable names, relational operators, and loop structures much as general programming does, to capture information and logic with machine-readable semantics. Whereas older manual CNC programming could only describe particular instances of parts in numeric form, parametric CAM programming describes abstractions which can be flowed with ease into a wide variety of instances. The difference is analogous to creating text as bitmaps versus using character encoding and glyphs, or to the way that HTML passed through a phase of using content markup for presentation purposes, then matured toward the CSS model. In all of these cases, a higher layer of abstraction was introduced in order to pursue what was missing semantically.
STEP-NC reflects the same theme, which can be viewed as yet another step along a path that started with the development of machine tools, jigs and fixtures, and numerical control, which all sought to "build the skill into the tool". Recent developments of G-code and STEP-NC aim to build the information and semantics into the tool.
Very good.
ตอบลบมีแบบภาาาไทย มีไหม