Hello Guest it is November 22, 2019, 04:14:57 PM

Author Topic: Set tool height when using Z axis tool height gage block  (Read 261 times)

0 Members and 1 Guest are viewing this topic.

Set tool height when using Z axis tool height gage block
« on: February 09, 2019, 02:28:33 PM »
I have my ATC changing tools properly. This morning I added a z Axis depth setter. It correctly goes and hits the depth setter.

But I do not know what to do with the value it returns. If my table surface is Z = 0.

When the Depth setter triggers the height is 3.3198" above the table surface. So how do I tell Mach that the Z axis height is 3.3198" when the setter triggered?

Then if I give the machine a command like:
G90
G00 Z1
I want it to move to a height 1" above the table surface.

How do i do this?

My code:
    -- Search for probe
    mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-4 F20") --probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) --Z Probe position in Machine coords
    mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0 ") --Retract
    mc.mcCntlGcodeExecuteWait(inst, "G00 G91 X-2.75 ") -- Move to clear spot

    -- Save offset
    local NewOffset = probedz
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Tool %.0f Offset = %.4f", selectedtool, NewOffset))
Re: Set tool height when using Z axis tool height gage block
« Reply #1 on: February 09, 2019, 03:30:22 PM »
Hi,
this is the action script for the Set Tool Button on the Offsets page:
Code: [Select]
--Set Tool button

local inst = mc.mcGetInstance()  
local GageBlock = scr.GetProperty("droGageBlockT", "Value")
local CurTool = mc.mcToolGetCurrent(inst) --Current Tool Num
local OffsetState = mc.mcCntlGetPoundVar(inst, 4008) --Current Height Offset State
mc.mcCntlGcodeExecuteWait(inst, "G49")
GageBlock = tonumber(GageBlock)
local ZPos = mc.mcAxisGetPos(inst, mc.Z_AXIS)
local OffsetVal = ZPos - GageBlock
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, CurTool, OffsetVal)
mc.mcCntlSetLastError(inst, string.format("Tool %.0f Height Offset Set: %.4f", CurTool, OffsetVal))
if (OffsetState ~= 49) then
    mc.mcCntlMdiExecute(inst, string.format("G%.1f", OffsetState))
end

Craig
My wife left with my best friend...
     and I miss him!
Re: Set tool height when using Z axis tool height gage block
« Reply #2 on: February 11, 2019, 06:59:24 PM »
Thanks, I haven't made it back to the shop yet to add the code, but this looks exactly like what I need.
Re: Set tool height when using Z axis tool height gage block
« Reply #3 on: February 11, 2019, 10:52:34 PM »
Hi,
well that code is already in Mach4....that's where I got it from.

Craig
My wife left with my best friend...
     and I miss him!