OK, this is what I have so far and I am stuck again.
The main concept works, but there are still issues that I need help with. I may need to reinstall because I now run into the issue where my Fixture offset for Z gets deleted when restarted. This may not be the correct way, but the Z offset is the distance from my table to the router collet, its the only way I could get the math to work the tool table bit length. if there is a correct way, please let me know. For reference, my Z height offset is set at -11.375
Problems
1) Initial M6 works because the machine has to move, if I do another m6 without first jogging the machine, I get an PMDX underrun error and have to restart the software. If I jog the machine away so it has to move between M6 commands it does what it is supposed to, to the extent I have tested it. Worst case I can check the location and skip the movements, but it doesnt seem correct to me.
2) If an z offset is enabled such a the bit or fixture while the m6 command is active it uses this value for the probe value and thus records the wrong bit length. I have not tried it with a program yet to see if that is going to occur, but I would like to find a way to prevent it in the event. I figured I could check the state, if it is enabled, turn if off, then turn it back on, but there may be an easier way.
function M6()
local inst = mc.mcGetInstance();
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)
local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
[color=blue] -- local currentheightoffset = mc.mcCntlGetOffset (inst , 2) basis for controlling event that tool offset is active
--local HOState = mc.mcCntlGetPoundVar(inst, 4008)
--if (HOState == 49) then
--mc.mcCntlMdiExecute(inst, "G43")
--else
--mc.mcCntlMdiExecute(inst, "G49")
--end[/color]
if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") --move z axis all the way up
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X0.464 Y-99.808") -- Move XY to above fixed touchplate location
local changetoo = mc.mcToolGetDesc(inst,selectedtool)
wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
if toollen ~= 0 then
local probestart = (-11 + toollen)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
if ProbeState == 0 then
repeat
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
ProbeState = mc.mcSignalGetState(hsig)
until(ProbeState == 1)
local zoffset = mc.mcAxisGetPos(inst, 2)
mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
--mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")
else
local zoffset = mc.mcAxisGetPos(inst, 2)
mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
--mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")
end
else
wx.wxMessageBox("No tool length currently defined Lower Z to above touch plate, hit enter to start probe")
[color=red] --need a way to lower Z manually here and have not verified this portion of code--[/color]
mc.mcCntlGcodeExecuteWait(inst," G91 G31 Z-.5 F25")
ProbeState = mc.mcSignalGetState(hsig)
repeat
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
until(ProbeState ~= 0)
mc.mcAxisSetPos(inst, 2, toolz)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
--wx.wxMessageBox("Please turn on spindle and click ok to continue") --can be removed if required
--mc.mcToolSetCurrent(inst, selectedtool)
mc.mcCntlSetLastError(inst, "ToolChange Finished")end
end
mc.mcToolSetCurrent(inst, selectedtool)
end
if (mc.mcInEditor() == 1) then
M6()
end