Rem	VBScript To center mill On quick relase handle In preparation For slot cutting

Dist = 10.0 'Maximum detection distance, radius should be larger than the number of cylinders, such as cylinder radius is 8, the maximum detection range can be set to about 10
ZDist = 2.0 'z-axis depth distance
Sat = 1.0  'After the probe hit£¬ the fall back distance


If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
Code "(Probe plate is grounded, check connection and try again)"
Else
DoSpinStop()
FeedCurrent = GetOemDRO(818) 'Get the current settings
XCurrent = GetDro(0)
YCurrent = GetDro(1)
ZCurrent = GetDro(2)

Code "G4 P1"	 'Pause 1s
Code "F25"	 'The speed is slower, for 25

Rem	Probe Down

ZNew = ZCurrent - ZDist	 'Probe down on the surface of the workpiece
Code "G31 Z" &ZNew   'Begin to probe
While IsMoving()	 
Sleep(200)
Wend
ZTop = GetDro(2)	 'Obtain the z coordinate of the workpiece surface

Code "G0 Z" &ZTop + Sat	 'Detected on the surface,go away
Code "G0 Y" &YCurrent + Dist	'
Code "G0 Z" &ZTop - ZDist	 '

Rem	Probe foward

Code "G31 Y" &YCurrent	 'Scan back edge
While IsMoving()
Sleep(200)
Wend
YPos1 = GetDro(1)	 'Record back edge position

Code "G0 Y" &YPos1 + Sat	'Move away from last scanned edge
Code "G0 Z" &ZTop +Sat	 'Move up above part surface
Code "G0 Y" &YCurrent - Dist	'Move   to front edge of part
Code "G0 Z" &ZTop - ZDist	 'Move down to  below part top edge

Rem	Probe backward

Code "G31 Y" &YCurrent	 
While IsMoving()
Sleep(200)
Wend
YPos2 = GetDro(1)	 

YCenter = (YPos1 + YPos2) / 2	 
Code "G0 Y" &YPos2 - Sat	 
Code "G0 Z" &ZTop + Sat	 

Rem	move To the center

Code "G0 Y" &YCenter	  
Code "G0 X" &XCurrent + Dist	 
Code "G0 Z" &ZTop - ZDist	  
Rem	Probe Left

Code "G31 X" &XCurrent	 
While IsMoving()	 'wait for the move to finish
Sleep(200)
Wend
XPos1 = GetDro(0)	  
Code "G0 X" &XPos1 + Sat	 
Code "G0 Z" &ZTop + Sat	  
Code "G0 X" &XCurrent-Dist	 
Code "G0 Z" &ZTop - ZDist	 

Rem	Probe Right

Code "G31 X" &XCurrent
While IsMoving()
Sleep(200)
Wend
XPos2 = GetDro(0)

XCenter = (XPos1 + XPos2) / 2	'center is midway between XPos1 and XPos2
Code "G0 X" &XPos2 - Sat	 
Code "G0 Z" &ZTop + Sat	 
Code "G0 X" &XCenter	  

While IsMoving()
Sleep(200)
Wend


Code "F" &FeedCurrent  'restore starting feed rate

Rem	Reset DROs

Call SetDro (0,0.00)	 'reset X axis DRO
Call SetDro (1,0.00)	 'reset Y axis DRO
Call SetDro (2,Sat)	 'reset Z axis DRO

End If   

