Overview: The Six Tool Change Modes
RosettaCNC handles M6 through a selectable tool change strategy rather than a single hard-coded routine. Three strategies are pre-built inside the CNC, and three route execution into a user-editable macro (subprogram) so the integrator controls every motion and handshake.
| Mode | Behaviour | Typical use |
|---|---|---|
| None |
M6 is ignored entirely; no motion, no prompt |
Single-tool jobs. T/M6 lines remain in the file and can still be used to segment and colour long programs (e.g. marble roughing/finishing blocks) in the viewer |
| Manual | Pre-built manual change driven by setup parameters | Machines without ATC: define change position, movement sequence, whether to use tool-table data or re-measure length each time |
| Automatic | Pre-built ATC sequence managed by the CNC/PLC | Machines with a carousel/rack changer using the standard handshake |
| Custom macro | User subprogram executes the whole change | Non-standard sequences, extra I/O, dust shoe lift, probe cycles |
| Custom macro - manual | User subprogram plus the built-in manual logic | Manual change with added site-specific steps |
| Custom macro - automatic | User subprogram plus the built-in automatic (PLC) logic | ATC where the macro handles safe positioning and state, and the PLC does the mechanical swap |
M106. Confirm which mode the machine is configured for before commissioning the macro below.Anatomy of the M6 Custom Macro
The macro is called whenever M6 appears in the main program or is issued from MDI. The tool number requested by the T word is passed in as argument #1.
; User defined tool change subprogram
; called when M6 is executed from program or MDI
;
; Arguments
; =========
; #1 tool id to change
; store actual state group 0
#4101=[#5101]
; store actual state M3, M4, M5
#4151=#5151
; store actual state M7, M9
#4153=#5153
; store actual state M8, M9
#4154=#5154
; disable spindle, flood & mist
m5
m9
g53 g0 z0
m109 p"Insert tool T#1" q2
g4 p1
; call default PLC tool change management
m106
; restore previous states
if [#4151 eq 3] then m3
if [#4151 eq 4] then m4
if [#4153 eq 7] then m7
if [#4154 eq 8] then m8
if [#4101 le 1] then g#4101
; enable offset xyz compensation
g43 h#1
Execution order, line by line
- Snapshot modal state. The current modal G-code of group 0 and the current spindle/coolant M-code states are copied from the read-only system variables into user variables so they survive the change.
-
Make the machine safe.
M5stops the spindle,M9kills flood and mist. Do this before any Z motion so nothing is spraying at the change position. -
Retract in machine coordinates.
G53 G0 Z0moves to machine Z zero independently of any active work offset (G54–G59) or Z shift. UsingG53here is the critical detail: a program-coordinateG0 Z0would crash into the part on most setups. -
Prompt or handshake.
M109 P"Insert tool T#1" Q2displays the message with the requested tool number substituted and waits for operator acknowledgement.G4 P1adds a dwell after the dialog closes so motion does not restart the instant the button is released. -
Perform the change.
M106hands off to the built-in PLC tool change management. - Restore modal state. Conditional restore of spindle direction, coolant, and motion mode.
-
Apply the length offset.
G43 H#1activates the tool length compensation for the tool just loaded.
System Variable Map Used by the Macro
| Variable | Direction | Meaning / expected values |
|---|---|---|
#1 |
In (argument) | Tool ID requested by the T word preceding M6
|
#5101 |
Read | Active modal G-code of group 0 (motion mode) |
#5151 |
Read | Active spindle state: 3 = M3, 4 = M4, 5 = M5 |
#5153 |
Read | Mist state: 7 = M7, 9 = M9 |
#5154 |
Read | Flood state: 8 = M8, 9 = M9 |
#4101, #4151, #4153, #4154
|
Write/Read | Storage copies of the four states above, used by the restore block |
Why the motion mode restore is guarded
if [#4101 le 1] then g#4101 restores only G0 and G1. That guard is intentional: re-issuing G2 or G3 as a bare modal word without I/J/K or R arguments is not meaningful, and canned-cycle or other group 0 modes above 1 should not be blindly re-armed after a tool change. If the interrupted block was an arc, the post-processed program will re-establish the correct mode on the next motion block anyway.
#5153) and flood (#5154) both report 9 when off, so you cannot infer both states from one variable. Store and test them separately, exactly as shown, or you will silently drop one coolant channel after every change.Automatic G43 H Application and How to Override It
Because the macro ends with g43 h#1, the length compensation for the newly loaded tool is applied automatically using the same number that was passed to M6. The practical effect on the part program:
; before - offset written by hand, mismatch possible
T5 M6
G43 H5 Z25.0
; after - macro applies G43 H5 itself
T5 M6
Z25.0
This removes a real class of crash: a typed H that does not match the T word, whether from a post-processor quirk or a keystroke error. The number can only ever be the tool actually requested.
Using a different offset than the tool number
The macro sets a modal state, so it can be overridden by the next G43 the program issues. To deliberately run tool 5 on a different offset, place an explicit G43 after the M6 line:
T5 M6 ; macro loads T5 and applies G43 H5
G43 H12 ; override: now using offset 12
Two cautions with this technique:
- The override must come after
M6, never before, otherwise the macro's trailingG43 H#1overwrites it. - Any later
M6resets the offset to match its own tool number, so re-issue the override after every change if it must persist.
If you prefer full manual control of H on this machine, delete or comment the final g43 h#1 line — but then every part program must supply its own G43 H, and you lose the typo protection.
Commissioning and Verification
-
Dry-run the retract with the spindle empty. Jog to a work position with a work offset active, then execute
T1 M6from MDI. Confirm the Z axis goes to machine zero, not to work zero. -
Verify the prompt string. The dialog should read "Insert tool T1" with the number substituted, proving
#1is being passed and expanded. -
Test modal restore. Start
M3andM8, then runM6. After the change, spindle should be running in the same direction and flood should be back on. Repeat withM4andM7. -
Test the off case. With spindle and coolant off before
M6, confirm nothing is switched on afterwards — theeqtests should all fail. - Verify the offset. After the change, check the tool length compensation display shows the offset from the tool table row matching the requested tool. Touch off a known surface and confirm the Z readout.
-
Test a first change from a cold start. With no offset previously active, run
T2 M6and confirmG43 H2takes effect without an intervening motion block. -
Test the mid-program case. Run a two-tool program and confirm the interrupted motion mode resumes correctly, especially if the block before
M6wasG1.
M106 PLC sequence, the tool table pocket assignments, and the safe change position agree with each other. A macro that retracts to G53 Z0 but a changer that expects a different clearance height will fail on the first swap. Keep the E-stop within reach for the first several cycles.Extending the Macro
Typical additions that belong inside this macro rather than in the part program:
- Move X/Y to a fixed change position with
G53 G0 X.. Y..after the Z retract, when the changer or the operator needs clearance from the workpiece. - Insert a tool length measurement cycle after
M106and beforeG43, if the setup calls for re-measuring rather than trusting the tool table. - Raise a dust shoe or open a guard through auxiliary M-codes before the retract, and restore it in the same conditional style used for spindle and coolant.
- Skip the entire sequence when the requested tool equals the tool already in the spindle, to avoid a pointless cycle on redundant
M6calls.
Keep the store/restore block symmetrical: anything you switch off at the top must be conditionally switched back on at the bottom, keyed off a stored variable rather than assumed.
Does RosettaCNC apply G43 automatically after M6?
Only if the tool change macro ends with g43 h#1. That line applies the length offset whose number matches the tool passed to M6, so the part program no longer needs its own G43 H line.
Can I use a tool offset number different from the tool number?
Yes. Issue an explicit G43 H<n> on the line after M6. It overrides the modal offset the macro just set. The next M6 will reset it back to the tool number.
Why does the macro use G53 G0 Z0 instead of G0 Z0?
G53 forces the move into machine coordinates, ignoring the active work offset. A plain G0 Z0 would move to work zero, which on most setups is at or inside the part.
Which variables hold the spindle and coolant state during a tool change?
#5151 reports 3, 4 or 5 for M3/M4/M5; #5153 reports 7 or 9 for mist; #5154 reports 8 or 9 for flood. The macro copies them to #4151, #4153 and #4154 before issuing M5 M9, then restores them conditionally.
Can RosettaCNC run a fully automatic ATC tool change?
Yes. Select the automatic mode for the built-in sequence, or the custom-macro-automatic mode to run your own macro that delegates the mechanical swap to the PLC through M106.