2216
« on: October 12, 2015, 04:22:35 PM »
OK something like this should work,
##
oemtrigger1 is not ok input5 would be great
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' oemtrigger1 is mapped to input5
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos as long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
Akttime = Timer
If Akttime - Starttime > 20 then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air otor off
End
End if
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air otor off
sleep(1000)
'look for Input5
if not IsActive(Input1) then
DOButton(3)
Messagebox("Tool changer not seated!")
end
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
Thomas