Back to Supported G-Codes

M218 - Set Tool Offset

DMC File Mode: Not Supported
Streaming Mode: Supported

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

M218 T<n> X<offset> Y<offset> Z<offset>
M218 T<n> X<offset>
M218 T<n> Z<offset>

Parameters

ParameterRequiredDescriptionExample
TYesTool number (0-7)T1
XNoX-axis offset in user unitsX0.5 or X-1.2
YNoY-axis offset in user unitsY-0.3
ZNoZ-axis offset in user unitsZ1.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:

actual_target = commanded_position + tool_offset

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

; Define offset for tool 1
M218 T1 X0.5 Y-0.3 Z1.2
; Select tool 1
T1
; Move to X10 — actual target becomes X10.5 due to offset
G0 X10

Multi-tool workflow

; Configure offsets for two tools
M218 T1 X1.0 Y0.0 Z-0.5
M218 T2 X2.0 Y0.5 Z0.0
 
; Machine with tool 1
T1
G1 X10 Y20 F500
 
; Switch to tool 2 — offset changes automatically
T2
G1 X10 Y20 F500

Partial offset update

; Set all three axes for tool 3
M218 T3 X1.0 Y2.0 Z3.0
; Update only X — Y and Z remain at 2.0 and 3.0
M218 T3 X1.5

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 T parameter 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