8
« on: May 01, 2021, 08:52:16 AM »
Ok guys, so after digging around i found some script in the Mach4 scripting manual. The supporting paragraph describes exactly what i need, but refers to 'customization manual' that doesn't exist.
Below is the script copied direct from the manual
-----------------------------------------------------------------------------
-- Auto Tool Setting Macro
-----------------------------------------------------------------------------
--[[
Requires the following instance registers to be defined
TS_XPos-----------X position of probe (machine position)
TS_YPos-----------Y position of probe (machine position)
TS_Type-----------Offset type (1 or 2)
TS_TouchPos-------Z position of touch off surface (machine position)
TS_ProbeH---------Height of probe above touch off surface
TS_DefaultL-------Default tool length guess
TS_Retract--------Retract distance after probe touch
Offset Type 1-----Length of tool from gauge line to tip
Offset Type 2-----Distance from tip of tool to the touch position
]]
--The function GetRegister() must be defined for use by macros
function m1005()
local inst = mc.mcGetInstance()
------------- Define Vars -------------
local ProbeSignal = mc.ISIG_DIGITIZE
------------- Get current state -------------
local CurTool = mc.mcToolGetCurrent(inst)
local CurHNum = mc.mcCntlGetPoundVar(inst, 2032)
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurZOffset = mc.mcCntlGetPoundVar(inst, 4102)
26
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
------------- Get touch off parameters -------------
local Xpos = GetRegister("TS_XPos", 1)
local Ypos = GetRegister("TS_YPos", 1)
local OffsetType = GetRegister("TS_Type", 1)
local TouchPos = GetRegister("TS_TouchPos", 1)
local ProbeHeight = GetRegister("TS_ProbeH", 1)
local RetractDistance = GetRegister("TS_Retract", 1)
local ToolLengthGuess = GetRegister("TS_DefaultL", 1)
------------- Check Probe -------------
local hsig = mc.mcSignalGetHandle(inst, ProbeSignal)
local ProbeState = mc.mcSignalGetState(hsig)
if (ProbeState == true) then
mc.mcCntlSetLastError(inst, "ERROR: Probe signal is activated")
do return end
end
------------- Calculations for Gcode -------------
local StartHeight = TouchPos + ProbeHeight + ToolLengthGuess + .5
------------- Generate GCode -------------
AutoToolSetGCode = ""
AutoToolSetGCode = AutoToolSetGCode .. "G00 G80 G40 G49 G90\n"
AutoToolSetGCode = AutoToolSetGCode .. "G00 G53 Z0.0\n"
AutoToolSetGCode = AutoToolSetGCode .. string.format("G00 G53 X%.4f Y%.4f\n", Xpos, Ypos)
AutoToolSetGCode = AutoToolSetGCode .. string.format("G00 G53 Z%.4f\n", StartHeight)
AutoToolSetGCode = AutoToolSetGCode .. "G91 G31 Z-2.0 F25.\n"
mc.mcCntlGcodeExecuteWait(inst, AutoToolSetGCode)
--Check probe contact
ProbeState = mc.mcSignalGetState(hsig)
if (ProbeState ~= 1) then
mc.mcCntlSetLastError(inst, "ERROR: No contact with probe")
mc.mcCntlGcodeExecuteWait(inst, "G0 G90 G53 Z0.0\n")
do return end
end
AutoToolSetGCode = ""
AutoToolSetGCode = AutoToolSetGCode .. string.format("G91 G00 Z%.4f\n", RetractDistance)
AutoToolSetGCode = AutoToolSetGCode .. "G91 G31 Z-1.0 F10.\n"
mc.mcCntlGcodeExecuteWait(inst, AutoToolSetGCode)
--Check probe contact
ProbeState = mc.mcSignalGetState(hsig)
if (ProbeState ~= 1) then
mc.mcCntlSetLastError(inst, "ERROR: No contact with probe")
mc.mcCntlGcodeExecuteWait(inst, "G0 G90 G53 Z0.0\n")
do return end
end
AutoToolSetGCode = ""
AutoToolSetGCode = AutoToolSetGCode .. "G90 G00 G53 Z0.0\n"
mc.mcCntlGcodeExecuteWait(inst, AutoToolSetGCode)
------------- Get touch position and set offset -------------
local ZProbed = mc.mcCntlGetPoundVar(inst, 5063)
local ZOffset = ZProbed - ProbeHeight + CurZOffset
if (OffsetType == 1) then
ZOffset = math.abs(TouchPos - ZOffset)
end
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, CurTool, ZOffset)
mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f",
ZOffset))
I have managed to touch off the spindle face in machine coords, and have the spindle face (gauge line- without holder) at -161.2219. My tool setter position is at x24.0 y436.0
Can someone help me understand where to put these values and how to get this damn thing to work please?
Tim