The reports of my death are greatly exaggerated — Mark Twain
Myth: G-Code Programming is a Thing of the Past
Reality: G-Code Programming Compliments CAM Extremely Well
Like Mark Twain sort of said, “The reports of GCode’s death are greatly exaggerated.” Even MMSOnline agrees that the idea G-Code programming by people instead of CAM software is still relevant.
How can that be true though? After all, modern CAM software is pretty darned wonderful about doing things a manual g-code programmer couldn’t even attempt. Programming a complex 3D surface is trivial with software like MeshCam, but pretty well impossible to do by hand unless the surface can be described by fairly simple mathematical equations. Why would you want to program any g-code by hand?
The answer lies in finding cases that are valuable but not addressed by CAM. These fall into the following general categories:
- Simple parts can be easier with g-code than CAM. You want a rectangular cover plate with 4 holes in it. If you’re proficient with g-code you’re done before you can create a CAD model, run it through CAM, get the gcode onto the machine, and run it. With Conversational CNC, you don’t even have to be proficient at g-code. For all those cases where you thought manual machining was faster, g-code or Conversational CNC will make the CNC machine an even better choice.
- Getting a Second Opinion on Your CAM Code. Even expensive CAM software can have bugs. Or, if they’re not strictly speaking bugs in the CAM, they may be problems with the post-processor. With just a little bit of knowledge about GCode and the help of a GCode Simulator, you can get a second opinion on the CAM-generated GCode and fix minor errors before you have to discover them on the machine.
- Specialized or Downstream Tasks that Complement CAM. As great as they are, CAM programs don’t do everything. There are many specialized tasks that are difficult or impossible to do with CAM. In addition, there are downstream tasks–things that come up when the job is actually on the machine that weren’t contemplated by the CAM or Post. Sometimes these tasks are relegated to GCode because the CAM software won’t do them. Sometimes it’s because the CAM is aiming at a generalized common denominator and something special comes up on the Shop Floor–for example, a slightly different cutting tool has to be used while we wait for another shipment of the normal tools. A simple feeds and speeds change in the gcode will handle it far faster than re-running the CAM, assuming we’re capable of making such simple changes.
It’s this latter category that I want to focus on here by providing an Omnibus List of Applications for GCode Programming alongside CAM.
Wait! G-Code is Hard to Write by Hand, That’s Why I Use CAM Software!
Hang on, quit psyching yourself out like that!
Listen, it is hard to do a lot of the things CAM does with hand coding. CAM excels at converting geometry from your CAD model into g-code that follows the right toolpaths. You don’t want to try to compete with that by hand!
But, the kinds of things we will talk about below don’t require you to convert geometry to g-code toolpaths. They’re much easier bite-sized bits of g-code. And often, that g-code can be re-used in a lot of your part programs once you’ve got it written.
And another thing. Tools exist that can help a lot. Modern g-code editing and simulation software can make complex g-code a lot more approachable.
Give G-Wizard a try. It will help tremendously to simplify your g-code work. Let’s dig in now and see what that work might be.
Applications for G-Code Programming That Complement CAM
1. Changing Feeds and Speeds
You get a new line of cutters in and you just want to try them quickly to decide if they work better. So, you dial in an improvement in the feeds and speeds directly into the gcode without going back through the CADCAM process. Or, you find some area in the part that is unexpectedly prone to breaking cutters. Something about it work hardens the material or does something the CAM didn’t account for. Perhaps there is chatter. Being able to quickly tweak the feeds and speeds there is helpful. Suppose you’re making tons of small cheap parts. You stand there at the machine the first time through and bump up the Feed Rate Override on each part until you are running 25% faster. Nothing is breaking. This is a win! Let’s quickly dial that into the part program by modifying the gcode.
2. Easy Performance Tweaks for Wasted Motion
CAM doesn’t always make the best choices. Have you ever seen the CAM’s gcode jump from one hole to one that’s far away instead of just doing the closest one? Sure, some CAM avoids that, but we’ve all seen CAM do things that was less than optimal. A little bit of gcode knowledge and it can be very easy to edit away those wasteful moves. It’s not worth it if you’re only making one part, but over the course of long hours of machining the same part, it can really add up. Changing the order of operations is relatively easy, but even easier would be something like doing a coordinated move in all axes instead of 2 moves first in Z and second in XY. You probably won’t know you can do that until you see it on the machine unless you have a very dialed in and sophisticated CAM and Simulation setup. Incidentally, CAM does things in weird order often because that’s the order those features appeared in the CAD file. Go figure.
3. Material Variations
Any time you expect there to be process variations at the machine–different materials, different cutters, different setup or fixturing, there may be an opportunity to save time with a little manual GCode tweaking. Suppose your next shipment of material is just different enough it is causing trouble. The aluminum is more gummy or the material is harder from one supplier than another. It’s often much easier to tweak that in by changing the GCode than going back through a CADCAM cycle.
4. Working Around Processing Mistakes
We all seen it–the first part is how we learned to make the second part, but it was the third part that was actually spot on. Because we programmed for speed at the CAM stage, we now have a full batch of parts that need rework. We could run the entire corrected CAM GCode again, or we could edit it by hand to jump to the rework part. Or, this week we only need 5, not the usual 20 that the fixture and GCode are set up for. Let it cut air, redo the CADCAM cycle, or tweak the GCode? Tweak the GCode is often fastest. Darn, that operator put the wrong tool in the changer for the roughing on one feature. We caught it, but we need to rerun just that one roughing on one op. You get the idea. These things come up constantly, and we’re at a real disadvantage if we have to go back to CAM every time.
5. Collision Avoidance
Dang, that first run took a divot out of my vise before I could hit the E-Stop. It’s not off by much, just need to reroute this one path slightly. Easy to do in the GCode, not to mention easy to pick up where we left off. Even if you have perfect simulation of the fixturing in CAM, things change out there on the Shop Floor.
6. Alarms and Errors When Running New Programs
If you’ve never had an alarm or error running your “perfect” CAM GCode on the machine, you just haven’t been doing it long enough or you have your CAM and Post extraordinarily well dialed in (WAY above the average!). Deciphering what’s going on when this happens really benefits from a knowledge of GCode.
7. Custom Post or GCode Tweak?
In theory, you could tweak your Post to do almost anything. And it is often worthwhile to tweak the Post. By doing so, you get the benefit of the tweak going forward. And that’s really the key–if the tweak is one-off or a few-off special case thing, why deal with the Post? Some Posts are very hard or even expensive (i.e. only the reseller can tweak the Post) to tweak. GCode is not that hard and is very easy to tweak. As a matter of fact, shops that frequently tweak the GCode have found they can tweak their Posts to facilitate their GCode tweaking downstream. That’s a very complementary approach. And BTW, if you are working on the Post yourself, you need to know GCode programming else it will be a real mess.
8. Simple Utilities
There are a host of simple utilities that can be handy to have around the shop that are pretty easy GCode programming projects. For example, machine warmup, zeroing all the wear offsets on a turning center, soft jaw boring, or a routine to square and clean up rough stock. Yes, many are available elsewhere, but for those that are not and those that you dream up on your own, consider GCode as one way to create the utility. Almost any repetitive manual task can be automated with a simple gcode utility.
9. Custom Drill Cycles
There is much to be gained from Custom Drill Cycles. The cycles that come built into your CNC machine are not optimum for most holes. They waste too much time or they may fail completely on a challenging deep hole. Ideally, you’d use a hybrid cycle–no need to peck until you reach a certain depth, then you want to peck every so often, and as you get deeper you want to peck more frequently. As you get deeper still you want to retract further to help with chip extraction. All this and much more is possible with a custom programmed drill cycle. In fact, our G-Wizard Editor has a built in Conversational CNC Wizard that’s tailor made for producing such cycles.
10. Tool Life Programming
The longer your machine can run without operator intervention, the better. And the more you can use automation to assist the operator the better. Tool Life Programming is a deep topic unto itself. It involves monitoring how long a particular tool has been in use, perhaps across jobs, and stopping the use of that tool to either prompt the operator to replace it or to select a duplicate tool from the changer just before the tool breaks or degrades in performance to harm the job. Some machines will have some or all of these capabilities built-in. Given this spans multiple jobs, most CAM will have little to say about it. Whether your machine has it built in or not, you can do a little or a lot with some custom g-code programming that facilitates Tool Life Management.
11. Multi-Part Fixturing
Multiple parts. How many parts today? Which slots in the fixture are used? Do we have a fancy Horizontal with pallet changer and tombstones that runs an every changing mix of parts for just in time inventory delivery? This is all excellent fodder for custom gcode.
12. Prompting the Operator for an Input
Is there something about the program that changes constantly? Why not prompt the operator to tell the program what to do this time? How many of the 12 parts on the fixture should we make? Is there an optional feature to machine that we will turn on or off based on today’s mix? Do we offer this part in more than one material? The operator can say which material we’re machining today. Is it time for the operator to inspect a feature and adjust a wear offset? The possibilities to use Operator Input are endless.
13. Entering Offset Data with G10 or System Variables
You don’t have to enter Tool and Work offset data by hand. It can be done in GCode using G10 or System Variables and it can be very helpful to do things this way.
14. Parts Tracking
Suppose you’re running a job for a customer that has to be done on the cheap. They want to run their parts only when there is no other higher priced job to run and only up to 30 parts a week. This is a true story, BTW, as told to me by a machinist not long ago. They used some simple macros to track how many of the parts had been made and to make it easy to switch a machine over from the high dollar job to this budget job very quickly. A parts counter was implemented in gcode that would tell the operator when he ran the gcode for the job whether to proceed, how many parts to load in the fixture if less than a full lot, and so on. Made it super easy for this shop and they can re-use the macros to do other similar jobs.
Machine time is perishable. Airlines and Hotels do this sort of thing, so why shouldn’t you have some cheap jobs that run when the high paying jobs are done?
15. Serialized Engraving
Perfect for gcode with macros–you’re making a run of parts that need unique serial numbers. Or maybe they need the date of manufacture engraved on them. Or virtually any other engraving that changes with every part.
16. Part Customization
While we’re on the subject of Serialized or Custom Engraving, consider any kind of Part Customization to be a candidate for some custom GCode and macros. Suppose you’re making some sort of product that has a lot of options so the buyer can personalize their particular model. They want certain engravings. Or you apply the engravings so that by matching the same engraving on different parts the right combination comes together at the end for each buyer. We live in an age where customers really value personalization. Being able to handle it well is a great way to differentiate your shop’s capabilities. But doing it by relying entirely on CAM is going to be very difficult.
17. Automatic Calibration of Fixture Offsets
Every time you change fixtures you potentially need to dial in new Work Offsets for the fixtures. You may have invested in a fancy tooling plate to make this easy. Great, but you’ll still benefit by having the Part Program dial up the right offsets for the fixtures in use. And you may want to inform the operator in the gcode to check and install the right fixture if needed. Lastly, even after all that, and especially if you don’t have a highly repeatable tooling plate, you still want to dial in the fixtures. You can eliminate a lot of manual work with a little cleverness. Why tram in a vise when a probe and a slick macro can measure the angle of the jaw and rotate the coordinate system to eliminate the tramming step quickly and easily?
18. Automatic Calibration of Part Zero
Pretty much the same story as Work Offsets only instead of focusing on some feature of the fixture, perhaps you need to focus on a feature on the part. Perhaps it is a second setup, and you want to dial in on the center of a hole or the corner of a part. Easy to do. Even if you don’t have a probe you can do some operator prompting (see #12 above) to guide them through using an Edge Finder or DTI to locate whatever feature is needed.
19. Part Count for Bar Puller
You figure it’s time to stop the machine and change the bar in the bar puller every 30 parts. Does your CAM know how to do this? Maybe. More likely you just need to program it in. Especially if you want to prompt the operator for bar length so you’re not assuming a full length bar every time.
20. Custom Machine Monitoring with DPRNT
Machine monitoring is all the rage these days. It’s something Top Shops really like to do once they have their CNC machines networked. It’s not hard to understand, there is a lot of value in tracking what the machines are doing and acting on that data. Besides generic machine state monitoring, wouldn’t it be awesome to know more about the state of a particular part program? You can monitor almost anything you want using a macro programming feature called “DPRNT”. DPRNT lets your machine send messages to the outside world about what it’s doing. Anything the gcode can monitor or test can result in a DPRNT being sent from the program.
21. Timing Events in a Program
Related to monitoring with DPRNT would be timing events in a program. Modern GCode includes the ability to time how long it takes to go from one point in the gcode to another with millisecond accuracy. You can learn a lot by looking at such timings. Certainly if you have a bunch of machines that time each feature in a part program and most fall inside the normal range but one is substantially outside the range you’d want to understand what’s going on. It could be anything from an operator turning down the feedrate so they’re disturbed from reading their paperback novel less often to a machine in need of maintenance.
22. Testing Offsets for Correctness
Load up a program and you’re ready to run it and the thought crosses your mind, “Are my tool length offsets correct?” It can really make your trigger finger itchy to realize this is a 4th axis setup and you are using some long reach tooling with way less clearance than usual. What’s a body to do about this? Well, if Mr Murphy is perverse enough, he can arrange for you to crash your CNC machine. But you can at least look for obvious problems. It’s entirely possible using some simple macros to tell the range of tool lengths in the carousel, for example (at least based on the reported lengths in the Tool Table). You could embed such a test to check against the known range your gcode program expects. If there’s something in the range of tools your part program will use that is outside that norm, you can stop the program and notify the operator.
23. Driving Accessory Devices
For example, Probes, Post Process Gaging, Bar Pullers, Hydraulic Fixtures, Indexers, Angle Heads, and many more. Anything off the beaten path may require some custom g-code.
A specific accessory I want to highlight is broaching, which we’ve written about before. It’s entirely straightforward to do broaching in your machining or turning center, but you’ll need custom g-code to do it.
25. Part Manipulation
Suppose you could manipulate parts with the machine instead of the operator? That would certainly open up some interesting possibilities. It’s been done and it has opened those possibilities. One variation has the parts being held in tool holders. Using special fixtures, the machine spindle can move the parts around by treating them as tools. I’ve seen this done as a way to load parts automatically onto the machine–each toolholder is a mini-pallet. There are also solutions that apply grippers or suction devices (like a pick and place machine) in toolholders. Then there are solutions where the machine uses the tip of a tool to push an actuator of some sort that causes the fixture to do something. This can range from triggering indexing in an air actuated indexer to triggering a pallet system of some kind. This is all very specialized stuff that your CAM software won’t do without a lot of custom g-code.
26. Confirm the Right Tool is in the Spindle
This is perhaps not so much a problem if all is well. But suppose the program is interrupted for some reason. Failed to clamp a part well enough or some such. The operator needs to restart in the middle of the program. But they accidentally restart just past the tool change, so the wrong tool is in the spindle. What to do? It’s pretty easy to do an automated check for this if you can do some custom gcode.
27. Custom In-Process Probing
There are many unique and powerful things that can be accomplished via in-process probing. That means probing that’s done in the middle of the part program. One of my favorite examples is the set of techniques developed by Renishaw for their RAMTIC manufacturing methodology. Renishaw makes probes which have to be machined accurately to ensure accurate programming. Suppose you need to hold super-tight tolerances on a commodity VMC that lacks glass scales, spindle chillers, and other fancy accessories. Moreover, suppose you need to hold a tolerance on a bore. With RAMTIC, you’d create a fixture from the same material as the part. You use the same material so thermal expansion is the same. On the fixture, you provide a sample bore that has been lovingly massaged within tolerance. With RAMTIC, you probe the sample bore. Suppose it is supposed to be 1.000 +0.0002″ -0.0000″. It can be too large by a little and never too small. Your probe tells you the sample bore on the fixture, which is an identical feature in the identical material, is 1.0003″. So it is a little out of tolerance. In the gcode, we apply a scaling factor that would bring the bore into tolerance. This will adjust to the current machine and environmental conditions so that the bore on the new part comes out within spec. There are many more things we can do with in-process probing that are extremely valuable, and most will benefit from the ability to do custom g-code.
28. Tool Pressure Deviation During Touch Offs
Here’s a sneaky way to improve your accuracy. When you touch off, minor pressure deviations can introduce error. If you’re trying to hold tight tolerances, you might very well have to do a bunch of trial machining to dial in your wear offsets well enough to be within tolerance. That can take time and use up expensive stock if you’re machining exotic materials. Even performing a skim cut instead of a touch off may not help because tool pressures in aggressive cutting are much higher. But what if you kept track of the wear offset needed when trial machining with a new setup and tooling? In fact, what if you had a library of these measurements that you could apply to brand new jobs based on the aggressiveness of the cut? With some simple gcode, it would be easy to dial in an adjustment to the initial touch off operation to eliminate or reduce the need for trial machining.
29. Simplifying Tricky Sizing Adjustments
It’s very common for the operator to have to make an adjustment based on an inspection of initial parts and trial machining. Sometimes, the geometry is such that the adjustment is tricky–the operator has to do some math to compute the amount of the adjustment. Why have the operator do that math when you can automate it and eliminate the potential for error? What you want is for the operator to plug in the value of a simple measurement and let some custom g-code figure out the rest.
Or how about arcs specified with R rather than I, J, and K? So much easier for the operator to modify a R-Based arc than an IJK. Our G-Wizard Editor can be used to convert IJK arcs to R automatically. Of course, you could also change your CAM post to emit R-based arcs too.
30. Inventing Your Own Compensation Types
Most machining centers don’t have the wear offsets that are a staple for turning centers. The 3D geometry of machining centers is much less amenable to something as simple as wear offsets which work well for 2D turned parts. But that doesn’t mean you couldn’t create a set of custom “wear offsets” that are appropriate to the geometry of your part. Do the trial machining or inspect every nth part and have your operator update a set of variables based on measurements they take that result in custom compensation.
31. Reporting Post Process Gaging for SPC
Statistical Process Control is a powerful and sophisticated method for maintaining tolerances and optimizing the reduction of effort needed to do so. It relies on reporting of measurements. You can use custom gcode to help automate the work your operator will need to do for this.
32. Automatically Back Up Your Fixture Offsets
You’ve just spent quite a lot of time dialing in a very complex fixture on your horizontal machining center. You’ve got a tombstone with a bunch of work offsets and it’s all been carefully checked out. How would you like to have to do all that over again? Why bother when you can easily back up all the information using some simple gcode?
33. Managing Part Mix on a Tombstone
We ran a great article on a company called Straightline Components. They make high end custom bicycle parts. What I liked about the story was the ability of two and a half machinists (two sons and their dad) and their two Horizontal Machine Centers to make all the parts for the business. Doing so meant they put a variety of parts on a tombstone, no doubt motivated by day-to-day changes in inventory levels. They’re running full on Lights Out production on these things–it’s the only way two and a half can keep up with the demand. What also struck me about the story was the complexity of managing that variable parts mix on those machines. Getting all the right part programs, work offsets, tool offsets, and everything else just right has to be fairly difficult. They even have a robot to autoload work pieces just to make it that much harder. There’s sure to be a fair amount of custom g-code associated with an operation like this.
34. Use Variables to Handle Cutting Condition Changes
I mention above that many have found they can set up their Posts to facilitate manual g-code tweaking. One easy way to do this is to have the Post create a feeds and speeds table at the top of the program. By using #variables for the feeds and speeds and grouping them into a table at the top with comments that identify the tool and the operation being performed, it’s easy to tweak those variables on the Shop Floor for maximum performance without having to rerun through CADCAM.
Here’s another idea. It’s very common to perform essentially the same operation with a number of passes, for example, cutting a pocket with 4 identical passes, where each is a little deeper. Most CAM will just output 4 copies of the code. It’s hard to read and harder to modify. But, with a g-code editor, it’s pretty east to stick a pass into a subprogram so there is one copy and then call it 4 times. This can be super helpful if, for example, you need to rework a part where a tool broke after 3 passes. You can specify to only run the bottom 2 passes out of 4 pretty easily when a program is organized like this.
Or consider using this pass plus subprogram calling to deal with different sizes of rough material. Rough material by definition is oversized relative to the original part. Let’s say for a particular part you run it varies from 0.05 inch to 0.25 inch oversize. You could create a worst-case program with slow feeds and speeds or many passes that’ll deal with the worst case. Or, you could write a macro that probes the part and specifies exactly the right number of passes to get it done in the shortest time.
35. Track Offset Changes During Tool Maintenance
We’ve talked about the idea that aggressive cutting leads to tool pressures that require initial wear offsets to hold tolerance versus setting up with tool touch offs. An even more sophisticated system would track the initial wear offset after a new tool is installed versus later offsets so that when new tools went in, the original wear offsets determined by trial machining wear automatically restored.
36. Test Part Program to Minimize Trial Machining
Trial machining is the task of trying to make a part in order to see what manual adjustments have to be made to stay within tolerances. It is commonplace for tight tolerance work. But sometimes making a full part is a wasteful way to accomplish the Trial Machining task of getting good starting wear offsets. Another approach is to create a Test Part that accomplishes the equivalent. To do so, it much have equivalently aggressive cuts for each tool that will be used. Other than that, it might be quite a lot simpler and faster to test than the actual part to be machined. Creating a test part can often be done quickly with simple gcode programming and no need for CAM.
37. Handle Raw Material Z Surface Variations
As has been mentioned, any variation in process conditions from what was envisioned at the CAM stage may create a need for adjustment. Z variations in the raw material are a good example. Adding a simple variable for the allowance in Z variation is easy to do.
We’ve presented a number of concrete examples where some manual gcode programming complements CAM programming extremely well. This list is by no means exhaustive. Rather, it’s intended to be thought provoking. It should be easier to see from the list where CAM leaves off and gcode can productively step in. There are many things that happen post-CAM or perhaps aside from CAM altogether (an accessory such as a broach that was never contemplated by CAM) that are great opportunities to solve with some custom gcode. The alternative in many cases is to have the operator do more manual operations, but this is inevitably slower, more expensive, and more error prone. A lot of the problems that can be solved this way come up often enough that you can leverage the work of the initial programming over and over for profit.
Give GCode a try, it isn’t all that hard to learn and it is a powerful tool to add to your arsenal. We’ve even got a handy free GCode Tutorial that will get you started on the path. And, whether you’re already up to speed on g-code or just learning, our G-Wizard G-Code Editor has powerful features to simplify your g-code work.
Like what you read on CNCCookbook?
Join 100,000+ CNC'ers! Get our latest blog posts delivered straight to your email inbox once a week for free. Plus, we’ll give you access to some great CNC reference materials including:
- Our Big List of over 200 CNC Tips and Techniques
- Our Free GCode Programming Basics Course
- And more!
Just enter your name and email address below:
100% Privacy: We will never Spam you!