5 Ways G-Code Simulators Crush CNC Errors [ Vids+Free Sim ]
You Don’t Run G-Code Without Testing It, Do You?!??
( Better not let the boss find out if you do… )
Use a G-Code Simulator to Test and Prove Your G-Code
Considering what can happen if there’s a mistake in the gcode, and even CAM software makes mistakes sometimes, you want to test your gcode before you run it to make chips. Testing can range from “cutting air” to using a G-Code Simulator.
“Cutting Air” just means running with part zero set high above the workpiece so the cutter (hopefully) doesn’t come in contact with any material until you see what it will do. Cutting Air is the least you should do to test (also referred to as “proving out” a part program) your gcode part program. The trouble with Cutting Air is it can be very time consuming and it ties up your expensive CNC machine the whole time.
If you must Cut Air, here’s how to do it:
What if there was a better way to get a second opinion and test your gcode? One that didn’t tie up the machine and that could be done much more quickly than Cutting Air? That’s what G-Code Simulators are for.
It’s actually cheap and easy to run a G-Code Simulation. You need a piece of software that has variously been called a G-Code Simulator, CNC Backplot, or G-Code Viewer. You’ll also hear the terms “Verification”, “Emulation”, and “Virtual CNC” batted around, though they’re a little less common than the other three.
I’m sure many of you are thinking, “Yup, I use the g-code simulator in my CAM Software all the time!”
Not so fast!
Doesn’t my CAM Software already have a Backplot / Simulator for this purpose?
The qualified answer is, “Probably Not.” The issue is the way CAM program simulators work. If your CAM program includes a true CNC g-code simulator, then yes, it can be used to help test g-code programs.
The thing is, most CAM programs don’t. They just plot the same geometry information that was used to create the g-code output by the postprocessor. This allows for subtle bugs to creep in that are not detectable in the CAM backplot. For example, bugs in the post cannot be detected this way because the post is downstream of that geometry info. In other words, you aren’t really performing an independent test on the g-code. Relying on this type of simulator is fraught with peril.
Because of that, a lot of experienced machinists insist on a separate simulated backplot as a sanity check for their g-code before they’ll run it. It doesn’t cost very much or take very long to have this peace of mind, so it’s something you should consider.
BTW, when we get done going over how to use a G-Code Simulator to test your CNC programs, we’ll also talk a bit about the other ways a simulator can help you out with your CAM Software.
5 Ways G-Code Simulators Test Your CNC Programs
Here are 5 Ways a G-Code Simulator Can Help Test Your CNC Programs:
1. Backplot: A quick visual indication of what motions the program will make with the cutter.
2. Extents and Soft Limits: Checks to make sure the cutter will stay within the area you want it in.
3. Alarm Checks: The backplot might look okay, but your program can still immediately alarm out on the machine. A good simulator will make many of the same tests as your machine controller ahead of time. For example, the if the distance from each endpoint to the center of an arc is not the same within a tolerance, you’ll get an alarm.
4. Tooling Summary: A good simulator will compile information about the tools or cutters required by the program. Checking over this list and making sure the right tools are loaded into the machine’s toolchanger is a great test to avoid errors.
5. Subprogram and Macro Tests: A good simulator collects all sorts of information about macros, subprograms, and the variables that are in use. This information can often turn up various problems the part program may encounter.
Not all simulators can do all 5 things. Our G-Wizard Editor can, because it offers full simulation. But many g-code viewers and editors are quite limited.
How to Use a GCode Simulator
|Deliverable: G-Code for the Part + Setup Sheet
The Backplot is a graphical 3D display of tool motions…
The Backplot is a graphical 3D display of the tool motions your g-code program will command the CNC Machine to make. You can tell a lot from a quick check of a backplot. For example, any surprising moves well outside the normal envelope of the motions are probably a bad idea. The tool motions should roughly correspond to the shape of your part.
You can run the backplot in the simulator and see the tool motions as they will unfold when the g-code is run. Watching this animation can also reveal issues that are unexpected. For example, you might find operations are happening in a different order than you expect or desire.
Check for Collisions and Gouges
|Deliverable: Program checked for Collisions and Gouges
Vericut simulation software showing a gouge in red on the simulated part…
Higher-end Simulation Software has Collision and Gouge checking.
With Collision checking, your machine and the workholding, such as a milling vise, will be pictured in the simulation. The simulator will automatically detect whether the tool comes into contact with the machine or workholding, both of which are generally very bad and should be avoided.
Gouging is when the tool touches the part while moving at rapids speeds. This can happen if the tool wasn’t retracted far enough before rapids were commanded. In most cases, this will be way to fast and the tool can be broken or chipped. These are again, things to be avoided.
Collision detection can be in the form of Soft Limits on your axis motion. This is less powerful than checking against real 3D models of your machine and workholding, but can still be very valuable. For example, you might know that your 4th axis is at a particular Y-coordinate and you want to avoid any tool motion on the wrong side of that coordinate lest the tool collide with an expensive 4th axis.
Note that while this checking makes collisions and gouges less likely, they’re still possible. For example, entering different tool length offsets on the machine than were assumed in the simulator could result in collisions that the simulator didn’t detect.
|Deliverable: Program checked for Machine Alarms and Other Errors
Spindle alarm on a Fanuc controller…
Many times more subtle errors can cause a part program to alarm out on the machine. For example, most machines will send an alarm and stop the part program if they encounter an arc command where the distance from each endpoint to the center of the arc differs by too much. The alarm is sent because it’s clear that there must’ve been a mistake of some kind made.
A good simulator can check for all sorts of Machine Alarm Errors so you aren’t scratching your head wondering what’s gone wrong in the middle of running the program on a machine.
Some error checking is more along the lines of a sanity check. For example, a simulator might check whether a tool was selected and spindle rpms and feedrate were selected before feed motion occurs.
Check Tool List
|Deliverable: Setup Sheet Tool List confirmed to match Part Program
Tool Crib display in G-Wizard Editor…
A good simulator will generate a list of the tools used by the g-code program. This list should be compared to the list in your Setup Sheet to make sure that they agree. Make sure all the same tools used by the program are in the Setup Sheet and that they have the same tool numbers so the right tools are selected from the Tool Changer.
Check Overall Program Stats
|Deliverable: Overall Program Stats checked against expectations for the program.
Simulators often have stat sheets that show the overall statistics for a part program. Such statistics include:
– Extent of travels in each axis
– Running time for the program
Making a quick read of the statistics to be sure they’re in line with expectations is always a good idea.
Check Tolerances vs Original CAD Model
|Deliverable: Machining operations verified to be within tolerances described by the CAD Model.
Vericut simulation software showing excess material that should’ve been removed according to the CAD model on the simulated part…
Higher-end Simulation Software has the ability to accept a CAD model of a part and compare it to a simulated model to see where the two differ. In the simulated model, simulated cutters carve away material as commanded by the part program.
This is a great final check that will identify cases where the part looked good visually in the simulation, but was actually off by more than some specified tolerance from the CAD model.
What is a G-Code Simulator?
Think of a G-Code Simulator (or cnc simulator if you prefer) as a piece of software that can execute g-code programs, but instead of controlling servo motors and a spindle on a machine, a g-code simulator produces a graphical display of what the machine would do. That graphical display is often referred to as a backplot. It shows the toolpath your cutter will follow if the g-code program is executed. Here is a backplot produced by the g-code simulator that’s built into the G-Wizard G-Code Editor:
The CNC Backplot is the graphical display on the right…
In this particular g-code program, we’re doing some engraving for an electrical panel that’s part of a CNC controller I put together.
Customization: Having a “Post” in the CNC Editor
As we’ve discussed, g-code has “dialects” depending on which controller you use. You may be thinking that since all your machines are Haas, or all your controllers are Fanuc, that a Fanuc G-Code Simulator or a Haas G-Code Simulator would be fine.
But you never know when you might bring in a different machine and be wishing your Simulator could deal with it. Also, your g-code editor and simulator software should be capable of understanding as many of these nuances as possible. In CAM software, the nuances are handled by what’s called the “Postprocessor” or “Post”. You want your editor to have a “Post” too. For more, see our page on G-Code Dialects.
By the way, a lot of g-code editor simulators offer very simplistic posts or even no post at all. They list only a few options or g-code dialects. Because of that, their simulations are not as faithful to your machine as you’d like. Be sure the g-code simulator you choose has full Post options.
Navigation in a CNC Simulator’s Backplot
A good G-Code Simulator can tell you all sorts of useful information. Let’s go through some of the information we can glean about the electrical panel engraving program from the screen shot above.
First of all, the graphics can often tell you at a glance whether the tool path is what you’re expecting. Be on the lookout for any sudden unexplained departures outside the envelope you’re expecting. The red lines are rapids motion and are red because rapiding into the workpiece is a bad thing to be on the lookout for. Green represents motions made at feedrate speeds.
In G-Wizard editor you can rotate the backplot by holding down the right mouse button while moving the mouse on the Perspective view. In the other views, such as Top, Front, and Right, holding down the right mouse button lets you pan the view.
You may need to zoom in close to see what’s happening. The mouse scroll wheel controls zoom. If you get lost in the forest of lines, simply press the icon on the toolbar that looks like a magnifying glass with an “A” in the middle. This is the “Zoom Extents” command, and it zooms the display and centers it based on the full extent of the motions for your program.
If you want to redraw the backplot from scratch, there is a “Backplot” button as well–the two arrows circling one another. Pressing the Backplot button forces re-parsing and re-plotting of the entire program.
The grid is there to give you an idea of position and size. It’s calibrated according to whether your Post is currently set for Imperial or Metric. Down on the status line at the bottom are X, Y, and Z coordinates of the tip of the mouse cursor, so you can point at something on the backplot to see its coordinates.
Single Stepping to Understand G-Code Better
A good simulator can do a lot more than just display a backplot; it can run through the program step by step and show you a great deal of information about what’s going on. With GWE, a set of buttons similar to what is found on your CNC is used to control the simulation:
To start a simulation, press the “Rewind” followed by “Cycle Start”. You can control playback speed as a percentage of maximum with the Playback Speed controls. The Tortoise makes it run slow, the Hare makes it run fast and you can change the percentage as well. If you want to step through block by block, turn on the “Single Block” button. It will turn red to signify it is active. To exit the simulator and show only the finished Backplot, just press “Feed Hold”.
Using these controls you can go through your program block by block. The “Special Stepping Controls” give you the ability to move ahead to points of interest more quickly:
– “5-Step” causes 5 blocks at a time to execute in Single Block mode instead of just one at a time. You can change the number of blocks this button will execute via the Simulator Options menu.
– “Next G00” moves the simulation ahead to the next G00. Often a g-code program will alternate between cutting moves and G00 moves to position for the next cut, so this is a convenient way to move forward.
– “Next G04” moves the simulator ahead to the next Dwell (G04). Why is that helpful? Dwells can be inserted almost anywhere in a program without causing a problem, so insert a Dwell in a place you want to be able to go to easily while debugging your program and use this button to get there quickly.
– “Next M06” moves the simulator ahead to the next Toolchange.
– “Next GOTO” moves the simulator ahead to the next place where the program jumps to a subroutine or block number. It’s handy if you’re trying to debug macros.
Simulator Screen Areas
When the Simulator is running, GWE displays quite a lot of additional information in a variety of screen areas:
Each screen area is called out in the illustration above in red. Here is the function of each:
This area shows you the g-code. The line being executed is highlighted. The illustration shows the very top line highlighted. If you click on this pane, GWE will offer to stop the simulation so you can edit the code.
This shows you the backplot of the moves made up to the currently executing line.
Position is like the position display on your machine controller. It’s showing you the X, Y, and Z coordinates, the Spindle RPM, the Feedrate, the current Tool, the Coolant status, and the time the program has run.
Modes tells you all the modal states of the controller. For example, is some work offset active? It also tells you the last few #variables that changed and what the values were that they changed to.
Hints: Data on Individual Lines
GWE has a unique feature called “Hints”. Every line has a hint that is displayed below the backplot when the cursor is on that line. You can also select the “Hints” tab and see the g-code replaced by a series of Hints. Hints are simply an English-language description of what the g-code does. They often include a lot of extra information that may not be obvious even to an expert just looking at the g-code. Here is a typical example of a Hint for a line containing an arc:
Line N400 has an arc. The Hint below the backplot tells all…
We haven’t learned arcs yet, but the line is as follows:
N400 G03 X0.5 Y0.375 I0. J0.125 F7.0
The fact we don’t yet know how arcs work makes the Hint even more valuable. Let’s take a close look at the Hint:
The Hint for an Arc…
It tells us the following:
– In bold at the top is the original text of the line. This is useful if we’re in Hints view and can’t see the g-code line text.
Right below the bold, it starts telling us all about what the line does:
– The Block Number is N400
– G03 performs Counter-clockwise circular interpolation. In other words, it tells the machine to move the cutter in a circular arc at feed speed.
– The Feed Rate was set to 7.0 on this line.
– We see what the IJK values parse to be. In this case, we have I=0, J=0.125, and no K
– The endpoint of the arc after the move is 0.5, 0.375, -0.04
– The coordinates of the center of the arc are 0.375, 0.375, -0.04.
– The center was determined by IJK (as opposed to R, which is another way)
– The angle of the arc runs from 270 degrees to 0, a total of 270 degrees.
After all that, the Hint skips a line and gives us a time. This is telling us how long it will take the g-code program to reach this line and finish it if we execute on the machine. In this case, we can see the arc will be completed 4 minutes and 54.7 seconds after the program starts executing.
Phew, that’s a lot of data spewed forth, but it can be extremely handy to have when you’re trying to figure out what a g-code program is doing or what’s wrong with one. And, like I said, it’s hard for an expert to tell all of this stuff at a glance.
GWE gives this level of detail for each and every line of the program.
Overall Program Information
In addition to detailed specific information on each g-code line, G-Wizard Editor also provides useful overall information about the program. GWE has an “Info” tab that holds the overall information. Take a look at the illustration to the right to see what the Info tab looks like. As you can see, it tells you a variety of information about your g-code program including:
– It’s size both in terms of lines and bytes. If you’re trying to make your program fit in the limited RAM memory available to an older controller, it’s important to be able to tell quickly how you’re doing.
– For each axis, GWE will spell out the range of motion used as well as the length, width, and height these ranges imply. You get the information both overall and in terms of just feedrate motion. The rapids will nearly always extend outside the feedrate envelope, but the feedrate envelope may give you a good idea of the rough stock size needed by the program.
– You get to see the range of spindle rpm’s used as well as the range of feedrates used in the program.
– You get to see the overall predicted run time of the program.
– Lastly, there is a count of the different classes of operations within the program, as well as a count of the number of errors GWE discovered in your program.
Why Use a G-Code Simulator?
Are you starting to get some ideas for how a g-code simulator could be useful to you? As you can see, a good simulator throws off a wealth of information to help you understand what’s going on in the program. Machinists need to know these things for a variety of reasons.
Here are some possibilities to think about:
– Learning and Training: CNC Simulators are great for getting a better understanding of what the g-code is doing, how specific g-codes work, and in general, answering “What will it do if…” sorts of questions. If you’re trying to learn the ins and outs of a controller that is slightly different than the one you “grew up with”, a simulator can be a good place to start getting used to the differences of the G-Code Dialects.
– Quick Sanity Check: You just posted some g-code out of your CAM program. Why not bring it up for a quick check in a good CNC Simulator. Are there any obvious errors being flagged? Does a quick visual check indicate nothing obvious is amiss? Most CAM programs have bugs (heck, all software does, the CAM people certainly aren’t immune). Most of the time, their backplots and simulations are not true G-Code simulations. They’re just geometry plots. If there is any kind of error in the post processing, the CAM simulator will not show you a faithful rendition of what your machine will be doing. I knew one machinist whose CAM program would periodically throw a wild rapid move in when he used work offsets. It was an easy fix, provided he caught it before running it on the machine. It became not only easy, but essential to do the quick sanity check on a CNC Simulator before running each program. After all, in many cases, the CAM program isn’t sitting right next to the machine. Do everything you can to make sure the program is right before trying to load it and execute it.
– Debugging Hand Written Code: Obviously if you’re writing g-code by hand, a CNC Simulator can be a real labor saver. In fact, I can’t imagine how you do it without one.
– Tracking Down Subtle Errors: You’ve got a g-code program. It appears to have no errors, your machine runs it okay, but when the resulting part is finished, there are problems. A CNC Simulator that can give you detailed information such as we worked through on the arc might help you to track down the source of the error and correct it, assuming the error stems from the g-code and not some other source.
– Trying Out New Ideas: Suppose you want to compare some different approaches to a part program. Is it faster to interpolate a hole to begin pocketing, or are you better of running an extra toolchange so you can make the hole faster with a 1″ indexable drill? These kinds of things are ideal to compare with simulations, assuming they have the ability to accurately predict the run time of your g-code program. When you consider that some complex expensive parts can spend many hours if not days on machines, it only makes sense to figure out everything you can about how to optimize the job before you get to the point of putting it on a machine.
There are probably lots of other reasons, but the bottom line is you can quickly tell what’s going on with your CNC program without risk to machine, materials, or tooling.
Error Checking Features
Every error you find in your editor or simulator is an error you don’t have to find at the machine, which saves you time and money. The more extensive the error checking your simulator can do, the better. It’s ability to check errors will be limited by the precision of the Post. The more detail it understands about your controller, the more accurate it can call out issues that the controller may object to. Another important capability is being able to ignore any error message. Sometimes errors should be treated more like warnings. Sometimes they’re not quite right because of controller parameters that may change the controller’s behavior. Either way, it’s convenient to be able to ignore them when you want to.
In the G-Wizard CNC Editor / Simulator, errors are displayed in the Hints view (see the prior chapter on CNC Editors for more on Hints).
Tool Data Management
This is a critical, and often overlooked function. Your editor should be able to maintain a Tool Crib or Tool Table. It should be possible to import and export these tables so they’ll stay in sync with your CAM program and the Tool Changers on your machines. Just as running a CNC machine without knowledge of the tools in the changer is bound to lead to trouble, so is running your simulator that way. For more on the Tool Data Management capabilities of G-Wizard Editor and other software, be sure to check our article on TDM:
It’s not part of the tutorial, but you should pop over and at least scan the articles some time so you know what the issues and concepts are for Tool Data Management.
What is G-Code Verification?
As mentioned above, CNC Verification often refers to a higher level of functionality than straightforward CNC Simulation and Backplotting. A full CNC Verification package will include capabilities such as:
– Full 3D simulation of the cutting. This is a basic requirement for verification and could as much be considered part of higher end CNC simulation as verification.
– 3D Import and Display: Some capacity to import 3D models, usually in the form of .STL files (Stereo Lithography, a common 3D file format). For example, you might import models of the machine, fixtures, cutters, or the finished part.
– Gouge detection: Gouge detection involves detecting a number of conditions, all of them bad. If the tool moves too quick, say at rapids, into the workpiece, that’s a gouge. If the tool moves into the fixtures (such as your Kurt Vise) or worse the machine itself, that’s also a gouge. Good verification software detects all of these conditions.
– Tolerance verification: With tolerance verification, you can import a 3D solid model of your finished part and the verification software will tell you how the simulated cut model deviates from it. Ideally, it can show you a color coded diagram that is marked with all the places where the g-code program either cut too deep or not deep enough based on the tolerances you’ve established.
– Full Machine Kinematics Simulation. This is the ability to show a faithful 3D reproduction of the machine with accurate modeling of everything from the machine’s physical travel limits on to even the exact performance envelope of the machine.
It’s tough to say exactly where CNC Simulation ends and Verification begins, but just because a package calls itself a Verification package doesn’t make it so. In particular, if it can’t do the 3D import of fixtures and finished part, if it can’t do gouge detection, and if it can’t do tolerance verification, you shouldn’t regard it as a verification package. It’s a fancy simulation package. True Verification software tends to be quite expensive, so caveat emptor (beware the buyer) if you seem to have found a cheap one. It may be too good to be true.
Simulators and Verifiers are extremely useful tools for CNC. There are a lot of other software tools available too. See our Digital Tooling article for a good overview of the different types that are available.
1. Get some sample g-code and load it into G-Wizard Editor so you can play with the backplotting capability. If you don’t have any samples, try our sample file page for some downloads, including the files displayed in the screen shots for this G-Code tutorial.
2. Experiment with the different views available in G-Wizard Editor.
3. Experiment with both Mill and Lathe sample g-code. Remember, you’ll have to change your machine profile from Mill to Lathe and be sure an appropriate controller profile is selected to view the different file types properly.
Next Article: Part Zero, Touch Offs, and Zeroing
4 More Reasons CAM Users Need a G-Code Editor & Simulator
I get asked this question a lot:
Why would I need a GCode Editor Simulator when I’ve got CAM and it has a Simulator too?
For many CNC’ers, they think CAM means they’ll never need or want to deal with g-code. So why would they ever consider having a G-Code Editor / Simulator like our G-Wizard Editor? Wouldn’t it be redundant?
Honestly, to me that’s like asking why I’d need bacon if I already have eggs for my breakfast. The two really do go together extremely well (eggs and bacon or CAM and GCode Editors–both go well together!).
We have run a survey for a long time that asks CNC’ers what their knowledge of g-code is, and here are the results:
Look how few CNC’ers can’t really work much with gcode…
Most CNC’ers discover that if you’re going to be into CNC, you owe it to yourself to pick up a decent grasp of gcode. It really is useful and fun.
We’ve talked at length above about how to use a G-Code Simulator to verify your gcode is correct before it goes on your CNC Machine. Here are 4 more reasons CAM Users need a G-Code Simulator:
#1 – Making Little Fine Tuning Changes Much Faster than you can with CADCAM
#2 – Learning GCode
#3 – Making Simple Parts Without CADCAM: Conversational CNC
#4 – Doing Special Uber-Cool Things That Win Big
Ready for Your Own G-Code Simulator?
G-Wizard Editor Makes it Easy
Here’s a look at why thousands of CNC’ers
trust G-Wizard Editor to make GCode easy for them too.
A G-Code Editor and Simulator with Everything You Need
Conversational CNC: a gigantic timesaver
Remember how easy it was to do simple things before CNC? No need for CAD or CAM, just walk up to the machine and make a part.
Conversational CNC generates gcode quickly and easily without having to fire up CAD or CAM. Make simple parts fast!
Extensive Error Checking
Your machine doesn’t just expect you to look at the backplot and figure it out–it has alarms.
Most Editors just give you the backplot, but G-Wizard has an array of powerful error checks, messages, and a dedicated tab that shows you all the errors and warnings for your gcode.
There’s much more available with our
G-Wizard G-Code Simulator and Editor!
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!