--****************Probe for Tool Length Offset*************-- --This can be used as a stand alone code in a button --Or it can be added to a macro --*****************-- --BlockHeight --BackOff --Ztrav --Feed --** Above are varibles that will be found --** below, and should be edited by the Users --** to work for their individual Machines --** USE CATION **-- ------------------------------------------------------------------------- local inst= mc.mcGetInstance() ------------------------------------------------- --Locals ------------------------------------------------- local BlockHeight = (.125) --If not using a touch off block enter Zero here local BackOff = (.2) --A reasonable value used for a retract distance after probe strike local Ztrav = -2.0 --the distance Z will travel while probing. local Feed = 20. --User defined Feed rate Value local CurTool = mc.mcToolGetCurrent(inst) --Current Tool Num local CurH = mc.mcCntlGetPoundVar(inst, 2032) --Current Selected H Offset local CurHVal = mc.mcCntlGetPoundVar(inst, 2035) --Value of Current H Offset OffsetState = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_8) --Current Height Offset State ------------------------------------------------ -------------------Probe for TLO---------------- if (OffsetState == 49)then mc.mcCntlSetLastError(inst, string.format("Tool %.0f Height Offset is NOT Active. Cannot Set TLO", CurTool)) else mc.mcCntlSetLastError(inst, 'Finding TLO for Tool#: ' .. CurTool) rc = mc.mcCntlGcodeExecuteWait(inst, string.format("G91 G31 Z%.4f F%.4f", Ztrav, Feed)) local ZPos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0) local RetractPoint = ZPos + BackOff rc = mc.mcCntlGcodeExecuteWait(inst, string.format("G91 G0 Z%.4f ", RetractPoint)) local OffsetVal = ZPos - BlockHeight mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, CurTool, OffsetVal) mc.mcCntlSetLastError(inst, string.format("Tool %.0f Height Offset Set: %.4f", CurTool, OffsetVal)) end