Insertions of sequences of ‘G’ and/or ‘M’ codes are possible at the beginning, at the end, and during tool changes. It is often helpful to add comments to the commands. Comments are enclosed in parentheses. Some commands cause program execution to pause and wait for the user to take action before resuming execution. When the characters ‘MSG,’ are entered at the beginning of the comment, the remainder of the comment is presented to the user in an “action dialog”. This helps instruct the user on what action to take before resuming execution.
The “tool-change” entry box contains commands that are run every time an M6 (tool change) command is encountered. By default, the “tool-change” entry box contains the following commands:
(Runs on M6, tool change)
M0 M6 (MSG, Change Tool)
These commands simply pause execution and prompt the user to change the tool.
The following example provides a set of commands that can be used to change the tool and then set the height of the z-axis after the tool change. This example assumes the use of a 0.75” (19.05mm) touch plate like the one shown here.
(Runs on M6, tool change)
M70
G21
G0Z100
M0 (MSG, Change tool and attach probe)
F100
G91
G38.2 Z-100
G92 Z19.05
G0 Z25
M0 (MSG, Remove probe)
M72
M70 tells the controller to save its current state (e.g. feed rate, distance mode, and units) so it can be recovered after the sequence is completed.
G21 tells the controller to operate in Metric units.
G0 Z100 raises the tool to 100mm so the tool can be replaced.
M0 (MSG, Change tool and attach z-probe) - The comment starts with ‘MSG,’ so the text “Change tool and attach z-probe” is presented to the user in the action dialog.
F100 says that the feed rate will be 100 mm/minute. This feed rate should be slow to prevent jamming the bit into the surface of the probe. Ideally, the search will stop at the instant that the bit touches the probe.
G91 puts the machine in “incremental distance mode” so it will probe downward by 100mm or until the probe is found in the next command.
G38.2 Z-100 tells the machine to move towards the probe and stop when the probe surface is found. If the search reaches Z = -100 without finding the probe surface, the search will stop and the probing command fails.
G92 Z19.05 sets the z axis to 19.05mm, which is the height of the probe base being used in this example.
G0 Z25 tells the machine to move up to Z = 25 so the probe can easily be removed.
M0 (MSG, Remove probe) reminds the user to remove the probe and waits for the user to click “Continue” to resume execution of the GCode program.
M72 restores the original state (e.g. feed rate, distance mode, and units) that existed at the beginning of the tool change procedure.