Yes. Thanks for all your good work.
I'm using Mach4 on Win10, and the whole thing is remarkably buggie. I reinstalled the controller board and Mach4, and that seemed to help a little.
I simplified your code to the extent possible and I stripped the code down to the bare minimum that I needed for my tool changes on a homemade mill, and then a lot of trial and error to get it to run. Here's the code I ended up with:
function m6()
local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local ProbeOperationDistance = -15 -- This is how far Z will move while looking for a probe hit.
local ProbeSpeed = 15 -- This is how fast Z will probe at. Keep this number small for acuracy.
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
mc.mcCntlSetLastError(inst, "Tool Change")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 X0.0 Y0.0")
mc.mcCntlSetLastError(inst, "Position the tool less than 1/2 inch over the touch plate and click Start")
mc.mcCntlToolChangeManual(inst,true)
mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z"..ProbeOperationDistance.." F"..ProbeSpeed)
local toolz = mc.mcAxisGetPos(inst, 2)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "Change the tool, reposition it over touch plate and click Start")
mc.mcCntlToolChangeManual(inst,true)
mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z"..ProbeOperationDistance.." F"..ProbeSpeed)
mc.mcAxisSetPos(inst, 2, toolz)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlSetLastError(inst, "Turn the spindle on, click cycle start, and we are cutting.")
mc.mcCntlToolChangeManual(inst,true)
end
end
if (mc.mcInEditor() == 1) then
m6()
end