Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: mike^3 on October 07, 2015, 04:06:28 PM

Title: CNC Lathe turret tool changer help?
Post 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    
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 09, 2015, 04:17:17 AM
Hi,
i have written down a small test script, not tested:

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 08:46:58 AM
Hi Thanks for the response, that does not seem to work....
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 09, 2015, 08:51:00 AM
so what is happening,

can you see Input1 - Input4 changing in diagnostic screen,
when it rotates ?

Thomas
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 08:52:58 AM
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 ;)
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 09, 2015, 08:53:46 AM
Hi,

found a mistake in my code:

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 09, 2015, 08:56:19 AM
pls copy code again, did an other change.

Code: [Select]

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
   

Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 09:01:45 AM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 09:02:21 AM
I mean see the input, (so turret does just keep spinning and spinning and spinning)

 ;D
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 09, 2015, 09:14:41 AM
ok,

here with DeActivate(Output6) and timeout,
hope it works.

Code: [Select]
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
    


Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 09:17:50 AM
Thanks will try it soon!
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 01:05:48 PM
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!!
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 09, 2015, 03:07:55 PM
ok,
maybe tomorrow.
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 09, 2015, 03:35:18 PM
Sweet thank u, I'll try it on my lathe shortly and upload a vid! ;)
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 10, 2015, 07:45:49 AM
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!
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 12, 2015, 02:25:22 AM
Hi,

ok here with stop dog

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 12, 2015, 08:05:55 AM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 12, 2015, 04:22:35 PM
OK something like this should work,
##

oemtrigger1 is not ok input5 would be great

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 12, 2015, 06:48:38 PM
I looked in mach3 for inputs and they only have inputs 1-4 that's why I mentioned oemtrigger1
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 13, 2015, 04:40:56 AM
Sorry my fault.

here the version with OEMTRIG1

Code: [Select]
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
    

Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 13, 2015, 06:02:46 AM
Wow sir, u are awesome!!! Thank u so very much!
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 16, 2015, 07:05:19 PM
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?
Title: Re: CNC Lathe turret tool changer help?
Post by: garyhlucas on October 16, 2015, 09:31:08 PM
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.
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 16, 2015, 10:04:46 PM
would that make any difference as to repeatability? .... let me try it and see...
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 17, 2015, 05:26:43 AM
 t0101  ???

your tool numbers can only be T1 - T8

whow should the program know in witch place t0101 is located.

Thomas
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 17, 2015, 07:05:28 AM
Ohh ya... it needs to know, I thoughts that's what was in the program haha.

Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 17, 2015, 07:37:29 AM
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!
Title: Re: CNC Lathe turret tool changer help?
Post by: garyhlucas on October 17, 2015, 08:09:14 AM
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!
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 17, 2015, 08:23:45 AM
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...



Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 04:06:09 AM
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:
Code: [Select]
'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



 
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 04:31:45 AM
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):

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 06:35:44 AM
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?
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 07:43:22 AM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 07:53:41 AM
OK let me try that new code! One min! :D
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 07:58:55 AM
... :| Doesnt work, gives me syntax error when trying to run it in VB editor...
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 08:02:16 AM
corrected version

Code: [Select]
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
   

Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 08:12:31 AM
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?

Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 08:15:39 AM
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)
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 08:49:14 AM
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!
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 09:02:00 AM
ok with recheck and retry, not tested

Code: [Select]
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
   
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 10:44:51 AM
I will try it tonight! Thank you TPS! :)
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 11:20:46 AM
made small modification,
because if tool = 8 then turretpos must be 1

else tool must be turretpos-1


Code: [Select]
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
    

Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 12:02:50 PM
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!

:)
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 18, 2015, 12:50:41 PM
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:

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 01:40:26 PM
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?
Title: Re: CNC Lathe turret tool changer help?
Post by: BR549 on October 18, 2015, 02:10:41 PM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 03:31:34 PM
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....

:)
Title: Re: CNC Lathe turret tool changer help?
Post by: BR549 on October 18, 2015, 03:44:53 PM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 04:01:37 PM
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

Title: Re: CNC Lathe turret tool changer help?
Post by: BR549 on October 18, 2015, 04:07:52 PM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 04:19:38 PM
Awesome, I think that part is essential for reliable parts, lol and non broken machines lol
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 10:23:36 PM
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!!!!
Title: Re: CNC Lathe turret tool changer help?
Post by: jofriedl on October 18, 2015, 10:30:36 PM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 18, 2015, 10:37:47 PM
Thanks joanthon!

Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 19, 2015, 04:29:46 AM
Hi Mike,

by reviewing the script i found a mistake,
pls try corrected code again.

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 19, 2015, 04:42:07 AM
Ok,

her the first try of the "single step" version

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 19, 2015, 07:34:16 AM
Hi!,

The last code just spins the turret, it doesn't stop, and then I hit etop after like 10 secs lol
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 19, 2015, 08:25:42 AM
Hi,

next try, the problem is i have no real trigger to lock the stop dog

Code: [Select]
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 19, 2015, 08:28:53 AM
Ohh I see, ill play with the sleep times to see If i can get it to work....few min :)
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 19, 2015, 08:46:03 AM
its working great, but it keeps saying tool changer not seated, but it is... ...checked the oem trigger and it is getting the signal;
Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 19, 2015, 08:55:10 AM
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
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 19, 2015, 09:01:28 AM
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
   

Title: Re: CNC Lathe turret tool changer help?
Post by: TPS on October 19, 2015, 09:21:46 AM
Ok,

sounds good.

Thomas
Title: Re: CNC Lathe turret tool changer help?
Post by: mike^3 on October 19, 2015, 09:40:04 AM
VIDEO! >:D https://www.youtube.com/watch?v=ItrtnRfjhB0