Wikipedia

Wikipedia

en.m.wikipedia.org

For other uses, see G-code (disambiguation) and G programming language (disambiguation). "RS-274" redirects here. For the photoplotter format, see Gerber format.

G-code (also RS-274), which has many variants, is the common name for the most widely used numerical control (NC) programming language. It is used mainly in computer-aided manufacturing to control automated machine tools.

G-code is a language in which people tell computerized machine tools how to make something. The "how" is defined by g-code instructions provided to a machine controller (industrial computer) that tells the motors where to move, how fast to move, and what path to follow. The most common situation is that, within a machine tool, a cutting tool is moved according to these instructions through a toolpath and cuts away material to leave only the finished workpiece. The same concept also extends to noncutting tools such as forming or burnishing tools, photoplotting, additive methods such as 3D printing, and measuring instruments.

Contents

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.[citation needed] A final revision was approved in February 1980 as RS-274-D.[1] 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.[2]

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 developed with CAD/CAM applications that can output the appropriate G-code called a post for a specific machine tool.

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, 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 PLC data, such as axis positioning data and tool data,[3] 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.

People have pointed out over the years that the term "G-code" is imprecise. 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 established as the common name of the language.

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.

Sources: Smid 2008;[4] Smid 2010;[5] Green et al. 1996.[6]

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

Sources: Smid 2008;[4] Smid 2010;[5] Green et al. 1996.[6]

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;[4] Smid 2010;[5] Green et al. 1996.[6]

Some older controls require M codes to be in separate blocks (that is, not on the same line).

Code Description Milling
( M ) Turning
( T ) Corollary info M00 Compulsory stop M T Non-optional—machine always stops on reaching M00 in the program execution. M01 Optional stop M T Machine only stops at M01 if operator pushes the optional stop button. M02 End of program M T Program ends; execution may or may not return to program top (depending on the control); may or may not reset register values. M02 was the original program-end code, now considered obsolete, but still supported for backward compatibility.

[9] Many modern controls treat M02 as equivalent to

M30.

[9] See

M30 for additional discussion of control status upon executing M02 or M30. M03 Spindle on (clockwise rotation) M T The speed of the spindle is determined by the address

S, in either

revolutions per minute (

G97 mode; default) or

surface feet per minute or [surface] meters per minute (

G96 mode [CSS] under either

G20 or

G21). The

right-hand rule can be used to determine which direction is clockwise and which direction is counter-clockwise.

Right-hand-helix screws moving in the tightening direction (and right-hand-helix flutes spinning in the cutting direction) are defined as moving in the M03 direction, and are labeled "clockwise" by convention. The M03 direction is always M03 regardless of local vantage point and local CW/CCW distinction.

M04 Spindle on (counterclockwise rotation) M T See comment above at M03. M05 Spindle stop M T M06 Automatic tool change (ATC) M T (some-times) Many lathes do not use M06 because the

T address itself indexes the turret.
Programming on any particular machine tool requires knowing which method that machine uses. 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.

[4] M07

Coolant on (mist) M T M08 Coolant on (flood) M T M09 Coolant off M T M10 Pallet clamp on M For machining centers with pallet changers M11 Pallet clamp off M For machining centers with pallet changers M13 Spindle on (clockwise rotation) and coolant on (flood) M This one M-code does the work of both

M03 and

M08. It is not unusual for specific machine models to have such combined commands, which make for shorter, more quickly written programs. M19 Spindle orientation M T 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.

The relevance of spindle orientation has increased as technology has advanced. Although 4- and 5-axis contour milling and CNC single-pointing have depended on spindle position encoders for decades, before the advent of widespread live tooling and mill-turn/turn-mill systems, it was not as often relevant in "regular" (non-"special") machining for the operator (as opposed to the machine) to know the angular orientation of a spindle as it is today, except in certain contexts (such as tool change, or G76 fine boring cycles with choreographed tool retraction). Most milling of features indexed around a turned workpiece was accomplished with separate operations on indexing head setups; in a sense, indexing heads were originally invented as separate pieces of equipment, to be used in separate operations, which could provide precise spindle orientation in a world where it otherwise mostly didn't exist (and didn't need to). But as CAD/CAM and multiaxis CNC machining with multiple rotary-cutter axes becomes the norm, even for "regular" (non-"special") applications, machinists now frequently care about stepping just about any spindle through its 360° with precision.

M21 Mirror,

X-axis M M21 Tailstock forward T M22 Mirror,

Y-axis M M22 Tailstock backward T M23 Mirror OFF M M23 Thread gradual pullout ON T M24 Thread gradual pullout OFF T M30 End of program, with return to program top M T Today, M30 is considered the standard program-end code, and returns execution to the top of the program. Most controls also still support the original program-end code,

M02, usually by treating it as equivalent to M30.

Additional info: Compare

M02 with M30. First, M02 was created, in the days when the

punched tape was expected to be short enough to splice into a continuous loop (which is why on old controls, M02 triggered no tape rewinding).

[9] The other program-end code, M30, was added later to accommodate longer punched tapes, which were wound on a

reel and thus needed rewinding before another cycle could start.

[9] On many newer controls, there is no longer a difference in how the codes are executed—both act like M30. M41 Gear select – gear 1 T M42 Gear select – gear 2 T M43 Gear select – gear 3 T M44 Gear select – gear 4 T M48 Feedrate override allowed M T

MFO (manual feedrate overide) M49 Feedrate override NOT allowed M T Prevent

MFO (manual feedrate overide). This rule is also usually called (automatically) within tapping cycles or single-point threading cycles, where feed is precisely correlated to speed. Same with

SSO (spindle speed override) and feed hold button. Some controls are capable of providing

SSO and MFO during threading. M52 Unload Last tool from spindle M T Also empty spindle. M60 Automatic pallet change (APC) M For machining centers with pallet changers M98 Subprogram call M T Takes an address

P to specify which subprogram to call, for example, "M98 P8979" calls subprogram O8979. M99 Subprogram end M T Usually placed at end of subprogram, where it returns execution control to the main program. The default is that control returns to the block following the M98 call in the main program. Return to a different block number can be specified by a P address. M99 can also be used in main program with block skip for endless loop of main program on bar work on lathes (until operator toggles block skip).

Example program

Tool Path for 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.)

Sample Block Code Description % Signals start of data during file transfer. Originally used to stop tape rewind, not necessarily start of program. For some controls (FANUC) the first LF (EOB) is start of 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. 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 [automatically varies the spindle 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 top of program, wait for cycle start % Signal end of data during file transfer. Originally used to mark end of tape, not necessarily end of program. ISO uses %, EIA uses ER (0x0B).

Several points to note:

  1. 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.
  2. Many codes are "modal, meaning they remain 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 nears 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.
  3. 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:
    1. Prevent machine damage in the event of tool breakage or a programming mistake.
      1. 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 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.
    2. 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."
  4. 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.
  5. 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. 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 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 feedrate that can be used to reduce the speed of the machine, allowing operators to stop program execution before a crash occurs.
  6. For educational purposes, line numbers have been included in the program above. They are usually not necessary for operation of a machine, and increase file sizes, 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).
  7. 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), CAM (computer-aided manufacturing), 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; and to the object-oriented approach in general). 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, macro programming describes abstractions that can easily apply in a wide variety of instances. The difference has many analogues, both from before the computing era and from after its advent, such as (1) creating text as bitmaps versus using character encoding with glyphs; (2) the abstraction level of tabulated engineering drawings, with many part dash numbers parametrically defined by the one same drawing and a parameter table; or (3) the way that HTML passed through a phase of using content markup for presentation purposes, then matured toward the CSS model. In all these cases, a higher layer of abstraction introduced 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. 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 and APT. Those efforts were fine for huge corporations like GM and Boeing. However, small and medium enterprises 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 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 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.[10] 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."[11] 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.[12][13] 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 at a time when memory was very expensive; 32K was considered plenty of room for manual programs. CAM software sometimes needs 100K to 500K for its posted coded. CAM excels at getting a program out quick 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 lots of 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 (which see).

See also

Extended developments

Similar concepts

Concerns during application

References

Bibliography

Source en.m.wikipedia.org

Report Page