Page 1 of 1

M6 Macro for Prolight 3000 or similar turret

PostPosted: Wed Jul 14, 2021 1:34 am
by eabrust
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

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Fri Apr 12, 2024 7:49 am
by Socke
The macro works quite well with my 6-position revolver.

eabrust wrote: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.


Could you get a grip on that one? I now change to tool 1 at the end of each program, to avoid problems.

What i find a bit sub-optimal is the direct way to the tool-change-position, which is not always the same, depending on using a tailstock or not. Maybe it's possible to look for the actual used tool-lengths and calculate the z-way accordingly? Also driving X and Z together may lead to crashing into the tailstock, so a configurable order would be nice.

Nevertheless it's a nice macro, which saved me from doing the portation mach3 -> uccnc myself :D

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Sat Apr 13, 2024 11:57 am
by eabrust
Socke wrote:
eabrust wrote: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.


Could you get a grip on that one? I now change to tool 1 at the end of each program, to avoid problems.

What i find a bit sub-optimal is the direct way to the tool-change-position, which is not always the same, depending on using a tailstock or not. Maybe it's possible to look for the actual used tool-lengths and calculate the z-way accordingly? Also driving X and Z together may lead to crashing into the tailstock, so a configurable order would be nice.

Nevertheless it's a nice macro, which saved me from doing the portation mach3 -> uccnc myself :D


Hi Socke, Finally, a fellow lathe user! :)

Yeah, I do have a very simple macro loop that runs to force tool# to sync on homing the turret, I guess I never got around to posting it back here.... It is :

Code: Select all
#VB

dim HomeState as boolean = exec.getled(59)
dim lastHomeState as boolean '= exec.getvar(6)



if lastHomeState <> Homestate andalso Homestate <> false then


exec.setcurrenttool(1)


else

end if

lastHomeState = Homestate


M601.txt
(277 Bytes) Downloaded 353 times


On my machine, I always send the turret/carriage to a clear fixed x/y position in the corner (manually make sure things are positioned clear before hitting HOME), then rotate A to home or tool. I don't use a tailstock, so I can't help much with determining an order of things to move to a clear spot. I always just make sure my part GCode results in the tools/turret being backed away enough that I have a 'clear line of sight path' to where the tool change will take place.

hope that helps.

regards
Eric

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Mon Apr 15, 2024 8:38 am
by Socke
eabrust wrote:Yeah, I do have a very simple macro loop that runs to force tool# to sync on homing the turret

I'm new to uccnc, so how do you sync that m601 with homing?

The more i think about it, the more i guess it's better, not to move the turret by the macro at all (just do the tool-change) and let that be done by the CAM, so it knows the exact position after the tool-change.

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Mon Apr 15, 2024 11:36 am
by eabrust
Socke wrote:
eabrust wrote:Yeah, I do have a very simple macro loop that runs to force tool# to sync on homing the turret

I'm new to uccnc, so how do you sync that m601 with homing?


Set M601 to run as a macro-loop in the settings, it isn't run as a standard macro called by anything.

It (M601 code) sits in the background, constantly running, and within the macro itself (frist lines), it gets the 'homestate' of UCCNC, and if there is a change in state that sets to 'true', it sets tool to 1. Once you get the concept of the macroloop, its pretty simple to do things on a 'state change'.

Eric

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Mon Apr 15, 2024 3:00 pm
by Socke
Thanks, I'll give that a try!

I see in your macro its possible, to set
Code: Select all
Return_Pos = true ' Set true to have tool moved back to last location after change
.
Could you also add an option, to not move at all as an option?

Best regards,
Sönke

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Thu Apr 18, 2024 5:04 pm
by Socke
Your M601-macro works perfect, thanks a lot!

I changed the M6-macro, so it behaves like I guess i need it:

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 Safe_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...
   Safe_Pos = true ' Set true to have tool moved to safe position before change
   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)
      
      if Safe_Pos=true
      'Move to safe position
      exec.Code("G0 G53 Z" & Safe_ZLoc & " X" & Safe_Xloc)
      'Pause for 1/2 second
      exec.Code("G04 P0.5")
      end if
      
      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 Safe_Pos=true
         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
        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

Re: M6 Macro for Prolight 3000 or similar turret

PostPosted: Fri Apr 19, 2024 1:53 pm
by eabrust
Hi Socke,

I'm glad you were able to get some use out of those macros for your project, and make the adaptations you need!

regards
Eric