We have a 12 ATC that we are trying to Initialize (find tool position one). The macro below works, but I think there might be a better way to move an axis and monitor an switch change.
My question is, while an axis is moving and a switch change is detected, what is the best way to 1) grab the position of the axis and stop the motor smoothly. Our Macro works, but the motor STOPS, it does not decelerate to a stop. We are using C Axis for the ATC Carousel Motor
'**********************************************************************
'
' M1002.mls Initialize the ATC 17NOV2009
'
' Initiailize the ATC
'
' 1) Checks if the Carousel is HOMED, if so, backs it off the HOME switch
' 2) Finds HOME and Moves 1/2 Revolution of the Motor Shaft
' 3) Checks the INDEX and HOME switchs to make sure we are correct
' 4) Sets the DROs to a know state
'
'**********************************************************************
Sub Main()
Dim AxisName As String
Dim CodeBuffer As String
Dim Timeout As Integer
' Define I/O and OEM Parameters
Const StopButton = 1003 ' OEM Stop Button
Const eStop = 1021 ' OEM eStop Button
Const HomeSW = Input4 ' Mapped to Input4
Const IndexSW = Input3 ' Mapped to Input3
Const MotorEnable = Output1 ' Mapped to Output1
Const CarouselMotor = 5 ' Mapped to C Axis
AxisName = "C" ' Mapped to C Axis
Message "Initializing the ATC..."
' Enable Motor and let the Motor Driver Stablize
ActivateSignal( MotorEnable )
Sleep 100
'
' If we are currently HOMEd, then move off of HOME.
'
If IsActive( HomeSW ) Then
' Get the current motors Position
Timeout = 0
MotorPosition = GetABSPosition( CarouselMotor )
MotorPosition = MotorPosition - 25
CodeBuffer = "G0 G56 " & AxisName & MotorPosition
' Message "ATC: CODE: " & CodeBuffer
Code CodeBuffer
While IsActive( HomeSW )
Sleep 10
' Check for TimeOut ( 5 Second )
Timeout = Timeout + 1
If Timeout = 500 Then
Message "!!! ATC Home Sw TimeOut 1 !!!"
Sleep 1000
DoOEMButton( eStop )
Exit Sub
End If
Wend
' Stop the Motor
DoOEMButton( StopButton )
While IsMoving()
Sleep 10
Wend
End If
'
' Move until we see the HOME Switch, then continue to the Middle
'
MotorPosition = GetABSPosition( CarouselMotor )
' Move until we see the Home SW, could be as much as 12 Positions
Timeout = 0
MotorPosition = MotorPosition + ( 25 * 12 )
CodeBuffer = "G0 G56 " & AxisName & MotorPosition
' Message "ATC: CODE: " & CodeBuffer
Code CodeBuffer
Do Until IsActive( HomeSW )
Sleep 10
' Check for TimeOut ( 25 Seconds )
Timeout = Timeout + 1
If Timeout = 2500 Then
Message "!!! ATC Home Sw TimeOut 2 !!!"
Sleep 1000
DoOEMButton( eStop )
Exit Sub
End If
Loop
' Stop the Motor
DoOEMButton( StopButton )
While IsMoving()
Sleep 10
Wend
' Grab the home Position we just found
MotorPosition = GetABSPosition( CarouselMotor )
Message "ATC: Home found at: " & MotorPosition
' Set the new target position and execute ( 1/2 Revelution of the Motor Shaft )
MotorPosition = MotorPosition + 12.5
CodeBuffer = "G0 G56 " & AxisName & MotorPosition
' Message "ATC: CODE: " & CodeBuffer
Code CodeBuffer
While IsMoving()
Sleep 10
Wend
'
' Make sure both the Home and Index Switches are Active
'
If Not( IsActive( HomeSW )) Then
Message "!!! ATC HOME Sw not Set !!!"
Sleep 1000
DoOEMButton( eStop )
Exit Sub
End If
If Not( IsActive( IndexSW )) Then
Message "!!! ATC INDEX Sw not Set !!!"
Sleep 1000
DoOEMButton( eStop )
Exit Sub
End If
'
' Clear DROs
'
SetMachZero( CarouselMotor ) ' Machine Cords
SetUserDRO( 1000, 1 ) ' ATC Tool Position
' Disable Motor Driver
DeActivateSignal( MotorEnable )
End Sub