Sorry I missed some parts of code...
Const TOOLCOUNT = 18 ' max Tool #
Const ATCFEEDRATE = 10 ' tool change feedrate
Const ToolZlockPos = -104.0 ' Z axe tool lock height abs
Const ToolZrotatePos = 10.0 ' Z axe tool rotate height abs
'------------------------------------------------------------------------------
' program variables - don't modify
'------------------------------------------------------------------------------
Dim ToolNew, ToolOld, CWturn, CCWturn, ActATCPos, CarousellRot As Integer
Dim ToolRdy, FloodLast, JogLast As Boolean
'------------------------------------------------------------------------------
' MACRO START
'------------------------------------------------------------------------------
Sub Main()
Message("ATC in progres...")
If(GetOEMLed(800)) Then ' MACH is at RESET condition
Message("ESTOP active - Tool Change terminated")
Sleep(150)
'WaitForMove
End
End If
If(GetOEMLed(807) Or GetOEMLed(808) Or GetOEMLed(809)) Then ' Machine not referenced
Message("You must reference machine first!")
Sleep(150)
'WaitForMove
End
End If
SetUserLED(1001, 1) ' User LED - toolchange in progress (Pause Feed Hold condition)
If Not IsActive(AtcHomePosSw) Or IsActive(AtcChangePosSw) Then
MachMsg("Wrong tool!", "Error!!!", 0)
End
End If
' Get actual tool # and new tool #
ToolOld = GetCurrentTool()
ToolNew = GetSelectedTool()
SetOemDro(SelectedToolDRO, ToolNew) 'sellected tool
FloodLast = GetOemLed(13) ' get flood led
JogLast = GetOemLed(JogLed) ' get Jog led
Message("Old tool =" & ToolOld &", New tool = " & ToolNew)
If GetOemLed(JogLed) Then 'disable Jog
DoOEMbutton(JogButton)
End If
DoOEMbutton(183) 'reset speed override
' The same position - no need to move
If (ToolNew = ToolOld) Then
SetCurrentTool( ToolNew )
Message("ATC is on position T "& ToolNew)
'WaitForMove
End
End If
If (ToolNew > TOOLCOUNT) Then
SetCurrentTool( ToolOld )
SetUserLED(1001, 0) ' Pause Feed Holf off
DoOEMButton(1003) ' Stop
DoOEMButton(1002) ' G-Code Rewind
Sleep(150)
Message("Tool number too high (above 18)")
Sleep(150)
End
End If
' T0 is a fake tool, no need to change
If (ToolNew = 0) Then
ToolNew = 0
SetCurrentTool( ToolNew )
Message("Succesful loaded tool T" & ToolNew)
'WaitForMove
End
End If
DoOEMButton(225)
'Message("Spindle stop...")
DoSpinStop() ' Stop spindle roration
'Message("Moving Z...")
ZtoChPosition ' Z axe to tool change position <<<--- HERE MACRO STUCK
End Sub
' -----------------------------------------------------------------------------
Sub ZtoChPosition() 'Move to Z tool position and wait until position reached
code("G53 G00 Z"& ToolZlockPos & "F" & ATCFEEDRATE) 'Z value as to be checked for exact match with carrousel height
WaitForMove
Sleep(1000)
End Sub
' -----------------------------------------------------------------------------
Sub WaitForMove
CntLoop = 60
While(IsMoving() And CntLoop > 0 )
CurPos = GetOemDRO(802)
Pom = CurPos - Destination
Sleep(250)
CntLoop = CntLoop - 1
If CntLoop = 0 Then
If RetryDialog("Error!!!", "IsMoving() timeout, Retry?") Then
CntLoop = 20
Else
End
End If
End If
Wend
End Sub
' -----------------------------------------------------------------------------
Function RetryDialog(CaptionMsg, UserMsg)
If MachMsg(UserMsg, CaptionMsg, 5) = 4 Then
RetryDialog = 1
Else
RetryDialog = 0
End If
End Function