Sunteți pe pagina 1din 6

G-code - Wikipedia, the free encyclopedia Page 1 of 6

G-code
From Wikipedia, the free encyclopedia

G-code is a common name for the programming language that controls NC and CNC machine tools.
Developed by the Electronic Industries Alliance in the early 1960s, a final revision was approved in
February 1980 as RS274D.

Due to the lack of further development, the immense 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 independently by manufacturers, and operators of a specific controller
must be aware of differences of each manufacturers' product. When initially introduced, CAM systems
were limited in the configurations of tools supported.

Manufacturers attempted to overcome compatibility difficulties by standardizing on 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/G21; they used parentheses for comments which
caused difficulty when they introduced mathematical calculations so the use square parentheses for
macro calculations; they now have nano technology recently in 32-bit mode but in the Fanuc 15MB
control they introduced HPCC (high-precision contour control) which uses a 64-bit RISC (reduced
instruction set computer) processor and this now has a 500 block buffer for look-ahead for correct shape
contouring and surfacing of small block programs and 5-axis continuous machining.

This is also used for NURBS to be able to work closely with industrial designers and the systems that
are used to design flowing surfaces. The NURBS has its origins from the ship building industry and is
described by using a knot and a weight as for bending steamed wooden planks and beams.

Contents
 1 Examples
 2 Example
 3 Basic ISO CNC Code
 4 See also
 5 External links

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.

http://en.wikipedia.org/wiki/G-code 3/17/2008
G-code - Wikipedia, the free encyclopedia Page 2 of 6

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.

Common Fanuc G Codes


Code Description
G00 Rapid positioning
G01 Linear interpolation
G02 CW circular interpolation
G03 CCW circular interpolation
G04 Dwell
G05.1 Q1. Ai Nano contour control
G05 P10000 HPCC
G10/G11 Programmable Data input/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

http://en.wikipedia.org/wiki/G-code 3/17/2008
G-code - Wikipedia, the free encyclopedia Page 3 of 6

G28 Return to home position


G30 2nd reference point return
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
G43 Tool offset compensation positive
G44 Tool offset compensation negative
G45 Axis offset single increase
G46 Axis offset single decrease
G47 Axis offset double increase
G48 Axis offset double decrease
G49 Tool offset compensation cancel
G53 Machine co-ordinate system
G54 to G59 Work co-ordinate systems
G54.1 P1 to
Extended work co-ordinate systems
P48
G73 High speed drilling canned cycle
G74 Left hand tapping canned cycle
G76 Fine boring canned cycle
G80 Cancel canned cycle
G81 Simple drilling cycle
G82 Drilling cycle with dwell
G83 Peck drilling cycle
G84 Tapping cycle
G84.2 Direct right hand tapping canned cycle
G90 Absolute programming (type B and C systems)
G91 Incremental programming (type B and C systems)
G92 Programming of absolute zero point
G94/G95 Inch per minute/Inch per revolution feed (type A system)
G98/G99 Inch per minute/Inch per revolution feed (type B and C systems)
Constant cutting speed (Constant surface speed)/Constant rotation speed (constant
G96/G97
RPM)

A standardized version of G-code known as BCL is used, but only on very few machines.

http://en.wikipedia.org/wiki/G-code 3/17/2008
G-code - Wikipedia, the free encyclopedia Page 4 of 6

G-code files may be generated by CAM software. 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 G-code is written by hand for volume production
jobs. In this environment, the inherent inefficiency of CAM-generated G-code is unacceptable.

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
Southwestern Industries' ProtoTRAK, Mazak's Mazatrol, Hurco's Ultimax and Mori Seiki's CAPS
conversational software.

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.)

Sample
Line Code Description
N01 M216 Turn on load monitor
G00 X20 Rapid move away from the part, to ensure the
N02
Z20 starting position of the tool
N03 G50 S2000 Set Maximum spindle speed
N04 M01 Optional stop
Select tool #3 from the carousel, use tool offset
N05 T0303 M6 values located in line 3 of the program table,
index the turret to select new tool
G96 S854 Variable speed cutting, 854 ft/min, High Tool Path for program
N06 M42 M03 spindle gear, Start spindle CW rotation, Turn
M08 the flood coolant on
G00 X1.1 Rapid feed to a point 0.1" from the end of the
N07
Z1.1 bar and 0.05" from the side
G01 Z1.0 Feed in horizontally until the tool is standing
N08
F.05 1" from the datum
Feed down until the tool is on center - Face the
N09 X0.0
end of the bar
N10 G00 Z1.1 Rapid feed 0.1" away from the end of the bar
Rapid feed up until the tool is standing at the
N11 X1.0
finished OD
Feed in horizontally cutting the bar to 1"
N12 G01 Z0.0
diameter all the way to the datum

http://en.wikipedia.org/wiki/G-code 3/17/2008
G-code - Wikipedia, the free encyclopedia Page 5 of 6

N13 M05 M09 Stop the spindle, Turn off the coolant
G28 G91 Home X axis in the machine coordinate
N14
X0 system, then home all other axes
N15 M215 Turn the load monitor off
Program stop, pallet change if applicable,
N16 M30
rewind to beginning of the program

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 that they stay in effect until they are cancelled or replaced by a
contradictory code. For example, once variable speed cutting 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 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.
3. 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.
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
skill of the programmer and 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 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.
6. 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).

Basic ISO CNC Code


|
M03, M04, M05 Spindle CW, Spindle CCW, Spindle Stop
|
M08, M09 Coolant/lubricant On, Coolant/lubricant Off
M02 Program Stop

http://en.wikipedia.org/wiki/G-code 3/17/2008
G-code - Wikipedia, the free encyclopedia Page 6 of 6

M30 Program end, rewind


M98 Subprogram call
M99 Return to call program
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

See also
 Direct Numerical Control
 Gerber file

External links
 Tutorial for G-code (http://www.linuxcnc.org/handbook/gcode/g-code.html)
 [http://www.isd.mel.nist.gov/personnel/kramer/pubs/RS274NGC_3.web/RS274NGC_3TOC.html
The NIST RS274NGC
 Dolphin CADCAM (http://www.dolphin.gb.com)

Interpreter]

Retrieved from "http://en.wikipedia.org/wiki/G-code"


Categories: CNC, CAD, and CAM | CAD file formats | Domain-specific programming languages |
Encodings
Hidden category: Wikipedia articles needing style editing from December 2007

 This page was last modified on 13 February 2008, at 17:03.


 All text is available under the terms of the GNU Free
Documentation License. (See Copyrights for details.)
Wikipedia® is a registered trademark of the Wikimedia
Foundation, Inc., a U.S. registered 501(c)(3) tax-deductible
nonprofit charity.

http://en.wikipedia.org/wiki/G-code 3/17/2008

S-ar putea să vă placă și