Hello Guest it is May 22, 2019, 11:24:42 AM

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

0 Members and 1 Guest are viewing this topic.

Offline mike^3

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

Offline TPS

*
  •  1,250 1,250
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #1 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
anything is possible, just try 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 #2 on: October 09, 2015, 08:46:58 AM »
Hi Thanks for the response, that does not seem to work....

Offline TPS

*
  •  1,250 1,250
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #3 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
anything is possible, just try 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 #4 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 ;)

Offline TPS

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

Offline TPS

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

« Last Edit: October 09, 2015, 08:58:26 AM by TPS »
anything is possible, just try 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 #7 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

Offline mike^3

*
  •  117 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #8 on: October 09, 2015, 09:02:21 AM »
I mean see the input, (so turret does just keep spinning and spinning and spinning)

 ;D

Offline TPS

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


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