This is part 2 of creating my own M6 Toolchange in mach4, Well couldnt fit it all in 2, in the last part we will add a failsafe for the code and do a bit of tidying up in the code.
https://youtu.be/TZ5fUIRjzxEThe Code so far in this part
function M6()
local inst = mc.mcGetInstance();
local guesslen = -60.00
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool)
local probestart = guesslen + toollen
local xstart = mc.mcAxisGetPos(inst,0)
local ystart = mc.mcAxisGetPos(inst,1)
if selectedtool == currenttool then
return
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X14 Y30")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart)
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-15 F25")
local toolz = mc.mcAxisGetPos(inst,2)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
local changetoo = mc.mcToolGetDesc(inst,selectedtool)
wx.wxMessageBox("Please change to tool number "..selectedtool.." "..changetoo.." and press ok to continue")
currenttool = selectedtool
toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool)
probestart = guesslen + toollen
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X14 Y30")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart)
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-15 F25")
mc.mcAxisSetPos(inst, 2 , toolz)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..xstart.." Y"..ystart)
mc.mcToolSetCurrent(inst, selectedtool)
wx.wxMessageBox('Toolchange finished')
end
end
if (mc.mcInEditor() == 1) then
M6()
end
DazTheGas