Manual Toolchange + Abs Z Probe (QtDragon)

  • SanzuiWorks
  • SanzuiWorks's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
21 May 2025 11:45 #328853 by SanzuiWorks
Replied by SanzuiWorks on topic Manual Toolchange + Abs Z Probe (QtDragon)
So far, this method is not working well.
Nothing happens when I load the NGC. For now, I would like to try a different method.

I am considering creating an action button that retrieves the first WSC from the loaded NGC and sends it to the MDI. ...

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

  • MennilTossFlykune
  • Offline
  • Senior Member
  • Senior Member
More
21 May 2025 14:57 #328861 by MennilTossFlykune
Replied by MennilTossFlykune on topic Manual Toolchange + Abs Z Probe (QtDragon)

Reading Work Coordinates When Loading a New NGC File  

When loading a new `.ngc` file in LinuxCNC, is it possible to read the work coordinates at that stage? Since the G-code has not been executed yet, the work coordinates might not be applied.  

Would it be possible to create a custom button, similar to "WCS Sync," that reads the `.ngc` file and sends commands like `G55` to MDI?  

Has anyone implemented something similar, or does LinuxCNC provide a built-in way to achieve this? Any insights or suggestions would be greatly appreciated.

Thanks!
 

You can add this under StatCanon in qt5_graphics.py:
    def set_g5x_offset(self, index, x, y, z, a, b, c, u=None, v=None, w=None):
        interpret.Translated.set_g5x_offset(self, index, x, y, z, a, b, c, u, v, w)        
        g5x = {
            1: 54,
            2: 55,
            3: 56,
            4: 57,
            5: 58,
            6: 59,
            7: 59.1,
            8: 59.2,
            9: 59.3
        }
        print(f"G{g5x[index]} on line {self.lineno}")

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

  • SanzuiWorks
  • SanzuiWorks's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
22 May 2025 12:29 - 22 May 2025 12:55 #328910 by SanzuiWorks
Replied by SanzuiWorks on topic Manual Toolchange + Abs Z Probe (QtDragon)
MennilTossFlykune

Thank you for your advice.

I've been focusing on incorporating this all day today, but I still can't get out of the error. To be honest, I don't even know where I am now.
Last edit: 22 May 2025 12:55 by SanzuiWorks.

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

  • SanzuiWorks
  • SanzuiWorks's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
22 May 2025 15:58 - 22 May 2025 16:06 #328922 by SanzuiWorks
Replied by SanzuiWorks on topic Manual Toolchange + Abs Z Probe (QtDragon)
I’ve managed to detect WCS (G54–G59) from a loaded .ngc file and output it to the terminal.
To be precise, it prints the WCS to the terminal log.
But I haven’t yet succeeded in sending it to MDI to change the GUI WCS.

Code implemented inside qt5_graphics.py > StatCanon:
def set_g5x_offset(self, index, x, y, z, a, b, c, u=None, v=None, w=None):
    g5x = {
        1: "G54", 2: "G55", 3: "G56", 4: "G57",
        5: "G58", 6: "G59", 7: "G59.1", 8: "G59.2", 9: "G59.3"
    }
    print(f"[DEBUG] {g5x.get(index)} on line {self.lineno}")
    super().set_g5x_offset(index, x, y, z, a, b, c, u, v, w)

Sample G-code:
G21
G90
G55
G0 X10 Y10
M2

Terminal output:
[DEBUG] G54 on line 0
[DEBUG] G55 on line 3
[DEBUG] G54 on line 5

As you can see, G54 appears at both the top and bottom.
This needs further filtering to ensure only the first actual WCS used in the program is considered.
Last edit: 22 May 2025 16:06 by SanzuiWorks.

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

  • SanzuiWorks
  • SanzuiWorks's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
26 May 2025 16:32 - 24 Jun 2025 13:57 #329166 by SanzuiWorks
Replied by SanzuiWorks on topic Manual Toolchange + Abs Z Probe (QtDragon)
I finally managed to implement this and it seems to work very well.

What it does:
- Detects the first G5x coordinate system (G54–G59.3) used in a G-code file
- Prints a debug log to the terminal: [DEBUG] G57 on line 4
- Sends the detected G5x via MDI so that the GUI updates to reflect the active work coordinate system

How I implemented it:
I added the following method to the StatCanon class in:
/usr/lib/python3/dist-packages/qt5_graphics.py

def set_g5x_offset(self, index, x, y, z, a, b, c, u=None, v=None, w=None):
    print("[DEBUG-TRACE] >>> set_g5x_offset() is running <<<")

    g5x = {
        1: "G54", 2: "G55", 3: "G56", 4: "G57",
        5: "G58", 6: "G59", 7: "G59.1", 8: "G59.2", 9: "G59.3"
    }

    print(f"[DEBUG] set_g5x_offset() called: {g5x.get(index)} on line {getattr(self, 'lineno', '?')}")

    if not getattr(self, "g5x_mdi_sent", False):
        if self.lineno > 0:
            self.g5x_mdi_sent = True  
            print(f"[DEBUG] Sending initial MDI: {g5x.get(index)}")
            try:
                import linuxcnc
                c = linuxcnc.command()
                c.mode(linuxcnc.MODE_MDI)
                c.wait_complete()
                c.mdi(g5x.get(index))
                print(f"[DEBUG] Sent MDI: {g5x.get(index)}")
            except Exception as e:
                print(f"[ERROR] Failed to send MDI: {e}")

    super().set_g5x_offset(index, x, y, z, a, b, c, u, v, w)


Notes:
- Make sure this method is placed inside the StatCanon class with consistent 4-space indentation.
- The initial G54 on line 0 and final G54 at the end (due to GUI reset) are ignored using: self.lineno > 0
- Only the first explicitly used G5x is applied via MDI.
- Verified to work reliably in QtDragon simulator config.

This improves usability by ensuring the GUI’s coordinate system matches what the G-code will actually use.

Tested with:
- LinuxCNC 2.9.4
- QtDragon (QtVCP)
- sim.qtdragon.qtdragon_tool_probe configuration

Let me know if this is helpful or if there’s a cleaner way to hook into the coordinate system logic.
Last edit: 24 Jun 2025 13:57 by SanzuiWorks.

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

Moderators: cmorley
Time to create page: 0.186 seconds
Powered by Kunena Forum