I spoke too soon!
I do have some problems with my code in the M6Start macro.....
I think the problem is with the while loop in the DoToolChange() sub.
What the code is supposed to do is:
- Check the tool number is valid, if its allowed proceed to DoToolChange()
-The tool number is sent to a PLC via modbus, that is giving a tool change allowed signal (INPUT1), but is waiting for the command to change the tool from mach (OUTPUT6).
-Once (OUTPUT6) goes high, the PLC sends (INPUT1) low while it cycles the tool. Once it has successfully located and locked the tool, it will set (INPUT1) high again. If it doesn't, something has gone wrong.
-The While loop is supposed to look at when (INPUT1) is low and wait for it to go high again, before it calls ToolComplete(), it should also start timing 4 seconds, by which time if it hasn't seen the signal it will call ToolFailed().
The while loop is doing something strange and won't go to either ToolComplete() or ToolFailed(), I think its something to do with the timer, but cant quite figure it out.
If anyone wouldn't mind looking over my code to see if anything jumps out please?
Thanks,
'-----------------------------------------------------------------------
'CYCLONE - Auto tool changer (8 pos turret type)
'V1.0
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'CONFIG
'-----------------------------------------------------------------------
NewTool = GetSelectedTool() 'Commanded tool number
OldTool = GetCurrentTool() 'Current tool number
MaxToolNum = 8 'Max number of tools for the changer
PreviousSpeed = GetRPM() '
ToolSpeed = 500
'-----------------------------------------------------------------------
'MACRO START
'-----------------------------------------------------------------------
DeActivateSignal(OUTPUT6) 'Make sure signal to PLC is negative
code"G91 G28 Z0" 'set incremental, return home via X first
SetSpinSpeed(ToolSpeed) 'Spindle speed change
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)
sleep 200
t = GetTimer(1)
While IsActive(INPUT1) = False 'While the turret is moving, count down
If IsActive(INPUT1) = True Then 'If input goes high again, tool has cycled
Call ToolComplete
'Else
If t > 4000 Then
Call ToolFailed
End If
End If
sleep 100
Wend
'End If
End Sub
'----------------------------------------------------------------------
'TOOL COMPLETE
'----------------------------------------------------------------------
Sub ToolComplete()
DeActivateSignal(OUTPUT6)
SetSpinSpeed(PreviousSpeed) 'RPM before tool change called
sleep 100
End Sub
'----------------------------------------------------------------------
'TOOL FAILED
'----------------------------------------------------------------------
Sub ToolFailed()
f = 1
DeActivateSignal(OUTPUT6)
While f = 1
Message("TURRET TIMEOUT")
Wend
End Sub