Hello Guest it is April 11, 2021, 03:58:55 PM

Author Topic: Auto zero script problem  (Read 301 times)

0 Members and 1 Guest are viewing this topic.

Auto zero script problem
« on: April 28, 2020, 12:53:34 PM »
Hi everyone, I wrote this script to zero all the axis.

When I try it step by step in the VB script editor everything works fine but when I try it in Mach3 hitting the "Auto Tool Zero" button it's working weirdly.

So I have two G31 moves for each axis, a "fast" feed rate move then retract and a second one very slow.

Here is the problem, On the X and Y axis, when the script perform the fast move it's actually in the wrong direction. All the others moves are in the correct direction. The Z axis moves (fast and slow) are also ok.

I can't find the problem by myself, please help :-\


Here is the code that I wrote taking inspiration from a few different one found online:

ToolRadius = GetOemDRO(1112)/2
PlateOffset = 20

CurrentFeed = GetOemDRO(818)
CurrentAbsInc = GetOemLED(48)
CurrentGmode = GetOemDRO(819)
CurrentFeedOverride = GetOEMDRO(821)

   'X 1st Pass at fast rate


   Message "X axis 1st pass"
   If GetOemLed (825) = 0 Then
      DoOemButton (1008)
      Code "G4 P0.5"
      SetOemDRO (821,100)
      Code "G90 G31 X20 F600"
      While IsMoving()
      Wend
      XProbePos = GetVar(2000)
      If Abs(XprobePos) <= Abs(20) - 0.1 Then
         Code "G0 X" &XProbePos
         While IsMoving()
         Wend
         Call SetDro (0,0)
         Code "G4 P0.25"
         Code "G1 X-1 F1000"
         While IsMoving()
         Wend
         Message "X axis 2nd pass"
      Else
         Code "G53 G0 X" &x
         While IsMoving()
         Wend
         Message "Material not found, check connection and try again"
         Code "F" &CurrentFeed
         SetOemDRO (821,CurrentFeedOverride)
         If CurrentAbsInc = 0 Then Code "G91"
         If CurrentGMode = 0 Then Code "G0"
         End If
   Else
   Message "Probe is grounded, check connection and try again"
   End If


   'X 2nd pass at slow rate


   DoOEMButton (1008)
   Code "G4 P0.5"
   Code "G31 X2 F30"
   While IsMoving()
   Wend
   XProbePos = GetVar(2000)
   If Abs(XprobePos) <= Abs(2) - 0.1 Then
      Code "G0 X" &XProbePos
      While IsMoving()
      Wend
      Call SetDro (0,-ToolRadius)
      Code "G4 P0.25"
      Message "X axis is now zeroed"
      Code "G91 G0 X-10"
      Code "G0 Y-20"
      Code "G0 X20"   
      While IsMoving()
      Wend
   Else
      Code "G53 G0 X" &x
      While IsMoving()
      Wend
      Message "Material not found, check connection and try again"
   End If



   'Y 1st Pass at fast rate


   Message "(Y axis 1st pass)"
   If GetOemLed (825) = 0 Then
      DoOemButton (1009)
      Code "G4 P0.5"
      Code "G90 G31 Y20 F600"
      While IsMoving()
      Wend
      YProbePos = GetVar(2001)
      If Abs(YprobePos) <= Abs(20) - 0.1 Then
         Code "G0 Y" &YProbePos
         While IsMoving()
         Wend
         Call SetDro (1,0)
         Code "G4 P0.25"
         Code "G1 Y-1 F1000"
         While IsMoving()
         Wend
         Message "Y axis 2nd pass"
      Else
         Code "G53 G0 Z0"
         Code "G53 G0 Y" & y & "X" & x
         Code "G53 G0 Z" & z
         While IsMoving()
         Wend
         Message "Material not found, check connection and try again"
         Code "F" &CurrentFeed
         SetOemDRO (821,CurrentFeedOverride)
         If CurrentAbsInc = 0 Then Code "G91"
         If CurrentGMode = 0 Then Code "G0"
         End If
   Else
   Message "Probe is grounded, check connection and try again"
   Code "F" &CurrentFeed
   SetOemDRO (821,CurrentFeedOverride)
   If CurrentAbsInc = 0 Then Code "G91"
   If CurrentGMode = 0 Then Code "G0"
   End If


   'Y 2nd pass at slow rate


   DoOEMButton (1009)
   Code "G4 P0.5"
   Code "G31 Y2 F30"
   While IsMoving()
   Wend
   YProbePos = GetVar(2001)
   If Abs(YprobePos) <= Abs(2) - 0.1 Then
      Code "G0 Y" &YProbePos
      While IsMoving()
      Wend
      Call SetDro (1,-ToolRadius)
      Code "G4 P0.25"
      Message "Y axis is now zeroed"
      Code "G91 G0 Y-5"
      Code "G0 Z50"
      Code "G90 G0 X20 Y20"   
      While IsMoving()
      Wend
   Else
      Code "G53 G0 Z0"
      Code "G53 G0 Y" & y & "X" & x
      Code "G53 G0 Z" & z
      While IsMoving()
      Wend
      Message "Material not found, check connection and try again"
      Code "F" &CurrentFeed
      SetOemDRO (821,CurrentFeedOverride)
      If CurrentAbsInc = 0 Then Code "G91"
      If CurrentGMode = 0 Then Code "G0"
   End If
Re: Auto zero script problem
« Reply #1 on: April 28, 2020, 06:11:16 PM »
I did some minor changes, I'm not an expert on coding, I'm learning!

Some times the script works well and sometime one, two or all three axis goes in the wrong direction, just for the fast movement though.

I tried many times the script and I think there is something going wrong between Mach3 and the control board, I'm using a cheap chinese 4axis usb controller.

That my guess, anyone had the same issue?
 


Code: [Select]
ToolRadius = GetOemDRO(1112)/2  'custom tool diameter DRO
PlateOffset = 20  'X and Y offset
PlateThickness = 15  'Z offset

CurrentFeed = GetOemDRO(818)
CurrentAbsInc = GetOemLED(48)
CurrentGmode = GetOemDRO(819)
CurrentFeedOverride = GetOEMDRO(821)


'X 1st Pass at fast rate


Message "X axis 1st pass"
Sleep 2000
If GetOemLed (825) = 0 Then
DoOemButton (1008)
Code "G4 P0.5"
SetOemDRO (821,100)
Code "G90 G31 X20 F600"
While IsMoving()
Wend
XProbePos = GetVar(2000)
If Abs(XprobePos) <= Abs(20) - 0.1 Then
Code "G0 X" &XProbePos
While IsMoving()
Wend
Call SetDro (0,0)
Code "G4 P0.25"
Code "G1 X-1 F1000"
While IsMoving()
Wend
Message "X axis 2nd pass"
Else
Code "G53 G0 X" &x
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Exit Sub
End If
Else
Message "Probe is grounded, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Exit Sub
End If


'X 2nd pass at slow rate


DoOEMButton (1008)
Code "G4 P0.5"
Code "G31 X2 F30"
While IsMoving()
Wend
XProbePos = GetVar(2000)
If Abs(XprobePos) <= Abs(2) - 0.1 Then
Code "G0 X" &XProbePos
While IsMoving()
Wend
Call SetDro (0,ToolRadius)
Code "G4 P0.25"
Message "X axis is now zeroed"
Code "G91 G0 X-10"
Code "G0 Y-20"
Code "G0 X20"
While IsMoving()
Wend
Else
Code "G53 G0 X" &x
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Exit Sub
End If



'Y 1st Pass at fast rate


Message "(Y axis 1st pass)"
If GetOemLed (825) = 0 Then
DoOemButton (1009)
Code "G4 P0.5"
Code "G90 G31 Y20 F600"
While IsMoving()
Wend
YProbePos = GetVar(2001)
If Abs(YprobePos) <= Abs(20) - 0.1 Then
Code "G0 Y" &YProbePos
While IsMoving()
Wend
Call SetDro (1,0)
Code "G4 P0.25"
Code "G1 Y-1 F1000"
While IsMoving()
Wend
Message "Y axis 2nd pass"
Else
Code "G53 G0 Z0"
Code "G53 G0 Y" & y & "X" & x
Code "G53 G0 Z" & z
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Exit Sub
End If
Else
Message "Probe is grounded, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Exit Sub
End If


'Y 2nd pass at slow rate


DoOEMButton (1009)
Code "G4 P0.5"
Code "G31 Y2 F30"
While IsMoving()
Wend
YProbePos = GetVar(2001)
If Abs(YprobePos) <= Abs(2) - 0.1 Then
Code "G0 Y" &YProbePos
While IsMoving()
Wend
Call SetDro (1,ToolRadius)
Code "G4 P0.25"
Message "Y axis is now zeroed"
Code "G91 G0 Y-5"
Code "G0 Z20"
Code "G90 G0 X20 Y20"
While IsMoving()
Wend
Else
Code "G53 G0 Z0"
Code "G53 G0 Y" & y & "X" & x
Code "G53 G0 Z" & z
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Exit Sub
End If

Offline Graham Waterworth

*
  • *
  •  2,304 2,304
  • Yorkshire Dales, England
    • View Profile
Re: Auto zero script problem
« Reply #2 on: April 28, 2020, 08:52:15 PM »
When ever you update a DRO or in a while loop or send a message you need to have a short sleep() 50 to 150 is usually enough time for mach to update data in the background.

If you still have problems make sure you have a genuine licence file.
Without engineers the world stops

Offline TPS

*
  •  2,097 2,097
    • View Profile
Re: Auto zero script problem
« Reply #3 on: April 29, 2020, 03:58:40 AM »
added some sleep's to your code, maybe it helps

Code: [Select]
ToolRadius = GetOemDRO(1112)/2  'custom tool diameter DRO
PlateOffset = 20  'X and Y offset
PlateThickness = 15  'Z offset

CurrentFeed = GetOemDRO(818)
CurrentAbsInc = GetOemLED(48)
CurrentGmode = GetOemDRO(819)
CurrentFeedOverride = GetOEMDRO(821)


'X 1st Pass at fast rate


Message "X axis 1st pass"
Sleep 2000
If GetOemLed (825) = 0 Then
DoOemButton (1008)
Sleep(250)
SetOemDRO (821,100)
Code "G90 G31 X20 F600"
While IsMoving()
Wend
Sleep(250)
XProbePos = GetVar(2000)
If Abs(XprobePos) <= Abs(20) - 0.1 Then
Code "G0 X" &XProbePos
While IsMoving()
Wend
Call SetDro (0,0)
Sleep(250)
Code "G1 X-1 F1000"
While IsMoving()
Wend
Message "X axis 2nd pass"
Sleep(250)
Else
Code "G53 G0 X" &x
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If
Else
Message "Probe is grounded, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If


'X 2nd pass at slow rate


DoOEMButton (1008)
Sleep(250)
Code "G31 X2 F30"
While IsMoving()
Wend
Sleep(250)
XProbePos = GetVar(2000)
If Abs(XprobePos) <= Abs(2) - 0.1 Then
Code "G0 X" &XProbePos
While IsMoving()
Wend
Call SetDro (0,ToolRadius)
Sleep(250)
Message "X axis is now zeroed"
Sleep(250)
Code "G91 G0 X-10"
Code "G0 Y-20"
Code "G0 X20"
While IsMoving()
Wend
Sleep(250)
Else
Code "G53 G0 X" &x
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If



'Y 1st Pass at fast rate


Message "(Y axis 1st pass)"
If GetOemLed (825) = 0 Then
DoOemButton (1009)
Sleep(250)
Code "G90 G31 Y20 F600"
While IsMoving()
Wend
Sleep(250)
YProbePos = GetVar(2001)
If Abs(YprobePos) <= Abs(20) - 0.1 Then
Code "G0 Y" &YProbePos
While IsMoving()
Wend
Call SetDro (1,0)
Sleep(250)
Code "G1 Y-1 F1000"
While IsMoving()
Wend
Message "Y axis 2nd pass"
Sleep(250)
Else
Code "G53 G0 Z0"
Code "G53 G0 Y" & y & "X" & x
Code "G53 G0 Z" & z
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If
Else
Message "Probe is grounded, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If


'Y 2nd pass at slow rate


DoOEMButton (1009)
Sleep(250)
Code "G31 Y2 F30"
While IsMoving()
Wend
Sleep(250)
YProbePos = GetVar(2001)
If Abs(YprobePos) <= Abs(2) - 0.1 Then
Code "G0 Y" &YProbePos
While IsMoving()
Wend
Call SetDro (1,ToolRadius)
Sleep(250)
Message "Y axis is now zeroed"
Code "G91 G0 Y-5"
Code "G0 Z20"
Code "G90 G0 X20 Y20"
While IsMoving()
Wend
Else
Code "G53 G0 Z0"
Code "G53 G0 Y" & y & "X" & x
Code "G53 G0 Z" & z
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Auto zero script problem
« Reply #4 on: April 30, 2020, 06:36:07 PM »
When ever you update a DRO or in a while loop or send a message you need to have a short sleep() 50 to 150 is usually enough time for mach to update data in the background.

If you still have problems make sure you have a genuine licence file.




Thank you Graham!
I'm Using the Demo version until the machine is finished.




added some sleep's to your code, maybe it helps

Code: [Select]
ToolRadius = GetOemDRO(1112)/2  'custom tool diameter DRO
PlateOffset = 20  'X and Y offset
PlateThickness = 15  'Z offset

CurrentFeed = GetOemDRO(818)
CurrentAbsInc = GetOemLED(48)
CurrentGmode = GetOemDRO(819)
CurrentFeedOverride = GetOEMDRO(821)


'X 1st Pass at fast rate


Message "X axis 1st pass"
Sleep 2000
If GetOemLed (825) = 0 Then
DoOemButton (1008)
Sleep(250)
SetOemDRO (821,100)
Code "G90 G31 X20 F600"
While IsMoving()
Wend
Sleep(250)
XProbePos = GetVar(2000)
If Abs(XprobePos) <= Abs(20) - 0.1 Then
Code "G0 X" &XProbePos
While IsMoving()
Wend
Call SetDro (0,0)
Sleep(250)
Code "G1 X-1 F1000"
While IsMoving()
Wend
Message "X axis 2nd pass"
Sleep(250)
Else
Code "G53 G0 X" &x
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If
Else
Message "Probe is grounded, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If


'X 2nd pass at slow rate


DoOEMButton (1008)
Sleep(250)
Code "G31 X2 F30"
While IsMoving()
Wend
Sleep(250)
XProbePos = GetVar(2000)
If Abs(XprobePos) <= Abs(2) - 0.1 Then
Code "G0 X" &XProbePos
While IsMoving()
Wend
Call SetDro (0,ToolRadius)
Sleep(250)
Message "X axis is now zeroed"
Sleep(250)
Code "G91 G0 X-10"
Code "G0 Y-20"
Code "G0 X20"
While IsMoving()
Wend
Sleep(250)
Else
Code "G53 G0 X" &x
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If



'Y 1st Pass at fast rate


Message "(Y axis 1st pass)"
If GetOemLed (825) = 0 Then
DoOemButton (1009)
Sleep(250)
Code "G90 G31 Y20 F600"
While IsMoving()
Wend
Sleep(250)
YProbePos = GetVar(2001)
If Abs(YprobePos) <= Abs(20) - 0.1 Then
Code "G0 Y" &YProbePos
While IsMoving()
Wend
Call SetDro (1,0)
Sleep(250)
Code "G1 Y-1 F1000"
While IsMoving()
Wend
Message "Y axis 2nd pass"
Sleep(250)
Else
Code "G53 G0 Z0"
Code "G53 G0 Y" & y & "X" & x
Code "G53 G0 Z" & z
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If
Else
Message "Probe is grounded, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If


'Y 2nd pass at slow rate


DoOEMButton (1009)
Sleep(250)
Code "G31 Y2 F30"
While IsMoving()
Wend
Sleep(250)
YProbePos = GetVar(2001)
If Abs(YprobePos) <= Abs(2) - 0.1 Then
Code "G0 Y" &YProbePos
While IsMoving()
Wend
Call SetDro (1,ToolRadius)
Sleep(250)
Message "Y axis is now zeroed"
Code "G91 G0 Y-5"
Code "G0 Z20"
Code "G90 G0 X20 Y20"
While IsMoving()
Wend
Else
Code "G53 G0 Z0"
Code "G53 G0 Y" & y & "X" & x
Code "G53 G0 Z" & z
While IsMoving()
Wend
Message "Material not found, check connection and try again"
Code "F" &CurrentFeed
SetOemDRO (821,CurrentFeedOverride)
If CurrentAbsInc = 0 Then Code "G91"
If CurrentGMode = 0 Then Code "G0"
Sleep(250)
Exit Sub
End If




Thanks TPS! I'm doing more tests, in a couple of days I'll share the results.