Automatic Tool Height Setup Question

Oh, I wrote my own! Not what you wanted to hear but this is an example as a M-code. Its easy to make it into a button if you feel better doing it that way.

WARNING! My numbers are in metric. Millimeters… sorry :face_with_diagonal_mouth:

-- SNZ Probe Z Axis --

local FastFeed = 200 -- I apparently don't use some of these, doh!
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, yval, zval)
	
	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
	
    PoundVarY = PoundVarX + 1
    PoundVarZ = PoundVarX + 2
	
    if (xval ~= nil) then
        mc.mcCntlSetPoundVar(inst, PoundVarX, xval)
    end
	
    if (yval ~= nil) then
        mc.mcCntlSetPoundVar(inst, PoundVarY, yval)
    end
	
    if (zval ~= nil) then
        mc.mcCntlSetPoundVar(inst, PoundVarZ, zval)
    end
	
end


function m10103()
	
	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 Z-50 F200")
	
	rc = checkProbe(0, 31); if not rc then; do return end; end
	
	------------- Back Off Probe -------------
	mc.mcCntlGcodeExecuteWait(inst, "G01 Z3 F350")
	
	------------- Slow Probe -------------
	mc.mcCntlGcodeExecuteWait(inst, "G31 Z-10 F50")
	
	rc = checkProbe(0, 31); if not rc then; do return end; end
	
	------------- Get Position + Data -------------
	local ZProbed = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z)
	local ZMachProbed = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_MACH_POS_Z)
	
	local HeightOffset = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, OffsetNum)
	local HeightOffsetW = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT_W, OffsetNum)
	
	------------- Calculate Offset -------------
	local NewWOVal = ZMachProbed - HeightOffset - HeightOffsetW
	
	------------- Set Offset-------------
	setFixOffset(nil, nil, NewWOVal)
	
	------------- Safe Z-------------
	--mc.mcCntlGcodeExecuteWait(inst, "G01 Z20 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
	m10103()
end

OK well yeah if I don’t have to write something, even just copy and pasting yours, because then I have to write all my probe routines correct? I guess I could learn how to probe in Fusion 360 but i was hoping to use something native to Mach4. Maybe I can change the probing routines to use g43 from the get go?

If you are using the Mach4 supplied probing routines then you need to read up on the “ESS/Probing_Failure_Disables_Mach” and that script is here;

-- Probe Disable ESS No-Contact-Fail Off
local inst = mc.mcGetInstance()

function m1018()
	hregProbingFailureDisablesMach = mc.mcRegGetHandle(inst, string.format("ESS/Probing_Failure_Disables_Mach"))
	mc.mcRegSetValue(hregProbingFailureDisablesMach , 0 )
	x = mc.mcRegGetValue(hregProbingFailureDisablesMach )
	print("ESS/Probing_Failure_Disables_Mach = "..x)
end

if (mc.mcInEditor() == 1) then
	m1018()
end

You will need to disable the “ESS/Probing_Failure_Disables_Mach” and then run the Mach4 probing routines and then re-enable them using the opposite.

I wrote many pages it about that stuff somewhere else on this forum.

http://documentation.warp9td.com/Shared/Mach4/Probing/Probing.htm

Look for the header " Mach4’s built in probing wizard (or utility or button) isn’t working right!"

1 Like

Yes I have done that already, from reading your post elsewhere, that’s how I got this far. :laughing:

1 Like

Yay! I helped somebody! :partying_face:

1 Like

OK read that page 3 times and its not helping, the only thing they say is if it is plunging through make sure it is registering a probe hit, which I am 99.9999% sure it is because it did on the first probe and the light comes on on the second probe hit.

I am ordering some wax to test with so I hopefully can avoid blowing up any more tips while testing. My new tips should arrive tomorrow…

Thanks again for all your help.

Ugh!

How I learned it was I took a thin carboard box and set it up under the Z. Then I touched off to it until I could figure out what was going on. Then if it decided to plunge straight down it bent the box, not the probe.

I would do it that way again. A box that is like 5in x 5in x 5in or so. Its soft when needed and its rigid enough to trip the probe. It doesn’t have to be accurate while you are figuring this out. It just need to quit breaking your expensive probe.

Try that. I am not sure wax is such a good idea. Go get an Amazon box and use that. THat is exactly what I used :stuck_out_tongue:

Ahh brilliant! A box makes so much sense, thanks!

1 Like