Dim x,y,z,a,b,c
Dim OldTool,NewTool,tool,MaxToolNum,ToolDown,ToolUpŁ¬ToolSafe
Dim Xpos,YPos
Dim ToolYaxisAdd
Dim BrushWaitTime,ToolReleaseWaitTime,ToolClampWaitTime

'ToolChange Macro For Bed type tool changer 11/05 Brian
'Sub Main()
Code "G90"
OldTool = GetOEMDRO (1200) 'Tool In spindle DRO You must add this to your settings screen
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )
tool = GetSelectedTool()
NewTool = tool
'Tool Changer Macro (Bed Type)
MaxToolNum = 6                         'Max number off tools for the changer
ToolSafe   = GetOEMDRO (1240)          'Tool Safe Position
ToolUp     = GetOEMDRO (1241)          '-1.0'Z Hieght to Rapid from tool to tool
ToolDown   = GetOEMDRO (1242)          '-239.47'Z Pos to Get or drop a tool
ToolYaxisAdd = GetOEMDRO (1243)        '100'Y Avoid Position Add
If NewTool = OldTool Then
    Message"Tool No Change"
    Exit Sub
End If

'SetUserLED(53, 1)

'------------------------------------------
'    Brush Control
'------------------------------------------
DeActivateSignal(Output6)
Message"Wait Brush Position Limit Signal "
BrushWaitTime = 0
while not IsActive(Input3)
Code "G4 P0.1"
While IsMoving()
Wend
if BrushWaitTime > 25 Then
    DoOEMBUTTON(1021)
    Message"Brush Wait OverTime"
    Exit Sub 
End If
BrushWaitTime = BrushWaitTime +1   
wend
'-------------------------------------------
'-------------------------------------------


Message"Tool Change"
While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Code "G00 G53 Z" & ToolSafe
While IsMoving()
Wend
Call MovePos(OldTool)
While IsMoving()
Wend
Code "G01 G53 X" & XPos & "Y" & YPos - ToolYaxisAdd & "F5000" 
Code "G4 P0.1"
While IsMoving()
Wend

Code "G4 P0.5"
While IsMoving()
Wend
Code "G0 G53 Z" & ToolDown
Code "G4 P.75"
While IsMoving()
Wend
Code "G01 G53 Y" & YPos & "F5000"
Code "G4 P.75"
While IsMoving()
Wend


'------------------------------------------
'    Tool Release Control
'------------------------------------------
ActivateSignal(Output5) 'Turn On Draw bar to release the tool
Message"Wait Tool Release Signal "
ToolReleaseWaitTime = 0
while not IsActive(29) 'OEM INPUT1
Code "G4 P0.1"
While IsMoving()
Wend
if ToolReleaseWaitTime > 25 Then
    DoOEMBUTTON(1021)
    Message"Tool Release feedback Signal Wait OverTime"
    Exit Sub 
End If
ToolReleaseWaitTime = ToolReleaseWaitTime +1   
wend
'-------------------------------------------
'-------------------------------------------

Code "G4 P1.0"    'Wait for the tool to release
Code "G0 G53 Z" & ToolUp
Call MovePos(NewTool)
While IsMoving()
Wend
Code "G01 G53 X" & XPos & " Y" & YPos & "F5000"
Code "G0 G53 Z" & ToolDown
Code "G4 P.75"
While IsMoving()
Wend

'------------------------------------------
'    Tool Clamp Control
'------------------------------------------
DeActivateSignal(Output5) 'Turn Off Draw bar to Clamp the tool
Message"Wait Tool Release Signal "
ToolClampWaitTime = 0
while not IsActive(30) 'OEM INPUT2
Code "G4 P0.1"
While IsMoving()
Wend
if ToolClampWaitTime > 25 Then
    DoOEMBUTTON(1021)
    Message"Tool Clamp feedback Signal Wait OverTime"
    Call SetUserDRO (1200,NewTool)
    SetCurrentTool( NewTool )
    Exit Sub 
End If
ToolClampWaitTime = ToolClampWaitTime +1   
wend
'-------------------------------------------
'-------------------------------------------

Code "G4 P1.0"    'Wait for the tool to Clamp
While IsMoving()
Wend

Code "G01 G53 Y" & YPos - ToolYaxisAdd & "F5000"
Code "G4 P1"
While IsMoving()
Wend

Code "G0 G53 Z" & ToolSafe
Code "M1801"
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )
'Code "G0 G53 X" & x & " Y" & y 'Move back to where the tool change was prompted
While IsMoving()
Wend

Message"Tool Change Finish"



'------------------------------------------
'    Tool Postion
'------------------------------------------
Sub MovePos(ByVal ToolNumber As Integer)

Select Case ToolNumber
       Case Is = 0
         Xpos = GetOEMDRO (1220)
         YPos = GetOEMDRO (1230)
       Case Is = 1
         'Xpos = 373.74
         'YPos = 3393.00
         Xpos = GetOEMDRO (1220)
         YPos = GetOEMDRO (1230)
       Case Is = 2
         'Xpos = 573.85
         'YPos = 3393.00
         Xpos = GetOEMDRO (1221)
         YPos = GetOEMDRO (1231)
       Case Is = 3
         'Xpos = 774.52
         'YPos = 3393.00
         Xpos = GetOEMDRO (1222)
         YPos = GetOEMDRO (1232)
       Case Is = 4
         'Xpos = 975.84
         'YPos = 3393.00
         Xpos = GetOEMDRO (1223)
         YPos = GetOEMDRO (1233)
       Case Is = 5
         'Xpos = 1177.93
         'YPos = 3393.00
         Xpos = GetOEMDRO (1224)
         YPos = GetOEMDRO (1234)
       Case Is = 6
         'Xpos = 1377.14
         'YPos = 3393.00
         Xpos = GetOEMDRO (1225)
         YPos = GetOEMDRO (1235)
End Select
End Sub
'-------------------------------------------
'-------------------------------------------


tool = GetSelectedTool()
SetCurrentTool( tool )

 
 


