I'm using this procedure:
first, the initialisation, which can be done with any tool, but usually with the first tool:
* pressing a button (connected to a GPIO)
* this starts an nc-file: wl-init.ngc. This moves the tool above the tool length sensor, then move down slowly until the sensor is touched.
* the touch-position is stored in global variable #2010 (which must be included in linuxcnc.var to make it global)
* then it prints a message on the screen: "manually move to the workpiece, touch the surface (Z0) and in G54 screen zero Z". The user must do this right now.
Now we got the difference between workpiece Z0 and the tool-length touch Z-position. This difference value is used for later calculation with other tools.
now, if M6 is in the g-code, a second ng-code is called: werkzeugwechsel.ngc
this is a very simple code which does:
* moves to a convenient position for manual tool change and opens a confirmation window
* the user changes the tool and confirms that on the screen
* This moves the tool above the tool length sensor, then move down slowly until the sensor is touched.
* this touch-Z-position is calculated against the #2010 and the result is stored in G43.1 (new offset)
I'm using this with qtdragon.
The files are attached. Sorry, the comments are in German, but you will understand the G codes.
Additional information:
to call the file werkzeugwechsel.ngc when M6 is detected, this has to be inluded in the ini file:
Section: [RS274NGC]
REMAP=M6 modalgroup=6 ngc=werkzeugwechsel
the initial file wl_init.ngc is called by pressing a button connected to a GPIO. This is done as usual by executing as MDI command
[HALUI]
MDI_COMMAND=o<wl_init> call
(the GPIO must be connected to halui.mdi-command-00 in the hal file)