Type of Variable | ||
#0 | Null | You can never assign a value to #0, it’s value is always “null”, which means “no value.” |
#1 – #33 | Local Variables | Local variables are used to pass arguments to macros and as temporary scratch storage. Your controller won’t remember the value of any local variables when the power is turned off. Local variables nest when used with suprograms, so be sure you understand how that works. |
#100 – # 199 How to remove aero glass watermark. #500 – #999 | Common Variables | Common Variables are shared by all your macro programs. When the power is turned off on the controller, #100 – #199 are cleared to null. #500 – #999 remember their values for the next time power is turned on. |
#1000 and up | System Variables | System variables can be used to tell things about what the controller is doing, such as the current position. Don’t assign anything to these unless you know what they do! |
Mach3 has 10,320 variables available, from #0 to #10320. There’s not quite the variety found in Fanuc, but still, plenty of system variables are accessible so you can get at things like work offsets. Mach3’s variables are saved from one control boot up to the next, so be sure to reset them if you aren’t expecting them to have a value.
Use variables whenever you think you might want to change a value in different situations. For example, suppose you have a macro or subprogram that cuts a square pocket. You probably want to have variables that let you define the size of the square and the feeds and speeds so they may vary as the material changes. Depending on the subprogram, you might want a variable for the top left corner of the square, or you might simply let that corner be the current position when the routine is called. You may want a variable defining the depth of the square pocket. And lastly, you may want a variable that defines the diameter of the tool.
Fanuc Uses | Function | ||
Power | #1 ** #2 raises #1 to the power #2. Power takes precedence over the other operators. | ||
Modulus | Modulus divides and returns the remainder. So 5 MOD 2 is the remainder of 5 divided by 2, which is 1. The modules of 4 divided by 2 is 0. Mod is a convenient way to keep a value with a range of 0 to the MOD divisor. | ||
Absolute Value | ABS | Absolute value. ABS(1) = 1. ABS(-1) = 1. | |
FIX | Rounds down to the next smaller integer. FIX(2.8) = 2, FIX(-2.8) = -3. | ||
Rounding Up | FUP | Rounds up to the next larger integer. FUP(2.8) = 3. FUP(-2.8) = -2. | |
ROUND | When used in a macro function like IF, ROUND rounds down by slicing off the fractional decimal places. ROUND(1.1) = 1.0. ROUND(-1.1) = -1.0. When used as a coordinate address, ROUND rounds off to the least input increment of the address = 0.001 for mm and 0.0001for inches. | ||
SQRT | |||
Natural Logarithm | |||
Exponential | |||
Trig Functions (Units are Degrees, 90 degrees 30 seconds = 90.5) | |||
COS | |||
Sine | SIN | ||
TAN | |||
Arc Cosine | ACOS | ||
ASIN | |||
Arc Tangent | ATAN | ||
Logical OR | OR | ||
AND | |||
Logical XOR | XOR | ||
Convert from BCD to BIN | See your Fanuc manuals for more details on these specialized functions. | ||
Convert from BIN to BCD | See your Fanuc manuals for more details on these specialized functions. |
Debugging Macro Variables and Expressions with G-Wizard Editor…
Just type your expressions on the left. In this case, we have a pretty simple set:
Macro variable values are shown below the backplot…
This little window shows all the modal activity, for example, we’re in G00 – Rapids mode. The values of Macro Variables are also modes of sorts, so they’re shown too. You get to see values for the last n variables whose value changed, and they’re sorted by variable #. Note how it also gives you a little hint about what the variable does. For example, it says #100, #101, and #102 are “Volatile Common Variables”. “Volatile” means their values are not remembered when the controller is switched off, and as we saw from the table up near the top of this page, variables in this range are Common Variables. G-Wizard doesn’t have all the variable values, but is has an awful lot of them and it will try to use this information to help you understand what’s going on.
1. Pull out your CNC controller manual and see what differences exist between your controller and what’s described here.
2. Use GWE to experiment with Macro Variables and Expressions until you’ve got a good grasp of them.
3. Modify one of your existing G-code programs to use some variables and expressions. Verify that it still produces the correct results when you’ve finished.