Hello Guest it is May 08, 2021, 02:32:19 PM

Author Topic: CNC Lathe turret tool changer help?  (Read 12340 times)

0 Members and 1 Guest are viewing this topic.

Offline TPS

*
  •  2,124 2,124
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #30 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
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline mike^3

*
  •  117 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #31 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?

Offline mike^3

*
  •  117 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #33 on: October 18, 2015, 07:53:41 AM »
OK let me try that new code! One min! :D

Offline mike^3

*
  •  117 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #34 on: October 18, 2015, 07:58:55 AM »
... :| Doesnt work, gives me syntax error when trying to run it in VB editor...

Offline TPS

*
  •  2,124 2,124
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #35 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
   

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline mike^3

*
  •  117 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #36 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?

Offline TPS

*
  •  2,124 2,124
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #37 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)
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline mike^3

*
  •  117 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #38 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!

Offline TPS

*
  •  2,124 2,124
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #39 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
   
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.