100% found this document useful (1 vote)
1K views

Mach3 ATC Macro

This document contains a macro for performing an automated tool change on a CNC machine. It includes steps to: 1) Save the current machine state including position, feedrate and coolant status. 2) Move to the tool change position, release the old tool, and pick up the new tool. 3) Option to automatically probe the new tool's position and set the Z-axis offset. 4) Restore the machine to its original state before continuing operation with the new tool.

Uploaded by

SimasArmonas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

Mach3 ATC Macro

This document contains a macro for performing an automated tool change on a CNC machine. It includes steps to: 1) Save the current machine state including position, feedrate and coolant status. 2) Move to the tool change position, release the old tool, and pick up the new tool. 3) Option to automatically probe the new tool's position and set the Z-axis offset. 4) Restore the machine to its original state before continuing operation with the new tool.

Uploaded by

SimasArmonas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

M6Start.

m1s
'M6 start macro with auto tool touch off

'M6Start.m1s
'Check all axes referenced
If (GetOemLed(807) Or GetOemLed(808) Or GetOemLed(809)) Then
Message(" Please Home Machine before Tool Change")

'Cycle Stop
' Button 3 - select Toolpath screen
DoButton(3)

Exit Sub
End If

'--------------- CONFIGURATION

' the X+y+z position of tool #0 is stored in DRO 1200, 1201, 1202
' THESE USER-DEFINED DROS MUST BE DEFINED IN THE SCREEN SET
' distance of tools inside the magazine along the Y axis
TOOLDISTANCE = 33.5
TOOLDISTANCE_Z = (33.5-36.5)/5
TOOLCHANGE_FEEDRATE = 150

' safe absolute Z position


SafeZ = 0
SafeX = 65

' position of the tool height sensor (magazine must be open)


THS_POS_X = 0
THS_POS_Y = 0
THS_POS_Z = 0
THS_PROBE_FEEDRATE = 5

' Thickness of touch plate in the offset-screen


PlateThickness = GetOEMDRO(1001)

'--------------- CURRENT PARAMETERS TO RESTORE

' Save the current feedrate.


CurrentFeed = GetOemDRO(818)

' Save current coordinate mode to restore it later


oldCoordinateMode = GetOemLED(48)

' Set absolute coordinate mode and feedrate


Code "G90 F" & TOOLCHANGE_FEEDRATE

' Save the current position


' WARNING, THESE DROS ARE DEPRECATED SINCE MACH3 1.90
CurrentPosX = GetDro(0)
CurrentPosY = GetDro(1)
CurrentPosZ = GetDro(2)
'--------------- TOOL CHANGE

tool = GetselectedTool()
oldTool = GetCurrentTool() 'GetOEMDRO(1212)
If oldTool = tool Then
Answer = MsgBox("old tool and new tool are identical", 0 + 16 )
Exit Sub
End If

Answer = MsgBox("experimental tool change from tool " & oldTool & " to new tool "
& tool, 0)

DoSpinStop()

' use the user LED to store the state of coolant,


' so it can be restored in M6end.m1s
If getoemled(13) Then
'OEM LED 13 = "Flood LED" thus coolant is on
' set user led on
setuserled(1000,1)
Code "M9"
Else
'coolent is off
' set user led off
setuserled(1000, 0)
End If

'Get the tool change pos from the settings page


ChangeX = 24 '=GetOEMDRO(1200)
ChangeYold = 35 + (oldTool * TOOLDISTANCE) '=GetOEMDRO(1201) + (oldTool *
TOOLDISTANCE)
ChangeYnew = 35 + (Tool * TOOLDISTANCE) '=GetOEMDRO(1201) + (tool *
TOOLDISTANCE)
ChangeZold = -33 + (oldTool * TOOLDISTANCE_Z)
'=GetOEMDRO(1202)
ChangeZnew = -33 + (Tool * TOOLDISTANCE_Z)

While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "moving to Zsafe=" & SafeZ & " quickly", 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' G53 = Move in absolute machine coordinate system


Code("G00 G53 Z" & SafeZ)
While IsMoving ()
Wend

' open magazine


ActivateSignal(OUTPUT2)

If CurrentPosX < SafeX Then


'===== DEBUG====
Response = MsgBox ( "We are above the tool magazine, moving to SafeX=" & SafeX &
" quickly" , 1 )
If Response = 2 Then ' Cancel pressed
Response = MsgBox ( "Aborting" , 1 + 16 )
End
End If
'===== DEBUG====

' go to old tool position in Y


Code("G00 G53 X" & Safex)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "moving to y_oldtool=" & ChangeYold & " quickly", 1 )
If Response = 2 Then ' Cancel pressed
Response = MsgBox ( "Aborting" , 1 + 16 )
End
End If
'===== DEBUG====

' go to old tool position in Y


Code("G00 G53 Y" & ChangeYold)
While IsMoving ()
Wend

Else
'===== DEBUG====
Response = MsgBox ( "moving to y_oldtool=" & ChangeYold & " quickly", 1 )
If Response = 2 Then ' Cancel pressed
Response = MsgBox ( "Aborting" , 1 + 16 )
End
End If
'===== DEBUG====

' go to old tool position in Y


Code("G00 G53 Y" & ChangeYold)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "moving to SafeX=" & SafeX & " quickly", 1 )
If Response = 2 Then ' Cancel pressed
Response = MsgBox ( "Aborting" , 1 + 16 )
End
End If
'===== DEBUG====

' go to old tool position in X


Code("G00 G53 X" & Safex)
While IsMoving ()
Wend
End If

'===== DEBUG====
Response = MsgBox ( "Moving down to ChangeZold=" & ChangeZold & " quickly" , 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' go to old tool position in Z


Code("G00 G53 Z" & ChangeZold)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "Placing tool in X=" & ChangeX & " slowly" , 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' go to old tool position in X


Code("G01 G53 X" & ChangeX & " F" & TOOLCHANGE_FEEDRATE)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "releasing the old tool" , 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' release the old tool


ActivateSignal(OUTPUT1)

'===== DEBUG====
Response = MsgBox ( "moving up to SafeZ slowly" , 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' move up
Code("G01 G53 Z" & SafeZ & " F" & TOOLCHANGE_FEEDRATE)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "moving over to y=" & ChangeYnew & " quick", 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' go to old tool position in Y


Code("G00 G53 Y" & ChangeYnew)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "lowering to Znew" & ChangeZnew & " slowly", 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' move up
Code("G01 G53 Z" & ChangeZnew & " F" & TOOLCHANGE_FEEDRATE)
While IsMoving ()
Wend

'===== DEBUG====
Response = MsgBox ( "grabbing the new tool" , 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' release the old tool


DeActivateSignal(OUTPUT1)

'===== DEBUG====
Response = MsgBox ( "moving to SafeX=" & SafeX & " slowly", 1 )
If Response = 2 Then ' Cancel pressed
End
End If
'===== DEBUG====

' carry the tool out


Code("G01 G53 X" & SafeX & " F" & TOOLCHANGE_FEEDRATE)
While IsMoving ()
Wend

'--------------- TOOL HEIGHT PROBE


Response = MsgBox ( "Would you like to set your Z height automatically? If so,
click OK", 1 )
If Response = 1 Then
' TODO THIS HAS NOT BEEN TESTED YET

' go to tool height sensor position


Code "G00 G53 X" & THS_POS_X & "Y" & THS_POS_Y
While IsMoving ()
Wend
While GetOemLed (825)=0
Message ("(Z-Plate is grounded, check connection and dismiss this dialog)")
Wend

Code "G31 Z-5 F" & THS_PROBE_FEEDRATE


While IsMoving()
Wend

'dwell for 0.25 seconds


Sleep(250)

ZProbePos = GetVar(2002)

'Go back to touch position (G31 backs off after touch)


Code "G0 Z" & ZProbePos
While IsMoving ()
Wend

'Set Z axis position DRO to touch plate thickness


' WARNING, THIS DRO IS DEPRECATED SINCE MACH3 1.90
Call SetDro (2, PlateThickness)

'Pause 0.5 seconds for Dro to update.


Sleep(500)

' go up again
Code "G00 G53 Z" & SafeZ
While IsMoving ()
Wend

Code "(Z axis is now zeroed)"


' restore the original feedrate
Code "F" & CurrentFeed
End If

SetCurrentTool( tool )

' close magazine


DeActivateSignal(OUTPUT1)

'--------------- RESTORE ORIGINAL PARAMETERS

' Reset coordinate mode to original value


If AbsMode = 0 Then
Code("G91")
End If

'===== DEBUG====
'Response = MsgBox ( "moving to back to " & CurrentPosX & " - " & CurrentPosY &" ,
then Z=" & CurrentPosZ , 1 )
'If Response = 0 Then ' Cancel pressed
' End
'End If
'===== DEBUG====

' go to old tool position


'Code("G00 G53 X" & CurrentPosX & "Y" & CurrentPosY)
'While IsMoving ()
'Wend
' go to old tool position
'Code("G00 G53 Z" & CurrentPosZ)
'While IsMoving ()
'Wend

' Reset feedrate to original value


Code("F" & CurrentFeed)

M6End.m1s

'M6End.m1s
tool = GetDRO(24)
oldTool = GetOEMDRO(1212)

' check user led


If getuserled(1000) Then
'coolant was on
Code "M8"
End If

If (oldTool <> tool) Then


SetOEMDRO(1212, tool)
End If

Kita versija:

Sub Main()
OldTool = GetOEMDRO (1200) 'Tool In spindle DRO You must add this to your settings
screen
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )

tool = GetSelectedTool()
NewTool = tool

'----------------Tool Changer Macro (Bed Type)----------------------

MaxToolNum = 4 'Max number off tools for the changer


ToolDown = -50 'Z Pos to Get or drop a tool
ToolUp = 0 'Z Hieght to Rapid from tool to tool

'--------------------Auto Tool Zero---------------------------------

PlateThickness = GetUserDRO(1151) 'Z-plate thickness DRO


If GetOemLed (825)=0 Then 'Check to see if the probe is already grounded or faulty
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Else
Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the
status bar if aplicable
End If
'-------------------------------------------------------------------
If NewTool = OldTool Then
Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Code "G00 G53 Z" & ToolUp
While IsMoving()
Wend
Call MovePos(OldTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.75"
While IsMoving()
Wend
ActivateSignal(Output1) 'Turn On Draw bar to release the tool
Code "G4 P1.0" 'Wait for the tool to release
'SystemWaitFor (7) 'Wait for the tool Release Limit switch
Code "G53 Z-0.5" & ToolUp
Call MovePos(NewTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.75"
While IsMoving()
Wend
DeActivateSignal(Output1) 'Turn Off Draw bar to Clamp the tool
Code "G4 P1.0" 'Wait for the tool to Clamp
While IsMoving()
Wend
Code "G53 Z" & ToolUp
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )

'-----------------------------Auto Tool Zero-----------------------------

Code "G0 X100 Y100" ' Move to Probe position


Code "G4 P5" ' this delay gives me time to get from computer to hold probe in place
Code "G31Z-10 F100" 'probing move, can set the feed rate here as well as how far to
move
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetVar(2002) 'get the axact point the probe was hit
Code "G0 Z" &ZProbePos 'go back to that point, always a very small amount of
overrun
While IsMoving ()
Wend
Call SetDro (2, PlateThickness) 'set the Z axis DRO to whatever is set as plate
thickness
Code "G4 P0.25" 'Pause for Dro to update.
Code "G0 Z1." 'put the Z retract height you want here
Code "(Z axis is now zeroed)" 'puts this message in the status bar
Code "G00 X" & x & " Y" & y 'Move back to where the tool change was prompted
End Sub
'---------------------------Tool Positio-------------------------------------
Sub MovePos(ByVal ToolNumber As Integer)

Select Case ToolNumber


Case Is = 1
Xpos = 120.00
YPos = 20.00
Case Is = 2
Xpos = 140.00
YPos = 20.00
Case Is = 3
Xpos = 160.00
YPos = 20.00
Case Is = 4
Xpos = 180.00
YPos = 20.00

End Select

Code "G53 X" & XPos & " Y" & YPos
End Sub
Main

You might also like