Macro calculating tool length difference

I am writing macros to control tool changes on a rotary. The first probe probes the rotary and then probes the set probe plate. Subsequent tool probes are done at the plate. This macro works and the new work zero is correct.

However I need to adjust the height of the tool when it returns to the original work position saved prior to the current tool change. I am not sure how to go about calculating the tool difference between the prior tool and the current tool. So far everything I have tried has failed. Any assistance would be appreciated.

You’d need to store the original tool touch plate zpos as the offset. On subsequent probes, the tool difference is always the difference between the zpos of the subsequent probe(s) and the first probe, which you can use by setting the Z on subsequent probes to the initial tool reference.

This is very close to what we do on fixed tool changing routines in the past.

You’d have to be more specific about what’s failing for you if you want more help.

I’d maybe reference the CNCjs TC macros by Neil Ferreri as for one approach on adjusting tools using the above strategy - it saves a TOOL_REFERENCE in one macro in the global namespace (so it persiss between macros/feeder runs) and then uses that in subsequent macros to adjust the Z after probe.

You can do similar thing using G43.1 - see the following (modified) TC macros for an idea how. It still uses TOOL_REFERENCE in the global state across macros.

For rotary toolchanging specifically, I’d be mindful of safe movements going to the probe block and back to the rotary chuck to avoid collisions.

Thanks. SLB is quite new to me. I have been following the code examples and have the initial tool and tool change working as it should. The issue is if I change to a longer tool then
; Keep a backup of current work position
%X0=posx, Y0=posy, Z0=posz

can cause an issue when returning to the work piece. I see the above example just returns to the top of Z height. Although this will work it would be better to return to the original change position. To do this I need to know the actual tool difference and I thought it would be easy by storing the prior tool in a global variable, after all it is called a variable, but I can’t update the global variable with each new tool length value. Maybe safe height will have to do. I did see someone say they used G59 but I have searched and cannot find it again. I am trying that out today to see what I can come up with.

So today I zeroed the top of the TLS during the tool measurement to G59 coordinate G10 L20 P6 Z0’

Now when I measure the new tool G59 Z reflects the difference from the prior tool probe.

I apply that to the saved [posz] when starting the tool change which returns me to the same work piece tool tip position prior to changing the tool

Glad you got it working!