Hello Guest it is March 29, 2024, 11:26:47 AM

Author Topic: Again with the tool setter  (Read 2337 times)

0 Members and 1 Guest are viewing this topic.

Again with the tool setter
« 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
Code: [Select]
-----------------------------------------------------------------------------
-- 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
Re: Again with the tool setter
« Reply #1 on: May 01, 2021, 08:55:31 AM »
I put a ticket into mach support for assistance, got a reply back that said 'read the manual'..... not much support from the support!!

Offline Tweakie.CNC

*
  • *
  •  9,196 9,196
  • Super Kitty
    • View Profile
Re: Again with the tool setter
« Reply #2 on: May 02, 2021, 12:55:20 AM »
I put a ticket into mach support for assistance, got a reply back that said 'read the manual'..... not much support from the support!!

Bet they didn't put their name to the reply  ;D

Tweakie.
PEACE
Re: Again with the tool setter
« Reply #3 on: May 02, 2021, 04:09:04 AM »
I put a ticket into mach support for assistance, got a reply back that said 'read the manual'..... not much support from the support!!

Bet they didn't put their name to the reply  ;D

Tweakie.
They did, but its not personal so i don't see the relevance of their name, as far as i am concerned i'm dealing with a company.

Does anyone have a similar setup to me ? could you share your method/script and help me get this working please?
Re: Again with the tool setter
« Reply #4 on: May 02, 2021, 08:18:38 AM »
Found the following code, just not sure exactly where to insert my manual tool change position and my tool height setter position? i see the variable at the top and i see that called in the probing move, but where do i set it?
Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local changeToTool = mc.mcToolGetSelected(inst)
    local changeFromTool = mc.mcToolGetCurrent(inst)
    local XPositionBeforeToolChange = mc.mcAxisGetPos(inst,0)
    local YPositionBeforeToolChange = mc.mcAxisGetPos(inst,1)
    local XToolProbePosition = "1"
    local YToolProbePosition = "1"
    local XManualToolChangePosition = "2"
    local YManualToolChangePosition = "2"
    local ColletAtProbeZCoordinate = -105 -- Machine Z-coordinate when collet tip touches TouchPlate (Must be more than ProbeOperationDistance - DefaultToolLength
    local ExtraProbeDistance = 5 -- SafetyMargin
    local ProbeOperationDistance = -50 -- Length of Probemove before giving up
    local ProbePrepSpeed = 100
    local ProbeSpeed = 25
    local DefaultToolLength = 70 -- Used if tool info is not found. (Should be a value slightly longer than the longest tool in the shop :D)
        -- QUICK REFERENCE
        -- G90 - Absolute (Go to coordinate)
        -- G91 - Incremental (Godistance along axis from current position)
        -- G53 - Machine Coordinate Move

    if changeToTool == changeFromTool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0\nM5" )
    RunProbe(inst,changeFromTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
    local ToolZCoordinate = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n G90 G53 G0 X"..XManualToolChangePosition.." Y"..YManualToolChangePosition)
    local changeToToolDescription = mc.mcToolGetDesc(inst,changeToTool)
    wx.wxMessageBox("Please change to tool number "..changeToTool.." "..changeToToolDescription.." and press ok to continue")
    RunProbe(inst,changeToTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
    mc.mcAxisSetPos(inst, 2 , ToolZCoordinate)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..XPositionBeforeToolChange.." Y"..YPositionBeforeToolChange)
    mc.mcToolSetCurrent(inst, changeToTool)
    wx.wxMessageBox("If Toolchange was Sucessful - click ok to continue")
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end

function RunProbe(finst,ftool,fXToolProbePosition,fYToolProbePosition,fDefaultToolLength,fColletAtProbeZCoordinate,fExtraProbeDistance,fProbePrepSpeed,fProbeSpeed,fProbeOperationDistance)
    mc.mcCntlGcodeExecuteWait(finst, "G90 G53 G0 X"..fXToolProbePosition.." Y"..fYToolProbePosition)
    local toollen = mc.mcToolGetData(finst, mc.MTOOL_MILL_HEIGHT, ftool)
    if toollen == 0 then
        toollen = fDefaultToolLength
        mc.mcCntlSetLastError(finst, "Tool length not found - using Default Length")
    end
    local probestart = fColletAtProbeZCoordinate + fExtraProbeDistance + toollen
    local GCODE = "G91 G31 G0 Z"..probestart.." F"..fProbePrepSpeed
    GCODE = ""..GCODE.." \n G91 G0 Z1 F"..fProbePrepSpeed.." \n G91 G31 Z"..fProbeOperationDistance.." F"..fProbeSpeed
    mc.mcCntlGcodeExecuteWait(finst,GCODE)
end

if (mc.mcInEditor() == 1) then
    M6()
end
Re: Again with the tool setter
« Reply #5 on: May 02, 2021, 04:40:57 PM »
Can anybody help with the script?
Re: Again with the tool setter
« Reply #6 on: May 02, 2021, 07:48:51 PM »
barn
i just want give you advice,if you put such long script and long question ,do you real think some one will now take hours to
test yours script and debug it?
try divide yours question into section ,try focus exactly yours question ,not so big global like" nothing work"
then i belive you will get many answers
hope i help little
Re: Again with the tool setter
« Reply #7 on: May 03, 2021, 02:38:52 AM »
barn
i just want give you advice,if you put such long script and long question ,do you real think some one will now take hours to
test yours script and debug it?
try divide yours question into section ,try focus exactly yours question ,not so big global like" nothing work"
then i belive you will get many answers
hope i help little
Thanks Katz, noted.
really i have tried a couple of scripts that essentially 'work' - i.e. the machine does what its supposed to, but the tool offsets are the problem.  It may be me not understanding something in the procedure, thats what i'm trying to find out.  So to divide the questions..

1. Should tool offsets be on or off when probing the tool setter?

2. I expect a length of tool to be in the table, but the measurement is not the length from the gauge line.  I'm trying to find out why!

Mach4 considering it is a paid program, has little support and no updated info (videos/tutorials) for nearly 5 years, i think this is quite poor for a software that is not free!

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Again with the tool setter
« Reply #8 on: May 03, 2021, 04:19:30 PM »
Some pictures of the machine may help.

Also are you working from the XYZ home position or are you moving the datum using G54 etc.

Do you know the distance from a fixed point on the spindle to the table top?

Do you know the distance from the same fixed point on the spindle to the tool setter trigger point?

Do you have a DRO on your screen to set the thickness of the material?

If you have this information its a simple calculation based on the trigger point of the G31


Without engineers the world stops
Re: Again with the tool setter
« Reply #9 on: May 03, 2021, 04:51:29 PM »
Hi Graham,
I will get some photos later of the machine. I know the distance in machine coordinate from z home to the trigger point, and the xy of the tool setter. I got the script to do a calculation for the tool length, which seemed to be ok (all tools set with offsets off), but when I tried to set the wpc z0 with a shim on the offsets page, it was not correct. It was a 0.1mm shim on the top of the stock, entered in the offsets page and the dro changed to 90 mm or so.  Only if I enter 0.1 in the program run page does it read right.
Next thing I ran a program with 2 tools, and Mach completely ignored the toolchange twice. Re started the program, it went for the tool change, measured the tool and the height was all wrong.
I have in my script to turn the tool offsets off after the change, then measure, then in the gcode the tool offset is called straight after.
On the tool panel the offset number did not match the tool offset called by the program or the tool in the spindle..
Seems very buggy and not reliable, but I hope it's just me doing something wrong!
Much appreciated Graham!