M6 Macro for Prolight 3000 or similar turret

While UCCNC does not currently have a TURN Modual Here is the place to discuss your wants and wishes for TURN

M6 Macro for Prolight 3000 or similar turret

Postby eabrust » Wed Jul 14, 2021 1:34 am

Hi All,

I've been converting a Prolight 3000 w/ 8 position turret over the last week, and have a suitably working M6 macro to post and share as an example. This lathe uses a 1-way ratcheting turret driven by a stepper, and has a single home switch near tool 1 (where as I think Emco and Denford used DC motors and multi-switches for a gray-logic position feedback). The turret is run as the 'A Axis', and is calibrated so one rev is 360 degrees, like a rotary table. I'm happy with how easy it was to get the tool changer working, and get the whole lathe converted over to an AXBB from the separate control box with multiple cables. I still wish I could have found a Denford Cyclone, but I gave up and settled :D The Prolight is a nice enough little bench machine.

This code started as a sample I found on M3 forum for the basic change strategy, and was built upon to add tool number reformatting and return to last position as options. Hopefully this will be of use for someone else's project.

M6 sample (written in VB... :)):
Code: Select all
#VB


' M6 Tool Turret macro for an 8 position stepper driven turret on a Prolight 3000 or similar lathe
' Turret is uni-directional rotation, single home switch at tool 1, and reverses to lock
' Need to set A (or chosen) axis to 360 degree / rev of turret, in my case, steps per unit was ~ 124 steps / degree.
' CCW move for locking was set by testing values to ensure lock without to much added stepper screech noise

' Code was ported from sample found on Mach3 forum, with additons for:
' Can accept double Tcode format (such as T0707) for tool 7, and makes it single digit for UCCNC
' User setable booleans to have tool return to position and show/hide messages
' Setable location for tool change in Machine coords.

'E Brust, 7/2021

If exec.IsLoading() Then   'Do Nothing, program loading

Else




   ' dim Variables

   dim Num_Tools As Integer


   dim CW_Feed As Integer
   dim CCW_Feed As Integer
   dim moves as integer
   dim total_move as integer
   dim CW_Move_Per_Tool as double
   dim CCW_Move as double
   dim Requested_Tool as string = exec.Getnewtool()
   dim Current_Tool as integer = exec.Getcurrenttool()
   dim Current_Feed as double = as3.Getfield(867)   ' save current feedrate
   dim Show_Messages as boolean
   dim Return_Pos as boolean
   
   dim Current_Offset as integer = exec.getactualmodalcode(12)
   dim Current_AbsIncMode as integer = exec.getactualmodalcode(3)
   dim Current_XLoc as double = exec.getXpos
   dim Current_ZLoc as double = exec.getZpos
   dim Safe_XLoc as double
   dim Safe_ZLoc as double
   
'' Get actual modal code numbers for reference:
' 3:  G90/91 INC/Abs
' 12:  G54-G59 work offset
' 7:  G40/41/42
' 2:  G17/18/19
' 5:  G93/94



'=================  Use RegEx to sort out odd lathe tool formats, such as T0202 for tool 2...

        Try
            Dim num4 = "([0-9][0-9][0-9][0-9])" ' regex to match a 4 digit number
            Dim num3 = "([0-9][0-9][0-9])" ' regex to match a 3 digit number

            Dim num2 = "([0-9][0-9])" ' regex to match a 2 digit number
            Dim num1 = "([0-9])" ' regex to match a number


            Dim tMatch4 = System.Text.RegularExpressions.Regex.Match(Requested_Tool, num4, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

            Dim tMatch3 = System.Text.RegularExpressions.Regex.Match(Requested_Tool, num3, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

            Dim tMatch2 = System.Text.RegularExpressions.Regex.Match(Requested_Tool, num2, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

            Dim tmatch1 = System.Text.RegularExpressions.Regex.Match(Requested_Tool, num1, System.Text.RegularExpressions.RegexOptions.IgnoreCase)



            Dim orderedString as string = ""

            If tMatch4.Success Then '4 digits found

                orderedString = tMatch4.Captures(0).Value

                tMatch4 = System.Text.RegularExpressions.Regex.Match(orderedString, num4, System.Text.RegularExpressions.RegexOptions.IgnoreCase)


                ' Need to take only the first 2 of 4 (last two assumed junk or from lathe tool offset)


                orderedString = microsoft.visualbasic.Strings.Left(tMatch2.Captures(0).Value, 2)


            ElseIf tMatch3.Success Then ' 3 digits found

                orderedString = tMatch3.Captures(0).Value

                tMatch3 = System.Text.RegularExpressions.Regex.Match(orderedString, num3, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

                ' Need to take only the first 1 of 3 (last two assumed junk or from lathe tool offset)


                orderedString = microsoft.visualbasic.Strings.Left(tMatch2.Captures(0).Value, 1)


            ElseIf tMatch2.Success Then ' 2 digits found

                orderedString = tMatch2.Captures(0).Value

                tMatch2 = System.Text.RegularExpressions.Regex.Match(orderedString, num2, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

                'Use 2 digits as found
                orderedString = tMatch2.Captures(0).Value


            ElseIf tmatch1.Success Then ' 1 digit found

                orderedString = tmatch1.Captures(0).Value

                'Use 1 digit as found
                tmatch1 = System.Text.RegularExpressions.Regex.Match(orderedString, num1, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                orderedString = tmatch1.Captures(0).Value
            Else
                orderedString = ""
                'MsgBox("word problem getting tool num")
            End If

         requested_tool = orderedString
            'Return orderedString
        Catch ex As Exception

        End Try
'================


   as3.setfield(requested_tool, 2652)
   as3.validatefield(2652)

'================
   ' set up some user set vars, Change these to match your machine needs...
   
   
   Show_Messages = false  '  Set true to show messages, false to not...
   Return_Pos = true ' Set true to have tool moved back to last location after change
   
   Num_Tools  = 8  ' Number of tools in changer
   CW_Feed  = 3000 ' Forward rotration rate, degree/min, for changing
   CCW_Feed  = 2000 ' Reverse rotration rate, degree/min, for locking
   CCW_Move = 7 ' Angle to reverse for locking, in degrees
   Safe_XLoc = -.250 ' Machine X coordinate location to change tool at   0 is at top
   Safe_ZLoc = -1.250  ' Machine X coordinate location to change tool at   0 is at far right
   
   CW_Move_Per_Tool = 360/Num_Tools ' Do not change this, this is angle per tool based on number of tools




   if(Current_Tool=0) then '// If new tool number is 0 means turret homed but did not set home position as tool 1
     exec.Setcurrenttool(1) '; //Set the current tool -> the new tool
     Current_Tool  = exec.Getcurrenttool()

     'return
   end if




   'Check for X, Z, and A axis to be homed.  If tool changer is not 'A', change '59' to be for proper axis
   if(not exec.GetLED(56) or not exec.GetLED(58) or not exec.GetLED(59)) then   ' // If machine was not homed then it is unsafe to move in machine coordinates, stop here...

      if Show_Messages Then
         MessageBox.Show("The machine was not yet homed, do homeing before executing a tool change!")
      end if
     exec.Stop()
     return

   end if



   while(exec.IsMoving)

   end while








'=================  start tool change here!
   
      if Show_Messages Then

         Messagebox.show("Requested Tool No=" & Requested_Tool)
      end if

   If Requested_Tool > Num_Tools Then
      'if Show_Messages Then
         Messagebox.show("Requested Tool No. too high, program stopped.")
      'end if
      
      exec.Code("M30")
      return
   End If

   If Requested_Tool < 1 Then
      'if Show_Messages Then
         Messagebox.show("Requested Tool No. too low, program stopped.")
      'end if
      
      exec.Code("M30")
      return
   End If





   If Requested_Tool = Current_Tool Then
   ' do nothing
   
   Else
      ' lets change tools
      If Requested_Tool > Current_Tool Then
      moves = Requested_Tool - Current_Tool
      end if
      
      If Requested_Tool < Current_Tool Then
      moves = Num_Tools - Current_Tool + Requested_Tool
      end if
      
      total_move = (moves * CW_Move_Per_Tool)+(CCW_Move/2)
      
      'Move to safe position
      exec.Code("G0 G53 Z" & Safe_ZLoc & " X" & Safe_Xloc)
      'Pause for 1/2 second
      exec.Code("G04 P0.5")

      exec.Code("G91 G94") 'incremental & Feed per minute
      exec.Code("G01 A" & total_move & " F" & CW_Feed)
      exec.Code("G01 A-" & CCW_Move & " F" & CCW_Feed)
      
      While exec.IsMoving()
      
      end while


      exec.wait(1000) ' Hold for a second so that TurnTable plugin  can update offsets



      if(not exec.Ismacrostopped()) '// If tool change was not interrupted with a stop only then validate new tool number

        exec.Setcurrenttool(Requested_Tool) '; //Set the current tool -> the new tool
       
       
       
        if Return_Pos=true
              exec.Code("G90") ' back to absolute movement
            exec.Code("G" & Current_Offset & "G0 Z" & Current_ZLoc & " X" & Current_XLoc)

              While exec.IsMoving()
      
            end while
        end if
       
       
        exec.Code("G" & Current_AbsIncMode) ' back to original abs/inc. mode
        exec.Code("F" & Current_Feed) ' reset original feed
         if Show_Messages Then
            MessageBox.Show("Tool change done.")
         end if
      else

        exec.StopWithDeccel()
          
         'if Show_Messages Then
           MessageBox.Show("Tool change was interrupted by user!")
         'end if 
      end if



   End If







End If

' end of tool change




Still on my to do list is a short macroloop code so that after A axis is homed, Tool1 will always be set as the 'active tool' in UCCNC. I assume macroloop is best way, as I'm not finding a way to use an axis home event to trigger a macro. If anyone knows different, let me know.

I'll be posting an update to the 'TurnTable' plugin later that adds additional controls to the interface, like initiating a tool change.

regards
Eric
Attachments
M6.txt
(8.38 KiB) Downloaded 38 times
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 254
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA

Return to UCCNC TURN (CNC Lathe)

Who is online

Users browsing this forum: No registered users and 1 guest