CNC Programming with G Code
What is CNC Programming?
CNC Programming (Computer Numerical Control Programming) is the art of programming CNC machines to make parts. A CNC Program is a text file that contains g-code. If you’re a professional who spends most of their time doing CNC Programming, your job title is probably CNC Programmer.
What is G-Code?
G-Code is the most common language used to control CNC machines. CNC stands for Computer Numerical Control.
It’s one type of CNC programming that CNC programmers use, the other type being CAM programming. CAM programs will generate g-code from a CAD drawing, but the end result is still g-code.
Your machine’s CNC controller probably executes g-code, although there are other possibilities–Heidenhain, Mazak, Shopbot, and others have proprietary formats. Some machines with proprietary formats can also run g-code. It is the Lingua Franca (working language) of CNC.
To make a part on a CNC machine, you tell it how to make the part using a G-Code Program.
There are several standards that attempt to define g-code, such as RS-274 and ISO-6983. Fanuc is probably the most widely used g-code, and therefore Fanuc is something of a default standard.
What are the different methods of CNC Programming?
CNC Machines are programmed using one of three methods:
CAM Software
Conversational Programming
G-Code Programming
Often, it’s advantageous to use multiple methods together. For example, you might create an initial CNC program using CAM Software and then edit the g-code from the CAM Software using G-Code Programming to make the program manufacture a part faster.
What’s the Best CNC Programming Software?
There are basically 3 kinds of CNC Programming Software:
CAM Software
Conversational Programming Software
GCode Editing and Simulating Software
Each has a well-defined role in CNC machine programming. Each corresponds to particular types of CNC programming.
CAM software (Computer Aided Manufacturing Software) is used to convert CAD models to gcode. It works by having the user identify features in the CAD model and then they create tool paths for the feature. It is perhaps the most powerful type of CNC programming software. Conversational Programming Software dispenses with the CAD model. It generates gcode based on a series of wizard-like questions the user answers. Lastly GCode Editing software is like a word processor that has been optimized for manual cnc programming.
What’s the best cnc programming software? If I had to choose, I suppose I would say CAM software. But that’s not the whole story. Ideally, I want all 3 kinds of software in my arsenal. There are things that only GCode Editing software can do, and not CAM software will tackle–more on that below. And there are times when Conversational Programming is just a whole lot faster than messing around with cad and cam software.
There Are Many Dialects of G-Code
There are many G-Code standards and dialects. While much of it remains the same from controller to controller (setting aside alternatives to G-Code from things like Mazatrol, Heidenhain’s Conversational CNC language, and others), 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.
For more details on the relative popularity of different dialects, check out our CNC Controller Survey.
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.