Rem	VBScript To center probe inside a pipe

Dist= 20.0 'Maximum detection depth 20.0
ZDist = 40.0 'When finished, put a knife 4.0
If GetOemLed (825) <> 0 Then 		'Check the probe if it is disconnected
	Code "(Probe plate is grounded, check connection and try again)"
Else
	DoSpinStop()
	FeedCurrent = GetOemDRO(818) 	'Save the feed rate
	XCurrent = GetDro(0)
	YCurrent = GetDro(1)
	ZCurrent = GetDro(2)
   
    

	Code "G4 P1"			'Pause 1s
	Code "F25"			'Adjust the speed more slow

Rem	Probe Left
	
	XNew = Xcurrent - Dist 		'probe 20mm to left
	Code "G31 X" &XNew
	While IsMoving()		'wait for the move to finish
	Wend
	XPos1 = GetOemDRO(800)		'get the probe touch location

	Code "G0 X" &XCurrent
	While IsMoving ()
	Wend
		'rapid move back to start point

Rem	Probe Right
	
	XNew = XCurrent + Dist		'probe 20mm to right
	Code "G31 X" &XNew
	While IsMoving()
	Wend
	XPos2 = GetOemDRO(800)

	XCenter = (XPos1 + XPos2) / 2	'center is midway between XPos1 and XPos2
	Code "G0 X" &XCenter
	While IsMoving ()
	Wend
		'rapid move to the x center location

Rem	Probe up

	YNew = YCurrent + Dist
	Code "G31 Y" &YNew
	While IsMoving()
	Wend
	YPos1 = GetOemDRO(801)

	Code "G0 Y" &YCurrent
	While IsMoving ()
	Wend


Rem	Probe down
	
	YNew = YCurrent - Dist
	Code "G31 Y" &YNew
	While IsMoving()
	Wend
	YPos2 = GetOemDRO(801)

	YCenter = (YPos1 + YPos2) / 2

Rem	move To the center
	
	Code "G0 Y" &YCenter
	While IsMoving ()
	Wend

	Code "F" &FeedCurrent  		'restore starting feed rate
	ZClear = Zcurrent + ZDist
	Code "Z" &ZClear
End If 