function m6() local inst = mc.mcGetInstance() local rc = mc.MERROR_NOERROR local selectedTool = mc.mcToolGetSelected(inst) local currentTool = mc.mcToolGetCurrent(inst) --Below are the machine cords locations for your rapid move to the touch pad local xmacloc = 5 local ymacloc = 10 local zmacloc = 0 local proberate = 20 --Feed rate we'd like to probe at local probedist = 5 --This will be in native units to control (so whatever the control is set to) ALREADY NEGATIVE, SHOULD BE POSITIVE VALUE if (selectedTool == currentTool) then mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do") else rc = mc.mcCntlMachineStatePush(inst) --So we can retain previous modal states. --First we will need to know where we came from so we can go back. local xold, rc = mc.mcAxisGetMachinePos(inst, mc.X_AXIS) local yold = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS) local zold = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) mc.mcCntlGcodeExecuteWait(inst, "G53 G00 " .. "Z" .. tostring(zmacloc)) --Move to Z machine location. mc.mcCntlGcodeExecuteWait(inst, "G53 G00 " .. "X" .. tostring(xmacloc) .. "Y" .. tostring(ymacloc)) --Move to machine cords for X and Y. mc.mcCntlSetLastError(inst, "Tool change active, cycle start to probe tool.") mc.mcCntlToolChangeManual(inst) --Waiting on cycle start mc.mcCntlGcodeExecute(inst, "G90") --Make sure we're not moving inc rc = mc.mcCntlGcodeExecuteWait(inst, "G31 F" .. tostring(proberate) .. " Z-" .. tostring(probedist)) --Probe at probe rate, z axis as far as probedistance strike, rc = mc.mcCntlProbeGetStrikeStatus(inst) if (strike == 1) then probepos = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) rc = mc.mcCntlMachineStatePop(inst) rc = mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, tonumber(selectedTool), tonumber(probepos)) --Set tool length offset for selected tool to probed pos. mc.mcCntlGcodeExecuteWait(inst, "G53 G00 " .. "Z" .. tostring(zmacloc)) --Move to Z machine location, retracted, so we can then plunge into the part via the GCODES next line. mc.mcCntlGcodeExecuteWait(inst, "G53 G00 " .. "X" .. tostring(xold) .. "Y" .. tostring(yold)) --Move to old X Y POS mc.mcCntlSetLastError(inst, "Tool change complete, cycle start to proceed.") mc.mcCntlToolChangeManual(inst) --Waiting on cycle start else mc.mcCntlEStop(inst) mc.mcCntlSetLastError(inst, "No probe strike, ESTOP in effect") return "ERROR, NO STRIKE" end mc.mcCntlSetLastError(inst, tostring(selectedTool)) mc.mcToolSetCurrent(inst, selectedTool) mc.mcCntlSetLastError(inst, "New TLO is: ".. tostring(probepos)) end end if (mc.mcInEditor() == 1) then m6() end