Hello,
I'm working on a tool changer turret for a lathe, but I'm having an issue I can't seem to overcome.
I have PLC controlling all of the logic behind the tool changer and this works absolutely perfectly! I am using a brain to send the value from CurrentTool through modbus. This works if I manually put a value in the Tool No DRO. However, If I run my macro, the Tool No DRO does not change and the PLC does not get the new tool number.
I input in the MDI: M6 T0101 for example
Am I missing something obvious here please?
Thanks,
M6 Start macro:
'-----------------------------------------------------------------------
'CYCLONE - Auto tool changer (8 pos turret type)
'V1.0
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'CONFIG
'-----------------------------------------------------------------------
Tool = GetSelectedTool()
OldTool = GetCurrentTool()
NewTool = Tool
MaxToolNum = 8 'Max number of tools for the changer
'-----------------------------------------------------------------------
'MACRO START
'-----------------------------------------------------------------------
IsActive(INPUT1)
DeActivateSignal(OUTPUT6) 'Make sure signal to PLC is negative
'code"G91 G28 Z0" 'set incremental, return home via X first
'While IsMoving()
'Wend
While NewTool > MaxToolNum 'Dont allow tool number greater 8
Message("MAX TOOL NUMBER = 8")
Wend
While NewTool < 0 'Dont allow tool number less than 1
Message("INVALID TOOL NUMBER")
Wend
If NewTool = OldTool Then
Call ToolComplete
Else
If IsActive(INPUT1) Then 'ok signal from PLC
Call DoToolChange
Else
Message("TURRET NOT READY!")
End If
End If
End
'----------------------------------------------------------------------
'TOOL CHANGE
'----------------------------------------------------------------------
Sub DoToolChange()
SetCurrentTool(NewTool) 'Update the tool DRO
Call ActivateSignal(OUTPUT6) 'Set tool change allowed signal to PLC
SetTimer(1)
t = GetTimer(1)
sleep 10
If Not IsActive(INPUT1) Then 'If input goes low, turret is moving
While Not IsActive(INPUT1) 'While the turret is moving, count down
If IsActive(INPUT1) Then 'If input goes high again, tool has cycled
Call ToolComplete
Else
If t > 4000 Then
Call ToolFailed
End If
End If
sleep 10
Wend
End If
End Sub
'----------------------------------------------------------------------
'TOOL COMPLETE
'----------------------------------------------------------------------
Sub ToolComplete()
DeActivateSignal(OUTPUT6)
End Sub
'----------------------------------------------------------------------
'TOOL FAILED
'----------------------------------------------------------------------
Sub ToolFailed()
f = 1
DeActivateSignal(OUTPUT6)
While f = 1
Message("TURRET TIMEOUT")
Wend
End Sub