366
« on: January 13, 2018, 03:30:45 PM »
Just when I think i am starting to understand lua I run into this. The code below is a macro that I have used many times and today I wanted to alter it a bit. When the changes didn't do what I thought it should i started putting in wxMessagBox calls in to see where it was failing. When the first message box didn't pop up I was surprised, but even more surprised that the macro continued to execute including the second popup telling me to switch gearing. What am I missing? I deleted the .mcc and .mcs.bak several times and completely restarted windows with the same results. I am at a total loss on this one.
function m6691(hVars)
local xNow,zNow,maxVal,rc
local ts,tr,te,sCode
local currPos
local plungeFeed=1
local roughDOC=0.018
local roughFeed=18
local roughSpeed=1200
local finishDOC=0.004
local finishFeed=8
local finishSpeed=1800
local endX=.850 --param1()
local inst=mc.mcGetInstance()
wx.wxMessageBox('nil') --HOW IS THIS SKIPPED?
if mc.mcSpindleGetCurrentRange(inst)~=1 then
--rt.rtAudio("notify")
--wx.wxSound('C:\\mach4Hobby\\Sounds\\Notify.wav',0):Play()
wx.wxMessageBox('Set Spindle Gearing to High Speed') --THIS ONE DOES GET EXECUTED!!!
mc.mcSpindleSetRange(inst,1)
end
if (hVars ~= nil) then
local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
if(DFlag == 1) then
endX = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
mc.mcCntlSetLastError(inst,"Turning Diameter to "..endX)
end
end
xNow,rc = mc.mcAxisGetPos(inst,0)
zNow,rc = mc.mcAxisGetPos(inst,2)
if xNow<=endX then
rt.rtAudio("chord")
wx.wxMessageBox("start X diameter "..xNow.." is <= to end diameter of "..tostring(endX))
return
end
if zNow<=0 then
rt.rtAudio("chord")
wx.wxMessageBox("start Z is less than or = to 0")
return
end
ts=os.time()
--rough cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed).."\ng04 p3.0")
currPos,rc=mc.mcAxisGetPos(inst,0)
while ((currPos-2*roughDOC)>(endX+finishDOC*2)) do
maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
sCode="G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC)
mc.mcCntlGcodeExecuteWait(inst,sCode)
currPos,rc=mc.mcAxisGetPos(inst,0)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
currPos,rc=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
if currPos==endX+2*finishDOC then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(math.max(endX+2*finishDOC,currPos-roughDOC)))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
if (currPos)==endX+2*finishDOC then
break
end
end
tr=os.difftime(os.time(),ts)/60
mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr))
--finish cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))
while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
currPos,rc=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX,currPos-finishDOC)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
currPos,rc=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(endX))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
currPos,rc=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
end
mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
te=(os.time()-ts)/60
mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr).." - Total Time: "..string.format("%.1f min",te))
end
if mc.mcInEditor()==1 then
m6691()
end
TIA
RT