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

0 Members and 1 Guest are viewing this topic.

Offline mike^3

  • Active Member
  • Posts: 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #40 on: October 18, 2015, 10:44:51 AM »
I will try it tonight! Thank you TPS! :)

Offline TPS

  • Active Member
  • Posts: 1,133
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #41 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
    

« Last Edit: October 18, 2015, 11:23:00 AM by TPS »
anything is possible, just try it.
if you find some mistakes, in my bad bavarian english,they are yours.

herr schmeiß hirn vom himmel

Offline mike^3

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

:)

Offline TPS

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

herr schmeiß hirn vom himmel

Offline mike^3

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

Offline BR549

  • Mach4 Alpha
  • Posts: 6,855
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #45 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

Offline mike^3

  • Active Member
  • Posts: 117
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #46 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....

:)

Offline BR549

  • Mach4 Alpha
  • Posts: 6,855
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #47 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
« Last Edit: October 18, 2015, 03:53:51 PM by BR549 »

Offline mike^3

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


Offline BR549

  • Mach4 Alpha
  • Posts: 6,855
    • View Profile
Re: CNC Lathe turret tool changer help?
« Reply #49 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