function m55() local inst = mc.mcGetInstance() local selectedTool = mc.mcToolGetSelected(inst) local currentTool = mc.mcToolGetCurrent(inst) local maxDown = -195.0000 --Max distance Z will go down in the touch routine local rate = 500 --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, "G01 G54 X1753.92 Y380.5 F3000") --Probe move 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 if (mc.mcInEditor() == 1) then m55() end