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 ![]()
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.
Wow! Thank you both, you have given me a lot of great info to absorb!
I hear exactly what you’re saying.
Maybe to say more simply: Use a macro to create a macro of defines.
M120 will do it (and it’s associated M commands for writing out data). This allows you to write data to a file.
So let’s say you have some kind of macro that is going to probe the corner of a part, you have it do the probing and then write the results of the probe to a file.
M120 “myprobelocations.mac”
-DEFINE ProbLocX12
-DEFINE ProbLocY12
Every time you run that probe calibration your DEFINEs in “myprobelocations.mac” get updated
Whenever you need your probe locations in ANY macro you just call your defines:
G65 “myprobelocations.mac” and you have them
If you want to see the data change live you can “tail” the file with notepad++
So now you can make a variable list with ANY data you want (text or numbers) and see the data LIVE change in a code editor. You can use it across any macros you want, and it will never get stepped on by anything else.
I think I’m grasping what you are saying… By writing a list of my own DEFINES I am circumventing Centroids standard variables and it shouldn’t matter if I stumble on something that centroid already used for another function because I’m only using MY variable during MY macro. Also a list of my own varibles through the define command would protect me from messing with AVID’s predefined items the same way it protects me from Centroid.
Thanks again both to both of you. I don’t know if I will get this figured out but i’m having a fun time making my own buttons for the VCP ![]()
Before you get too deep into customizing that park location, look into
These are configurable in the Centroid UI and can be executed with a 1 line command. I bet they are likely exactly what you are after.
I did see those two commands exist while reading through the manual. Is there a simple way to verify if reference points aren’t already being used for another function?
Just look at them in the setup UI to see if they’re being used. If they’re all zeroed out they haven’t been used.
We (avid) don’t use them currently
In this example, the variable that was created by the DEFINE function is “ProbLocX12”?
If “ProbLocX12” ends up being “16.5” (or any arbitrary number) were is that value recorded and/or recalled?
It’s stored in memory until you exit cnc12
If you want to store it permanently you create a macro to call your defines. You can also make a macro create a defines macro.
See my description above. When I’m back at a computer I can find an example
This is the part were an example will be helpful. I understand the concept, I just need to see a couple examples.
Thank you!
