Hello Guest it is April 11, 2021, 09:55:21 PM

Author Topic: Auto tool zero scfipt  (Read 815 times)

0 Members and 1 Guest are viewing this topic.

Auto tool zero scfipt
« on: October 31, 2019, 07:25:50 PM »
I have just set up a home built cnc router and I'm having a few issues with the auto tool zero!!!! When I press the button everything runs great but after I get my message that the z axis has been zeroed, but when I press go to zro button my tool stops short by 4 mm! Not sure what i am doing wrong. Here is the script that I am running I'm hoping someone can help me:

'VB Code Start
'-------------------
CurrentAbsInc = GetOemLED (48) 'Copy current G90/G91 state
CurrentGMode = GetOemDRO (819) 'Copy current G0/G1 state
CurrentFeed = GetOemDRO (818) 'Copy current feedrate
Contact = 0 'Clear the contact flag
PlateThickness = 19.19 'Touch Plate thickness is set here
ProbeFeed = 100 'Probing feedrate is set here
SetVar (1, -30) 'Maximum probing distance is set here
SetVar (2, 5) 'Retract height is set here
Code "M5" 'Ensures spindle is not running
Code "G21" 'Ensure metric units are used
Zs = GetOemDRO (61) 'Copy current Z-Scale DRO
Call SetOemDRO (61,1) 'Set Z-Scale DRO to 1
Label1: 'Entry point for Retry
DoOemButton (1010) 'Zero Z-Axis DRO
Code "(Setting Tool Zero)" 'Message for status bar
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = 0 Then 'Check to see if touch plate is already grounded
Code "G90 G31 Z #1 F" & ProbeFeed 'Probing move
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = True Then 'Check to see if probe has touched plate
Contact = 1 'Set the contact flag
End If
ProbePos = GetVar (2002) 'Exact point probe touched
Code "G0 Z" & ProbePos 'Go back to exact point of touch if there was any overrun
While IsMoving () 'Wait until task has been completed
Wend
Call SetDRO (2,PlateThickness) 'Set Z-Axis DRO to Touch Plate thickness
Code "G0 Z 25" 'Retract off Touch Plate the set distance
While IsMoving () 'Wait until task has been completed
Wend
Code "(Z-Axis is now Zeroed.)" 'Message for status bar
Code "F" & CurrentFeed 'Restore feedrate to original setting
If Contact = 0 Then 'Probe reached max travel without touching
Code "(ERROR - Probe did not touch.)" 'Message for status bar
Response = MsgBox ("ERROR - Probe did not touch.",37,"Auto Tool Zero")
If (Response = 4) Then 'User chose Retry
GoTo Label1 'Retry Probing routine
End If
End If
Else
Code "(ERROR - Touch Plate is grounded.)" 'Message for status bar
Response = MsgBox ("ERROR - Touch Plate is grounded.",16,"Auto Tool Zero")
End If
Call SetOemDRO (61,Zs) 'Restore Z-Scale DRO to original setting
If CurrentAbsInc = 0 Then 'If G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then 'If G0 was in effect before then return to it
Code "G0"
End If

 '-------------------
'VB Code Stop
Re: Auto tool zero scfipt
« Reply #1 on: October 31, 2019, 08:38:04 PM »
When I comment out the following lines:

ProbePos = GetVar (2002) 'Exact point probe touched
Code "G0 Z" & ProbePos 'Go back to exact point of touch if there was any overrun
While IsMoving () 'Wait until task has been completed
Wend

It works, where can I go see what this GetVar (2002) is getting as a value cause it looks like it is addinf=g the 4 mm there.

Offline Tweakie.CNC

*
  • *
  •  8,690 8,690
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Auto tool zero scfipt
« Reply #2 on: November 01, 2019, 02:37:28 AM »
I have made a couple of changes to your script. Please try it and see how it goes.

Tweakie.

Code: [Select]
'VB Code Start
'-------------------
CurrentAbsInc = GetOemLED (48) 'Copy current G90/G91 state
CurrentGMode = GetOemDRO (819) 'Copy current G0/G1 state
CurrentFeed = GetOemDRO (818) 'Copy current feedrate
Contact = 0 'Clear the contact flag
PlateThickness = 19.19 'Touch Plate thickness is set here
ProbeFeed = 100 'Probing feedrate is set here
SetVar (1, -30) 'Maximum probing distance is set here
SetVar (2, PlateThickness+5) 'Retract height above Plate is set here
Code "M5" 'Ensures spindle is not running
Code "G21" 'Ensure metric units are used
Zs = GetOemDRO (61) 'Copy current Z-Scale DRO
Call SetOemDRO (61,1) 'Set Z-Scale DRO to 1
Label1: 'Entry point for Retry
DoOemButton (1010) 'Zero Z-Axis DRO
Code "(Setting Tool Zero)" 'Message for status bar
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = 0 Then 'Check to see if touch plate is already grounded
Code "G90 G31 Z #1 F" & ProbeFeed 'Probing move
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = True Then 'Check to see if probe has touched plate
Contact = 1 'Set the contact flag
End If
DoOemButton (1003) 'Clear a possible feed-hold condition
ProbePos = GetVar (2002) 'Exact point probe touched
Code "G0 Z" & ProbePos 'Go back to exact point of touch if there was any overrun
While IsMoving () 'Wait until task has been completed
Wend
Call SetDRO (2,PlateThickness) 'Set Z-Axis DRO to Touch Plate thickness
Code "G0 Z #2" 'Retract off Touch Plate the set distance
While IsMoving () 'Wait until task has been completed
Wend
Code "(Z-Axis is now Zeroed.)" 'Message for status bar
Code "F" & CurrentFeed 'Restore feedrate to original setting
If Contact = 0 Then 'Probe reached max travel without touching
Code "(ERROR - Probe did not touch.)" 'Message for status bar
Response = MsgBox ("ERROR - Probe did not touch.",37,"Auto Tool Zero")
If (Response = 4) Then 'User chose Retry
GoTo Label1 'Retry Probing routine
End If
End If
Else
Code "(ERROR - Touch Plate is grounded.)" 'Message for status bar
Response = MsgBox ("ERROR - Touch Plate is grounded.",16,"Auto Tool Zero")
End If
Call SetOemDRO (61,Zs) 'Restore Z-Scale DRO to original setting
If CurrentAbsInc = 0 Then 'If G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then 'If G0 was in effect before then return to it
Code "G0"
End If

 '-------------------
'VB Code Stop

KEEP SAFE !

Offline TPS

*
  •  2,097 2,097
    • View Profile
Re: Auto tool zero scfipt
« Reply #3 on: November 01, 2019, 03:34:57 AM »
where the z-axis is going to when you press the Goto Zero Button depends on your Settings in Config -> Save_Z-Setup. Goto Diagnostic page and have a look for all the Coords.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Auto tool zero scfipt
« Reply #4 on: November 01, 2019, 10:30:29 PM »
I'm still getting strange numbers when the script tries to GetVar (2002) for exact point where probe touched, seems to be different every time.  which in turn screws the tool zero because it sends up the tool before it sets it to plate thickness!!!!

Offline Tweakie.CNC

*
  • *
  •  8,690 8,690
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Auto tool zero scfipt
« Reply #5 on: November 02, 2019, 02:25:13 AM »
Which version of Mach3 are you using ?

Are you using a Chinese external motion controller ?

Can you attach <your profile> .xml file ?
« Last Edit: November 02, 2019, 08:16:55 AM by Tweakie.CNC »
KEEP SAFE !

Offline TPS

*
  •  2,097 2,097
    • View Profile
Re: Auto tool zero scfipt
« Reply #6 on: November 02, 2019, 07:31:57 AM »
try to Change:

Code "G90 G31 Z #1 F" & ProbeFeed 'Probing move

to

Code "G90 G31 Z #1 F" & ProbeFeed 'Probing move
Sleep(300)


anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.