Hello Guest it is May 14, 2021, 04:10:23 AM

Author Topic: Auto tool offset not working?  (Read 286 times)

0 Members and 1 Guest are viewing this topic.

Auto tool offset not working?
« on: February 18, 2020, 05:33:19 PM »
Hi guys, new to the forum, mach 4 and lua so please take it easy. I tried making an auto tool touch off script for tool changes with M6. Everything works as I expected other than no offset is present. The Z axis remains as if the height of the old tool was still there?

Anyways code is below, any help is appreciated.
Code is based on the mach support youtube video (https://www.youtube.com/watch?v=6-4JkDv9AgM)

--START CODE--

function M6()
   
local inst = mc.mcGetInstance()

----------------------------------------------------------------------------------
--change lines here to either auto rapid, or manually jog to a tool change position
----------------------------------------------------------------------------------
--Manual Lines. Uncomment line below to allow you to manually jog to a tool change position.
--local MyChoice = wx.wxMessageBox("Click OK, \nThen Jog to A Safe Tool Change Position,\nInsert New tool,\nThen Click Cycle Start.","Click OK to continue" , 16)
---------------------------------------------------------------------------------
--Auto Lines.  Uncomment both lines below (and comment out local MyChoice line above) to automatically move to tool change position.
--Edit to include the machine coordinate values of that tool change position.

--AUTO LINES

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
   
 if selectedtool == currenttool then
        mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
 else
   mc.mcCntlGcodeExecuteWait(inst, "G0 X0 Y0 ")--Back to work zero
   mc.mcCntlGcodeExecuteWait(inst, "G21 \nG53 G0 Z0\nG53 G0 Y-1022.41550 \nG53 G0 X-1.7780")--Move the Z to Home.Then to the X, Y Coords for our touch pad.
   mc.mcCntlSetLastError(inst, 'Now in Tool Change Position. Hit Cycle Start!')
   mc.mcCntlToolChangeManual(inst, true);
   mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. "   Previous Tool == " .. tostring(currenttool))
   mc.mcToolSetCurrent(inst, selectedtool)

local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
        mc.mcCntlSetLastError(inst, "Probing in Progress!")
      mc.mcCntlGcodeExecuteWait(inst, " G91 G0 Z-5. F300.")
        mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-50. F125.")--probe the new tool
local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
        mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
      mc.mcCntlGcodeExecuteWait(inst, "G20 G00 G53 Z0 ")--Retract
      mc.mcCntlGcodeExecuteWait(inst, "G0 X0\nG0 Y0 ")--Back to work zero
 
local NewOffset = probedz
  mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
  mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
wx.wxMessageBox("Toolchange Complete.\nTLO Set")
        end

end

if (mc.mcInEditor() == 1) then
 M6()
end

--END CODE--
Re: Auto tool offset not working?
« Reply #1 on: May 03, 2021, 03:10:07 AM »
Hi guys, new to the forum, mach 4 and lua so please take it easy. I tried making an auto tool touch off script for tool changes with M6. Everything works as I expected other than no offset is present. The Z axis remains as if the height of the old tool was still there?

Anyways code is below, any help is appreciated.
Code is based on the mach support youtube video (https://www.youtube.com/watch?v=6-4JkDv9AgM)

--START CODE--

function M6()
   
local inst = mc.mcGetInstance()

----------------------------------------------------------------------------------
--change lines here to either auto rapid, or manually jog to a tool change position
----------------------------------------------------------------------------------
--Manual Lines. Uncomment line below to allow you to manually jog to a tool change position.
--local MyChoice = wx.wxMessageBox("Click OK, \nThen Jog to A Safe Tool Change Position,\nInsert New tool,\nThen Click Cycle Start.","Click OK to continue" , 16)
---------------------------------------------------------------------------------
--Auto Lines.  Uncomment both lines below (and comment out local MyChoice line above) to automatically move to tool change position.
--Edit to include the machine coordinate values of that tool change position.

--AUTO LINES

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
   
 if selectedtool == currenttool then
        mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
 else
   mc.mcCntlGcodeExecuteWait(inst, "G0 X0 Y0 ")--Back to work zero
   mc.mcCntlGcodeExecuteWait(inst, "G21 \nG53 G0 Z0\nG53 G0 Y-1022.41550 \nG53 G0 X-1.7780")--Move the Z to Home.Then to the X, Y Coords for our touch pad.
   mc.mcCntlSetLastError(inst, 'Now in Tool Change Position. Hit Cycle Start!')
   mc.mcCntlToolChangeManual(inst, true);
   mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. "   Previous Tool == " .. tostring(currenttool))
   mc.mcToolSetCurrent(inst, selectedtool)

local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
        mc.mcCntlSetLastError(inst, "Probing in Progress!")
      mc.mcCntlGcodeExecuteWait(inst, " G91 G0 Z-5. F300.")
        mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-50. F125.")--probe the new tool
local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
        mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
      mc.mcCntlGcodeExecuteWait(inst, "G20 G00 G53 Z0 ")--Retract
      mc.mcCntlGcodeExecuteWait(inst, "G0 X0\nG0 Y0 ")--Back to work zero
 
local NewOffset = probedz
  mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
  mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
wx.wxMessageBox("Toolchange Complete.\nTLO Set")
        end

end

if (mc.mcInEditor() == 1) then
 M6()
end

--END CODE--
Did you ever get this working?