1
VB and the development of wizards / ATC Macro works 95% of the time
« on: June 24, 2016, 07:31:21 AM »
Hi, I have written a m6start macro for my carousel type tool changer.
It works flawlessly 95% of the time but unfortunately rarely grabs a tool 1 position out.
Here is a copy of the macro.
ANY help would be muchly apreciated.
any questions about my macro im happy to answer.
Sub Main()
OldTool = GetCurrentTool() 'Tool In spindle DRO You must add this to your settings screen
NewTool = GetSelectedTool()
Z_changePos = -122 'z change position
Z_safePos = 0
MaxToolNum = 21 'Max number off tools for the changer
If NewTool = OldTool Then
Exit Sub 'exit if tool as same selected
End If
code "M5"
If OldTool >= MaxToolNum Then
Code "G00 G53 Z" & Z_safePos 'move z to carriage engage height
While IsMoving()
Wend
MsgBox " Please remove TOOL #" & OldTool & Chr(13) & " Then press OK to Continue"
OldTool = question ("Please enter current Tool carriage position then press OK to CYCLE START")
GoTo spindlecheck
End If
chuckCheck:
If IsActive(input2) = IsActive(input3) Then
Code "G00 G53 Z" & Z_safePos 'move z to carriage engage height
While IsMoving()
Wend 'wait until its moved
Else
If IsActive(input2)=0 = IsActive(input3) Then
code "G00 G53 Z" & Z_changePos
While IsMoving()
Wend
End If
End If
spindlecheck:
If IsActive(input4) Then 'check spindle rotation input
GoTo engage
Else
GoTo spindleAlign
End If
spindleAlign:
code "M3 S60" 'correct spindle rotation
While IsActive(input4)=0
Wend
code "M5"
sleep(2000)
GoTo spindlecheck
engage:
SetOutBit(100,2) 'engage tool carriage
sleep(100)
ResetOutBit(100,2)
sleep(100)
While GetInBit(100,1)=0
Wend 'wait for engagement
sleep(100)
SetOutBit(100,6) 'engage power tool bar / tool release
While GetInBit(100,3)=0
Wend 'wait for draw bar engaged / tool released
Code "G53 Z" & Z_safePos 'move z to tool carriage spin height
Code "G4 P.75"
While IsMoving() 'wait for z to move
Wend
If NewTool >= MaxToolNum Then
GoTo NewTooltoobig
End If
CWPos = NewTool - OldTool 'calculate CW distance
If CWPos < 0 Then
CWPos = CWPos + MaxToolNum
End If 'invert number if minus
CCWPos = MaxToolNum - CWPos 'calculate CCW distance
If CWPos < CCWPos Then 'take shortest distance
GoTo CW
Else
GoTo CCW
End If 'goes to CW or CCW script
CW: 'CW count sequence
moved1 = 0
starting1:
SetOutBit(100,5)
sleep(50)
While IsActive(input1)
Wend
sleep(20)
While IsActive(input1)=0
Wend
moved1 = moved1+1
ResetOutBit(100,5)
If CWPos = moved1 Then
While IsActive(input1)=0
Wend
GoTo finish
Else
GoTo starting1
End If 'end CW count sequence
CCW: 'CCW count sequence
moved2 = 0
starting2:
SetOutBit(100,4)
sleep(50)
While IsActive(input1)
Wend
sleep(20)
While IsActive(input1)=0
Wend
moved2 = moved2+1
ResetOutBit(100,4)
If CCWPos = moved2 Then
While IsActive(input1)=0
Wend
GoTo finish
Else
GoTo starting2
End If 'end CCW count sequence
NewTooltoobig:
SetOutBit(100,3) 'disengage tool carriage
sleep(100)
ResetOutBit(100,6)
While IsActive(input3)
Wend 'disengage power draw bar / tool clamp
ResetOutBit(100,3)
sleep(100)
While GetInBit(100,0)=0
Wend 'wait for disengagement
sleep(100)
MsgBox " Please insert TOOL #" & NewTool & Chr(13) &" Then press OK to CYCLE START"
sleep(500)
SetCurrentTool(NewTool)
GoTo theveryend
finish:
Code "G00 G53 Z" & Z_changePos 'move z to carriage engage height
While IsMoving()
Wend
ResetOutBit(100,6) 'disengage draw bar
sleep(600)
If IsActive(input2) = IsActive(input3) Then 'check for good tool clamp
DoOEMButton(1021)
SetCurrentTool(NewTool) 'reset mach and give fail message
MsgBox "TOOL CLAMP FAILURE "
Exit Sub
End If
SetCurrentTool(NewTool) 'changes current tool DRO
SetOutBit(100,3) 'disengage tool carriage
sleep(100)
ResetOutBit(100,3)
sleep(100)
While GetInBit(100,0)=0
Wend 'wait for disengagement
sleep(100)
theveryend:
SetCurrentTool(NewTool)
code "G43"
sleep(250)
End Sub
Thanks very much in advance!
Ben Smith
It works flawlessly 95% of the time but unfortunately rarely grabs a tool 1 position out.
Here is a copy of the macro.
ANY help would be muchly apreciated.
any questions about my macro im happy to answer.
Sub Main()
OldTool = GetCurrentTool() 'Tool In spindle DRO You must add this to your settings screen
NewTool = GetSelectedTool()
Z_changePos = -122 'z change position
Z_safePos = 0
MaxToolNum = 21 'Max number off tools for the changer
If NewTool = OldTool Then
Exit Sub 'exit if tool as same selected
End If
code "M5"
If OldTool >= MaxToolNum Then
Code "G00 G53 Z" & Z_safePos 'move z to carriage engage height
While IsMoving()
Wend
MsgBox " Please remove TOOL #" & OldTool & Chr(13) & " Then press OK to Continue"
OldTool = question ("Please enter current Tool carriage position then press OK to CYCLE START")
GoTo spindlecheck
End If
chuckCheck:
If IsActive(input2) = IsActive(input3) Then
Code "G00 G53 Z" & Z_safePos 'move z to carriage engage height
While IsMoving()
Wend 'wait until its moved
Else
If IsActive(input2)=0 = IsActive(input3) Then
code "G00 G53 Z" & Z_changePos
While IsMoving()
Wend
End If
End If
spindlecheck:
If IsActive(input4) Then 'check spindle rotation input
GoTo engage
Else
GoTo spindleAlign
End If
spindleAlign:
code "M3 S60" 'correct spindle rotation
While IsActive(input4)=0
Wend
code "M5"
sleep(2000)
GoTo spindlecheck
engage:
SetOutBit(100,2) 'engage tool carriage
sleep(100)
ResetOutBit(100,2)
sleep(100)
While GetInBit(100,1)=0
Wend 'wait for engagement
sleep(100)
SetOutBit(100,6) 'engage power tool bar / tool release
While GetInBit(100,3)=0
Wend 'wait for draw bar engaged / tool released
Code "G53 Z" & Z_safePos 'move z to tool carriage spin height
Code "G4 P.75"
While IsMoving() 'wait for z to move
Wend
If NewTool >= MaxToolNum Then
GoTo NewTooltoobig
End If
CWPos = NewTool - OldTool 'calculate CW distance
If CWPos < 0 Then
CWPos = CWPos + MaxToolNum
End If 'invert number if minus
CCWPos = MaxToolNum - CWPos 'calculate CCW distance
If CWPos < CCWPos Then 'take shortest distance
GoTo CW
Else
GoTo CCW
End If 'goes to CW or CCW script
CW: 'CW count sequence
moved1 = 0
starting1:
SetOutBit(100,5)
sleep(50)
While IsActive(input1)
Wend
sleep(20)
While IsActive(input1)=0
Wend
moved1 = moved1+1
ResetOutBit(100,5)
If CWPos = moved1 Then
While IsActive(input1)=0
Wend
GoTo finish
Else
GoTo starting1
End If 'end CW count sequence
CCW: 'CCW count sequence
moved2 = 0
starting2:
SetOutBit(100,4)
sleep(50)
While IsActive(input1)
Wend
sleep(20)
While IsActive(input1)=0
Wend
moved2 = moved2+1
ResetOutBit(100,4)
If CCWPos = moved2 Then
While IsActive(input1)=0
Wend
GoTo finish
Else
GoTo starting2
End If 'end CCW count sequence
NewTooltoobig:
SetOutBit(100,3) 'disengage tool carriage
sleep(100)
ResetOutBit(100,6)
While IsActive(input3)
Wend 'disengage power draw bar / tool clamp
ResetOutBit(100,3)
sleep(100)
While GetInBit(100,0)=0
Wend 'wait for disengagement
sleep(100)
MsgBox " Please insert TOOL #" & NewTool & Chr(13) &" Then press OK to CYCLE START"
sleep(500)
SetCurrentTool(NewTool)
GoTo theveryend
finish:
Code "G00 G53 Z" & Z_changePos 'move z to carriage engage height
While IsMoving()
Wend
ResetOutBit(100,6) 'disengage draw bar
sleep(600)
If IsActive(input2) = IsActive(input3) Then 'check for good tool clamp
DoOEMButton(1021)
SetCurrentTool(NewTool) 'reset mach and give fail message
MsgBox "TOOL CLAMP FAILURE "
Exit Sub
End If
SetCurrentTool(NewTool) 'changes current tool DRO
SetOutBit(100,3) 'disengage tool carriage
sleep(100)
ResetOutBit(100,3)
sleep(100)
While GetInBit(100,0)=0
Wend 'wait for disengagement
sleep(100)
theveryend:
SetCurrentTool(NewTool)
code "G43"
sleep(250)
End Sub
Thanks very much in advance!
Ben Smith