The final piece is in place: the m6 macro.
I've more-or-less duplicated the functionality of my favorite Screenset 2010 features via two button scripts and an M6. Hopefully I've commented them enough to make the journey a bit easier for someone in the future. Other than assigning the scripts to two buttons and editing m6.mcs, the only other setup is using the Regfile plugin to create an Instance Register named "Tool_Offset" with an initial value over 90. (an arbitrary flag value as the Register is dual use -- as a flag (unset) and a value (set).)
There is a lot of room for adding elegance and error checking, but those are both for another day. In the words of Red Green, "This is only temporary. Unless it works."
The M6 has some DazTheGas code, some ArtSoft code, and a bunch of ugly by your's truly.
function m6()
local inst = mc.mcGetInstance();
local offset = mc.mcRegGetHandle(inst,"iRegs0/Tool_Offset")
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
local FixedPlateX = 16.212 -- machine coordinate of fixed plate
local FixedPlateY = 0.153 -- machine coordinate of fixed plate
local initialX = mc.mcAxisGetPos(inst,0)
local initialY = mc.mcAxisGetPos(inst,1)
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool")
else
mc.mcCntlSetLastError(inst, "ToolChange Activated ...")
mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0 X".. FixedPlateX .. " Y".. FixedPlateY); -- Position for tool change and probing
if mc.mcRegGetValue(offset) >= 99 then
wx.wxMessageBox("Initial tool. Press enter to probe for offset")
mc.mcRegSetValue(offset, probePlate()) -- Store offset
mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0") -- move up for toolchange
end
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to zero") --Message at beginning of tool change
mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
mc.mcAxisSetPos(inst, mc.Z_AXIS, probePlate()) -- Set new tool to fixed plate offset value
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") -- goto machine Z Zero
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X".. initialX.." Y".. initialY .. "F40") -- return to starting positions
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
mc.mcRegSetValue()
end
end
if (mc.mcInEditor() == 1) then
m6()
end
function probePlate()
local inst = mc.mcGetInstance()
local SlowProbeRate = 0.7 -- IPM
local FastProbeRate = 5.0 -- IPM
local JogRate = 60
local Pos
-- Fast probe Z zero
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z-2.5") -- Pre-position
mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-3.0 F".. FastProbeRate)
-- Retract slightly
mc.mcCntlSetLastError(inst, "Retract . . .")
mc.mcCntlGcodeExecute(inst,"G91 Z0.05 F".. JogRate)
-- Slow probe Z zero
mc.mcCntlSetLastError(inst, "Slow Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)
-- Get touch position and jog to it in case of overshoot
Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0) -- Get Touch Position (work coordinates)
mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
return Pos
end
The initial tool zero button routine communicates through a register to let M6 know an offset needs to be measured.
probeMove = coroutine.create(function()
local inst = mc.mcGetInstance()
hreg = mc.mcRegGetHandle(inst, "iRegs0/Tool_Offset")
local TouchPlate = 0.622 -- Thickness of touchplate above material
local SlowProbeRate = 0.7 -- IPM
local FastProbeRate = 5.0 -- IPM
local JogRate = 60
local Pos
wx.wxMessageBox("1) Check that touch plate is connected.\n2) Position the tool\'s tip above and within 2\" of the plate.\n Press ENTER.")
-- Fast probe Z zero
mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-2.0 F".. FastProbeRate)
coroutine.yield()
-- Retract slightly
mc.mcCntlGcodeExecute(inst,"G91 Z0.05 F".. JogRate)
coroutine.yield()
-- Slow probe Z zero
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)
coroutine.yield()
-- Get touch position (G53) and jog to it in case of overshoot
Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0) -- Get Touch Position (work coordinates)
mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
coroutine.yield()
-- Set DRO to height of touchplate and retract to a safe height
mc.mcAxisSetPos(inst, mc.Z_AXIS, TouchPlate)
mc.mcCntlGcodeExecute(inst,"G91 Z1.0 F".. JogRate)
coroutine.yield()
mc.mcCntlSetLastError(inst, "Z Zero set")
mc.mcRegSetValue(hreg,99.9)
mc.mcCntlReset(0)
end)
And lastly a very simple button code to set X/Y zero to my laser crosshairs:
local inst = mc.mcGetInstance();
local offsetX = -4.7335 -- X axis distance from laser crosshairs to spindle center
local offsetY = -0.0137 -- Y axis distance from laser crosshairs to spindle center
mc.mcAxisSetPos(inst,0,offsetX)
mc.mcAxisSetPos(inst,1,offsetY)
mc.mcCntlSetLastError(inst, "Workpiece X/Y zeros set to laser crosshair")