To many of us, “G-code” is a minor mystery. We know that without it, a CNC machine does nothing but occupy space. But running the proper G-code program will produce highly precise parts of amazing complexity – with astonishing speed and low cost. To manufacturers, G-code is the language of love. So, just what is G-code?
Simply put, G-code is an artificial language that converts human-readable information into computer-readable format. G-code allows you to send instructions to a machine tool that its computer numerical control (CNC) system understands and obeys. There are alternatives to G-code, but it is the most widely used method of CNC programming.
A CNC program is the set of all instructions (called commands) required to complete a task, like machining a part. G-code programs organize commands into lines of instruction called “blocks.” The number of blocks required depends on the complexity of the task to perform.
Commands within the block are called “words,” typically consisting of a letter address (like G, T, M, X, and Y), which indicates a setting or function. Commands beginning with a “G” are G-codes, those beginning with an “X” are X codes, and so on. The letter address is followed by a numerical value (00, 54, 17, 90, 99, etc.), which supplies a value to the setting or function.
Now let’s look at this program’s code in detail.
Block #1 – startup commands
- G54 select work coordinate G54 (this coordinate location is set, and reset for every program. It’s a location defined by the machine operator.)
- G17 select XY axis plane
- G20 set machine to inch mode
- G90 select absolute positioning mode (location in relation to coordinate G54)
Block #2 – select tool 1
- T1 select tool 1
- M06 place tool 1 into spindle
Block #3 – start spindle
- M3 rotate spindle forward
- S1000 set spindle to 1000 revolutions per minute
Block #4 – rapid to start position
- G00 set machine’s axis to move at maximum speed
- X0 position X axis to 0 in relation to coordínate G54
- Y0 position Y axis to 0 relation to coordínate G54
- Z1. position Z axis to 1 inch abovework piece on machine table
- G43 add value of length offset (from H01) to commanded position (G54)
- H01 store distance from tip of each cutting tool to workpiece on machine table
Block #5 – drill a 2″ deep hole
- G81 select canned cycle G81, a basic drilling cycle (drill to “Z” depth at “F” feed rate and quickly retract drill to “R” depth)
- Z-2. set drill depth of hole to 2 inches
- R.1 set cutting tool to retract to .1 inches above the programmed zero point above the workpiece on the machine table
- F10. set feed rate to 10 inches per minute
Block #6 – program end
- M30 end program
Back in the 1950s, John T. Parsons developed the first numerical control (NC) system for machine tools, using punched-card calculators to control the machine tool’s spindle and table along their axes. When Parsons approached MIT for help with some servomotor problems, the university developed a system of its own – using a two-ton, seven-track, punch-tape computer housed in three cabinets. The U.S. Air Force acquired several MIT systems and began an effort to simplify programming, resulting in several NC language systems.
G-code evolved from the RS-274 programming language developed in the early 1960s by the now-defunct Electronic Industries Alliance (EIA) to provide a standard for writing NC programs. The latest version, RS-274D, is the current programming standard for CNC machines. North American CNC users refer to the language and its variants simply as “G-code,” while it is sometimes called “G programming language” outside of North America.
Focused on efficiency and competiveness, many of today’s manufacturers use software to design and machine parts. Computer Aided Design (CAD) software is a powerful tool used to produce a highly accurate digital drawing. Computer Aided Manufacturing (CAM) software creates a CNC program using the CAD digital file. CAM software generates and uploads the same type of G-code program that you would manually enter by hand-coding a CNC control, but requires much less effort and time.
For those who rely on CAM software, there are still benefits to having a good working knowledge of G-code. An experienced G-code programmer is more efficient when using CAM than one who has no G-code experience. And for relatively simple parts, hand-coding can be less time-consuming than using CAM. A significant additional benefit is the ease of making simple adjustments to CAM-generated programs at the machine’s control – saving time and money.
While G-code is the most common CNC programming language, some CNC manufacturers have invented their own proprietary conversational method of programming to simplify the machining process. Conversational programming either hides or completely bypasses the use of G-code, and instead leads a user through a series of on-screen steps. For example, The Haas Intuitive Programming System (IPS) makes creating programs and cutting parts easy – even without knowing G-code. Using an easy-to-read format with full color graphics, the Haas IPS guides an operator through the necessary steps to machine a part.
Ultimately, technology depends on CNC machine tools – and CNC machine tools depend on G-code.