3
« on: May 30, 2012, 03:45:07 PM »
Thamks for your helpful messages and your warm welcome to the forum sterling I feel most welcome here thanks to you. As dont post on forums much Iam feeling my way round I sent an open post as far as I saw it. The code is as follows I think I have set up the inputs correctly I coppied and pasted some code from other files but Iam stuck were the argument else. If anyone could help I would grateful
Sub Main()
OldTool = GetOEMDRO (1200) 'Tool In spindle DRO You must add this to your settings screen
x = GetToolChangeStart( 0 )
z = GetToolChangeStart( 2 )
'Inputs are as follows:
'
'
'OEMTRIG1 = Encoder Bit 1
'OEMTRIG2 = Encoder Bit 2
'OEMTRIG3 = Encoder Bit 3
'OEMTRIG4 = Encoder Bit 4
'OEMTRIG5 = Encoder Bit 5
'OEMTRIG6 = Encoder Bit 6
'OEMTRIG7 = Encoder Bit 7
'OEMTRIG8 = Encoder Bit 8
'OEMTRIG9 = Lock Proximity Switch
'OEMTRIG10 = Door Switch
'
'
'Outputs are as follows:
'
'
'OUTPUT10 = Lock Solenoid
'
'
'If IsActive(OEMTRIG10) Then 'check Door state
'MsgBox("Close the Door")
'End If
'Read the Encoder Bits
If IsActive(OEMTRIG1) Then
Bit1 = 1
Else
Bit1 = 0
End If
If IsActive(OEMTRIG2) Then
Bit2 = 1
Else
Bit2 = 0
End If
If IsActive(OEMTRIG3) Then
Bit3 = 1
Else
Bit3 = 0
End If
If IsActive(OEMTRIG4) Then
Bit4 = 1
Else
Bit4 = 0
End If
If IsActive(OEMTRIG5) Then
Bit5 = 1
Else
Bit5 = 0
End If
If IsActive(OEMTRIG6) Then
Bit6 = 1
Else
Bit6 = 0
End If
If IsActive(OEMTRIG7) Then
Bit7 = 1
Else
Bit7 = 0
End If
If IsActive(OEMTRIG8) Then
Bit8 = 1
Else
Bit8 = 0
End If
'Where the hell is the turret now?
If Bit1=1 Then Position = 1
If Bit2=1 Then Position = 2
If Bit3=1 Then Position = 3
If Bit4=1 Then Position = 4
If Bit5=1 Then Position = 5
If Bit6=1 Then Position = 6
If Bit7=1 Then Position = 7
If Bit8=1 Then Position = 8
Else
MsgBox("Turret out of position")
End
End If
OldTool = Position
NewTool = GetSelectedTool()
NumberOfStations = 0
LockProx = 0
IndexProx = 0
Rotation = 0
If NewTool < 1 Then
MsgBox("Tool Number Too Low")
End
End If
If NewTool > 8 Then
MsgBox("Tool Number Too High")
End
End If
If NewTool = OldTool Then
MsgBox("Selected Current Tool")
End
End If
'Determine which way to turn and how many stations
If NewTool > OldTool Then
NumberOfStations = (NewTool-OldTool)
Else
NumberOfStations = (OldTool-NewTool)
End If
If NewTool = (OldTool+NumberOfStations) Then
Rotation = 1
ElseIf NewTool = (OldTool-NumberOfStations) Then
Rotation = -1
ElseIf (OldTool+NumberOfStations) > 8 Then
Rotation = 1
ElseIf (OldTool-NumberOfStations) < 1 Then
Rotation = -1
Else
Rotation = 1
End If
DoOemButton(138) 'Go home
While IsMoving() 'wait for movement
sleep(100)
Wend 'to end
For I = 1 To 18 'Slow jog is needed
DoOemButton(112) 'for extra torque
Next I '
If Rotation = 1 Then
DoOemButton(310) 'Rotate Turret CCW (axis Y-)
Else
DoOemButton(309) 'Rotate Turret CW (axis Y+)
End If
sleep (500) 'Turn for .5 sec
DoOemButton(1003) 'Stop Motor
For I = 1 To 18 'Back to Fast jog
DoOemButton(111)
Next I
If Rotation = 1 Then
DoOemButton(310) 'Rotate Turret CCW (axis Y-)
Else
DoOemButton(309) 'Rotate Turret CW (axis Y+)
End If
For I = 1 To NumberOfStations 'Count number of stations
While Strobe1 = 0 'Wait for Strobe1 to go high
If IsActive(OEMTRIG6) Then
Strobe1 = 1
Else
Strobe1 = 0
End If
Wend
While IsActive(OEMTRIG6) 'Look for Strobe1 to go low
Wend 'Number of Srobe1 falls =
'Number of stations
Strobe1 = 0
Next I
ActivateSignal(OUTPUT10) 'Energize lock solenoid
While LockProx = 0 'Look for Lock Proximity Switch
If IsActive(OEMTRIG9) Then 'to go high
LockProx = 1
Else
LockProx = 0
End If
Wend
DoOemButton(1003) 'stop motor
Sleep(100) 'wait for damping
For I = 1 To 18 'slow jog
DoOemButton(112) 'for increased torque
Next I
If Rotation = 1 Then 'Reverse Motor
DoOemButton(309) 'Rotate Turret CW (axis Y+)
Else
DoOemButton(310) 'Rotate Turret CCW (axis Y-)
End If
sleep (200) 'Turn for .2 sec
DoOemButton(1003) 'Stop Motor
For I = 1 To 18 'Fast Jog
DoOemButton(111)
Next I
If Rotation = 1 Then 'Continue to Reverse Motor
DoOemButton(309) 'Rotate Turret CW (axis Y+)
Else
DoOemButton(310) 'Rotate Turret CCW (axis Y-)
End If
While IndexProx = 0 'Look for IndexProx to go high
If IsActive(OEMTRIG8) Then 'IndexProx must complete
IndexProx = 1 'OFF-ON-OFF
Else
IndexProx = 0
End If
Wend
While IsActive(OEMTRIG8) 'Look for IndexProx to go low
Wend
DoOemButton(1003) 'Stop motor
sleep(200)
DeActivateSignal(OUTPUT10) 'De-Energize Lock Solenoid
'Now in position
SetCurrentTool( NewTool )
Main
EDIT: code tags added by mod.