Hello Guest it is October 04, 2023, 10:43:47 PM

Author Topic: Can OB1 and OB2 be used inside the G-code ?  (Read 1252 times)

0 Members and 1 Guest are viewing this topic.

Can OB1 and OB2 be used inside the G-code ?
« on: January 27, 2019, 03:45:16 PM »
I am trying to control 8 stepper motors (simultaneously and independently) for custom application (non-CNC based). Since the software does provide an option to map motor 6 and motor 7 to OB1 and OB2, I was wondering if there is any way in which I can give OB1 and OB2 position values in the g-code. I am using a Pokeys57CNC controller which allows the use of up to 8 motors. really appreciate any help/suggestion/tips :)
Re: Can OB1 and OB2 be used inside the G-code ?
« Reply #1 on: January 28, 2019, 12:19:56 AM »
Mach4 allows up to six coordinated axes. Each axis may have one or more slaves.
Mach4 also allows up to six OB axes, but these are NOT coordinated with either themselves OR the six primary
(coordinated) axes.

Further they cannot be controlled with Gcode in the normal way. They must be 'jogged' into position. That could be
done manually with buttons but for your purposes you will require macros to handle 'programmed jogging', sort of
similar to MDI motion commands.

The jogging API's that have been provided are:


'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Can OB1 and OB2 be used inside the G-code ?
« Reply #2 on: January 28, 2019, 02:02:39 PM »
Thanks Craig. I am not familiar with programming on Mach4. Are you tying to say that it can be done by modifying the script ? And how do i access these API's ?
Really appreciate your input!
Re: Can OB1 and OB2 be used inside the G-code ?
« Reply #3 on: January 29, 2019, 12:43:16 AM »
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.

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'