Machsupport Forum
		Mach Discussion => General Mach Discussion => Topic started by: glinner81 on April 15, 2023, 02:18:02 PM
		
			
			- 
				hi all
 apologies as i realise this subject has prob been done to death..
 i have a new to me boxford lathe with an 8 position atc and running mach3. guy i bought it from said it all worked fine. for multiple reasons i didnt get to try it and bought it anyway.  ::)
 everything works well (mostly) except the turret. i have checked the macro in the m6start folder in mach3 turn.
 it doesnt work, if i manually drive the atc and set the a axis (i have screen sets for a axis) to tool 01 and zero the a axis out (zero world a) and then type T0202 to move to tool 02 offset 02 it skips past position 02, to an unknown location between tool 02 and tool 03.
 this atc has a ratchet i believe so it has to go past the location and then back a small amount to lock in place. it does use g91 for this to avoid losing steps..?
 also if i am at say t0606 position and i enter t0101 in the mdi line it tries to go clockwise against the ratchet which just stalls the motor.
 i copied a macro from this site which works ok, it moves the atc in 45deg increments but it doesnt allow for the atc to move back a couple of degrees to lock the turret on the pin...
 
 this is the macro below that came already in the m6start folder:
 
 'This macro drives an 8 position stepper driven ATC.
 'It drives forward past a ratchet, then backwards a little to stall the motor
 'The A axis is setup for 20 steps per mm, my ATC requires 900 steps per index
 'of 45 degrees.
 'Because of the stall, steps are lost. So, we switch to INC mode for the ATC,
 'then back to ABS mode before we exit.
 
 
 'OEMDRO(803) is utilized to store the last used tool (OldTool) and is updated
 'upon final execution of the macro. This is resorted to as the Txxyy will overwrite
 'the "CurrentTool" DRO.
 'The A axis is zeroed if tool is Number1, to prevent an overflow of the DRO after
 'multiple changes.
 
 
 'M6Start.m1s
 Message ("macro running")
 
 OldTool = GetOEMDRO (803)
 Tool = GetSelectedTool()
 MaxToolNum = 8 'Max number of tools for the changer
 
 If OldTool = Tool Then
 Message ("Selected Tool already loaded")
 Exit Sub
 End If
 
 While Tool > MaxToolNum
 Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
 Wend
 
 xval= getoemdro(800)   'get x
 zval= getoemdro(802)   'get z
 Call Dooembutton(138)
 While IsMoving()
 Wend
 
 
 moveto = Tool- OldTool
 
 If moveto<1 Then moveto=8+moveto
 
 code "G91"   'inc mode
 
 code "G00 A"+Str((moveto*45)+5)
 While IsMoving()
 Wend
 
 
 code "G00 A-5"
 While IsMoving()
 Wend
 
 code "G01 A-2 F100"
 While IsMoving()
 Wend
 
 code "G90"   'abs mode
 
 NewTool=Tool
 If NewTool=1 Then
 Call DoOemButton (1011)      'zero A
 End If
 
 
 Call SetUserDRO (803, NewTool)
 SetCurrentTool(NewTool)
 code "G0 Z"+Str(zval)      'return to initial position
 code "G0 X"+Str(xval)      'before tool change
 While IsMoving()
 Wend
 
 
 this is one i copied from a previous thread that works ok but for some reason does not move to t0404 but all other tools! also does not move back a few degrees to lock the atc in position. and also if im on say t0505 and then enter t0101 it tries to move clockwise against the pin. atc can only move counter clockwise for tool position moves. (the emoji is actually an eight)
 
 Sub Main()
 
 NumSlots=8
 OldTurretPos=(GetOEMDRO(803))
 OldToolSlot=Abs(GetOEMDRO(803)*8)
 NextTool = GetSelectedTool()
 NextToolSlot = (NextTool-1)*360/NumSlots
 
 
 If OldToolSlot = NextToolSlot Then
 SetCurrentTool(NextTool)
 Exit Sub
 End If
 
 If NextTool>8 Or NextTool<1 Then
 Message("Next Tool out of range")
 Exit Sub
 End If
 
 MoveDis = (NextToolSlot-OldTurretPos)
 
 If Abs(MoveDis) >180 Then
 If MoveDis < 0 Then
 MoveDis = 360 - MoveDis
 Else
 MoveDis = MoveDis + 360
 End If
 End If
 
 ActivateSignal(OUTPUT3)  'Release Turret holding pin
 Code "G4 P0.5"
 While IsMoving ()
 Wend
 Code "G00 G91 a" & MoveDis
 While IsMoving ()
 Wend
 
 DeActivateSignal(OUTPUT3)  'Engage Turret holding pin
 
 SetCurrentTool(NextTool)
 Code "G90"
 End Sub
 
 i have verified that the atc moves 1degree when i in put g91 g0 a1...
 i am a complete novice to this and any help would be much appreciated
 
- 
				The macro that came with the machine looks good, it could be that the turret is sticking and needs oil,  You could also reduce the velocity on the A axis and up the acceleration time to stop any missed steps.
 
 The second macro is not for your machine.
- 
				Thanks for reply - atc moves freely. Its maybe something I'm missing in the tool table, I haven't set angles for the different tool positions... my thinking was if mach3 knows where the first tool position is then the macro would be able to drive to correct position for say t0202 etc. Also I'm not sure why it tries to move clockwise sometimes 
			
- 
				You could try this one I did many years ago for Boxford 125/160 lathes.
 
 Rename the file and put it in the correct profile macro folder.
- 
				I will give it ago tomorrow hopefully and report back. Thanks a mil
			
- 
				My turret just keeps rotating with the new macro
			
- 
				What language is the macro written in? Is python or c++ or something else? 
			
- 
				Cypress VB
 
 http://support.machsupport.com/de/downloads/files/mach3-macro-programming-guide/download
 https://www.machsupport.com/wp-content/uploads/2013/02/VBScript_Commands.pdf
- 
				Hi Graham your script looks very promising. I just can't see why it keeps the atc rotating.. any ideas?
			
- 
				Graham's script has parameter's for the step's per tool
 
 from Graham's script:
   steps_per_tool = 900 ' number of steps needed to move 1 tool position (45 deg)
 steps_after_pawl = 100 ' set to amount to clear pawl after move (5 deg)
 steps_to_lock_back_on_pawl = 140 ' number of steps to lock onto pawl (7 deg
 
 and it looks like your machine is set to degrees witch means it needs 45 step's per tool.
 so you have to set the parameters right.
 
   steps_per_tool = 45 ' number of steps needed to move 1 tool position (45 deg)
 steps_after_pawl = 5 ' set to amount to clear pawl after move (5 deg)
 steps_to_lock_back_on_pawl = 7 ' number of steps to lock onto pawl (7 deg)
 
 i would expect.
- 
				Will give that a go tomorrow. Thank you 
			
- 
				Yesss! That works spot on thank you both very much :)
 One final thing could tell me how I could get the atc to move to a safe position prior to the tool change? Thank you again
- 
				I guess it would have to read the current position, then move to say machine 0,0 do the atc change and then move back to last dro position so that it would keep the same position for the program?
			
- 
				here:
 https://www.machsupport.com/forum/index.php/topic,36624.msg251085.html#msg251085
 
 you can find a macro i poted some year's ago it shows how to move to "safe" position first.
 this will also make necessary to have the axis referenced/homed to know for sure the position
 in machinecoords.
- 
				would this move it to position using the previous script and added in from your script the x and z axis moves?
 
 ' (C) Graham Waterworth Mach forum.
 ' rough draft for a lock back to pawl type tool changer
 ' this has not been tried on any tool changer
 ' use/modify it as you wish, I take no responsibility
 ' for any damage to you or your equipment.
 
 ' NOTE current values are for a Boxford 125/160 lathe
 ' 8 position tool changer using MM calibration.
 ' set axis steps per to 20
 
 If IsLoading() Then
 ' do now't, program loading
 Else
 
 ' dim some vars
 
 Dim next_tool As Integer
 Dim current_tool As Integer
 Dim steps_per_tool As Integer
 Dim steps_after_pawl As Integer
 Dim max_tools As Integer
 Dim rotateCW As Integer
 Dim moves As Integer
 Dim fast_feed As Integer
 Dim slow_feed As Integer
 Dim axis As String
 Dim zero As Integer
 Dim to_pawl As Integer
 
 ' set up some vars
 
 zero = 0
 axis = "A" ' change to what ever axis you use for tool changer
 rotateCW = 0 ' set to 1 for CCW and 0 for CW rotation
 max_tools = 8 ' number of tools on turret
 
 ' stepper driver should be set to 1 step NO MICRO STEPPING!
 
 steps_per_tool = 900 ' number of steps needed to move 1 tool position (45 deg)
 steps_after_pawl = 100 ' set to amount to clear pawl after move (5 deg)
 steps_to_lock_back_on_pawl = 140 ' number of steps to lock onto pawl (7 deg)
 next_tool = GetSelectedTool()
 current_tool = GetCurrentTool()
 fast_feed = 1000 ' set to safe rapid rotation speed
 slow_feed = 200 ' set to safe creep speed back onto pawl.
 
 ' do some tool changing
 
 If next_tool > max_tools Then
 Message "Tool number too high, program stopped."
 Code "M30"
 End
 End If
 
 If next_tool<1 Then
 Message "Tool number too low, program stopped."
 Code "M30"
 End
 End If
 
 If next_tool=current_tool Then
 ' do nowt, we got it already
 
 Message "ATC X-Axis to TC position"
 Code "G90 G53 G0 X2"
 While IsMoving()
 Sleep(15)
 Wend
 
 Message "ATC Z-Axis to TC position"
 Code "G90 G53 G0 Z2"
 While IsMoving()
 Sleep(15)
 Wend
 Else
 ' lets do some checking
 If next_tool > current_tool Then moves = next_tool - current_tool
 If next_tool < current_tool Then moves = max_tools - current_tool + next_tool
 ' work out how far to move
 rapid_move = (moves * steps_per_tool) + steps_after_pawl
 to_pawl = zero - steps_to_lock_back_on_pawl
 ' reverse moves if needed
 If rotateCW = 1 Then
 rapid_move = zero - rapid_move
 to_pawl =  Abs(to_pawl)
 End If
 ' set axis to zero
 Code "G92 " & axis & "0"
 Code "G91 G94 G61"
 ' start the move
 Code "G01 " & axis & rapid_move & " F" & fast_feed
 Code "G04 P250"
 While IsMoving()
 Wend
 ' move back to locking point
 Code "G01 " & axis & to_pawl &  " F" & slow_feed
 While IsMoving()
 Wend
 ' tell mach3 new tool
 SetCurrentTool next_tool
 Code "G90" ' back to absolute movement
 End If
 End If
 
 ' end of tool change
- 
				modified your code a little bit:
 
 ' (C) Graham Waterworth Mach forum.
 ' rough draft for a lock back to pawl type tool changer
 ' this has not been tried on any tool changer
 ' use/modify it as you wish, I take no responsibility
 ' for any damage to you or your equipment.
 
 ' NOTE current values are for a Boxford 125/160 lathe
 ' 8 position tool changer using MM calibration.
 ' set axis steps per to 20
 
 If IsLoading() Then
 ' do now't, program loading
 Else
 
 ' dim some vars
 
 Dim next_tool As Integer
 Dim current_tool As Integer
 Dim steps_per_tool As Integer
 Dim steps_after_pawl As Integer
 Dim max_tools As Integer
 Dim rotateCW As Integer
 Dim moves As Integer
 Dim fast_feed As Integer
 Dim slow_feed As Integer
 Dim axis As String
 Dim zero As Integer
 Dim to_pawl As Integer
 
 ' set up some vars
 
 zero = 0
 axis = "A" ' change to what ever axis you use for tool changer
 rotateCW = 0 ' set to 1 for CCW and 0 for CW rotation
 max_tools = 8 ' number of tools on turret
 
 ' stepper driver should be set to 1 step NO MICRO STEPPING!
 
 steps_per_tool = 900 ' number of steps needed to move 1 tool position (45 deg)
 steps_after_pawl = 100 ' set to amount to clear pawl after move (5 deg)
 steps_to_lock_back_on_pawl = 140 ' number of steps to lock onto pawl (7 deg)
 next_tool = GetSelectedTool()
 current_tool = GetCurrentTool()
 fast_feed = 1000 ' set to safe rapid rotation speed
 slow_feed = 200 ' set to safe creep speed back onto pawl.
 
 ' do some tool changing
 
 If next_tool > max_tools Then
 Message "Tool number too high, program stopped."
 Code "M30"
 End
 End If
 
 If next_tool<1 Then
 Message "Tool number too low, program stopped."
 Code "M30"
 End
 End If
 
 If next_tool=current_tool Then
 ' do nowt, we got it already
 
 Else
 
 'X-Axis not in reference
 If GetOEMLED(807) Then
 DoButton(3)
 Sleep(500)
 Message ("X-Axis not referenced -> Abort !!")
 Code "M30"
 Exit Sub
 End If
 
 'Z-Axis not in reference
 If GetOEMLED(809) Then
 DoButton(3)
 Sleep(500)
 Message ("Z-Axis not referenced -> Abort !!")
 Code "M30"
 Exit Sub
 End If
 
 
 Message "ATC X-Axis to TC position"
 Code "G90 G53 G0 X2"
 While IsMoving()
 Sleep(15)
 Wend
 
 Message "ATC Z-Axis to TC position"
 Code "G90 G53 G0 Z2"
 While IsMoving()
 Sleep(15)
 Wend
 
 ' lets do some checking
 If next_tool > current_tool Then moves = next_tool - current_tool
 If next_tool < current_tool Then moves = max_tools - current_tool + next_tool
 ' work out how far to move
 rapid_move = (moves * steps_per_tool) + steps_after_pawl
 to_pawl = zero - steps_to_lock_back_on_pawl
 ' reverse moves if needed
 If rotateCW = 1 Then
 rapid_move = zero - rapid_move
 to_pawl =  Abs(to_pawl)
 End If
 ' set axis to zero
 Code "G92 " & axis & "0"
 Code "G91 G94 G61"
 ' start the move
 Code "G01 " & axis & rapid_move & " F" & fast_feed
 Code "G04 P250"
 While IsMoving()
 Wend
 ' move back to locking point
 Code "G01 " & axis & to_pawl &  " F" & slow_feed
 While IsMoving()
 Wend
 ' tell mach3 new tool
 SetCurrentTool next_tool
 Code "G90" ' back to absolute movement
 End If
 End If
 
 ' end of tool change
 
- 
				works perfect, thank you very much  8)