This is an old revision of this page, as edited by AnomieBOT (talk | contribs) at 23:32, 23 January 2022 (Dating maintenance tags: {{Original research}}). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Revision as of 23:32, 23 January 2022 by AnomieBOT (talk | contribs) (Dating maintenance tags: {{Original research}})(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff) Programming languages For other uses, see G-code (disambiguation) and G programming language (disambiguation). "RS-274" redirects here. For the photoplotter format, see Gerber format.Paradigm | Procedural, Imperative |
---|---|
Designed by | Massachusetts Institute of Technology |
First appeared | 1950s (first edition) |
Filename extensions | .gcode, .mpt, .mpf, .nc and several others |
Major implementations | |
many, mainly Siemens Sinumerik, FANUC, Haas, Heidenhain, Mazak. Generally there is one international standard—ISO 6983. |
G-code (also RS-274) is the most widely used computer numerical control (CNC) programming language. It is used mainly in computer-aided manufacturing to control automated machine tools, and has many variants.
G-code instructions are provided to a machine controller (industrial computer) that tells the motors where to move, how fast to move, and what path to follow. The two most common situations are that, within a machine tool such as a lathe or mill, a cutting tool is moved according to these instructions through a toolpath cutting away material to leave only the finished workpiece and/or an unfinished workpiece is precisely positioned in any of up to nine axes around the three dimensions relative to a toolpath and, either or both can move relative to each other. The same concept also extends to noncutting tools such as forming or burnishing tools, photoplotting, additive methods such as 3D printing, and measuring instruments.
Implementations
The first implementation of a numerical control programming language was developed at the MIT Servomechanisms Laboratory in the late 1950s. In the decades since, many implementations have been developed by many (commercial and noncommercial) organizations. G-code has often been used in these implementations. The main standardized version used in the United States was settled by the Electronic Industries Alliance in the early 1960s. A final revision was approved in February 1980 as RS-274-D. In other countries, the standard ISO 6983 is often used, but many European countries use other standards. For example, DIN 66025 is used in Germany, and PN-73M-55256 and PN-93/M-55251 were formerly used in Poland.
Extensions and variations have been added independently by control manufacturers and machine tool manufacturers, and operators of a specific controller must be aware of differences of each manufacturer's product.
One standardized version of G-code, known as BCL (Binary Cutter Language), is used only on very few machines. Developed at MIT, BCL was developed to control CNC machines in terms of straight lines and arcs.
During the 1970s through 1990s, many CNC machine tool builders attempted to overcome compatibility difficulties by standardizing on machine tool controllers built by Fanuc. Siemens was another market dominator in CNC controls, especially in Europe. In the 2010s, controller differences and incompatibility are not as troublesome because machining operations are usually developed with CAD/CAM applications that can output the appropriate G-code for a specific machine through a software tool called a post-processor (sometimes shortened to just a "post").
Some CNC machines use "conversational" programming, which is a wizard-like programming mode that either hides G-code or completely bypasses the use of G-code. Some popular examples are Okuma's Advanced One Touch (AOT), Southwestern Industries' ProtoTRAK, Mazak's Mazatrol, Hurco's Ultimax and Winmax, Haas' Intuitive Programming System (IPS), and Mori Seiki's CAPS conversational software.
G-code began as a limited language that lacked constructs such as loops, conditional operators, and programmer-declared variables with natural-word-including names (or the expressions in which to use them). It was unable to encode logic, but was just a way to "connect the dots" where the programmer figured out many of the dots' locations longhand. The latest implementations of G-code include macro language capabilities somewhat closer to a high-level programming language. Additionally, all primary manufacturers (e.g., Fanuc, Siemens, Heidenhain) provide access to programmable logic controller (PLC) data, such as axis positioning data and tool data, via variables used by NC programs. These constructs make it easier to develop automation applications.
Specific codes
G-codes, also called preparatory codes, 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 movement (transport the tool as quickly as possible in between cuts)
- Controlled feed in a straight line or arc
- Series of controlled feed movements that would result in a hole being bored, a workpiece cut (routed) to a specific dimension, or a profile (contour) shape added to the edge of a workpiece
- Set tool information such as offset
- Switch coordinate systems
There are other codes; the type codes can be thought of like registers in a computer.
It has been pointed out over the years that the term "G-code" is imprecise because "G" is only one of many letter addresses in the complete language. It comes from the literal sense of the term, referring to one letter address and to the specific codes that can be formed with it (for example, G00, G01, G28), but every letter of the English alphabet is used somewhere in the language. Nevertheless, "G-code" is metonymically established as the common name of the language.
Example program
This section possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (January 2022) (Learn how and when to remove this message) |
This is a generic program that demonstrates the use of G-Code to turn a part that is 1" diameter by 1" long. 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.
Block / Code | Description |
---|---|
% |
Signals start of data during file transfer. Originally used to stop tape rewind, not necessarily start of the program. For some controls (FANUC) the first LF (EOB) is the start of the program. ISO uses %, EIA uses ER (0x0B). |
O4968 (OPTIONAL PROGRAM DESCRIPTION OR COMMENT) |
Sample face and turn program. Comments are enclosed in parentheses. |
N01 M216 |
Turn on load monitor |
N02 G20 G90 G54 D200 G40 |
Inch units. Absolute mode. Activate work offset. Activate tool offset. Deactivate tool nose radius compensation. Significance: This block is often called the safe block or safety block. Its commands can vary but are usually similar to the ones shown here. The idea is that a safety block should always be given near the top of any program, as a general default, unless some very specific/concrete reason exists to omit it. The safety block is like a sanity check or a preflight checklist: it explicitly ensures conditions that otherwise would be implicit, left merely to assumption. The safety block reduces risk of crashes, and it can also helpfully refocus the thinking of the humans who write or read the program under hurried conditions. |
N03 G50 S2000 |
Set maximum spindle speed in rev/min — This setting affects Constant Surface Speed mode |
N04 T0300 |
Index turret to tool 3. Clear wear offset (00). |
N05 G96 S854 M03 |
Constant surface speed , 854 sfm, start spindle CW rotation |
N06 G41 G00 X1.1 Z1.1 T0303 M08 |
Enable cutter radius compensation mode, rapid position to 0.55" above axial centerline (1.1" in diameter) and 1.1 inches positive from the work offset in Z, activate flood coolant |
N07 G01 Z1.0 F.05 |
Feed in horizontally at rate of 0.050" per revolution of the spindle until the tool is positioned 1" positive from the work offset |
N08 X-0.016 |
Feed the tool slightly past center—the tool must travel by at least its nose radius past the center of the part to prevent a leftover scallop of material. |
N09 G00 Z1.1 |
Rapid positioning; retract to start position |
N10 X1.0 |
Rapid positioning; next pass |
N11 G01 Z0.0 F.05 |
Feed-in horizontally cutting the bar to 1" diameter all the way to the datum, 0.05in/rev |
N12 G00 X1.1 M05 M09 |
Clear the part, stop the spindle, turn off the coolant |
N13 G91 G28 X0 |
Home X axis — return the machine's home position for the X axis |
N14 G91 G28 Z0 |
Home Z axis — return to machine's home position for the Z axis |
N15 G90 |
Return to absolute mode. Turn off load monitor |
N16 M30 |
Program stop, rewind to the top of the program, wait for cycle start |
% |
Signal end of data during file transfer. Originally used to mark the end of the tape, not necessarily the end of the program. ISO uses %, EIA uses ER (0x0B). |
- Many codes are modal, meaning they remain in effect until cancelled or replaced by a contradictory code. For example, once variable speed cutting (CSS) had been selected (G96), it stays in effect until the end of the program. In operation, the spindle speed increases as the tool near the center of the work to maintain constant surface speed. Similarly, once rapid feed is selected (G00), all tool movements are rapid until a feed rate code (G01, G02, G03) is selected.
- It is common practice to use a load monitor with CNC machinery. The load monitor stops the machine if the spindle or feed loads exceed a preset value that is set during the set-up operation. The jobs of the load monitor are various:
- Prevent machine damage in the event of tool breakage or a programming mistake.
- This is especially important because it allows safe "lights-out machining", in which the operators set up the job and start it during the day, then go home for the night, leaving the machines running and cutting parts during the night. Because no human is around to hear, see, or smell a problem such as a broken tool, the load monitor serves an important sentry duty. When it senses overload condition, which semantically suggests a dull or broken tool, it commands a stop to the machining. Technology is available nowadays to send an alert to someone remotely (e.g., the sleeping owner, operator, or owner-operator) if desired, which can allow them to come to intercede and get production going again, then leave once more. This can be the difference between profitability or loss on some jobs because lights-out machining reduces labor hours per part.
- Warn of a tool that is becoming dull and must be replaced or sharpened.
- Prevent machine damage in the event of tool breakage or a programming mistake.
- 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 preference of the programmer or operator and the 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, vice, or machine under high power. This can be costly, especially in newer machining centers. It is possible to intersperse the program with optional stops (M01 code) that let the program run piecemeal for testing purposes. The optional stops remain in the program but are skipped during normal running. Most CAD/CAM software ships with CNC simulators that display the movement of the tool as the program executes. Nowadays the surrounding objects (chuck, clamps, fixture, tailstock, and more) are included in the 3D models, and the simulation is much like an entire video game or virtual reality environment, making unexpected crashes much less likely.
- 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. Additionally, many machines support operator overrides for both rapid and feed rate that can be used to reduce the speed of the machine, allowing operators to stop program execution before a crash occurs.
- The line numbers that have been included in the program above (i.e.
N0 ... N16
) are usually not necessary for the operation of a machine and increase file sizes, so they are seldom used in the 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.
Abbreviations used by programmers and operators
This list is only a selection and, except for a few key terms, mostly avoids duplicating the many abbreviations listed at engineering drawing abbreviations and symbols.
Abbreviation | Expansion | Corollary info |
---|---|---|
APC | automatic pallet changer | See M60. |
ATC | automatic tool changer | See M06. |
CAD/CAM | computer-aided design and computer-aided manufacturing | |
CCW | counterclockwise | See M04. |
CNC | computerized numerical control | |
CRC | cutter radius compensation | See also G40, G41, and G42. |
CS | cutting speed | Referring to cutting speed (surface speed) in surface feet per minute (sfm, sfpm) or meters per minute (m/min). |
CSS | constant surface speed | See G96 for explanation. |
CW | clockwise | See M03. |
DNC | direct numerical control or distributed numerical control | Sometimes referred to as "Drip Feeding" or "Drip Numerical Control" due to the fact that a file can be "drip" fed to a machine, line by line, over a serial protocol such as RS232. DNC allows machines with limited amounts of memory to run larger files. |
DOC | depth of cut | Refers to how deep (in the Z direction) a given cut will be |
EOB | end of block | The G-code synonym of end of line (EOL). A control character equating to newline. In many implementations of G-code (as also, more generally, in many programming languages), a semicolon (;) is synonymous with EOB. In some controls (especially older ones) it must be explicitly typed and displayed. Other software treats it as a nonprinting/nondisplaying character, much like word processing apps treat the pilcrow (¶). |
E-stop | emergency stop | |
EXT | external | On the operation panel, one of the positions of the mode switch is "external", sometimes abbreviated as "EXT", referring to any external source of data, such as tape or DNC, in contrast to the computer memory that is built into the CNC itself. |
FIM | full indicator movement | |
FPM | feet per minute | See SFM. |
HBM | horizontal boring mill | A type of machine tool that specializes in boring, typically large holes in large workpieces. |
HMC | horizontal machining center | |
HSM | high speed machining | Refers to machining at speeds considered high by traditional standards. Usually achieved with special geared-up spindle attachments or with the latest high-rev spindles. On modern machines HSM refers to a cutting strategy with a light, constant chip load and high feed rate, usually at or near the full depth of cut. |
HSS | high-speed steel | A type of tool steel used to make cutters. Still widely used today (versatile, affordable, capable) although carbide and others continue to erode its share of commercial applications due to their higher rate of material removal. |
in | inch(es) | |
IPF | inches per flute | Also known as chip load or IPT. See F address and feed rate. |
IPM | inches per minute | See F address and feed rate. |
IPR | inches per revolution | See F address and feed rate. |
IPT | inches per tooth | Also known as chip load or IPF. See F address and feed rate. |
MDI | manual data input | A mode of operation in which the operator can type in lines of program (blocks of code) and then execute them by pushing cycle start. |
MEM | memory | On the operation panel, one of the positions of the mode switch is "memory", sometimes abbreviated as "MEM", referring to the computer memory that is built into the CNC itself, in contrast to any external source of data, such as tape or DNC. |
MFO | manual feed rate override | The MFO dial or buttons allow the CNC operator or machinist to multiply the programmed feed value by any percentage typically between 10% and 200%. This is to allow fine-tuning of speeds and feeds to minimize chatter, improve surface finish, lengthen tool life, and so on. The SSO and MFO features can be locked out for various reasons, such as for synchronization of speed and feed in threading, or even to prevent "soldiering"/"dogging" by operators. On some newer controls, the synchronization of speed and feed in threading is sophisticated enough that SSO and MFO can be available during threading, which helps with fine-tuning speeds and feeds to reduce chatter on the threads or in repair work involving the picking up of existing threads. |
mm | millimetre(s) | |
MPG | manual pulse generator | Referring to the handle (handwheel) (each click of the handle generates one pulse of servo input) |
NC | numerical control | |
OSS | oriented spindle stop | See comments at M19. |
SFM | surface feet per minute | See also speeds and feeds and G96. |
SFPM | surface feet per minute | See also speeds and feeds and G96. |
SPT | single-point threading | |
SSO | spindle speed override | The SSO dial or buttons allow the CNC operator or machinist to multiply the programmed speed value by any percentage typically between 10% and 200%. This is to allow fine-tuning of speeds and feeds to minimize chatter, improve surface finish, lengthen tool life, and so on. The SSO and MFO features can be locked out for various reasons, such as for synchronization of speed and feed in threading, or even to prevent "soldiering"/"dogging" by operators. On some newer controls, the synchronization of speed and feed in threading is sophisticated enough that SSO and MFO can be available during threading, which helps with fine-tuning speeds and feeds to reduce chatter on the threads or in repair work involving the picking up of existing threads. |
TC or T/C | tool change, tool changer | See M06. |
TIR | total indicator reading | |
TPI | threads per inch | |
USB | Universal Serial Bus | One type of connection for data transfer |
VMC | vertical machining center | |
VTL | vertical turret lathe | A type of machine tool that is essentially a lathe with its Z-axis turned vertical, allowing the faceplate to sit like a large turntable. The VTL concept overlaps with the vertical boring mill concept. |
See also
- 3D printing
- Canned cycle
- LinuxCNC - a free CNC software with many resources for G-code documentation
- Drill file
- HP-GL
Extended developments
Similar concepts
Concerns during application
- Cutter location, cutter compensation, offset parameters
- Coordinate systems
References
- Karlo Apro (2008). Secrets of 5-Axis Machining. Industrial Press Inc. ISBN 0-8311-3375-9.
- EIA Standard RS-274-D Interchangeable Variable Block Data Format for Positioning, Contouring, and Contouring/Positioning Numerically Controlled Machines, Washington D.C.: Electronic Industries Association, February 1979
- Martin., Libicki (1995). Information Technology Standards : Quest for the Common Byte. Burlington: Elsevier Science. p. 321. ISBN 9781483292489. OCLC 895436474.
- "Fanuc macro system variables". Retrieved 2014-06-30.
- Marinac, Dan. "Tool Path Strategies For High-Speed Machining". www.mmsonline.com. Retrieved 2018-03-06.
- ^ Korn, Derek (2014-05-06), "What is arbitrary speed threading?", Modern Machine Shop.
Bibliography
- Oberg, Erik; Jones, Franklin D.; Horton, Holbrook L.; Ryffel, Henry H. (1996), Green, Robert E.; McCauley, Christopher J. (eds.), Machinery's Handbook (25th ed.), New York: Industrial Press, ISBN 978-0-8311-2575-2, OCLC 473691581.
- Smid, Peter (2008), CNC Programming Handbook (3rd ed.), New York: Industrial Press, ISBN 9780831133474, LCCN 2007045901.
- Smid, Peter (2010), CNC Control Setup for Milling and Turning, New York: Industrial Press, ISBN 978-0831133504, LCCN 2010007023.
- Smid, Peter (2004), Fanuc CNC Custom Macros, Industrial Press, ISBN 978-0831131579.
External links
- CNC G-Code and M-Code Programming
- Tutorial for G-code
- Kramer, T. R.; Proctor, F. M.; Messina, E. R. (1 Aug 2000), "The NIST RS274NGC Interpreter – Version 3", NIST, NISTIR 6556
- http://museum.mit.edu/150/86 Has several links (including history of MIT Servo Lab)
- Complete list of G-code used by most 3D printers
- Fanuc and Haas G-code Reference
- Fanuc and Haas G-code Tutorial
- Haas Milling Manual
- G Code For Lathe & Milling
- M Code for Lathe & Milling