Hello Guest it is November 27, 2021, 07:07:50 AM

Author Topic: Mission - Make ATC M6 Macro from Mach3 VB Script!  (Read 598 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
Mission - Make ATC M6 Macro from Mach3 VB Script!
« on: August 04, 2019, 12:51:42 PM »
Here is my code for the Mach3 script that works for my tool changer. My tool changer is purely mechanical. It moves above the Z home position and back down to ratchet the turret to the next tool. Pretty simple, but it still takes some coding.
I do have some concerns over Mach4 knowing what tool was loaded when you shut down and restart the software and having means to correct the tool number if something gets out of whack. This would happen with Mach3 at times so I added in some checks for a tool number out of the range  of realism. Maybe Mach4 is better with this and it won't happen?
I also thought about adding a startup question of asking what tool is loaded when you first turn on the machine.
Anyway, I am starting to try to convert thus to Lua. If anyone wants to help or has suggestions it is much appreciated.
I will post questions here as I get stuck figuring it out. I am pretty new to trying to use this code and even the VB took me awhile to figure out.
Code: [Select]
'Tool change macro for 7 tool turret
Sub Main()
'Sets variable OldTool to what is currently loaded
OldTool=GetCurrentTool()

'Sets Variable MaxToolNum to the max number of tools possible
MaxToolNum=7

'Sets variable Newtool to the one being selected with M6 T#
NewTool=GetSelectedTool()

'Get positions before moving to do tool change
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )

'If the current tool loaded is 0 or greater than 7 then tool has been lost
'so need to ask what tool is currently loaded
While OldTool=0 Or OldTool>7
OldTool=Question ("Current tool unknown, enter tool in spindle 1 to " & MaxToolNum)
Wend

'Sets CurrentTool to Oldtool in case it was lost and entered above
SetCurrentTool(OldTool)

'When the tool asked for is invalid then this makes you select a valid tool
While NewTool > MaxToolNum Or NewTool <1
NewTool = Question ("Invalid tool chosen, enter tool number 1 to " & MaxToolNum)
Wend

        'If the tool asked for is the same one that is already loaded then exit macro
If NewTool=OldTool Then
Message "Tool already loaded or tool not specified with T# (ex:M6 T4)"
Exit Sub
End If

'Turn off soft limits if they are on
If GetOEMLED(23) Then
DoOEMButton(119)
End If

'Moves To Z home from where ever it is
code "G53G0Z0"
While IsMoving()
Wend

'Sets ChangeNums to 0 for safety in case it is not at 0
ChangeNums=0

'Makes the magic happen and moves the proper number of times if new tool is higher than old
If NewTool>OldTool Then
For ChangeNums=1 To NewTool-OldTool

'Moves Z axis to the top of tool change
code "G53 G1 F70 Z5.800"
While IsMoving()
Wend

'Moves back to bottom of tool change area
code "G53 G1 F70 Z3.8"
While IsMoving()
Wend

Next

'Makes the magic happen and moves the proper number of times if new tool is lower than old
Else
For ChangeNums=(OldTool-NewTool) To 6

'Moves Z axis to the top of tool change
code "G53 G1 F70 Z5.800"
While IsMoving()
Wend

'Moves back to bottom of tool change area
code "G53 G1 F70 Z3.8"
While IsMoving()
Wend

Next
End If

'Move Back to Z Home
code "G53 G1 F70 Z0"
While IsMoving()
Wend

'Should be a succesful tool change at this point so this sets the NewTool as the current tool
SetCurrentTool(NewTool)

'Turn back on soft limits
DoOEMButton(119)
End Sub           
« Last Edit: August 04, 2019, 12:53:30 PM by jevs »