Machsupport Forum
		Mach Discussion => VB and the development of wizards => Topic started by: AalderinkEJ on April 21, 2021, 08:28:06 AM
		
			
			- 
				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
			 
			
			- 
				A direct question possibly related to the script.
After a job is completed the machine returns to the home position. If I then load a new job and press cycle start I get a softlimits warning on my Z axis.
My current workaround is I run m6 (which moves my spindle to my TC position) and my Auto Zero Tool script and then I can start the script without issue.
Any ideas?
EJ
			 
			
			- 
				It could be you have a G43 active with a tool offset and the machine is trying to move up in Z to this position.
Add a G49 to the safe start line of your programs and remove any G43 commands until you have a Z move.
E.g.
G21 G40 G80 G49
N1 (Spot Drill)
T1 M6
G54 G00 G90 X0 Y0 S4000 M3
G43 Z10.
G01 Z1. F250.
Etc....
			 
			
			- 
				Thanks for you reply Graham.
Unfortunately I still don't understand the cause.
Does it have to do with coordinates 'currently' set. See attached picture. Where my spindle is in home position and my workspace appears to be much further away?
And if I power off and back on I get the second picture.
Best regards,
EJ