Misplaced Pages

G-code: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 01:51, 17 August 2006 edit67.164.229.216 (talk)No edit summary← Previous edit Revision as of 01:56, 17 August 2006 edit undo67.164.229.216 (talk)No edit summaryNext edit →
Line 32: Line 32:
(*) 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. (*) 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, however, may use the same code to perform different functions: even machines that use the same CNC control. Some may have said that "]" G-code is standard, but that is a myth. Different machine tools, however, may use the same code to perform different functions: even machines that use the same CNC control. Some have stated that "]" G-code is standard, but this is in fact a myth.





Revision as of 01:56, 17 August 2006

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

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 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 position
Y position
Z position
M code (another "action" register or Machine code(*))
F feed rate
S spindle speed
N line number
R Radius
T Tool selection
I Arc data X axis
J Arc data Y axis.
K Arc data Z axis.

(*) 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, however, may use the same code to perform different functions: even machines that use the same CNC control. Some have stated that "Fanuc" G-code is standard, but this is in fact a myth.


Common Fanuc G Codes
G00 Fast positioning
G01 Linear interpolation
G02 CW circular interpolation
G03 CCW circular interpolation
G17 X-Y plan selection
G18 X-Z plan selection
G19 Y-Z plan selection
G20 Programming in inches
G21 Programming in mm
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 Feed
G96/G97 Constant cutting speed/Constant rotation speed

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 some machinists.

G-code files are output by CAM software such as Smartcam, Gibbscam, Featurecam, Edgecam, Surfcam, Mastercam, OneCNC, 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.

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

Tool Path for program
Sample
N01 M216 (Turn on load monitor)
N02 G00 X20 Z20 (Rapid move away from the part, to ensure the starting position of the tool)
N03 G50 S2000 (Set Maximum spindle speed)
N04 T03 (Choose tool #3 from the carousel)
N05 G96 S854 M42 M03 M08 (Variable speed cutting, 854 ft/min, High spindle gear, Start spindle CW rotation, Turn the coolant on)
N06 G00 X1.1 Z1.1 T0303 (Rapid feed to a point 0.1" from the end of the bar and 0.05" from the side, Use offset values for tool #3)
N07 M01 (Optional Stop)
N08 G01 Z1.0 F.05 (Feed in horizontally until the tool is standing 1" from the datum)
N09 X0.0 (Feed down until the tool is on center - Face the end of the bar)
N10 G00 Z1.1 (Rapid feed 0.1" away from the end of the bar)
N11 X1.0 (Rapid feed up until the tool is standing at the finished OD)
N12 G01 Z0.0 (Feed in horizontally cutting the bar to 1" diameter all the way to the datum)
N13 G00 X1.1 (Rapid feed 0.05" away from the surface of the part)
N14 G00 X20 Z20 (Rapid feed back out away from the work)
N15 M05 M09 (Stop the spindle, Turn off the coolant)
N16 M215 (Turn the load monitor off)
N17 M02 (End of program)


Several points to note:

  1. 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.
  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 (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.
  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 programing mistake. Furthermore, to some extent it can warn of a tool that 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 and comfort level of the programmer.
  5. If the program is wrong, there is a high probability that the machine will crash! That can be very costly. It is possible to intersperse the program with optional stops (M01 code) which allow the program to be run piecemeal. 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.

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
M99 Subprogram end
M00, M01 Program stop, optional stop
|
G96, G97 Constant surface speed, Constant Spindle speed
G50 Maximum spindle speed
G18, G19 Feed mm pr revolvation, feed mm/min
G00, G01 rapid movement, Linear Interpolation (cutting in a straight line)
|
F Feed
S Spindle Speed
|
direction Coordinats X Y Z A B C



Example of a simple CNC lathe program

File:Cnc prog.jpg
the stock and the part the program produces
O1234
G50 S2000
G96 S300 M03
G00 T0606 (ROUGHT TURN TOOL)
G18 X37. Z0.
G01 X-1. F0.2
Z1.
G00 X30.
G01 Z-20.
X33.
X35. Z-21.
Z-25.
X37.
G00 X150. Z300.
M01
T0101 (18MM DRILL)
G97 S1000
G19 M03
X0. Z5.
G01 Z-25. F100
G00 Z5.
X150. Z300.
M05
M30



Example of a simple CNC milling program

A simple example might be a 4" x 2" rectangle. The basic code might read something like:

File:Cnc prog mill.jpg
the stock and the part the program produces
N1X0Y0T01
N2X0Y2000
N3X4000Y2000
N4X4000Y0
N5X0Y0
N6M00
Line 1 (N1) tells the machine to traverse to grid point X0Y0 and to pick tool #1
Line 2 tells the machine to traverse to grid point X0Y2.000
Line 3 tells the machine to travel to grid point X4.000Y2.000
Line 4 tells the machine to travel to grid point X4.000Y0
Line 5 returns the machine to origin
Line 6 stops the machine
Note that the program does nothing to define the tool cutting path. If the machine is a router and uses a 1/8" radius cutter, the actual part will end up 1/4" smaller than designed (1/8" per side). To compensate, a G-code command (in this case) may be used to adjust the tool path.
N1G44M0125
N2X0Y0T01
N3X0Y2000
N4X4000Y2000
N5X4000Y0
N6X0Y0
N7M00
In this case, the controller sees the first line and adjusts the location of the cutter to .125 (or 1/8") to the outside of the cutting profile. Now the machine will make a part that matches the one designed. Depending on the cutting tool, the compensation can be set as needed. For example, a laser with a very fine beam might have a compensation of .005", while a waterjet with a .060 inside tip diameter may need a compensation of .030.


See also

External links


Template:Metalworking - CNC, CAD, and CAM

Categories: