Mach3 – Automate Tool Zeroing with VB

Tool zeroing by aligning the machine manually and setting the DRO to zero is a time consuming process. Using a touch plate to set the zero greatly improves accuracy. For my machine, there was a touch plate available, but it plugged into the side of the car and needed to be set out manually and removed for the machine to work.

I wanted to make it so it wasn’t necessary to leave the terminal to get the machine to zero. The best way I could think of doing this was to set a fixed touchplate to the side of the bed (just outside of the work area) and slightly below the bed of the table.

This way, I am able to reliably reset the 0 for the Z axis of the machine even if a full sheet is on the table.

The touchplate is set to some distance below the bed and this is included in the macro so the offset can be compensated for.

Demonstration

Below is a short video demonstrating the tool zeroing cycle.

Code

'M200 Auto Zero-ing Mach3 Script 
'Created: C. Stewart cstewart000@gmail.com 09/01/2017 

Private Sub home() 

	Dim ZprobeDepth, ZfeedRate, Zsafe, XcoordTouchPlate, YcoordTouchPlate, Ret, CurrentZMachinePos, ZprobCoord
	
	Dim isZeroPlateTouched As Boolean
	
	
	isZeroPlateTouched = false
	
	ZprobeDepth = -30 
	Zsafe = 30
	
	ZfeedRatePlunge = 100
	ZfeedRateRetract = 1000
	FeedRateJog = 2000
	
	
	ZdepthTouchPlate = -3
	
	
	XcoordTouchPlate = 45
	YcoordTouchPlate = 95
	
	
	Ret = MachMsg("Is the tool at safe Z? i.e. clear of all obstructions? If no, click 'NO' And  jog To safe Z Then re-run ", "Check Z!", 4)
	If Ret = 6 Then
		Message( "Safe Z Confirmed" )
	
	ElseIf Ret = 7 Then
		'Abort 
		'Trigger E-stop
		DoOemButton(1021)
		Message( "jog To safe Z Then re-run " )
		Exit Sub
		
	End If
	
	'Move to the touch plate
	Code "G53 X" & XcoordTouchPlate & " Y" & YcoordTouchPlate & "F"&  FeedRateJog
	
	
	Message( "Auto Tool Zeroing..." )
	
	'Check if the touch plate has been hit
	If IsSuchSignal (22) Then
		
		'Call SetUserDRO( 2, 0.00 ) 
		'Get the current machine Z co-ordinate
		CurrentZMachinePos = GetABSPosition(2)
		ZprobCoord = CurrentZMachinePos + ZprobeDepth
		
		code "G31 Z" & ZprobCoord & " F" & ZfeedRatePlunge
		While IsMoving()
		
			If GetOemLed(825) = -1 Then 
				isZeroPlateTouched = true
				
			Else
			
				isZeroPlateTouched = false		
			End If 
		Wend
		Call setMachZero(2) 'zero the Z axis
		'Call SetUserDRO( 2, ZdepthTouchPlate )  
		code "G53 Z" & Zsafe & "F" & ZfeedRatePlunge
		
		
	End If 
	
	If (isZeroPlateTouched) Then
	
		Message( "Tool Zero-ed: " & isZeroPlateTouched)
		
		'Move back to machine zero X and Y
		Code "G53 X0 Y0" & "F"&  FeedRateJog
	
	Else
	
		Message( "Tool Zeroing failed: " & isZeroPlateTouched )
		MachMsg( "The tool failed to zero automatically. Please check and retry", "Tool Zero Failed!", 0)
		
		'Trigger E-stop
		DoOemButton(1021)
		Exit Sub

		
	End If


End Sub
            

 

Video Walkthrough

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s