Hi everyone, I converted an old cnc lathe that already had a turret on it. After converting the entire machine over to mach3 I needed to control the turret. I receieved a macro from a different site but no one seems to have any info on it.
My turret is equipped with a stepper motor and a pawl. The macro simply rotates the turret past the tool location then backs up tight against the pawl.
I installed this macro and I can successfully index my turret from tools 1-6 as long I call the next tool in order. If for instance I'm using tool 3 and call up tool 6 my turret seems to not rotate far enough, its off by a couple degrees. Is there a math error in the macro? I can't see it being the stepper tuning since It works perfect if I call up the tools in order. I indexed the tools in order for 3 full rotations with no errors but as soon as I command it to call up a tool that's a couple slots away it loses its spot.
Here's the macro I installed:
If IsLoading() Then
'Do Nothing, program loading
Else
' Dim Variables
Dim Num_Tools As Integer
Dim CW_Steps_Per_Tool As Integer
Dim CCW_Steps As Integer
Dim HoldingDRO As Integer
Dim Requested_Tool As Integer
Dim Current_Tool As Integer
Dim CW_Feed As Integer
Dim CCW_Feed As Integer
'Dim moves As Integer
'Dim total_move As Integer
' set up some vars
Num_Tools = 6
CW_Move_Per_Tool = 360/Num_Tools
CCW_Move = 10
HoldingDRO = 1050
Requested_Tool = GetSelectedTool()
Current_Tool = GetCurrentTool()
CW_Feed = 3000
CCW_Feed = 2000
Current_Feed = GetOEMDRO(818)
' start tool change
Message ("Requested Tool No=" & Requested_Tool)
If Requested_Tool > Num_Tools Then
Message "Requested Tool No. too high, program stopped."
Code "M30"
End
End If
If Requested_Tool < 1 Then
'Message "Requested Tool No. too low, program stopped."
Code "M30"
End
End If
If Requested_Tool = Current_Tool Then
' do nothing
Else
' lets do some changing
If Requested_Tool > Current_Tool Then moves = Requested_Tool - Current_Tool
If Requested_Tool < Current_Tool Then moves = Num_Tools - Current_Tool + Requested_Tool
total_move = (moves * CW_Move_Per_Tool)+(CCW_Move/2)
'Move to safe position
Code "G0 G53 Z-1 X-.25"
'Pause for 1/2 second
Code "G04 P0.5"
Code "G91 G94" 'incremental & Feed per minute
Code "G01 A" & total_move & " F" & CW_Feed
Code "G01 A-" & CCW_Move & " F" & CCW_Feed
While IsMoving()
sleep(10)
Wend
SetCurrentTool Requested_Tool
SetUserDRO HoldingDRO, Requested_Tool
Code "G90" ' back to absolute movement
Code "F" & Current_Feed
End If
End If
' end of tool change