Thanks for the help. I was getting really frustrated and about to just give up. The routine did the positioning I needed, I just wanted to "make it pretty!" I tried creating a function that resides in the screen load script and calling that function after the yield. That worked. Why? I dunno.
I was really working on two scripts (in buttons). One to move to a safe Z position (Machine coord. -0.5) and one that moves the router to the edge of the table where it it easy to swap bits. After clicking, the scripts changes the display to Machine coords, checks to make sure the machine has been homed, moves the router into position, then changes back to work coords, and in the case of tool change, disables the machine. The functions handle everything after the move.
The button script for Safe Z...
--10FE20
--This script is to test using a coroutine so that when a Gcode
--is sent, the DRO's are updated live and the completion message doesn't
--show up until the move is complete
--another post on Mach4 suggested checking to see if the machine is indeed in the
--correct location before displaying the finished message in case something happened
-- to prevent it from getting there - not sure how to do that yet.
local inst = mc.mcGetInstance()
local val
local rc
local homed
--Change to machine coords
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_CORD)
local sig = mc.mcSignalGetState(hsig)
if (sig == 0) then
mc.mcSignalSetState(hsig,1)
end
--check if Z is homed . if not - do nothing
homed , rc = mc.mcAxisIsHomed(inst,mc.Z_AXIS)
if homed == 1 then
SafeZ = coroutine.create(function()
mc.mcCntlGcodeExecute(inst, "G53 G1 Z-0.5 F25")
coroutine.yield()
val,rc = mc.mcAxisGetMachinePos(inst,mc.Z_AXIS)
if val == -0.5000 then
--wx.wxMessageBox("Safe Z Finished")
readytogoZzero()
--mc.mcCntlSetLastError("Safe Z completed")
else
wx.wxMessageBox("Oops! - Didn't make it to -0.5'")
end
--wx.wxMessageBox("Safe Z Finished")
end)
else
wx.wxMessageBox("Move Cancelled - Z is not homed")
end
The function in the screen load script...
function readytogoZzero()
--wx.wxMessageBox("readytogo from function")
local hsigCORD = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_CORD)
mc.mcSignalSetState(hsigCORD,0)-- go back to work coords
mc.mcCntlSetLastError(inst, "Safe Z reached...")
end
I use the message boxes for testing to let me know the script got to a certain spot. Also, some of the notes are outdated. I've ben using these buttons since last year, but I decided I wanted to spruce them up a bit (like disabling the machine after moving to bit swapping position).
I use the same idea for the tool change script but I check all three axes for homing and disable the machine once it gets moved.
Thanks again for the help. I still don't understand why this worked, but it does work well, so....
Tony