G-Code is the language used to control CNC machines. It’s one type of CNC programming that CNC programmers use, the other type being CAM programming. Your machine’s CNC controller probably executes g-code. Some machines with proprietary formats can also run g-code. It is the Lingua Franca (working language) of CNC.
In order to make a part on a CNC machine, you tell it how to make the part using a G-Code Program.
Why Learn G-Code?
Even if it is not essential, if you’re interested in CNC machining and 3D printing, you should know a bit of g-code. Nowadays you do not need to buy an industrial machine to make parts. You can use g-code commands on almost all FFF desktop 3D printers. These affordable machines are CNC machines and can be directly controlled using G-Code.
While much of the g-code remains the same from controller to controller, there are important details and defaults you need to be aware of to understand the particular dialect of g-code your controller needs to be happy.
In terms of sheer numbers of users, the Fanuc dialects of G-Code are probably the most common among professionals and Mach3 among hobbyists. This is not to say they are better than other G-Code dialects, just that they are more common and so if you're going to talk to other machinists or move around from job to job and machine to machine, it may be helpful if you're familiar with those dialects and how they differ if your machine doesn't use one of these two controllers.
G-Code has an extremely long history. The first attempts at standardizing it came out of the Electronics Industry Association's RS-274 standard which has evolved to NIST's RS-274NGC standard. The original EIA standards work was begun in the 1960's but the first standard wasn't released until 1980. Even though there are now standards (ISO has one too that is nearly the same as RS-274), it isn't clear how many controllers out there are purely standards based. Indeed, many controls will claim to be some standard or other, but when you look closely at the details they're pretty non-standard.
How Are the Dialects Different?
G-Code dialects differ in a variety of ways. Most manufacturers have added their own little bells and whistles to make their dialect better for competitive and marketing reasons. For example, Haas has a series of special g-codes for pocket milling, as well as some special parameters and capabilities on some standard G-Codes. It pays to understand the special capabilities of your machine because they were probably put there to save time based on feedback the manufacturer got from its customers.
In general, we see the following categories of differences between G-Code dialects:
- Which G-Codes are Supported. Not all controllers support all G-Codes. For example, many early lathe controls do not support the G71 and similar roughing cycles.
- G-Code mappings. Sometimes the same function will be supported by different g-code numbers on different controls.
- Parameters and Macro Programming. Parametric programming with macros is something that emerged after the basic standards were in place. Fanuc Macro B is probably the most common standard for it. Many controls are very limited in their capabilities around Macro Programming and there are a lot of detail differences around exactly how Macros work.
- Parameters. Many G-Codes need additional information to do their job, so they use other words (letters) to collect that information. Exactly which words collect which information can vary from one control to the next.
- Formatting. Some controls allow G0 or G00. Some insist on G00. Some allow numbers with no decimal, others insist on a decimal or even a trailing zero. "1", "1.", and "1.0" are all variations that may be accepted, rejected, or required when specifying the number 1.
For simple programs and Manual Data Input Mode (MDI) use, obviously a lot of the above won't matter, but if you need to write complex hand-written G-Code you'll need to be aware of the dialect issues.