Dear all,
I just registered to the forum to share my attempt to write a Auto tool zero script. See below.
About a year ago I bought a 6040CNC from China. Last Monday I 'quickly' wanted to figure out how to get my tools to auto zero and found many video's/tutorials online. Lazy as I am I copied and pasted the script and voilá we're done.
However...
The script never zeroed my Z axis where it needed and thus began the search of what the script actually was doing. So you had your movement blabla G31 blabla and 'GetVar(2002)' kept showing up. Stepping down the script in the editor I found that this was supposed to be where the Z axis was zeroed but it never did. A search on the interwebs let me to believe my remote control(W Xhc) for some reason conflicted with the GetVar(2002) code. I haven't confirmed this but accepted this as the cause nonetheless.
So we write/borrow our own script. I've borrowed the message pop-up from Charlie Sarsfield but that's about it. Mainly instead of using GetVar(2002) I've ended up using G92 to set the value of my Z axis. And it appears my controller likes to sleep before taking any actions.
Please if any of you could be so kind to give it a quick glance over to see if I haven't made any stupid mistakes or if I've overlooked something that could make it 'simpler'.
I hope this helps anyone that has run into the same issue I have.
Best regards,
Evert-Jan
'G31 command move until probe triggerd
'G53 command move from machine coordinates
'G92 command used to set Z value
DownMovementMax = -65 'Set Z down movement
DownMovementSafe = -25 'Safe to move down Quickly
DownFeedRateQuick = 150 'Set FeedRate(speed) of Z down movement
DownFeedRateSlow = 50
DownFeedRateSafe = 500
G53FeedRateUp = 1000
UpMovement = 2
TouchPlateSize = 20.15
VarOffSetCalc = 0
VarRunBox = 1
VarBoxMaterialSize = 0
If VarRunBox = 1 Then MaterialDialog
Code "G1"
Code "G53 Z0" &" F" &G53FeedRateUp 'Move to machine Z0
While IsMoving() 'Wait
Sleep 100
Wend
Code "G92 Z0" 'Zero Z value
Sleep 100
Code "G53 F4000 X366 Y527"
While IsMoving() 'Wait
Sleep 100
Wend
Code "G53 Z" &DownMovementSafe &" F" &DownFeedRateSafe 'Quick move to safe posistion
While IsMoving() 'Wait
Sleep 100
Wend
Code "G90 G31 Z" &DownMovementMax &" F" &DownFeedRateQuick 'probe movement start
While IsMoving() 'Wait
Sleep 100
Wend
Code "G91 Z" &UpMovement &" F" &DownFeedRateQuick 'move up for second slow probe
While IsMoving() 'Wait
Sleep 100
Wend
Code "G90 G31 Z" &DownMovementMax &" F" &DownFeedRateSlow 'Slow probe movement start
While IsMoving() 'Wait
Sleep 100
Wend
VarBoxMaterialSize = VarBoxMaterialSize * -1 'Make dialog input negative
Sleep 100
VarOffSetCalc = VarBoxMaterialSize + TouchPlateSize 'Add dialog input plus touchplate to get Z value
Sleep 100
Code "G92 Z" &VarOffSetCalc 'Zero Z value with value above
Sleep 100
Code "G53 Z0" &" F" &G53FeedRateUp 'Move to machine Z0
While IsMoving() 'Wait
Sleep 100
Wend
Exit Sub
Sub MaterialDialog
Begin Dialog MaterialOffset 110,68,"Material thickness"
OKButton 42,52,26,12
Text 0,0,100,10, "Material Height"
TextBox 35,20,30,10, .SecText
Text 60,20,30,15, "mm"
End Dialog
Dim Dlg1 As MaterialOffset
Dlg1.SecText = VarMaterialSize 'Material size
Button = Dialog (Dlg1) 'SHOW DIALOG AND WAIT FOR BUTTON REPLY
If Button = 0 Then 'IF CLOSE BUTTON
Message "Auto zero abort"
End 'END SCRIPT
End If
If IsNumeric(Dlg1.SecText) = True Then
VarBoxMaterialSize = Int(Dlg1.SecText)
Else
Message "Use numerical value"
MaterialDialog 'RESTART SUB
End If
End Sub