What is the future beyond today’s G-code? To understand that, you need to know the fundamentals.
Much of today’s multitask and multiaxis machining would not work without machine programming. Here are the fundamentals of the languages of machine programming: G-code, M-code and CAM—with a look to the future beyond G-code.
To comprehend the role of machine programming in CNC manufacturing today requires a basic understanding of G-code and M-code.
“CNC machining has been around for 40 or 50 years, so it’s not a new process in our industry,” says Kevin Finan, an instructor at Atlantic Technical College and Technical High School. When Finan teaches manufacturing and machining, he begins by making sure students understand the blueprint of a part. After that they learn some manual machining, then CNC machining using G-code and M-code, and after that, CAM (computer-aided manufacturing) software.
G-Code Commands vs. M-Codes: What’s the Difference?
G-code commands are a set of specific letter and number combinations that dictate to the machine which part to move, how to move and where to go. Generic G-code commands are usually the same for any machine, for example:
- G0 is a rapid move to another location
- G1 is a straight-line cut
- G2 is a clockwise arc
- G3 is a counterclockwise arc
“These codes are combined with XYZ coordinates, so for example, the G0 command will move the machine rapidly to the specified location,” says Finan.
“Years ago they used to ask students and interns to memorize the codes, but I don’t necessarily do that because you will ultimately memorize them just simply by using them, and they can be found online and in the machinist’s handbook,” he says.
G-codes can be read and processed by the machine controller to move either the head or the bed to perform cutting operations within a cutting plane. They work alongside M-codes in the same program (M stands for miscellaneous).
M-codes control auxiliary (non-cutting) functions of the machine such as coolant flow or an air compressor to blow chips away. On more complex mill-turn machines, an M-code might command the tailstock to grab the part off the front stock so the back of the part can be machined.
From G-Code Commands to CAM Systems
“It used to be that you’d handwrite these G-codes,” says Chris MacBain, technical marketing manager at 3D Systems. “The programmer would envision what the tool should do to create the part—how to move, where to cut, how fast to cut, and then convert those movements into a text file consisting of G-codes and M-codes.”
According to MacBain, CNC machining historically began with the movement commands entered on punch cards or punch tape that was fed into the machine.
“The controller, which is the brains of the CNC machine, would read the holes in the cards or in the tape and then perform the appropriate motion,” he says.
But paper cards and tape in a busy machine shop environment tended to get torn, dirtied, lost or fed into the machine out of order, causing scrapped parts and crashed machines. Eventually electronic controllers were built where the operator could punch the codes in directly while standing at the machine.
“Then, as manufacturing became more advanced, 3-axis and 5-axis machining made writing G-code by hand nearly impossible—that’s when computer-aided manufacturing, or CAM systems, were born,” says MacBain.
“There’s so much more that the controller could do—for example, it could monitor the power in the spindle, so that as a sharp tool becomes duller, the power increases to maintain your cutting speed.”
Creating G-Code Commands with CAM System Programming
“CAM systems allow you to take a computer-aided design model of a part and dictate where you want that cutter to cut, what tool you want to use, how fast you want it to move, where you want it to start, where you want it to stop, how much material to take off, and how close you want the tool to come down to the part before it starts cutting,” says MacBain. “It really expedites the G-code creation process.”
But before the CAM system creates the G-code, it allows the programmer to build a toolpath simulation of the way the machine will operate in order to create the part.
“Like the old saying, ‘garbage in, garbage out’ and these machines will do exactly what you asked them to do no matter what,” says MacBain. “If you tell a tool to move down 8 inches, the code doesn’t recognize that there may be something in the way, such as fixturing or a piece of the part, but the CAM system allows you to preview what the tool is going to do before you actually press the button.”
MacBain compares CAM software to the specific print driver that a computer requires in order to print an image. The driver is called a post processor, which creates the G-code that moves the CNC machine.
“All controllers use the same generic G and M commands, but the order they’re in, the way they’re spaced, the way the numbers are presented with or without leading zeroes, are specific to the machine,” says MacBain. “So just like each printer needs a specific driver, each CNC machine needs a different post processor that creates G-code specifically for that machine.”
The action of post processing in a CAM system is what creates the G-code, which is then posted to the machine controller, either over a network or with a flash drive. The file is posted to the machine and then the operator pulls the program up onto the controller monitor and looks at the G-code to make sure it’s running the correct part with the correct tools at the correct offset.
“At that point, the operator can make changes to the code if needed, and once the machine is prepared to run the program, they would hit the green button and execute the program to make the part,” says MacBain.
Need advice from other experienced machinists and metalworking specialists? Jump in on the conversations over at the metalworking forum. [registration required]
Talk to Us!
Thoroughly enjoyed the Information Posted & strangley enough I understood what needed to be done & why in order for the Machines to Operate to Individual Specifications!:)
46Hi Mara, we're happy to hear you enjoyed the information shared.
49I’ve worked with these styles of machines for a very long time and the information that you are sharing is spot on. Keep up the good work at continuing to try to get the next generation interested in these processes.
37Thanks for sharing, 'Monday Motivation' to keep manufacturing strong!
47Would like to learn more
38Thanks for your interest in this type of content.
38I work for a machinist trade school Name, New Pathways Tech in Culpeper Co. Virginia. We teach Cnc both mill and lathe.
48Thanks for sharing Paul. Are students who leave your school able to find jobs easily after going through the cirriculum?
58I want lto earned or enhance more using CNC machine. I only knows how to opiate the the machine
46I am not a machinist but I found G-codes am M-codes interesting am Mechanical tech at CNC machine shop I do repair to these machines I found knowing some of these codes is very helpful if there is any information out there in regards to troubleshooting CNC you can past on via my above email address
36Your email address doesn't get submitted with this form. You can email us at BetterMRO@mscdirect.com and we'll share the requested information with you.
58I need help in CNC programming for some drawings using NC plot
48Leave a reply
Your email address will not be published. Required fields are marked *