M06 G-Code Command
M06 is a G-code command used in CNC machining to perform a tool change. When the machine receives the M06 command, it swaps the tool in the spindle to the next tool that is in the ready position of the automatic tool changer.
Depending on the machine software being operated the M06 command can behave differently.
For example, in some machines the M06 command also stops the spindle, stops coolant, moves the machines axes to the tool change position, orientates the spindle and then executes the tool change.
Other machines may only orientate the spindle and activate the tool change. In this situation the program needs to pre position the spindle to the home position first and the spindle needs to be stopped or the machine will error out.
This difference in behavior is usually reflected in how the M06 is used in the program. If the machine software needs to have the spindle moved to its home position first the M06 can be on the same line as the tool number, eg, T1 M06.
But if the M06 also moves the machine to the home position and stops the spindle etc, then the M06 usually has to have a line of its own in the program, like this;
This is because the M06 will trigger a macro program in the software to operate all the other commands first so having other commands on the same line can cause an error message and halt the tool change.
How M06 G-Code Command Is Used
Here’s an example of how M06 is used in a G-code program with comments in brackets:
G91 G28 X0 Y0 Z0 (move machine to the home position) T1 M06 (call up T1 and initiate tool change) G00 G54 X50 Y90 (rapid move to start position) M03 S2000 (turn on spindle and set speed to 2000 rpm) G43 H01 Z20 (apply tool length compensation for tool 1) G01 X10 Y10 Z5 F500 (move to first cutting position) G01 X20 Y20 Z10 F1000 (move to second cutting position) G00 Z50 (move to safe Z height) M05 (turn off spindle) G91 G28 X0 Y0 Z0 (move machine to the home position) M30 (end program)
In this example, the program begins by moving the machine to the home position, calls up T1 and initiates the tool change. Then it rapid moves to the start position, turning on the spindle at 2000 rpm, and applying tool length compensation for tool 1. It then moves to the first cutting position, where it will use tool 1 to finish the program. Finally, the program moves above the part, turns off the spindle with the M05 command, goes to its home position and ends the program with an M30.