HOME

TheInfoList



OR:

G-code (also RS-274) is the most widely used
computer numerical control Numerical control (also computer numerical control, and commonly called CNC) is the automated control of machining tools (such as drills, lathes, mills, grinders, routers and 3D printers) by means of a computer. A CNC machine processes a p ...
(CNC)
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
. It is used mainly in
computer-aided manufacturing Computer-aided manufacturing (CAM) also known as computer-aided modeling or computer-aided machining is the use of software to control machine tools in the manufacturing of work pieces. This is not the only definition for CAM, but it is the most ...
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 A machine tool is a machine for handling or machining metal or other rigid materials, usually by cutting, boring, grinding, shearing, or other forms of deformations. Machine tools employ some sort of tool that does the cutting or shaping. Al ...
such as a
lathe A lathe () is a machine tool that rotates a workpiece about an axis of rotation to perform various operations such as cutting, sanding, knurling, drilling, deformation, facing, and turning, with tools that are applied to the workpiece ...
or
mill Mill may refer to: Science and technology * * Mill (grinding) * Milling (machining) * Millwork * Textile mill * Steel mill, a factory for the manufacture of steel * List of types of mill * Mill, the arithmetic unit of the Analytical Engine early ...
, a
cutting tool In the context of machining, a cutting tool or cutter is typically a hardened metal tool that is used to cut, shape, and remove material from a workpiece by means of machining tools as well as abrasive tools by way of shear deformation. The major ...
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 3D printing or additive manufacturing is the construction of a three-dimensional object from a CAD model or a digital 3D model. It can be done in a variety of processes in which material is deposited, joined or solidified under computer co ...
, and measuring instruments.


Implementations

The first implementation of a numerical control programming language was developed at the
MIT The Massachusetts Institute of Technology (MIT) is a private land-grant research university in Cambridge, Massachusetts. Established in 1861, MIT has played a key role in the development of modern technology and science, and is one of the m ...
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 The Electronic Industries Alliance (EIA; until 1997 Electronic Industries Association) was an American standards and trade organization composed as an alliance of trade associations for electronics manufacturers in the United States. They devel ...
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 DIN or Din or din may refer to: People and language * Din (name), people with the name * Dīn, an Arabic word with three general senses: judgment, custom, and religion from which the name originates * Dinka language (ISO 639 code: din), spoken by ...
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 Siemens AG ( ) is a German multinational conglomerate corporation and the largest industrial manufacturing company in Europe headquartered in Munich with branch offices abroad. The principal divisions of the corporation are ''Industry'', ''E ...
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 Nature, in the broadest sense, is the physical world or universe. "Nature" can refer to the phenomena of the physical world, and also to life in general. The study of nature is a large, if not the only, part of science. Although humans ar ...
-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 In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be easier to u ...
. Additionally, all primary manufacturers (e.g., Fanuc, Siemens, Heidenhain) provide access to
programmable logic controller A programmable logic controller (PLC) or programmable controller is an industrial computer that has been ruggedized and adapted for the control of manufacturing processes, such as assembly lines, machines, robotic devices, or any activity t ...
(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 Metonymy () is a figure of speech in which a concept is referred to by the name of something closely associated with that thing or concept. Etymology The words ''metonymy'' and ''metonym'' come from grc, μετωνυμία, 'a change of name' ...
established as the common name of the language.


Letter addresses

Some letter addresses are used only in milling or only in
turning Turning is a machining process in which a cutting tool, typically a non-rotary tool bit, describes a helix toolpath by moving more or less linearly while the workpiece rotates. Usually the term "turning" is reserved for the generation ...
; most are used in both. Bold below are the letters seen most frequently throughout a program. Sources: Smid 2008;. Smid 2010;. Green et al. 1996..


List of G-codes commonly found on FANUC and similarly designed controls for milling and turning

Sources: Smid 2008; Smid 2010; Green et al. 1996. ::Note: ''Modal'' means a code stays in effect until replaced, or cancelled, by another permitted code. ''Non-Modal'' means it executes only once. See, for example, codes G09, G61 & G64 below.


List of M-codes commonly found on FANUC and similarly designed controls for milling and turning

Sources: Smid 2008; Smid 2010; Green et al. 1996. Some older controls require M codes to be in separate blocks (that is, not on the same line).


Example program

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. (Caution: This is generic, it might not work on any real machine! Pay particular attention to point 5 below.) Several points to note: # There is room for some programming style, even in this short program. The grouping of codes in line could have been put on multiple lines. Doing so may have made it easier to follow program execution. # 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 (), 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 (), all tool movements are rapid until a feed rate code () 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. Thus, an operator tending multiple machines is told by a machine, essentially, "Pause what you're doing over there, and come attend to something over here." # 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 and/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 ( code) that let the program run piecemeal for testing purposes. The optional stops remain in the program but are skipped during normal running. Fortunately, 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 model In 3D computer graphics, 3D modeling is the process of developing a mathematical coordinate-based representation of any surface of an object (inanimate or living) in three dimensions via specialized software by manipulating edges, vertices, an ...
s, 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. ... ) 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. ). # Some machines do not allow multiple M codes in the same line.


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 combine CAD (
computer-aided design Computer-aided design (CAD) is the use of computers (or ) to aid in the creation, modification, analysis, or optimization of a design. This software is used to increase the productivity of the designer, improve the quality of design, improve co ...
), CAM (
computer-aided manufacturing Computer-aided manufacturing (CAM) also known as computer-aided modeling or computer-aided machining is the use of software to control machine tools in the manufacturing of work pieces. This is not the only definition for CAM, but it is the most ...
), and richly featured G-code editors. (G-code editors are analogous to
XML editor An XML editor is a markup language editor with added functionality to facilitate the editing of XML. This can be done using a plain text editor, with all the code visible, but XML editors have added facilities like tag completion and menus and but ...
s, using colors and indents semantically lus other featuresto aid the user in ways that basic
text editor A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be ...
s can't. CAM packages are analogous to IDEs in general programming.) Two high-level paradigm shifts have been toward: # 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 The visual system comprises the sensory organ (the eye) and parts of the central nervous system (the retina containing photoreceptor cells, the optic nerve, the optic tract and the visual cortex) which gives organisms the sense of sight ...
techniques in general programming) # 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; and to the
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
approach in general). Macro (parametric) CNC programming uses human-friendly variable names,
relational operator In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality (''e.g.'', ) and inequalities (''e.g.'', ). In pr ...
s, 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, macro programming describes abstractions that can easily apply in a wide variety of instances. The tendency is comparable to a computer programming evolution from
low-level programming language A low-level programming language is a programming language that provides little or no Abstraction (computer science), abstraction from a computer's instruction set architecture—commands or functions in the language map that are structurally sim ...
s to high-level ones.
STEP-NC STEP-NC is a machine tool control language that extends the ISO 10303 STEP standards with the machining model in ISO 14649, adding geometric dimension and tolerance data for inspection, and the STEP PDM model for integration into the wider ent ...
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. This idea is not new; from the beginning of numerical control, the concept of an end-to-end CAD/CAM environment was the goal of such early technologies as
DAC-1 DAC-1, for ''Design Augmented by Computer'', was one of the earliest graphical computer aided design systems. Developed by General Motors, IBM was brought in as a partner in 1960 and the two developed the system and released it to production in 196 ...
and
APT Apt. is an abbreviation for apartment. Apt may also refer to: Places * Apt Cathedral, a former cathedral, and national monument of France, in the town of Apt in Provence * Apt, Vaucluse, a commune of the Vaucluse département of France * A ...
. Those efforts were fine for huge corporations like GM and Boeing. However,
small and medium enterprises Small and medium-sized enterprises (SMEs) or small and medium-sized businesses (SMBs) are businesses whose personnel and revenue numbers fall below certain limits. The abbreviation "SME" is used by international organizations such as the World Bank ...
went through an era of simpler implementations of NC, with relatively primitive "connect-the-dots" G-code and manual programming until CAD/CAM improved and disseminated throughout the industry. Any machine tool with a great number of axes, spindles, and tool stations is difficult to program well manually. It has been done over the years, but not easily. This challenge has existed for decades in CNC screw machine and rotary transfer programming, and it now also arises with today's newer machining centers called "turn-mills", "mill-turns", "multitasking machines", and "multifunction machines". Now that
CAD/CAM CAD/CAM refers to the integration of Computer-aided design (CAD) and Computer-aided manufacturing (CAM). Both of these require powerful computers. ''CAD'' software helps designers and draftsmen; ''CAM'' "reduces manpower costs" in the manufacturi ...
systems are widely used, CNC programming (such as with G-code) requires CAD/CAM (as opposed to manual programming) to be practical and competitive in the market segments these classes of machines serve. ''Online ahead of print.'' As Smid says, "Combine all these axes with some additional features, and the amount of knowledge required to succeed is quite overwhelming, to say the least.". At the same time, however, programmers still must thoroughly understand the principles of manual programming and must think critically and second-guess some aspects of the software's decisions. Since about the mid-2000s, it seems "the death of manual programming" (that is, of writing lines of G-code without CAD/CAM assistance) may be approaching. However, it is currently only in ''some'' contexts that manual programming is obsolete. Plenty of CAM programming takes place nowadays among people who are rusty on, or incapable of, manual programming—but it is not true that ''all'' CNC programming can be done, or done ''as well'' or ''as efficiently'', without knowing G-code. Tailoring and refining the CNC program at the machine is an area of practice where it can be easier or more efficient to edit the G-code directly rather than editing the CAM toolpaths and re-post-processing the program. Making a living cutting parts on computer-controlled machines has been made both easier and harder by CAD/CAM software. Efficiently written G-code can be a challenge for CAM software. Ideally, a CNC machinist should know both manual and CAM programming well so that the benefits of both brute-force CAM and elegant hand programming can be used where needed. Many older machines were built with limited
computer memory In computing, memory is a device or system that is used to store information for immediate use in a computer or related computer hardware and digital electronic devices. The term ''memory'' is often synonymous with the term '' primary storag ...
at a time when memory was very expensive; 32K was considered plenty of room for manual programs whereas modern CAM software can post gigabytes of code. CAM excels at getting a program out quickly that may take up more machine memory and take longer to run. This often makes it quite valuable to machining a low quantity of parts. But a balance must be struck between the time it takes to create a program and the time the program takes to machine a part. It has become easier and faster to make just a few parts on the newer machines with much memory. This has taken its toll on both hand programmers and manual machinists. Given natural turnover into retirement, it is not realistic to expect to maintain a large pool of operators who are highly skilled in manual programming when their commercial environment ''mostly'' can no longer provide the countless hours of deep experience it took to build that skill; and yet the loss of this experience base can be appreciated, and there are times when such a pool is sorely missed because some CNC runs still cannot be optimized without such skill.


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 Engineering drawing abbreviations and symbols are used to communicate and detail the characteristics of an engineering drawing. This list includes abbreviations common to the vocabulary of people who work with engineering drawings in the manufactu ...
.


See also

*
3D printing 3D printing or additive manufacturing is the construction of a three-dimensional object from a CAD model or a digital 3D model. It can be done in a variety of processes in which material is deposited, joined or solidified under computer co ...
* Canned cycle * LinuxCNC - a free CNC software with many resources for G-code documentation * Drill file *
HP-GL HP-GL, short for Hewlett-Packard Graphics Language and often written as HPGL, is a printer control language created by Hewlett-Packard (HP). HP-GL was the primary printer control language used by HP plotters. It was introduced with the plotteHP-89 ...


Extended developments

*
Direct Numerical Control Direct numerical control (DNC), also known as distributed numerical control (also DNC), is a common manufacturing term for networking CNC machine tools. On some CNC machine controllers, the available memory is too small to contain the machining p ...
(DNC) *
STEP-NC STEP-NC is a machine tool control language that extends the ISO 10303 STEP standards with the machining model in ISO 14649, adding geometric dimension and tolerance data for inspection, and the STEP PDM model for integration into the wider ent ...
*
MTConnect MTConnect is a manufacturing technical standard to retrieve process information from numerically controlled machine tools. As explained by a member of the team that developed it, "This standard specifies the open-source, royalty-free communicatio ...


Similar concepts

*
Gerber file The Gerber format is an open ASCII vector format for printed circuit board (PCB) designs. It is the de facto standard used by PCB industry software to describe the printed circuit board images: copper layers, solder mask, legend, drill data, et ...


Concerns during application

*
Cutter location A cutter location (CLData) refers to the position which a CNC milling machine has been instructed to hold a milling cutter by the instructions in the program (typically G-code). Each line of motion controlling G-code consists of two parts: the t ...
, cutter compensation, offset parameters *
Coordinate system In geometry, a coordinate system is a system that uses one or more numbers, or coordinates, to uniquely determine the position of the points or other geometric elements on a manifold such as Euclidean space. The order of the coordinates is sig ...
s


References


Bibliography

* * * *


External links


CNC G-Code and M-Code Programming
* * 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





Haas Milling Manual




{{DEFAULTSORT:G-Code Computer-aided engineering Domain-specific programming languages Encodings Metalworking