491
Mach4 General Discussion / Lua Macro Parameters
« on: February 24, 2017, 12:10:04 PM »
The following code compiles and executes in the script editor. After it executes the editor I get a message saying the editor has failed and is closed yet it is open. hParam is always 'error' when run in the editor. When I try to run in Mach4 mdi 'm6690 D.9' the last error line says 'Do MDI 1' and nothing happens. What am I doing wrong and how do you track down/test this?
Thanks for any help,
RT
Code: [Select]
--Reel Seat Insert
--Turn from current Z down to 0 from current X down to parameter D or .850
function m6690(hParam)
local xNow,zNow,maxVal
local TS,TR,TT --timer values Mach3 niy
local plungeFeed=6
local roughDOC=0.015
local roughFeed=15
local roughSpeed=900
local finishDOC=0.004
local finishFeed=8
local finishSpeed=1400
local inst=mc.mcGetInstance()
local endX=.850 --param1()
local inst=mc.mcGetInstance()
mc.mcCntlSetLastError(inst,'')
if (hParam ~= nil) then
local DFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_D)
if(DFlag == 1) then
endX = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_D)
end
end
xNow = mc.mcAxisGetPos(inst,0)
zNow = mc.mcAxisGetPos(inst,2)
if xNow<=endX then
wx.wxMessageBox("start X is less than end Diameter of "..tostring(endX))
return
end
if zNow<=0 then
wx.wxMessageBox("start Z is less than or = to 0")
return
end
--ts=Timer
--rough cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed))
while (mc.mcAxisGetPos(inst,0)>(endX+finishDOC*2)) do
currPos=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX+2*finishDOC,currPos)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC))
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
currPos=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX+2*finishDOC,currPos)
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
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
if currPos==endX+2*finishDOC then
break
end
end
-- tr=Timer-ts
--wx.wxMessageBox("Roughing Time: "..tostring(tr))
--finish cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))
while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
currPos=mc.mcAxisGetPos(inst,0)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(currPos-finishDOC))
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
currPos=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(currPos-finishDOC))
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
if mc.mcSpindleGetSensorRPM(inst)==0 then
wx.wxMessageBox("Spindle Stopped")
return
end
currPos=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
end
mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
--te=Timer-ts
--wx.wxMessageBox("Roughing Time: "..tostring(tr).." - Total Time: "..tostring(te))
end
if (mc.mcInEditor() == 1) then
m6690()
end
Thanks for any help,
RT