Who Makes the Most Popular End Mills for CNC?
Take for our annual End Mill Survey and we'll tell you the
THREE WAYS TO SHARE
5 Ways G-Code Simulators Test Your CNC Programs
You Don’t Run G-Code Without Testing It, Do You? Use a G-Code Simulator!
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 it 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. 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.
CNC Verification can sometimes have a little different meaning, referring to the high end of the market for this kind of software, so let’s leave it to talk about until the end. Meanwhile, let’s take a look at CNC Simulation Software, and we’ll use that name for the rest of the tutorial.
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.
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.
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.
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 two part series on TDM:
Part 1 is the basics of Tool Length and other Tool Data.
Part 2 goes into topics like Tool Presetters and software to manage Tool Data.
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
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.