This is my current macro which sits entirely in the After M6 area. On the last test it just went back to T5 every time when I ran the GCode for all 3 M6’s
; ATC - COMPLETE M6
; Use in gSender AFTER M6 area.
;
; global.atc.currentTool = physical tool currently in spindle
; global.atc.requestedTool = requested M6 tool
;
; New gSender session starts with no known tool loaded.
;
; Deposit dwell = 0.5 sec
; Pickup dwell = 3 sec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CONSTANTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%RACK_X = -1232.29
%RACK_Z = -69.92
%SAFE_Z = -5
%PROBE_X = -0.5
%PROBE_Y = -1200
%PROBE_Z = -7.5
%PROBE_DISTANCE = 150
%PROBE_FAST = 500
%PROBE_SLOW = 50
%T1_Y = -443.05
%T2_Y = -503.31
%T3_Y = -564.42
%T4_Y = -623.80
%T5_Y = -684.99
%T6_Y = -743.84
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; INITIALIZE OUR ATC STATE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%global.atc = global.atc || {}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GET CURRENT PHYSICAL TOOL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%currentTool = Number(global.atc.currentTool || 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GET REQUESTED TOOL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%requestedTool = Number([tool])
%global.atc.requestedTool = requestedTool
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DEBUG
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(msg, ATC M6 START)
(msg, ATC CURRENT TOOL = [currentTool])
(msg, ATC REQUESTED TOOL = [requestedTool])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DETERMINE CURRENT TOOL RACK POSITION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%toolY = (currentTool == 1) ? T1_Y : ((currentTool == 2) ? T2_Y : ((currentTool == 3) ? T3_Y : ((currentTool == 4) ? T4_Y : ((currentTool == 5) ? T5_Y : ((currentTool == 6) ? T6_Y : 0)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DETERMINE REQUESTED TOOL RACK POSITION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%requestedToolY = (requestedTool == 1) ? T1_Y : ((requestedTool == 2) ? T2_Y : ((requestedTool == 3) ? T3_Y : ((requestedTool == 4) ? T4_Y : ((requestedTool == 5) ? T5_Y : ((requestedTool == 6) ? T6_Y : 0)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DEBUG RACK POSITIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(msg, ATC CURRENT RACK Y = [toolY])
(msg, ATC REQUESTED RACK Y = [requestedToolY])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; STOP SPINDLE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
M5
G4 P0.5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; MACHINE COORDINATES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
G21
G90
G53 G0 Z[SAFE_Z]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PUT AWAY CURRENT TOOL
;
; If currentTool = 0, there is no known tool to put away.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[currentTool > 0 ? ‘G53 G0 X’ + RACK_X + ’ Y’ + toolY : ‘’]
[currentTool > 0 ? ‘G53 G0 Z’ + RACK_Z : ‘’]
[currentTool > 0 ? ‘G4 P0.5’ : ‘’]
[currentTool > 0 ? ‘G53 G0 Z’ + SAFE_Z : ‘’]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PICK UP REQUESTED TOOL
;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.atc.hasReference || false
%toolOffset = (!hasReference) ? 0 : (measuredZ - global.atc.referenceZ)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SAVE FIRST TOOL REFERENCE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%global.atc.referenceZ = (!hasReference) ? measuredZ : global.atc.referenceZ
%global.atc.hasReference = true
(msg, ATC TOOL OFFSET = [toolOffset])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; APPLY TOOL LENGTH OFFSET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
G43.1 Z[toolOffset]
G4 P0.1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; UPDATE PHYSICAL TOOL STATE
;
; This is the ONLY place currentTool is changed.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%global.atc.currentTool = requestedTool
(msg, ATC CURRENT TOOL NOW = [global.atc.currentTool])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RETURN TO JOB COORDINATE SYSTEM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
G90
G53 G0 Z[SAFE_Z]
G54
G17
G21
G90