Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: TTalma 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))
-
Hi,
this is the action script for the Set Tool Button on the Offsets page:
--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
-
Thanks, I haven't made it back to the shop yet to add the code, but this looks exactly like what I need.
-
Hi,
well that code is already in Mach4....that's where I got it from.
Craig