+MsgBox("This is under construction")' Sub Main()' ' Z- Probing Script' ' Author verser' ' vers.by - touch probes, tool setters and precision home switches' Dim FRate1, FRate2' Dim DMax, Latch, EdgeLength' Dim XYclearance' Dim AutoZeroFlag' Dim ToolNo' Dim ToolD' Dim ProbeD' Dim Zdepth' Dim ZHit' Dim Zpos' Dim ZScale' Dim AbsIncFlag' Dim CurrentFeed' 'Init vars' FRate1 = abs(GetUserDRO(1821))' FRate2 = abs(GetUserDRO(1822))' DMax = abs(GetUserDRO(1823))' ToolNo = GetCurrentTool()' ToolD = GetToolParam(ToolNo,1) ' If GetUserDRO(1829) = 0 then ' ProbeD = ToolD ' Else ' ProbeD = GetUserDRO(1829) ' End If' Latch = abs(GetUserDRO(1825))' Zdepth = GetUserDRO(1830)' If GetOEMLED(1871) Then' AutoZeroFlag=1' Else' AutoZeroFlag=0' End If' AbsIncFlag = GetOEMLED(49) ' Get the current G91 state' 'Temporary save all Axis Scale factors' ZScale = GetOEMDRO(61)' 'Set Z Scale to 1' SetOEMDRO(61,1)' Sleep(250)' 'Check for Errors' If GetOemLED(16)<>0 Then ' Check for Machine Coordinates' Message "Please change to working coordinates"' SetOEMDRO(61,ZScale)' Sleep(250)' Exit Sub ' Exit if in Machine Coordinates' End If' If GetOemLED(825)<>0 Then' Message "Probe is active! Check connection and try again"' Call SetOEMDRO(61,ZScale)' Sleep(250)' Exit Sub ' Exit if probe is tripped' End If' CurrentFeed = GetOEMDRO(818) 'FeedRate()' 'main working ' 'Save Z start position ' Zpos = GetDRO(2) ' 'Probe Z- ' ZHit=ProbeZ(-1,DMax,Latch,FRate1,FRate2) ' If ZHit=999999 Then ' Exit Sub ' End If ' SetUserLabel (14, Format(ZHit, "####0.000")) ' PushMSG("Z- = " & (ZHit)) ' 'Safe back to start position ' If Not SafeMoveZ((Zpos-GetDRO(2)),FRate1) Then ' PushMSG("Return to the search position is interrupted") ' Exit Sub ' End If ' If AutoZeroFlag = 1 Then ' SetOEMDRO(42, ZHit) ' Sleep(150) ' End If' 'epilog' SetOEMDRO(61,ZScale)' Sleep(250)' Call SetLED49(AbsIncFlag)' SetOEMDRO(818,CurrentFeed) 'SetFeedRate(CurrentFeed)' Sleep(125)' End Sub' 'Functions' Function ProbeZ(Dir,DMax,Latch,FRate1,FRate2) ' Dim Res ' Dim Zstart ' Dim Ftmp ' Dim AbsIncF ' ProbeZ=999999 ' Zstart = GetDRO(2) ' Ftmp = FeedRate() 'FeedRate() ' AbsIncF=GetOEMLED(49) ' 'Fast Probe Z ' Code "G91" ' Code "F" & FRate1 ' Sleep(125) ' Call WaitProbeReady() ' Code "G31 Z" & (Dir*DMax) ' While IsMoving() ' Wend ' Res = GetVar(2002)' ' PushMSG("Res=" & Res &", Zstart=" & Zstart & ", DMax=" & DMax & ", FRate1=" & FRate1) ' If Abs(Res - Zstart - Dir*DMax) < 0.01 Then ' PushMSG("Error: G31 Z search finished without making contact") ' PushMSG("Manually return to the starting position and repeat the search") ' Call SetLED49(AbsIncF) ' SetOEMDRO(818,Ftmp) ' Sleep(125) ' Exit Function ' End If ' 'Move back ' Code "G00 Z" & -Dir*Latch ' While IsMoving() ' Wend ' Call WaitProbeReady() ' 'Latch Probe Z ' Zstart = GetDRO(2) ' Code "F" & FRate2 ' Sleep(125) ' Code "G31 Z" & Dir*Latch*2 ' While IsMoving() ' Wend ' 'Save result ' Res = GetVar(2002) ' If Abs(Res - Zstart - Dir*Latch*2) < 0.01 Then ' PushMSG("Error: G31 Z latch finished without making contact") ' PushMSG("Manually return to the starting position and repeat the search") ' Call SetLED49(AbsIncF) ' SetOEMDRO(818,Ftmp) ' Sleep(125) ' Exit Function ' End If ' Code "G00 Z" & -Dir*Latch ' While IsMoving() ' Wend ' Call SetLED49(AbsIncF) ' SetOEMDRO(818,Ftmp) ' Sleep(125) ' ProbeZ=Res' End Function' Function SafeMoveZ(Z1, F1) As Boolean 'return 1 (error) if probe tripped ' Dim Zstart ' Dim Ftmp ' Dim AbsIncF ' SafeMoveZ=True ' Zstart = GetDRO(2) ' Ftmp = FeedRate() 'FeedRate() ' AbsIncF=GetOEMLED(49) ' Code "G91" ' Code "F" & F1 ' Sleep(125) ' Call WaitProbeReady() ' Code "G31 Z" & Z1 ' While IsMoving() ' Sleep(100) ' Wend ' ZHit = GetVar(2002) ' Call SetLED49(AbsIncF) ' SetOEMDRO(23,Ftmp) ' Sleep(125)' End Function' Function PushMSG(Str1 As String) As Boolean ' SetUserLabel (21,GetUserLabel(20)) ' SetUserLabel (20,GetUserLabel(19)) ' SetUserLabel (19,GetUserLabel(18)) ' SetUserLabel (18,GetUserLabel(17)) ' SetUserLabel (17,Str1) ' Message Str1 ' PushMSG=True' End Function ' Sub WaitProbeReady() ' While GetOemLED(825) ' Sleep(100) ' Wend' End Sub' Sub SetLED49(Flag) ' If Flag Then ' Code "G91" ' Sleep(125) ' Else ' Code "G90" ' Sleep(125) ' End If' End Sub
0 commit comments