Here are 2 m6s I have done. Neither of these are for ATC though. Both are for manual/manumatic. Descriptions are in the comments in the code.
This one is the current default m6 that comes with Mach4. It was recently updated. It is meant for those doing manual tool changes. It does not stop the spindle, coolant, update any offsets, etc. It just stops running the Gcode. Gcode is resumed with a press of cycle start.
function m6()
local inst = mc.mcGetInstance()
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
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --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.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
end
end
if (mc.mcInEditor() == 1) then
m6()
end
The code below is very similar to the default above. Only instead of just pausing the Gcode it allows you to jog to a probing position and once over the probe, click cycle start. This will begin a probing move. If that probe move is successful it will update the tools height in the tool table. It is very important to have the default move after the probing in the Gcode....... or you could add this default move to the m6 itself but it is not in it as is.
function m6()
local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
local currentTool = mc.mcToolGetCurrent(inst)
local maxDown = -4.0000 --Max distance Z will go down in the touch routine
local rate = 30 --Feed rate the Z will go down in the touch routine
local safeZ = 0 --Machine coordinates the Z will rapid to after touch move
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0.0") --Uncomment this line if you would like to move the Z axis to machine coords 0
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to touch off") --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.mcToolSetCurrent(inst, selectedTool)
mc.mcCntlSetLastError(inst, "Performing touch routine")
mc.mcCntlGcodeExecuteWait(inst, string.format("G31 Z%0.4f F%0.4f\nG0 G53 Z%0.4f", tostring(maxDown), tostring(rate), tostring(safeZ))) --Probe move
mc.mcCntlSetLastError(inst, "Touch move complete")
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
local didStrike, rc = mc.mcCntlProbeGetStrikeStatus(inst)
if (didStrike == 1) then
--#5063 = User position #5073 = Machine position
value, rc = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z)
--value, rc = mc.mcCntlGetPoundVar(inst, 5063) --Same as line above but line above uses the Mach constant instead of the #var
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, value) --Set the tool height to what was determined by probe move
mc.mcCntlGcodeExecute(inst, string.format("G43 H" .. tostring(selectedTool)))
mc.mcCntlSetLastError(inst, string.format("Tool " .. tostring(selectedTool) .. " H offset set to %0.4f", value))
else
mc.mcCntlSetLastError(inst, "The touch move did not touch so we did not set a tool offset.") --Message that shows after Cycle Start
end
end
end
if (mc.mcInEditor() == 1) then
m6()
end