$190/hr + 3 hr minimum since you are a friend 
-- SNZ Probe X Axis --
local FastFeed = 200
local SlowFeed = 80
local BackOff = 3
local OffsetNum = 99
local ProbeSigTable = {
[31] = mc.ISIG_PROBE,
[31.0] = mc.ISIG_PROBE,
[31.1] = mc.ISIG_PROBE1,
[31.2] = mc.ISIG_PROBE2,
[31.3] = mc.ISIG_PROBE3
}
function checkProbe(state, code)
local inst = mc.mcGetInstance()
local check = true
local ProbeSignal = ProbeSigTable[code]
if (ProbeSignal == nil) then
mc.mcCntlSetLastError(inst, "ERROR: Invalid probing G code")
mc.mcCntlEStop(inst)
do return end
end
------------- Check Probe -------------
local hsig = mc.mcSignalGetHandle(inst, ProbeSignal)
local ProbeState = mc.mcSignalGetState(hsig)
local errmsg = "ERROR: No contact with probe"
if (state == 1) then
errmsg = "ERROR: Probe obstructed"
end
if (ProbeState == state) then
mc.mcCntlSetLastError(inst, errmsg)
mc.mcCntlEStop(inst)
check = false
end
return check
end
function setFixOffset(xval)
local inst = mc.mcGetInstance()
local FixOffset = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_14)
local Pval = mc.mcCntlGetPoundVar(inst, mc.SV_BUFP)
local FixNum, whole, frac
if (FixOffset ~= 54.1) then --G54 through G59
whole, frac = math.modf (FixOffset)
FixNum = (whole - 53)
PoundVarX = ((mc.SV_FIXTURES_START - mc.SV_FIXTURES_INC) + (FixNum * mc.SV_FIXTURES_INC))
else --G54.1 P1 through G54.1 P100
FixNum = (Pval + 6)
if (Pval > 0) and (Pval < 51) then -- G54.1 P1 through G54.1 P50
PoundVarX = ((mc.SV_FIXTURE_EXPAND - mc.SV_FIXTURES_INC) + (Pval * mc.SV_FIXTURES_INC))
elseif (Pval > 50) and (Pval < 101) then -- G54.1 P51 through G54.1 P100
PoundVarX = ((mc.SV_FIXTURE_EXPAND2 - mc.SV_FIXTURES_INC) + (Pval * mc.SV_FIXTURES_INC))
end
end
mc.mcCntlSetPoundVar(inst, PoundVarX, xval)
end
function m10101()
local inst = mc.mcGetInstance()
local rc = checkProbe(1, 31); if not rc then; do return end; end
------------- Get current machine state -------------
local CurFeed = mc.mcCntlGetPoundVar(inst, mc.SV_FEEDRATE)
local CurZOffset = mc.mcCntlGetPoundVar(inst, mc.SV_ORIGIN_OFFSET_Z)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_1)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3)
local CurPosition = mc.mcAxisGetPos(inst, mc.Z_AXIS)
------------- Set Probe Offset, Relative Positioning -------------
mc.mcCntlGcodeExecuteWait(inst, string.format("G43 H%.0f", OffsetNum))
mc.mcCntlGcodeExecuteWait(inst, "G91")
------------- Fast Probe -------------
mc.mcCntlGcodeExecuteWait(inst, "G31 X50 F200")
rc = checkProbe(0, 31); if not rc then; do return end; end
------------- Back Off Probe -------------
mc.mcCntlGcodeExecuteWait(inst, "G01 X-3 F350")
------------- Slow Probe -------------
mc.mcCntlGcodeExecuteWait(inst, "G31 X10 F50")
rc = checkProbe(0, 31); if not rc then; do return end; end
------------- Get Position + Data -------------
local XProbed = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_X)
local XMachProbed = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_MACH_POS_X)
print("Mach Probe X "..XMachProbed)
local probeRadius = (25.4 * 0.125) / 2
print("Mach Probe X Radius "..probeRadius)
------------- Calculate Offset -------------
local NewWOVal = XMachProbed + probeRadius
------------- Set Offset-------------
setFixOffset(NewWOVal)
------------- Safe Z-------------
--mc.mcCntlGcodeExecuteWait(inst, "G01 X-10 F350")
------------- Reset Machine State ------------------------------------
mc.mcCntlSetPoundVar(inst, mc.SV_FEEDRATE, CurFeed)
mc.mcCntlSetPoundVar(inst, mc.SV_MOD_GROUP_1, CurFeedMode)
mc.mcCntlSetPoundVar(inst, mc.SV_MOD_GROUP_3, CurAbsMode)
end
if (mc.mcInEditor() == 1) then
m10101()
end
I would eliminate the G43 H99
. My probe is set to #99 and I don’t use a touch plate. I have been meaning to make that script a library but i never get around to it. It was written as a test file before I added the buttons to my screen.
EDIT;
local probeRadius = (25.4 * 0.125) / 2
can be replaced as well. That would be the diameter of your probe. Make it a constant of read from a register.
Very ugly script 