How to measure tool offset with fixed tool sensor in PlanetCNC TNG software

This tutorial will explain how to correctly use Tool Offset / Measure  feature with fixed tool sensor using PlanetCNC TNG software and PlanetCNC motion controllers.


Fixed tool sensor

For fixed tool sensor we can use a dedicated tool measuring switch or, most basic solution, a standard micro switch fixed to machine table.

When tool activates tool sensor, controllers corresponding input is activated and software sets new tool offset value.

Example of fixed tool sensor used with Mk3 controller:


Connecting movable sensor with PlanetCNC motion controller

MK3 controller:



Mk3/4 controller:


MK3DRV controller:


MK3ECO controller:


Configuring fixed tool sensor in  PlanetCNC TNG software

In PlanetCNC TNG under File/Settings/Program Options/Measure configure input pin that you intend to use for fixed tool sensor.

You can select between either Sensor 1 or Sensor 2 option. It doesn’t matter which one you choose.


Sensor input pin is selected from drop down menu:

Now that your sensor is connected and configured, it is best to activate sensor by hand to check if everything is functioning OK. Jog your machine (it can be in any direction) and see if machine stops when you activate sensor.

Under IO tab of main display check if input is activated correctly:


Now move  machine to position where fixed sensor is mounted. Make sure that tool is right above the center of fixed tool sensor or in case that you use micro switch, above the lever.

Write down Machine coordinates of  X and Y axis. These values will be used for configuration of sensors X and Y axis position:


Jog Z axis towards the sensor. When sensor is activated, write down Machine coordinate of  Z axis. This value will be used for configuration of sensor Z axis position:


Under File/Settings/Program Options/Measure/Fixed Sensor/Sensor Position, insert values that you previously wrote down.



Measuring tool offset with  PlanetCNC TNG software

Tool offset measure procedure can be executed via menu item Machine/Tool Offset/Measure or  with left toolbar button:


Default sequence of Tool Offset Measure procedure:

-Machine will ascend to safe height and move from current position to sensors XY position(the one we set in settings).

-Machine will descend towards sensor with probe speed and when sensor gets activated, machine will stop and ascend to safe height.

-Software will set new tool offset value

-Machine will return back to XYZ position


Measure tool offset script file

Work Position Measure procedure uses script file. If you would like to edit script code or have more in-depth look at the procedure itself, you can do that by opening script file.

You can generate, access and edit script file  in two ways:

a.) In settings under File/Settings/Program Options/Scripts/Tool Offset -> Tool Offset Measure click button Edit Script.  Script file will open in your default text editor.


b.) When you execute tool Offset Measure procedure for the first time, either via toolbar button or via Machine menu, _Tool_Offset.Measure.gcode default file will be created. Locate your PlanetCNC TNG software installation folder and locate script file under Profiles/Default/Scripts ->_Tool_Offset.Measure.gcode


Default script code:

O<PlanetCNC> if[[#<_sensor1_pin> GT 0] OR [#<_sensor2_pin> GT 0]]
M70 (store state)
#<xpos> = #<_x> (store current x position)
#<ypos> = #<_y> (store current y position)
#<zpos> = #<_z> (store current z position)
G90 (absolute mode)
G53 G0 Z#<_motorlimit_zp> (move to safe height)
G53 G0 X#<_sensor_x> Y#<_sensor_y> (move to tool sensor position)
F#<_speed_probe> (set probe speed)
G38.2 Z-100000 (touch down)
G43.1 Z[#<_probe_z> - #<_sensor_z>] (set tool offset)
G53 G0 Z#<_motorlimit_zp> (move to safe height)
G0 X#<xpos> Y#<ypos> (move to last xy position)
#<zposm> = [ToMachine[#<zpos>, 2]] (calculate new machine position of last z)
o<100> if[[#<zposm> LT #<_motorlimit_zp>] AND [#<zposm> GT #<_motorlimit_zm>]]
G0 Z#<zpos> (move to last z position)
o<100> endif
M72 (restore state)
O<PlanetCNC> else
(msgdlg,Sensor is not configured)
O<PlanetCNC> endif


Description of parameters and g-codes(in order of appearance in script g-code):

This g-code saves states of of all modal g-codes currently used by software. When Machine.Tool_Offset.Measure_Tool.gcode procedure is executed in its entirety, all states will be restored to their previous values.

#<xpos> = #<_x> (store current x position): Stores value of current X axis position as parameter #1.
#<ypos> = #<_y> (store current y position):
Stores value of current Y axis position as parameter #2.
#<zpos> = #<_z> (store current z position):
Stores value of current Z axis position as parameter #3.

With G90 g-code we set absolute mode of motion. Prior to “Measure Tool” procedure , motion mode could be different so we used M73 to save current modal states.

G53 G0 Z#<_motorlimit_zp>: Machine ascends to safe height.

G53 G0 X#<_sensor_x> Y#<_sensor_y>: Machine moves to sensor XY position.

F#<_speed_probe>: Speed at which machine descends to measure tool. Set with Probe Speed in settings(File/Settings/Program Options/Probe Speed). This value can be set directly with new F value. In such case you should delete the “#<_speed_probe>” line of code.

G38.2 Z-100000: This g-code moves selected axis in selected direction. G38.2 g-code uses parameter X(-/+)Value,Y(-/+)Value or Z(-/+)Value which define to which coordinate value machine should move and in what direction. When probe activation occurs over the time of machine travel, machine will stop.

G43.1 Z[#<_probe_z> – #<_sensor_z>]: When G38.2 g-code senses that sensor is activated and stops the machine, this g-code sets tool offset.

G53 G0 Z#<_motorlimit_zp>: Machine moves in absolute coordinates to safe height.

G0 X#<xpos> Y#<ypos> (move to last xy position): Rapid move to position from which we started the “Measure Tool” procedure .

#<zposm> = [ToAbs[#<zpos>, 2]]: calculate new absolute position of last z

o<100> if[[#<zposm> LT #<_motorlimit_zp>] AND [#<zposm> GT #<_motorlimit_zm>]]
G0 Z#<zpos> (move to last z position)
o<100> endif

With this subroutine program we make sure that even with new tool offset value, we are safely within Z axis machine limits when machine moves back to position from which we started the “Measure Tool” procedure .