G53 not ignoring tool length offset after a Python M6 remap

More
17 May 2025 12:21 - 17 May 2025 12:33 #328623 by DonatasO
Hi,

I'm writing an M6 remap in Python and encountered strange and dangerous behavior. After the first M6 call, G53 G0 takes into account the tool length offset, which should not be happening.
I'm unsure if I'm doing something wrong or if this is a bug in LinuxCNC. I hope you can help me clarify and resolve it.

LinuxCNC version: 2.9.4
UI (probably irrelevant): qtdragon_hd

This is a minimal working code to reproduce the issue:
# REMAP=M6 modalgroup=6 prolog=change_prolog python=is_this_a_bug epilog=change_epilog
def is_this_a_bug(self):
    if self.task == 0:  # ignore the preview interpreter
        return INTERP_OK

    emccanon.CHANGE_TOOL_NUMBER(self.selected_pocket)
    yield INTERP_EXECUTE_FINISH
    pose = EmcPose()
    pose.z = -50
    emccanon.USE_TOOL_LENGTH_OFFSET(pose)
    yield INTERP_OK

Steps to reproduce the issue:
  • Turn on and home the machine
  • T6 M6: the tool is loaded and offsets are set correctly.
  • G53 G0 Z0: the spindle rapids down to -50mm. This is not expected.
  • G49: cancel tool length compensation.
  • G43: enable tool length compensation
  • G53 G0 Z: the spindle rapids back up to zero. This is expected.
The issue can no longer be reproduced by issuing T6 M6, everything works correctly.

Attaching debug logs for each command:

T6 M6
Warning: Spoiler!


G53 G0 Z0
Warning: Spoiler!


G49
Warning: Spoiler!


G43
Warning: Spoiler!


G53 G0 Z0
Warning: Spoiler!
Last edit: 17 May 2025 12:33 by DonatasO.

Please Log in or Create an account to join the conversation.

More
17 May 2025 13:44 - 17 May 2025 13:48 #328628 by Aciera
Not sure but I think that 'emccanon.USE_TOOL_LENGTH_OFFSET(pose)'
might actually not be a good approach here.

 Note that 'G53' will actually use the 'tool_offset' values to calculate the target coordinates:

if(block->z_flag) {
            *pz = block->z_number - s->origin_offset_z - s->axis_offset_z - s->tool_offset.tran.z;
        } else {
            *pz = s->current_z;
        }
github.com/LinuxCNC/linuxcnc/blob/1b8867.../interp_find.cc#L197
My guess would be that your change of tool-length is possibly not reflected in 'tool_offset.tran.z'.

Generally I've become very cautious about using 'emccanon' commands to manipulate offset values  in remaps. I've had a similar issue setting work offsets this way.
I changed to using 'self.execute(..' instead (although that has its own pitfalls).

See the mentioned issue with work offsets:
forum.linuxcnc.org/20-g-code/48199-chang...-self-execute#264285
Last edit: 17 May 2025 13:48 by Aciera.

Please Log in or Create an account to join the conversation.

More
17 May 2025 14:31 #328629 by DonatasO
Thanks for the reply.

I can't use self.execute() as using INTERP_EXECUTE_FINISH is unavoidable in my procedure, and no MDI commands can be sent after it. I made it possible to switch between ATC and manual tool change (like drop tool, ask to insert a new one).

At least my understanding about emccanon.USE_TOOL_LENGTH_OFFSET() is that it's supposed to be the equivalent of G43, as it issues the same EMC_TRAJ_SET_OFFSET message. Apparently, it does not fully update the initial state.

Calling USE_TOOL_LENGTH_OFFSET() multiple times before moving does not resolve the problem.

Please Log in or Create an account to join the conversation.

More
17 May 2025 14:53 #328632 by DonatasO

My guess would be that your change of tool-length is possibly not reflected in 'tool_offset.tran.z'.

You're right, it's not updated. Setting `self.tool_offset = pose` manually resolves the issue.

Am I missing some call to auto-update it, or does it have to be handled in the remap?

Please Log in or Create an account to join the conversation.

More
17 May 2025 15:10 #328634 by Aciera

At least my understanding about emccanon.USE_TOOL_LENGTH_OFFSET() is that it's supposed to be the equivalent of G43, as it issues the same EMC_TRAJ_SET_OFFSET message. Apparently, it does not fully update the initial state.


note that 'G43' reads the tool-offset values from the tool table:
github.com/LinuxCNC/linuxcnc/blob/6c4303...erp_convert.cc#L6202

and calls emccanon.USE_TOOL_LENGTH_OFFSET() in line 6280:
  USE_TOOL_LENGTH_OFFSET(tool_offset);


BUT it also sets 'tool-offsets' in line 6299:
 settings->tool_offset = tool_offset;

So it seems that you will have to handle this in the remap.

Please Log in or Create an account to join the conversation.

More
17 May 2025 15:17 #328635 by DonatasO
Thanks again!

Looking at the file you linked, I see ways to simplify some parts in my remap.

This is resolved now. Only the tool length sensor's side will remain scarred :D

Please Log in or Create an account to join the conversation.

Time to create page: 0.115 seconds
Powered by Kunena Forum