Hello Guest it is January 28, 2020, 09:05:19 AM

Author Topic: Is there an Auto Tool Zero script for a button that works?  (Read 297 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  306 306
    • View Profile
Is there an Auto Tool Zero script for a button that works?
« on: October 20, 2019, 08:55:43 PM »
I am trying to create my own from what I can find, but it is turning into dead ends and no answer to be found on google.

The screen set that has this button is just blank on the button, so it does nothing.

I kind of have it working, but not very good....the wxMessageBox stuff in there is not really working right.
Everything I find here is old.
In the mean time I am still working on my own starting with some example of an M6 with auto tool change code in it, but something that just works would be nice.....

The manual references setting up an Auto Tool Zero macro in the manual for setting your TLO's using the gage line method....but then that becomes a dead end to actually do it since I cannot find anything further.

Offline jevs

*
  •  306 306
    • View Profile
Re: Is there an Auto Tool Zero script for a button that works?
« Reply #1 on: October 20, 2019, 11:01:33 PM »
This seems to be working with the on screen button "Auto Tool Zero" I made where there was a blank button in my screen set. It is calling out the function AutoToolZero() when you click it.

This code is in the Screen Load Script in the functions area section I made for my mill.

Code: [Select]
-----Auto Tool Zero button------
function AutoToolZero()
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)  --ERASE THIS LINE IF NOT NEEDED
local currenttool = mc.mcToolGetCurrent(inst)

--Get positions before moving to do tool change
local valX, rc = mc.mcAxisGetMachinePos(inst, mc.X_AXIS) --Get the position of the X axis in Machine Position
local valY, rc = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS) --Get the position of the Y axis in Machine Position
local valZ, rc = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) --Get the position of the Z axis in Machine Position

rc = mc.mcCntlGcodeExecuteWait(inst, "M05") --Turns off the spindle (includes decel time)
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000") --Move the Z to Home
rc = mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X19.5300 Y14.4500") --Move the the X, Y Coords to to the touch pad location.
rc = mc.mcCntlSetLastError(inst, 'Now in Tool Measuring Position')

local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)

if (MyChoice == 16) then
rc = mc.mcCntlSetLastError(inst, 'Auto Tool Zero was cancelled.')
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000 F15.0") --Retract back to Z home
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location
return
elseif (MyChoice == 4) then
        mc.mcCntlSetLastError(inst, "Probing in Progress!")
        mc.mcCntlGcodeExecuteWait(inst, "G90 G31.1 Z-5. F5.0") --probe the new tool
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0000 F15.0") --Retract back to Z home
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location

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
local NewOffset = probedz
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool, NewOffset)
mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
wx.wxMessageBox("Toolchange Complete.\nTLO Set")
end
end

Please feel free to critique.

I do think I want to add a data entry field on the screen to enter the height of the Tool Height Setter (Probe G31.1) and then utilize that in an equation to get proper offsets.....I am still trying to figure out how all this works with the 3D probe as tool 1....
« Last Edit: October 20, 2019, 11:05:32 PM by jevs »
Re: Is there an Auto Tool Zero script for a button that works?
« Reply #2 on: November 12, 2019, 01:01:32 PM »
HI,

 Im working on a tool setting macro to work into my M6 tool change.  my super simple M6 that im currently using took all of my LUA knowledge so m im getting way out there in my world.  Thanks for the head start