Hello Guest it is March 29, 2024, 09:41:30 AM

Author Topic: Creating an M6 Toolchange in Mach4 (Part 2)  (Read 3754 times)

0 Members and 1 Guest are viewing this topic.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Creating an M6 Toolchange in Mach4 (Part 2)
« on: October 08, 2015, 07:26:07 PM »
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/TZ5fUIRjzxE

The Code so far in this part

Code: [Select]
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
New For 2022 - Instagram: dazthegas