Hello Guest it is January 18, 2020, 07:48:48 AM

Author Topic: macro for Reference All Axes  (Read 1085 times)

0 Members and 1 Guest are viewing this topic.

macro for Reference All Axes
« on: January 05, 2018, 05:44:14 PM »
I'm having trouble creating a macro that will reliably do the same thing as the "Reference All Axes" button.  The following works every time in the Lua editor:

function reference_all()
    inst = mc.mcGetInstance()
    mc.mcAxisHomeAll(inst)
end

reference_all()

However, if I create following macro it works great in the Lua editor, but when I run it as an m code, nothing happens.

function m91048()
    reference_all()
end

I figure that it has something to do with the "Reference All Axes" button using a coroutine, but I am not sure how to get a macro coroutine to communicate with the plc. (or if that is even the right approach) Just looking for the simplest way to get the m code to work the same way as it does running it from the Lua editor.

Thanks for any help!

p.s.
I will add a little more background information in case it helps.  I am trying to create a homing routine for Clearpath motors that have hardstop homing.  (meaning that you run the axis into a wall and the motor senses the resistance and stops itself) So I am hardstopping the axes, backing off a preset amount and then need to zero all the axes. With Mach4 set to "home in place" G28.1 causes strange and erratic behavior, either crashing Mach4 or wildly jerking the motors, so I need a good alternative.
« Last Edit: January 05, 2018, 06:00:37 PM by dbt3000files »
Re: macro for Reference All Axes
« Reply #1 on: January 28, 2018, 01:16:35 AM »
Did you ever figure this out? I'm trying to add a physical button to ref all axis on my lathe screen.

Is there a function code already in the Mach 4 API? So I can just add a simple code to the script?
Re: macro for Reference All Axes
« Reply #2 on: February 04, 2018, 11:54:52 PM »
Didn't figure out my problem, however you should be able to copy the script of the ref all home button in the wx4 screen.  If you also copy the Ref All Home section of the wx4 screen load script and transfer it to the screen you want to you use, it should work.

I think that there is some issue about putting a homing command in a macro in mach4.  I'm still trying to figure out what that's all about.
Re: macro for Reference All Axes
« Reply #3 on: February 05, 2018, 01:34:44 AM »
OK thanks.
Re: macro for Reference All Axes
« Reply #4 on: February 05, 2018, 05:32:03 AM »
Hi,
Quote
I think that there is some issue about putting a homing command in a macro in mach4.  I'm still trying to figure out what that's all about.
The problem with putting a homing command in a macro is that a macro is run by the interpreter whereas the homing command is initiated by the GUI.

There are two Lua chunks that make up Mach. One chunk is contains the Gcode interpreter. If you run a Gcode job it is this chunk of Lua code that does the business
which includes running macros. The common macros in Gcode files are M01, M02,M03,M06 etc. If you write your own macro it might be M120 say, and the Gcode interpreter
would open and run that macro.

The GUI is the other chunk and it is responsible for the screen and all its functions like Homing buttons. Homing functions are initiated from the GUI and passed to the motion
controller. The controller reports back to the calling function in the GUI.

These two chunks of Lua code cannot run at the same time.

When Mach is running control passes back and forth between these two chunks. The mechanisms for doing it are vital to Mach and determine a lot of its 'character'.
A good deal of Mach programming involves having both Lua chunks running their own bits of code and they have to combine to do the job that you want and constitutes
perhaps the biggest challenge in successfully programming complex behavior in Mach.

The simple expedient is 'Have the GUI do GUI things and have the Gcode Interpreter do Gcode Interpreter things', trying to combine them or worse have then swap
roles is likely to be very difficult if not impossible.

Craig



My wife left with my best friend...
     and I miss him!
Re: macro for Reference All Axes
« Reply #5 on: February 08, 2018, 03:20:23 PM »
Thanks Craig for the explanation! That seems to make sense.  If I'm hearing you correctly it seems like trying to automate homing operations with Mach4 is maybe not a good idea in the first place.

Maybe you or someone out there would have some advice for me.  I am using hardstop homing (no limit switches) and I written a routine that homes the machine and then checks to make sure all of the axes have been referenced.  I would like for anyone running the machine to be able to home it without manually hitting the ref all home button. (This way no-one can accidentally hit the button when the machine has not actually been homed.)  Maybe this is just not in the cards for Mach4, but I'd really appreciate any ideas anyone has.
Sorry if I'm beating a dead horse, but it sure would be nice to have something like a g28.1 work for Mach4.

David
Re: macro for Reference All Axes
« Reply #6 on: February 08, 2018, 06:05:20 PM »
Hi,
the last crash I had, and a goody, was because I forgot to reference the machine before I hit <cycle start>.
The particular work I was doing required repeated re-referencing and I got complacent after 4 hours or so...and whammo!

As a result I re-did the code behind the cycle start button which prevents me from hitting <cycle start>
UNTIL the machine has been referenced. Not hard to do.

Craig
My wife left with my best friend...
     and I miss him!
Re: macro for Reference All Axes
« Reply #7 on: February 08, 2018, 10:40:17 PM »
Hi,
My three axis machine homes automatically without trouble. I've got into the habit of before hitting <RefAll>
reaching over to the machine and flicking the roller plunger microswitches (my home switches) while watching
the Machine Diagnostics page and confirm that Mach is 'seeing' the home switches.

Once it starts homing I have the pendant in hand with finger on the Estop. Because I have my home switches
set up to operate near the end of travel if a switch is for any reason ignored then the time to get to the Estop is
very limited. I often think that I should shift the home switches so that they operate with a couple of inches travel to spare.
They have not however led me to crash so they are still where I put them. There is no more permanent thing
than a temporary measure!

Craig
My wife left with my best friend...
     and I miss him!