Hello Guest it is April 23, 2024, 02:59:38 AM

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

0 Members and 1 Guest are viewing this topic.

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Again with the tool setter
« Reply #10 on: May 03, 2021, 05:35:04 PM »
Where did you get the code below from?
Without engineers the world stops
Re: Again with the tool setter
« Reply #11 on: May 03, 2021, 06:12:39 PM »
Don't remember exactly, but I was searching for it. I'm not a programmer and I don't really have a grasp on the scripting for Mach so I started from searching. I actually used the code from the Mach support video, which seemed to be ok ISH... IE. it was simple, seemed to work but the tool lengths were coming out wrong- repeatable but still not bringing all the tools to the same wpc z0.

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Again with the tool setter
« Reply #12 on: May 03, 2021, 08:30:01 PM »
Try this version of the code, read the comments first.
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" -- Change to position of probe in X
    local YToolProbePosition = "1" -- Change to position of probe in Y
    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 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
Without engineers the world stops
Re: Again with the tool setter
« Reply #13 on: May 04, 2021, 03:35:30 AM »
You may have seen this already but this video provides a good walkthrough of setting up the tool offsets in Mach4 https://www.youtube.com/watch?v=tywAByswH2Q
Re: Again with the tool setter
« Reply #14 on: May 10, 2021, 03:45:02 PM »
You may have seen this already but this video provides a good walkthrough of setting up the tool offsets in Mach4 https://www.youtube.com/watch?v=tywAByswH2Q
Yes i saw that, but it does not really explain how to use mach with a fixed tool setter, and what procedure top use in context with a program setup, this is not clear.  It shows one method, no relation to tool table and job setup g54
Re: Again with the tool setter
« Reply #15 on: May 13, 2021, 11:22:02 AM »
Try this version of the code, read the comments first.
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" -- Change to position of probe in X
    local YToolProbePosition = "1" -- Change to position of probe in Y
    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 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

Tried the code and got the following message in the output window


stack traceback:
   [C]: in ?
   [C]: in function 'require'
   C:\Users\cnc\AppData\Local\Temp\.2D69.tmp:1: in main chunk
   [C]: in ?
Program completed in 0.07 seconds (pid: 2224).

Not sure about this
Re: Again with the tool setter
« Reply #16 on: June 01, 2022, 09:10:06 AM »
Hey Barneskite28,

Did you ever find a resolution to this?  I have been researching the gauge line method for tool offsets, and this is a quagmire of 'scripts' written by all sorts of folks with differing opinions.  And, the posts from the folks who actually might know what is going on act like scripting is something everyone is adept at.  I agree with one of your first comments - we pay for this, especially the Industrial version.  On top of that, we can't get support direct, as we are OEM and our vendor knows less than we do.

So - did you find a solution?  Were you attempting to use the 'master tool' or 'gauge line' foundation for your tool offset?  I really want my tool offsets to be independent from any table or bed reference, only referenced from the gauge line or spindle nose - like every other machine we have. 

Thanks - and I appreciate your frustrations!
Re: Again with the tool setter
« Reply #17 on: June 01, 2022, 09:46:07 AM »
Hey Barneskite28,

Did you ever find a resolution to this?  I have been researching the gauge line method for tool offsets, and this is a quagmire of 'scripts' written by all sorts of folks with differing opinions.  And, the posts from the folks who actually might know what is going on act like scripting is something everyone is adept at.  I agree with one of your first comments - we pay for this, especially the Industrial version.  On top of that, we can't get support direct, as we are OEM and our vendor knows less than we do.

So - did you find a solution?  Were you attempting to use the 'master tool' or 'gauge line' foundation for your tool offset?  I really want my tool offsets to be independent from any table or bed reference, only referenced from the gauge line or spindle nose - like every other machine we have. 

Thanks - and I appreciate your frustrations!

Yes i did manage to get my code working, and i used the dimension from the spindle face to the tool setter to make the tool length calculations.  Up to now this has been working ok apart from a coupe of issues that are unrelated in my mind to the code.  First issue is sometimes the fist tool change after power up (and yes, after activating offsets first and then zero the workpeice) can be ~10mm off, forcing me to re-zero the work piece z0 after which all tool changes are spot on.  Second issue, is recently out of the blue Mach4 started to hang when the tool setter was reached - every time.  powered down and back up and the same story.  No idea why but it caused me a massive pita, had to detlete mach, reinstall and restore the mach config and then reinstate the same code which then worked fine again.  This is more frustrating than getting it to work in the first place, and proves to me that for some reason known only to the programmers Mach4 is not robust and stable enough to provide reliable operation.  For me it has worked fine for 100's of power cycles, then out of the blue screwed itself up with no input from me.  It just started happening one time after power up and would not go away without me reinstalling everything.

The other strange issue i have seen is sometimes during the homing sequence mach has a pause after reaching the endstops.... not all the time though.  I have checked the PC and it is running fine with no lack of resources, and nothing else running.

I will re-post my working tool change script for you so that you can see how it works for mine, and you can modify for your machine.
Re: Again with the tool setter
« Reply #18 on: June 01, 2022, 10:38:23 AM »
Hey,

Awesome news, and congrats on slaying that beast. 

Ok - have you considered referencing everything to machine coordinate home versus a G54 or other work offset (or fixture)?  I think this is what I want to do.  Why?  Because I could build in some code that does a 'QC' check of the tool setter and the Z home every time I do the auto home sequence. 

For me, I always worry if my limit switches for machine home are being bumped, get dirty, or whatever.  If I get a power out during a program, how can you recover if the machine home is moving around?  If you buy into that, how do I know my tool setter is reliable? 

If we take the Z-home to the spindle nose measurement (it shouldn't change - ever), then run a Tool 0 touch off, I should know my limit switch and tool setter are in the green.  And, all my tools can be set up with the auto tool setter or outside the machine manually (like if a tool breaks during a long program). 

It seems everyone with routers only wants to use touch off plates and reference everything from the bed.  Trouble for me is ALL the macros and scripts were written this way, and I want to invert that idea and make the machine home the center of the universe!

Please post your code, and I will do the same when I get ours going.  That may give some other folks options!
Re: Again with the tool setter
« Reply #19 on: June 16, 2022, 04:11:20 AM »
Hi,
Essentially my machine is referenced to the home switches - which are all proximity switches.  The tool lengths reference the distance from the spindle nose, and the work offset is just a zero point at a specific machine coordinate.  In this case i have had good luck with power down and power on - but with Mach4 being so buggy it sometimes does not store the last WCS.  If i am doing a critical job i have also cut a reference circle into my bed/fixture plate - so if all else fails i can model from that point and always ensure to reset within a couple of thou.  The issue that i do have as i mentioned before - is on the z0 moving on the foirst couple of cycles - it did it twice today - the first run being 130mm too high, and the second being 0.8mm too low.  after another setting of z0 it was fine