G-code
From Wikipedia, the free encyclopedia
- This article is about the machine tool programming language. For the video recorder programming system, see Video recorder scheduling code.
G-code is a common name for the programming language that drives NC and CNC machine tools. It was developed by EIA in the early 1960s, a final revision was approved in February 1980 as RS274D.
Due to the lack of further development, the sheer variety of machine tool configurations, and little demand for interoperability, few machine tool controllers (CNCs) adhere to this standard. Extensions and variations have been added to it independently by manufacturers, meaning that operators have to know the dialects and quirks of the particular machines they use, and CAM systems have had to limit themselves to the lowest common denominator of all the tools that they support.
Many manufacturers tried to overcome this difficulty of remaining compatible by following the lead of a machine tool controller built by Fanuc. Unfortunately, Fanuc does not remain consistent with RS-274 or its own previous standard, and has been slow at adding new features and exploiting the increase in computing power. For example, they changed g70/g71 to g20/21; they used parentheses for comments which caused difficulty when they introduced mathematical calculations; they started to use nanometers just recently (requires 64 bit); they introduced the nurbs to overcome slow fetching of blocks from memory (instead of caching).
Contents |
[edit] Examples
G-code is also the name of any word in a CNC program that begins with the letter G, and generally 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.
- change a pallet
- Set tool information such as offset.
There are other codes; the type codes can be thought of like registers in a computer
- X absolute position
- Y absolute position
- Z absolute position
- A position (rotary around X)
- B position (rotary around Y)
- C position (rotary around Z)
- U Relative axis parallel to X
- V Relative axis parallel to Y
- W Relative axis parallel to Z
- M code (another "action" register or Machine code(*))(otherwise referred to as a "Miscellaneous" function"
- F feed rate
- S spindle speed
- N line number
- R Arc radius or optional word passed to a subprogram/canned cycle
- P Dwell time or optional word passed to a subprogram/canned cycle
- T Tool selection
- I Arc data X axis
- J Arc data Y axis.
- K Arc data Z axis, or optional word passed to a subprogram/canned cycle
- D Cutter diameter/radius offset
- H Tool length offset
(*) M Codes control the overall machine, causing it to stop, start, turn on coolant, etc. Whereas other codes pertain to the path traversed by cutting tools. Different machine tools may use the same code to perform different functions; even machines that use the same CNC control.
G00 | Fast positioning |
G01 | Linear interpolation |
G02 | CW circular interpolation |
G03 | CCW circular interpolation |
G10/G11 | Data writing/Data write cancel |
G17 | X-Y plane selection |
G18 | X-Z plane selection |
G19 | Y-Z plane selection |
G20 | Programming in inches |
G21 | Programming in mm |
G28 | Return to home position |
G31 | Skip function (used for probes and tool length measurement systems) |
G33 | Constant pitch threading |
G34 | Variable pitch threading |
G40 | Tool radius compensation off |
G41 | Tool radius compensation left |
G42 | Tool radius compensation right |
G90 | Absolute programming |
G91 | Incremental programming |
G94/G95 | Inch per minute/Inch per revolution feed |
G96/G97 | Constant cutting speed (Constant surface speed)/Constant rotation speed (constant RPM) |
A standardized version of G-code known as BCL is used, but only on very few machines.
G-code is understood by Gerber photoplotters, machine tool controls, and CNC machinists. CNC is written by hand for volume production jobs. In this environment, the inherent inefficiency of CAM-generated g-code is unacceptable.
G-code files may be generated by CAM software such as Alphacam, Artcam, Edgecam, Featurecam, Gibbscam, Mastercam, OneCNC, Plasma cam, Router-CIM, SmartCAM, Surfcam, etc. Those applications typically use translators called post-processors to output code optimized for a particular machine type or family. Post-processors are often user-editable to enable further customization, if necessary. G-code is also output by specialized CAD systems used to design printed circuit boards. Such software must be customized for each type of machine tool that it will be used to program.
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 Mazak's Mazatrol, Hurco's Ultimax and Mori Seiki's CAPS conversational software.
[edit] Example
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.)
It is considered poor practice to include line numbers for every line of a program. Line numbers and optional stops facilitate running a program out of order or testing individual blocks or operations. Actual part/tool distances are tested using rapid and feed rates. For shorter programs for limited runs, operator stops with block delete are used for program debugging. On testing longer programs, operator stops may be used without any other modifiers. These are removed after the program is proven.
M216 | (Turn on load monitor) |
G00 X20 Z20 | (Rapid move away from the part, to ensure the starting position of the tool) |
G50 S2000 | (Set Maximum spindle speed) |
M01 | (Optional stop) |
N01 T0303 M6 (CUTTER #3 FOR OPERATION) | (Line 1 for flow control Prepare tool #3 with offset #3 from the carousel, index turret to select new tool) |
G96 S854 M42 M03 M08 | (Variable speed cutting, 854 ft/min, High spindle gear, Start spindle CW rotation, Turn the coolant on) |
G00 X1.1 Z1.1 | (Rapid feed to a point 0.1" from the end of the bar and 0.05" from the side) |
G01 Z1.0 F.05 | (Feed in horizontally until the tool is standing 1" from the datum) |
X0.0 | (Feed down until the tool is on center - Face the end of the bar) |
G00 Z1.1 | (Rapid feed 0.1" away from the end of the bar) |
X1.0 | (Rapid feed up until the tool is standing at the finished OD) |
G01 Z0.0 | (Feed in horizontally cutting the bar to 1" diameter all the way to the datum) |
M05 M09 | (Stop the spindle, Turn off the coolant) |
G28 X0 | (Home X axis in the machine coordinate system, then home all other axes) |
M215 | (Turn the load monitor off) |
M30 | (Program stop, pallet change if applicable, reset program) |
Several points to note:
- There is room for some programming style, even in this short program. The grouping of codes in line N05 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 had been selected (G97), 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 cutting 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 programing 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.
[edit] Basic ISO CNC Code
- |
- M03, M04, M05 Spindle CW, Spindle CCW, Spindle Stop
- |
- M08, M09 Coolant/lubricant On, Coolant/lubricant Off
- M02 Program Stop
- M30 Program end, rewind
- M98 Subprogram call
- M99 Subprogram end
- M00, M01 Program stop, optional stop
- |
- G96, G97 Constant surface speed, Constant Spindle speed
- G50 Maximum spindle speed
- G95, G94 Feed mm per revolution, feed mm/min
- G00, G01 rapid movement, Linear Interpolation (cutting in a straight line)
- |
- F Feed
- S Spindle Speed
- |
- direction Coordinates X Y Z A B C U V W
[edit] See also
[edit] External links
Metalworking:
|
|||
---|---|---|---|
2.5D | CAD | CAE | CAM | CNC | G-code | Numerical control | Stewart platform |
|||
|