User defined variables for custom macro

Hi, I would like to write a couple macros and wanted to know if there is a directory of sorts showing what user defined variables are already taken? I assume if I write something that uses a variable that is unknowinly part of another macro I can create some major problems…?

What control platform are you talking about? EX or Mach 4?

I have the EX controller.

I want to duplicate the existing park function and basicially make Park 1 and Park 2. One will send the spindle to the back right or left corner to load sheets and the other to park right off of the home position before i shut down for the night so that it is ready to home the next time I turn on the machine.

Another thing I would like to do is modify the manual tool change routine to go to an interim park position (Park 3) to allow me to change the tool before going to the tool lenth measure probe. That way, if and when my tool drops out the the collet while I’m loosening it up with the two wrenches, it will fall onto the spoil board and not the floor…

That should be pretty doable. You can go into the CNCM/AvidMacros and poke around in there. Most of the “Avid” macros are in there.

The tool change script is a little more complex to edit. But maybe you don’t have to… when you do a tool change and the tool goes over the touch plate you can just jog it away, change your tool and press cycle start and it will go back to the touch plate for you.

All of the run time macros are all done in the Centroid scripting language which is fully documented here:

All of the Avid Macros are mostly in the that folder and are all uncompiled so you can look at how they work.

Awsome, thank you.

I made a copy of the stock router profile to screw around with and I’ll post what ever I figure out.

Correct, I have had trouble when using variables and then calling another macro those variables can get stomped on and then when returning from the other macro things don’t work as you’d expect.

I’m hoping some day Centroid will update CNC12 to allow users to define their own variables. The predefined, and enumerated variables are hard to use reliably, and make reading the code very difficult since you have to constantly look up variable numbers while reading/writing macro code.

You can #define variables, but that only helps you decipher your own code, and doesn’t help the safety aspect of not having secure variables.

They already do. You can use a DEFINE command. You can define anything in a “DEFINE”

You can write your own “DEFINES” file. I am moving to this now.. basically it’s just a big file that I have hundreds of my own DEFINEs in. I call that file first before running any other macro.

The current DEFINE is just a text alias. It lets you substitue any text with a word. It doesn’t create anything new. So it is helpful in that you can use it to make your code readable by making sensible names for the enumerated variables, but that doesn’t stop the use of that same variable in any other macro.

What is really needed is the ability for a user to create a unique variable (like any computer language lets you do), that way it has its own memory space and no other code would be using it, so it makes your macro safe and self contained. Without this creating a macro is a bit of a crap shoot because you don’t know where else that variable may be used.

You’re pretty much describing exactly what DEFINEs can do :slight_smile:

What you should do is this:

Make a file that has nothing but defines in it. Put in as many as you want, call them whatever you want.

On the first line of any macro you write call G65 “mydefines.mac” and it will set all of your defines.

Now, lets say you want your macro to store defines (say the result of a formula or something) you can use M130 commands to write a DEFINEs file with a macro.

This is a gross over simplication but you can do something like this:

M130 “lasermacrodefines.mac”
;DEFINE laser offset x 12
;DEFINE laser offset Y 12

Your macro now creates a macro with the new defines in it, and you can then call it again the next time your macro runs.

So basically you get unlimited storage for whatever information you want.

Best of all, if we, or someone else happens to use the same define in another macro it will work fine as long as you call your defines macro when you run your macro…hopefully that makes sense.

You can also get clever with the temporary variables (#100 - #149) and use those to read/write defines too

The DEFINE doesn’t create anything, its just a text substitution tool.

If you do this in the code:

DEFINE X1 Y0

Then the interpreter or parser (depending on what kind of language you are using) will just substitute in “X1 Y0” whenever it sees “start position”. Then it will compile or run (depending again on the language) the code.

So you can do this in a macro:

DEFINE #149
DEFINE #149
DEFINE #149

Then you can write macro code that refers to #149 by any of the 3 defined aliases, or directly as #149, but in all cases you are using the pre-existing variable #149, and therefore it is not truely safe to use unless you know if and how its used in all other code in your environment. You can set the value of the variable at the top of your macro, call another macro, and when you return from the call you may find your variable has a new value due to the macro you called. This has happend to me when calling the M6 macro.

In contrast, in a normal computer language if you do this:
global Bobs_var = 1

You’ve just created a brand new variable with a name, its own unique memory space, and the value 1. If you are judicious with your variable naming, it will make sense when debugging your code, but more importantly will be unique if you want it to be. If you pick a name that is already used, it will tell you so at compile/run time.

CNC12 has a good number of variables in the range of 29,000 to 31,999, so you can make your own aliases for some of those for your own code, but you can’t guarantee that they aren’t used somewhere else in the environment without some work.

I haven’t run across a good way to get a list of what variables are used other than searching all the macro code.
I’m glad AVID is starting to make an aliases file with DEFINEs so at least we can refer to that and avoid those variable numbers. That is helpful.