M218 - Set Tool Offset
Description
M218 defines position offsets for a specific tool in the tool offset table. Each tool (0-7) can have independent X, Y, and Z offsets that are automatically applied to target positions during subsequent moves when that tool is active.
Tool offsets are only applied in absolute positioning mode (G90). In relative positioning mode (G91), offsets are ignored since the move distance is independent of the coordinate system origin.
Use T0-T7 to select the active tool. The active tool determines which offset entry is applied to moves.
Syntax
Parameters
| Parameter | Required | Description | Example |
|---|---|---|---|
| T | Yes | Tool number (0-7) | T1 |
| X | No | X-axis offset in user units | X0.5 or X-1.2 |
| Y | No | Y-axis offset in user units | Y-0.3 |
| Z | No | Z-axis offset in user units | Z1.2 |
Only specified axes are updated. Omitted axes retain their previous offset values for that tool.
How Offsets Are Applied
When a move command (G0, G1, G2, G3) is executed in absolute positioning mode, the active tool's offset is added to the target position before the move is calculated:
For arc moves (G2/G3), the offset is applied to the arc endpoint only. The arc center point (I, J, K parameters) is not affected by tool offsets.
Examples
Set offset for a single tool
Multi-tool workflow
Partial offset update
Streaming API (C)
#include "gcode_api.h"
int main() {
const char* key = getenv("GCODE_LICENSE_KEY");
GCodeHandle h = gcode_create(key);
gcode_connect(h, "192.168.1.100");
gcode_configure_linear_axis(h, 'X', 'A', 1000.0, 100.0);
gcode_configure_linear_axis(h, 'Y', 'B', 1000.0, 100.0);
gcode_configure_linear_axis(h, 'Z', 'C', 1000.0, 50.0);
gcode_add_command(h, "M218 T1 X0.5 Y-0.3 Z1.2");
gcode_add_command(h, "T1");
gcode_add_command(h, "G1 X10 Y20 F500");
gcode_start(h);
gcode_wait_for_queue_empty(h, 30000);
gcode_disconnect(h);
gcode_destroy(h);
return 0;
}Notes
- Tool numbers must be 0-7. Values outside this range will return an error.
- The
Tparameter is required. Omitting it will return an error. - All tool offsets default to zero (X=0, Y=0, Z=0) at startup.
- Offsets are applied in absolute positioning mode (G90) only. In relative mode (G91), offsets have no effect.
- Offsets persist until explicitly changed with another M218 command.
- Offset values are specified in user units (the same units configured for each axis).
Related Commands
- T0-T7 - Tool Change — Select the active tool whose offset will be applied to subsequent moves.
- G90/G91 - Positioning Modes — Tool offsets are only applied in absolute mode (G90).