Hi all!
For the last moths I've been trying to program a semi automated toolchange command. But it just won't work.
I have a small Router for which I bought a laser light barrier to act as a height sensor.
I want the cnc to move to the toolchanger location and if it is the first tool in the program
rapidly move down to a safe height (that is calculated using the last tool length in the tool table) and measure the old tool and store its length. Then it should move to a position where I can easily change the new tool and measure the new tool (while using the stored length of the old tool) like before and then apply the tool length compensation.
All I have managed until now is a function to probe the tool. But it is acting very irregularly. When I freshly open Mach3 it works as expected and starts from the correct position, but when I repeat the Machto the Probing position is shifted down.
Here is my M998 Macro to test the function:
Sub main()
Dim a
zerotoolL = 27.7
a = gettoollength(1, -83.456,false,100,10,zerotoolL)
' if a = 9999 then
' MsgBox "Error"
' End if
End Sub
Function gettoollength(tool, ZProbe,isreftool,SearchSpeed,SlowSpeed,zerotoolL)
Dim zmachine
Dim ZDRO
Dim startzheight
Dim distZmachineProbe
Dim ProbeinDRO
XProbe = 10.34
YProbe = 42.25
Code "G00 G53 Z0"
Code "G00 G53 X" & XProbe & "Y" & YProbe
Sleep (100)
While IsMoving()
Sleep(100)
Wend
'MsgBox "got to probe location"
zmachine = getParam("ZMachine")
ZDRO = getParam("ZDRO")
distZmachineProbe = ZProbe + zmachine
ProbeinDRO = ZDRO + distZmachineProbe
'coordinateoffset = zmachine - ZDRO
'Code "S1000 M3" 'Annoying (tool would have to spin for better accuracy with the laser)
if isreftool = true then
zheight = 0
Else
'MsgBox "Not ref tool"
toollength = GetToolParam(tool,2)
knownlength = toollength - zerotoolL
'MsgBox "toollength from" & toollength
'MsgBox "toollength compared to old tool" & knownlength
startzheight = ProbeinDRO + knownlength + zerotoolL + 10
MsgBox "startzheight =" & startzheight
zheight = ProbeinDRO + knownlength + zerotoolL -10
MsgBox "End height =" & zheight
End if
'MsgBox "Hi 1"
While IsMoving()
Sleep(100)
Wend
Code "G00 Z" & startzheight
'MsgBox "vor messen"
Code "G31 Z" & zheight & "F" & SearchSpeed
Call WaitProbeReady()
'error = WaitProbeReady(1)
' if error = 9999 then
' Exit Function
' gettoollength = 9999
' End if
'I tried to use the Waitprobeready as a function, so it would spit out an Errorcode if the probe didnt trip but then the whole Macro didnt work
measuredZ = getParam("ZDRO")
Code "G00 Z" & measuredZ + 1
Code "G31 Z" & zheight & "F" & SlowSpeed
Call WaitProbeReady()
'error = WaitProbeReady(1)
' if error = 9999 then
' Exit Function
' gettoollength = 9999
' End if
gettoollength = getParam("ZDRO")
MsgBox gettoollength
End Function
Sub WaitProbeReady()
Message "Waiting for Probe to trip"
Sleep(1000)
n = 0
While IsMoving()
Sleep(100)
Wend
While not GetOemLED(825) and n < 50
Sleep(100)
n = n + 1
Message n
Wend
if n > 49 then
MsgBox "Error Probe did not trip!"
'WaitProbeReady = 9999
End if
End Sub
It would be extremely kind if anyone could help me or at least explain what is going on, or even show me a new macro that simply works, because I don't wnow what to do anymore.
Thanks Philipp
[Im sorry for any grammar/spelling errors and my really bad code]