Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: mike^3 on October 07, 2015, 04:06:28 PM
-
;D I appreciate all help!!!
Hello everyone! I am retrofitting my CHNC4, I am working on the lathe portion now. Currently there are 4 wires coming off the lathe encoder.
Here is the output states of each wire to what tool it is at.
Output 6 is the output to start and stop the turret.
Tool pin 2 pin 3 pin 4 pin 5
1 1 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 0 1 0
5 1 0 1 0
6 0 1 1 0
7 1 1 1 0
8 0 0 0 1
Here is the script I started. However I have 2 questions:
Question #1: What do I need to add to the script to update the current tool and tool offset to reflect selected tool?
Question #2: How would I be able to compare the signals for example when I get to tool 7 when pin 2,3, and 4 are HI? To tell mach, yes you are at tool 7 because all states are HI? I tried to put Active1 & active2 etc etc when the 2 or more signals need to be compared. However when I emulate an active state on those inputs, mach does not activate output6 or stop when I hit the emulated key (it shows on the diagnostic screen that it is active when I hit the key)
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
If GetSelectedTool = 1 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active1) Then Exit Do
Loop
DeActivateSignal(Active1)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 2 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active2) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 3 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active1) & IsActive(Active2) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 4 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active3) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 5 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active1) & IsActive(Active3) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 6 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active2) & IsActive(Active3) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 7 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active1) & IsActive(Active2) & IsActive(Active3) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
If GetSelectedTool = 8 Then
Message "Moving to Tool# " &GetselectedTool()
Do
ActivateSignal(OutPut6)
If IsActive(Active4) Then Exit Do
Loop
DeActivateSignal(OutPut6)
Message("Tool#1 Loaded")
End If
End
-
Hi,
i have written down a small test script, not tested:
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
Dim ActTurretPos as long
ActTurretPos = 0
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(OutPut6)
While ActTurretPos <> tool
ActTurretPos = GetTurret()
Wend
ActivateSignal(OutPut6)
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurrent + 1
End if
If IsActive(Input1) Then
GetTurret = GetTurrent + 2
End if
If IsActive(Input1) Then
GetTurret = GetTurrent + 4
End if
If IsActive(Input1) Then
GetTurret = GetTurrent + 8
End if
End Function
Regards Thomas
-
Hi Thanks for the response, that does not seem to work....
-
so what is happening,
can you see Input1 - Input4 changing in diagnostic screen,
when it rotates ?
Thomas
-
Hello,
I can see the 4 inputs, but your code seems off, you are only looking for one input for each tool change, input1
look at your code ;)
-
Hi,
found a mistake in my code:
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
Dim ActTurretPos as long
ActTurretPos = 0
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(OutPut6)
While ActTurretPos <> tool
ActTurretPos = GetTurret()
Wend
ActivateSignal(OutPut6)
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
copy and paste error
-
pls copy code again, did an other change.
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
Dim ActTurretPos as long
ActTurretPos = 0
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(OutPut6)
While ActTurretPos <> tool
ActTurretPos = GetTurret()
Wend
ActivateSignal(OutPut6)
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
-
Seems to work, can you add a time out incase it doesnt see the code?
And It still would need a deactivate output 6, so the turret stops LOL
-
I mean see the input, (so turret does just keep spinning and spinning and spinning)
;D
-
ok,
here with DeActivate(Output6) and timeout,
hope it works.
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
Dim ActTurretPos as long
ActTurretPos = 0
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(OutPut6)
While ActTurretPos <> tool
ActTurretPos = GetTurret()
Akttime = Timer
If Akttime - Starttime > 20 then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(OutPut6)
End
End if
Wend
DeActivateSignal(OutPut6)
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
-
Thanks will try it soon!
-
Seems to be working great here, can you put in 2 things?
1. There is a switch (oemtrigger1) when it is active low the turret is not seating properly, can you put this in after each tool change, if it does not sense the HI then try again, but if it does not sense the HI then estop the machine and msg box "Turret not seating!"
2. Can you put an estop in after ther turret timeout, to 3stop the machine? and msg box "Turret could not find tool ESTOP machine"?
You are awesome my friend!!
-
ok,
maybe tomorrow.
-
Sweet thank u, I'll try it on my lathe shortly and upload a vid! ;)
-
Hi TPS, I am running into a challenge, I cant get the turret to stop accurately
...So...I was thinking... can we put a deactivate output 5 before the deactivate output 6 with a time delay (that I can adjust)?
So that when output 5 disables (engages the stop dog) keep output 6 active for like 1 second until the stop dog stops the turret.
The stop dog is NOT a pin, its like a finger, and when output 5 is disabled...the finger grabs onto the bottom turret and when the turret spins, it will then stop to the next tool. Then we can deactive output 6 (after 1 second), which stops the air and drops the turret (the finger from the stopdog will stop the turret, and then output 6 will just stop the air to the air motor and then drop the turret)
I believe this will make it work perfectly...
So...
activate output 5 ' unlocks stop dog
wait for a second
activate output 6 ' raises turret and spins
wait for case command
when case is true for right tool
deactivate output 5 'locks the stop dog
wait 1 second
then
deactivate output 6 ' stops the turret and lowers it
continue program...
:D
Could we put this in? Along with estop and time outs?
Is there anything I can do in return for your help?
Thank you!
-
Hi,
ok here with stop dog
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
Dim ActTurretPos as long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
Akttime = Timer
If Akttime - Starttime > 20 then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air otor off
End
End if
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air otor off
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
Thomas
-
That works great thomas! May I ask one last thing? Also can I paypal you some money for helping me?
1. Can I put in a command that, after output 6 deactivates wait 1 second, then the macro looks for oemtrigger1 and if it is low, then estop the machine and msgbox 'Tool changer not seated!
2. Can we put in, only tools 1-8 are valid, if >8 and <1 dont proceed, kinda like this
If NewTool > 8 Or NewTool < 1 Then
MsgBox" Tool # not a valid Number 1-8 ONLY, ENDING Program RUN "
DoButton(3)
End
End If
THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D :D :D :D :D :D :D :D :D :D :D :D
-
OK something like this should work,
##
oemtrigger1 is not ok input5 would be great
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' oemtrigger1 is mapped to input5
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos as long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
Akttime = Timer
If Akttime - Starttime > 20 then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air otor off
End
End if
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air otor off
sleep(1000)
'look for Input5
if not IsActive(Input1) then
DOButton(3)
Messagebox("Tool changer not seated!")
end
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
Thomas
-
I looked in mach3 for inputs and they only have inputs 1-4 that's why I mentioned oemtrigger1
-
Sorry my fault.
here the version with OEMTRIG1
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos as long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
Akttime = Timer
If Akttime - Starttime > 20 then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End if
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'look for OEMTRIG1
if not IsActive(OEMTRIG1) then
DOButton(3)
Messagebox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
-
Wow sir, u are awesome!!! Thank u so very much!
-
Well, it does work great, however, turret change is not repeatable. Meaning when I call for t0101 it could goto tool 2/6/3 etc. there is no repeat able way for this.
So I was thinking,
Can I just run 1 wire for each tool change position?, would you know what the code would be?
I would make each input oemtrigger 1-8 and the tool changer down switch to active 1.
I am thinking mach3 cant add the inputs nicely enough to make it work.
Or plc?
-
Didn't see it mentioned here but the inputs ought to be in reversed order left to right, because then they give you the tool number in 4 bit binary. Tool 1 is 0001, tool 2 is 0010, tool 3 is 0011, tool 4 is 0100, and so on.
-
would that make any difference as to repeatability? .... let me try it and see...
-
t0101 ???
your tool numbers can only be T1 - T8
whow should the program know in witch place t0101 is located.
Thomas
-
Ohh ya... it needs to know, I thoughts that's what was in the program haha.
-
Here is how the turret works...
The encoder puts out a series of signals, on active pins 1-4,
Tool# active1 active2 active3 active 4 (Active# is the input number in mach3)
1 1 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 0 1 0
5 1 0 1 0
6 0 1 1 0
7 1 1 1 0
8 0 0 0 1
So if you see above, the macro needs to get selected tool.
Activate output 5
wait 1 sec
Activate output 6
' now is needs to find the right tool, for example if I wanted tool one, I put in t0101, then using the above table, the macro needs to sense that Active 1 is (HI) and active 2, 3, and 4, are (LOW), this indicates its at tool one,
Tool# active1 active2 active3 active 4 (Active# is the input number in mach3)
1 1 0 0 0
Then deactivate output 5
wait 1 sec
deactivate output 6
wait for oemtrigger for turret seated,
then continue program.
Same for tool 2-8, one more example: If I wanted tool 7, I put in t0707 on the mdi line, then using the above table, the macro needs to sense that Active 1,2 and 3, is (HI) and active 4, is (LOW), this indicates its at tool seven,
Tool# active1 active2 active3 active 4 (Active# is the input number in mach3)
7 1 1 1 0
Does this clarify it a bit :)? Any ideas as to the macro needed? THANK YOU!
-
Ohh ya... it needs to know, I thoughts that's what was in the program haha.
t0101 ???
your tool numbers can only be T1 - T8
whow should the program know in witch place t0101 is located.
Thomas
t0101 ???
your tool numbers can only be T1 - T8
whow should the program know in witch place t0101 is located.
Thomas
Thomas,
T0101 in binary format is T5. Bit positions for binary: 8 4 2 1 so 0101 is 4+1=5. So if you read the inputs pins into a variable as a binary number it can be converted directly to the correct tool number in decimal. Computers only use binary, they just show you decimal because your eyes glaze over when you see a long string of zeros and ones!
-
I think I follow ya, but, When I put in the MDI line T0101 (it means in mach 3, change to tool 1 with offset 1), it activates the tool change macro.
The macro needs to see the inputs and goto them accordingly... I mapped the inputs to the table seen above, how we want to hangle those inputs is up for grabs, just need to call a tool, then sense the inputs, then stop the tool, and update the tool and keep running program...
-
Sorry,
i debugged with T0101
it gives you not Tool 1 Offest 1
the GetSelectedTool() gives you 101 as Tool number.
i know the difference between binary and decimal.
That is whant my subfunction:
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
it convertes binary inputs to a decimal value.
but i have seen you are trying an other way in an other thread.
Thomas
-
Hi,
after a while of thinking my idea is that the switches will never be activated
simultanius.
so for example Turretpos = 3 then Input1 and Input2 have to be on.
but if Input1 ist only 10ms earlier it will read Pos = 1.
so i modified my code a little bit to give the inputs a chance (200ms):
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
END
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos as long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
'give the other inputs a chance
If ActTurretPos <> 0 Then
Sleep(200)
ActTurretPos = GetTurret() 'read Turretpos again
Endif
Akttime = Timer
If Akttime - Starttime > 20 then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End if
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'look for OEMTRIG1
if not IsActive(OEMTRIG1) then
DOButton(3)
Messagebox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End if
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End if
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End if
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End if
End Function
Thomas
-
I am trying both types of code....I'm kind of stumped....when the cam puts out gcode it will put out t1m6 or t010 correct?
-
Heres a video of whats going on...http://www.machsupport.com/forum/index.php?action=post;topic=30989.30;num_replies=31
https://www.youtube.com/watch?v=sK_UEFM9VtQ
-
OK let me try that new code! One min! :D
-
... :| Doesnt work, gives me syntax error when trying to run it in VB editor...
-
corrected version
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos As Long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
'give the other inputs a chance
If ActTurretPos <> 0 Then
Sleep(200)
ActTurretPos = GetTurret() 'read Turretpos again
End if
Akttime = Timer
If Akttime - Starttime > 20 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
-
nope...still doesnt work :( it might change to the right tool, but then if you try to call up different tools, it might miss a tool or not...
Any ideas?
-
try to reduce:
'give the other inputs a chance
If ActTurretPos <> 0 Then
Sleep(200)
ActTurretPos = GetTurret() 'read Turretpos again
End if
to Sleep(50)
-
Looks like it's working great, however, can we put some code in there that says that if the turret stops and it's not at the right tool change, loop and try again?
Because the inputs trigger the tool changer to stop, yet it really stops one tool after, and that's fine, I'll just mark what tool is what ;).
For example if get tool 1, tool 1 encoder is read, stops turret, really stops at tool 2 which is active 2 hi, that's ok just need some kind of checking logic.
Tps, u rock!
-
ok with recheck and retry, not tested
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos As Long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
tryagain:
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
'give the other inputs a chance
If ActTurretPos <> 0 Then
Sleep(50)
ActTurretPos = GetTurret() 'read Turretpos again
End if
Akttime = Timer
If Akttime - Starttime > 20 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'recheck the turretpos and retry
If (GetTurret()-1) <> tool then
goto tryagain
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
-
I will try it tonight! Thank you TPS! :)
-
made small modification,
because if tool = 8 then turretpos must be 1
else tool must be turretpos-1
Sub Main()
' -------------------------------------------------------------------------------
' TPS 09.10.2015
' simple Test for Toolchange
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim ActTurretPos As Long
ActTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
tryagain:
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While ActTurretPos <> tool 'turn until we are in the wright position
ActTurretPos = GetTurret()
'give the other inputs a chance
If ActTurretPos <> 0 Then
Sleep(50)
ActTurretPos = GetTurret() 'read Turretpos again
End if
Akttime = Timer
If Akttime - Starttime > 20 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'recheck the turretpos and retry
If tool <> 8 then
If (GetTurret()-1) <> tool then ' from tool is 1-7 toolno -1
goto tryagain
End If
Else
If GetTurret() <> 1 then ' if tool = 8 then turretpos must be 1
goto tryagain
End If
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret positiom
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
-
Wow you are awesome, I will try the code tonight when I get home and let you know, I'll make a video of running.
I figure having that check in there will eliminate the worry of the wrong tool being seated and running/destroying stuff lol!
:)
-
Ok Mike,
depending on the fact, that i am getting older
some processes of thinking taking more time.
so the function GetTurretpos() has got a little brother
witch is called GetNextTurretPos() witch will bring us
the possibility to touch the "brake" early enough to stop
in the wright position.
here the code:
Sub Main()
' -------------------------------------------------------------------------------
' TPS 18.10.2015
' Toolchange for a 8 place turret
' V 4.0.0
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim NextTurretPos As Long
NextTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
tryagain:
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While NextTurretPos <> tool 'turn until we are in the wright position
NextTurretPos = GetNextTurret()
'give the other inputs a chance
If ActTurretPos <> 0 Then
Sleep(50)
NextTurretPos = GetNextTurret() 'read NextTurretpos again
End if
Akttime = Timer
If Akttime - Starttime > 20 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'recheck the turretpos and retry
If GetTurret() <> tool then
GoTo tryagain
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret position
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
'function to get the next actual turret position
Function GetNextTurret() As Long
GetNextTurret = 0
If IsActive(Input1) Then
GetNextTurret = GetNextTurret + 1
End If
If IsActive(Input2) Then
GetNextTurret = GetNextTurret + 2
End If
If IsActive(Input3) Then
GetNextTurret = GetNextTurret + 4
End If
If IsActive(Input4) Then
GetNextTurret = GetNextTurret + 8
End If
If GetNextTurret = 8 Then
GetNextTurret = 1
Else
GetNextTurret = GetNextTurret + 1
End If
End Function
regards Thomas
-
Thanks Thomas! I will try that code tonight! :) I really appreciate your help! :) I would like to help you out in return! Anything I can help you with?
-
Just a side note BUT the Ismoving() is NOT just for motion related functions it is for ANY TIME mach3 may be busy doing something such as read Dro or Led or Write to file that may take a longer time to do.
And you will notice that there IS a bug in Mach3 and Ismoving() that can cause a race condition where it CAN skip over several sections of code.
One of the problems is dealing with an Air motor that drives teh Turret. They are know for Speed variations due to temp/air pressure cycles and moisture content of the air. I had also looked at advance notice of the next tool to get a head start but that did not work out well either as the speed variations can effect it as well. AND if you use a closest direction to the next tool routine that throws it out the door as well.
I do have the script working "HERE" I have been running test on it for several weeks now. I DID find a new bug I never knew about so had to create a workaround for it .
AND this is a BAD application for Mach3 to have to try and pull off with CB and a macro. It is NOT great on data aquisition type stuff where timing is critical.
Just a thought, (;-) TP
-
HI TP, I tried both your version as well as TPS, TPS seemed to work slightly better, however both versions were not reliably seating the proper tool, I will try TPS's version tonight, but I think if there is a logic portion that says, "I completed the tool change, whoops Im at the wrong tool. Let me try again" That could work....
:)
-
Mike you have not run the version I have here working. Even the version you have would run "HERE" but there were some quircks to it I did not like. I had to set up a test station here to verify it. Then I had to work out THE FASTEST way to read all 4 inputs in time to activate the Stop DOG so it would catch the correct station EVERY time. You are not the first to try this with that type turret.
NOW is my version going to be perfect? NOPE not with Mach3 and its CB timing problems. It is going to depend on how busy Mach3 is when teh macro runs as to IF it will hit EVERY time correctly. I explained that to you from the start. I can tune it so it works fine HERE with this PC and would work probably 95% of the time. The error traps would catch the other 5%
You would be FAR better off to remove that air motor and install a simple stepper motor to rotate teh turret. OR go to a PLC controller for the Turret.
IF you want a GREAT lathe controller I would consider a Tormach PathPilot@ Lathe controller setup. They seem to have it down pat for lathe control.
(;-) TP
-
The challenge with replacing the air turret is complicated. I would have to build new plates, and blocks, and bearing seats, etc etc...
I was thinking of a PLC, but have no experience.
I havnt heard from you in a while, didn't know if you still wanted to work on it. ;)
The speed is very constant...I thought it would vary but observing it for as long as I have, (I even bought a big 60gallon compressor to make sure the air is constant)...
That air flow adjustment works great and its a very fine tuning option...which I slowed it down all the way, its not an issue of speed, for some reason mach might be seeing inputs when its not supposed too....I think that's why it was missing tools, also I tried different debouncing, and it did not help...
I would love to try your gcode as well TP, I got TPS's gcode I will try tonight...Is yours working yet TP? I could try yours as well...
I appreciate all of your help....I am going to make a video once its all done, nicely of course, and explain how I got it work for future friends! :D
-
PS I alreadsy thought of the verify tool position by reverifing teh encoder code before releasing the tool change back to mach3 , error out with message if not correct.
(;-) TP
-
Awesome, I think that part is essential for reliable parts, lol and non broken machines lol
-
It works!!! https://www.youtube.com/watch?v=sqyWY0Dk5fk
Thank you TPS! Question tho, you notice that the tool changer does one tool at a time when the wrong tool is sensed? Can we just do that instead of free spin the turret and try to catch the correct tool?
Meaning when we ask for a tool, it will goto each tool, sit down for like 1/2 second, read input, if not at right tool, keep going, etc etc till it gets the right tool?
That would complete the tool changer!!!!
-
Congrats! Good to see you got it working finally. I'm thinking that since it finds the tool reliably while only stepping through the tools one tool at a time, its not a hardware issue and can probably be fine tuned to work all the time every time.
joanthon
-
Thanks joanthon!
-
Hi Mike,
by reviewing the script i found a mistake,
pls try corrected code again.
Sub Main()
' -------------------------------------------------------------------------------
' TPS 18.10.2015
' Toolchange for a 8 place turret
' V 4.0.1
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim NextTurretPos As Long
NextTurretPos = 0
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
tryagain:
ActivateSignal(output5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
While NextTurretPos <> tool 'turn until we are in the wright position
NextTurretPos = GetNextTurret()
'give the other inputs a chance
If NextTurretPos <> 0 Then
Sleep(50)
NextTurretPos = GetNextTurret() 'read NextTurretpos again
End if
Akttime = Timer
If Akttime - Starttime > 20 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
'recheck the turretpos and retry
If GetTurret() <> tool then
GoTo tryagain
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret position
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
'function to get the next actual turret position
Function GetNextTurret() As Long
GetNextTurret = 0
If IsActive(Input1) Then
GetNextTurret = GetNextTurret + 1
End If
If IsActive(Input2) Then
GetNextTurret = GetNextTurret + 2
End If
If IsActive(Input3) Then
GetNextTurret = GetNextTurret + 4
End If
If IsActive(Input4) Then
GetNextTurret = GetNextTurret + 8
End If
If GetNextTurret = 8 Then
GetNextTurret = 1
Else
GetNextTurret = GetNextTurret + 1
End If
End Function
Thomas
-
Ok,
her the first try of the "single step" version
Sub Main()
' -------------------------------------------------------------------------------
' TPS 18.10.2015
' Toolchange for a 8 place turret (single step)
' V 5.0.0
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
Dim StopDog as boolean
tryagain:
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
Akttime = Timer
While Akttime - Starttime < 40 'try until timeout
ActivateSignal(output5) 'unlocks stop dog
StopDog = True
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
'wenn we left the turretpos lock the stop dog
If GetTurret() = 0 Then
DeActivateSignal(output5) 'locks stop dog
StopDog = false
End if
If ((GetTurret() <> 0) and (StopDog = False)) Then
DeActivateSignal(OutPut6) 'turn air motor off
sleep(1000)
End if
'check the position
If GetTurret() = tool Then
GoTo finished
End If
Akttime = Timer
If Akttime - Starttime > 30 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
finished:
'recheck the turretpos and retry
If GetTurret() <> tool then
GoTo tryagain
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret position
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
Thomas
-
Hi!,
The last code just spins the turret, it doesn't stop, and then I hit etop after like 10 secs lol
-
Hi,
next try, the problem is i have no real trigger to lock the stop dog
Sub Main()
' -------------------------------------------------------------------------------
' TPS 19.10.2015
' Toolchange for a 8 place turret (single step)
' V 5.0.1
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
tryagain:
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
Akttime = Timer
While Akttime - Starttime < 50 'try until timeout
ActivateSignal(OutPut5) 'unlocks stop dog
Sleep(1000) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
Sleep(1000)
'check the position
If GetTurret() = tool Then
GoTo finished
End If
Akttime = Timer
If Akttime - Starttime > 40 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
finished:
'recheck the turretpos and retry
If GetTurret() <> tool then
GoTo tryagain
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret position
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
Thomas
-
Ohh I see, ill play with the sleep times to see If i can get it to work....few min :)
-
its working great, but it keeps saying tool changer not seated, but it is... ...checked the oem trigger and it is getting the signal;
-
Ok let's try and error
please change
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) Then
to
'look for OEMTRIG1
If IsActive(OEMTRIG1) = False Then
should be the same put try please.
Thomas
-
WORKs!
Here Is my final code, I cant thank you enough! THANK YOU!
Sub Main()
' -------------------------------------------------------------------------------
' TPS 19.10.2015
' Toolchange for a 8 place turret (single step)
' V 5.0.1
' -------------------------------------------------------------------------------
' pin2 is mapped to Input1
' pin3 is mapped to Input2
' pin4 is mapped to Input3
' pin5 is mapped to Input4
' charger seated is mapped to OEMTRIG1
'get the new tool ---------------------------------------------------------------
tool = GetSelectedTool()
' nothing to do
If GetSelectedTool() = GetCurrentTool() Then
message("Tool is the same NO tool change needed")
End
End If
If tool > 8 Or tool < 1 Then 'check tool number to be in range
Message (" Tool " & tool & " is not a valid Number 1-8 ONLY, ENDING Program RUN ")
DoButton(3)
End
End If
tryagain:
'get actual starttime
Starttime = Timer
Message "Moving to Tool# " &GetselectedTool()
Akttime = Timer
While Akttime - Starttime < 50 'try until timeout
ActivateSignal(OutPut5) 'unlocks stop dog
Sleep(100) 'wait for a second
ActivateSignal(OutPut6) 'turn air motor on
Sleep(100) 'wait for a second
DeActivateSignal(OutPut5) 'locks stop dog
Sleep(200) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
Sleep(300)
'check the position
If GetTurret() = tool Then
GoTo finished
End If
Akttime = Timer
If Akttime - Starttime > 40 Then 'Timeout 20s
Message("Turret timeout")
DeActivateSignal(output5) 'locks stop dog
Sleep(1000) 'wait for a second
DeActivateSignal(OutPut6) 'turn air motor off
End
End If
Wend
finished:
'recheck the turretpos and retry
If GetTurret() <> tool Then
GoTo tryagain
End If
'look for OEMTRIG1
If Not IsActive(OEMTRIG1) = false Then
DOButton(3)
MsgBox("Tool changer not seated!")
End
End If
Message("Tool " & tool & " Loaded")
SetCurrentTool( tool )
End Sub
'function to get the actual turret position
Function GetTurret() As Long
GetTurret = 0
If IsActive(Input1) Then
GetTurret = GetTurret + 1
End If
If IsActive(Input2) Then
GetTurret = GetTurret + 2
End If
If IsActive(Input3) Then
GetTurret = GetTurret + 4
End If
If IsActive(Input4) Then
GetTurret = GetTurret + 8
End If
End Function
-
Ok,
sounds good.
Thomas
-
VIDEO! >:D https://www.youtube.com/watch?v=ItrtnRfjhB0