CNC Software CNC Software

Subscribe

 

Categories

G-Wizard Editor’s New Macro Variable Tab, SETVN, and Naming #Variables in Macros

Mar 29, 2013   //   by Bob Warfield   //   Blog, GCode, Software  //  3 Comments

Macros and subprograms are potent addition to the g-coder’s arsenal.  Used properly, they will make your g-code programs shorter, more general purpose, and easier to understand.  Unfortunately, not every g-code dialect supports macros.  Some have fewer features than others, while some have no support at all.  Others will have very sophisticated and feature rich sets of macro programming features.  Fanuc Macro B is probably the most common example.  But, another controller dialect that has very sophisticated macro features is LinuxCNC.  Perhaps that’s because it is open source and many software developers work on it and add features to it.  Your average software developer looks at the g-code syntax and finds it to be pretty primitive, so it is perhaps no wonder that a control aimed at that audience will have some pretty nice programming features.

Getting a high quality LinuxCNC post-processor together for our G-Wizard G-Code Editor and Simulator is the priority around here right now, and I was just sitting down to start implementing the various heavy-duty macro programming features of LinuxCNC when a thought struck me.  As I often do, I started out by looking at sample code our fabulous user community had sent over.  Once program was filled with LinuxCNC macro variable declarations.  I got to thinking about how to keep all of that straight.  LinuxCNC at least has symbolic naming, so you can give a variable a human readable name instead of just a number like Fanuc’s “#100″.  But still, a big program will have a lot of variables, and one with no symbolic names is an even bigger chore to read and understand.

So, I decided to add a new macro variable tab to the G-Wizard Editor to make it easier to keep up with what’s going on.  It looks like this:

G-Code Macro Variable Viewer

The inset shows the g-code that goes with that Variable list…

You access the Variables list as a sub-tab under “Macros”, which used to be called “Subprograms” back before we had a “Variables” tab.  In the list you will find every single variable your program accesses together with the symbolic name (if any) and the last value the variable had when the simulator ran.  Now you have an easy way to find out what variables your programs access.  You could even use this tab to help document a g-code program if you need to.

While I’m on the subject of macro variables, I wanted to revisit a couple of items.  First, GW Editor supports the full Fanuc “SETVN” syntax, which you see in action in the screen shot.  SETVN can be used to give variables friendlier names.  But, there’s more (and no, I’m not talking about steak knives here!):

G-Wizard Editor Let’s You Name Your Variables Even If Your Controller Doesn’t

This is a very cool feature, so let me just say it a second time:

You can give your variables names even if your controller doesn’t allow that syntax.

Essentially, this works by letting you use SETVN with controls that don’t even have SETVN.  I call it a “Soft” SETVN feature, and no other editor simulator has this capability that I am aware of.  It allows you to place SETVN statements in comments that begin with “*GWE*”. For example, suppose we have the following version of the program from the screen shot above:

%
( SETVN Test )
( *GWE* SETVN 500 [PROBEDIA, HOLEDIA, XPOS, YPOS] )
#500 = 0.010
#501 = 3.000
#502 = 0.0
#503 = 1.0
#600 = #500
#601 = #501
#602 = #502
#603 = #503
M30
%

It’s legal for most controls that support #variables at all, because the SETVN is in a comment.

Now go to the Tools Revise menu and choose the “GWE Directives” choice. Make sure the “SETVN Do” radio button is selected and press “Apply”. The program is now transformed as though your controller supports SETVN:

%
( SETVN Test )
( *GWE* SETVN 500 [PROBEDIA, HOLEDIA, XPOS, YPOS] )
#PROBEDIA = 0.010
#HOLEDIA = 3.000
#XPOS = 0.0
#YPOS = 1.0
#600 = #PROBEDIA
#601 = #HOLEDIA
#602 = #XPOS
#603 = #YPOS
M30
%

What’s happening is that #PROBEDIA, for example, is the same as #500.  Cool beans, eh?

You can write and debug your macros with variable names that are actually understandable. When you get ready to save, just run the “Undo” form of the same revision and it strips all the SETVN names back out and restores the correct numbers as defined in your *GWE* comments.  But here is the cool part:

Since the SETVN’s are still in the comments, you can just reload the file if you need to work on it some more and they’ll still be there.

If you’re doing g-code programming, give this feature and our new Variable tab a try.  They’ll simplify your work.

And, as always, if you’ve never tried G-Wizard Editor, give it a shot.  We have a free 30-day trial and we’re even running a big sale on it for a few days longer.

 

Like what you read on CNCCookbook?

Join 30,000+ Machinists, Designers, Engineers, and Hobbyists!  Get our latest blog posts delivered straight to your email inbox once a week for free. Just enter your email address below:

 

100% Privacy: We will never Spam you!

3 Comments

  • [...] G-Wizard Editor's New Macro Variable Tab, SETVN, and Naming #Variables in Macros – CNCCookbook … on Less Than A Week Left On Our Sale, And A Special Bonus Offer I’m Adding Today [...]

  • What about an extension fo this idea: Being able to flatten a g-code programn with variables and macros to something that even the most basic of g-code interpreters can understand. Basically just replacing every variable or macro usage with their values in simple g-code.

    • Yes, I’ve already done preliminary experiments along the lines you describe to see if it is doable. It’s a ways out though.

      Cheers,

      BW

Leave a comment

Home

Software

  GW Calculator

  GW Editor

  Gearotic

  Conversational

  Deals and Steals

CNC Blog

  Software

  Techniques

  Beginner

  Cool

  Projects

 

Cookbooks

     Feeds and Speeds

     G-Code Tutorial

     CNC Machining & Manufacturing

     DIY CNC Cookbook

     CNC Dictionary

CNC Projects

Resources

     Machinist's Search

     Videos

     Online Groups

     Individuals

     Reference Data

     Books

     CNC Dictionary

     Suppliers

     Tool Brands

Workshop

     Hall of Fame

     Organization: Soon!

 

About

     Customers

     Partners

     Our History

     Privacy Policy

 
All material © 2010-2014, CNCCookbook, Inc.