3152
« on: January 29, 2019, 12:43:16 AM »
Hi,
Gcode it simply a long series of movement instructions, it does not have the ability to be 'programmed'.
Lets take an example. Lets say you are surfacing a piece of material. You do one complete pass and then measure
the height of the material with a G31 code. Now if the height of the material is 5mm you wish to take another complete
cut of 2mm over the surface. If however the height is only 4mm then we want to leave it alone.
As you can see it would require Gcode to make a decision and do one thing if...so and so....and do something else
if not. Gcode can't do that, at least Gcode that is commonly supported by Mach3 and Mach4Hobby. Mach4Industrial
supports Macro B Gcode which does have some capacity but that is a side issue at the moment.
What Mach, or rather the Gcode Interpreter can do however is execute a macro, a so called M code. You will be familiar with
the likes of M3, M4 and M5 which turn the spindle on and off or M6 for changing tools. You can however write your own
macros. Macros with names under 100, ie M99 and lower are considered as belonging to Mach and therefore best left
alone. Macros named M100 and higher are suitable for personal use. Having said that there are some macros that ship
with Mach in that range. Two which come to mind are m162 and m163 which are for laser operations. Before you go writing
your own scripts it may pay to have a look and make sure you are not overwriting something which may be useful later on.
The real advantage of a macro is that, at least in Mach4, is written in Lua which is a very capable programming language in its
own right. In order for a program, ie your script or macro, to affect the behavior of your machine it must use API's.
API's (Application Program Interface) are the means that you have to control the inner workings of Machs core and therefore
affect machine movements, set outputs, display data communicate with other devices.....and the list goes on.
As an example:
rc = mc.mcCntlConfigStop(Inst)
If you included this statement in your macro the Gcode interpreter would stop. Lets say you have a temperature sensor in
your spindle and if it goes over 900 then you would or could execute this API.
To gain control of OB axes this is the approach you will have to take.
You can also write scripts which reside in the GUI which can be used to effect all manners of behavior but for OB axes
this is an added complexity that need not concern you....yet!
The complete list of API's are in API.chm which is in Mach4Hobby/Docs folder. There are hundreds of them.
Craig