Displaying Active Work Coordinate System

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
21 Aug 2025 15:46 #333762 by Todd Zuercher
Displaying Active Work Coordinate System was created by Todd Zuercher
I'm trying to modify a GladeVCP to have a label that displays the current active work coordinate system.  And to put it bluntly Python is kicking my butt.  So how exactly would one set up the python handler file to read the linuxcnc stat.g5x_index then use that to change the string that is displayed in the gtk label? 
In my  GladeVCP the label I want to use is named "work_coord_label" and I would like the label to read "G54(front)" when the G54 coordinate system is active, and "G55(Rear)" when G55 is active.  (The other coordinate systems can meerly read G56,G57... as there is no plan to use them at this point.)

PS.  This is on a machine running Linuxcnc ver 2.7.25 (And I don't think I can ugrade because this system requires a very low latency RTAI config that I don't think I can easily replicate with newer versions.)
Attachments:

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

More
22 Aug 2025 01:28 - 22 Aug 2025 01:31 #333768 by cmorley
Replied by cmorley on topic Displaying Active Work Coordinate System
I think you need to add a timer to call a function to read linuxcnc's stat.
Here is most of the odea - not tested:

# add this at top:
import gobject

#add this to to bottom of __init__ :
# called every 100 ms
gobject.timeout_add(100, self.periodic_check)
self.last = 1
self.convert = { 1:"G54(Front)", 2:"G55(Rear)", 3:"56", 4:"57", 5:"58", 6:"59", 7:"59.1", 8:"59.2", 9:"59.3"}

# add this function
def periodic_check(self):
    self.stat.poll()
    current =  self.stat.g5x_index
    if current != self.last:
        text = self.convert[int(current)]
        # update label
        self.builder.get_object('work_coord_label').set_text(text)
    self.last = current
    return True
Last edit: 22 Aug 2025 01:31 by cmorley.
The following user(s) said Thank You: Todd Zuercher

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
22 Aug 2025 10:58 #333772 by Todd Zuercher
Replied by Todd Zuercher on topic Displaying Active Work Coordinate System
Well, not sure why but it isn't working.  I'm seeing several references to "object has no attribute 'stat'" in the terminal, the first 3 of which were there before adding this modification to the glade panel.   Any ideas what I'm doing wrong?

Here is what was printed to the terminal.
digital4@digital4:~/Desktop$ linuxcnc
LINUXCNC - 2.7.15-28-gd7ded6e
Machine configuration directory is '/home/digital4/linuxcnc/configs/Digital_4g'
Machine configuration file is 'double.ini'
Starting LinuxCNC...
.
Found file(REL): ./Digital_4w.hal
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 99, in _f
    return f(self, *a, **kw)
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 461, in on_activate
    ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)
AttributeError: 'EMC_Action_MDI' object has no attribute 'stat'
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 99, in _f
    return f(self, *a, **kw)
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 461, in on_activate
    ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)
AttributeError: 'EMC_Action_MDI' object has no attribute 'stat'
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 99, in _f
    return f(self, *a, **kw)
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 461, in on_activate
    ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)
AttributeError: 'EMC_Action_MDI' object has no attribute 'stat'
/usr/bin/gladevcp:212: RuntimeWarning: missing handler 'on_window1_destroy'
  builder.connect_signals(handlers)
Xlib.protocol.request.QueryExtension
Xlib.protocol.request.QueryExtension
Traceback (most recent call last):
  File "./double.py", line 47, in periodic_check
    self.stat.poll()
AttributeError: HandlerClass instance has no attribute 'stat'
^Ctask: 105602 cycles, min=0.000034, max=0.022691, avg=0.010203, 0 latency excursions (> 10x expected cycle time of 0.010000s)
Traceback (most recent call last):
  File "/usr/bin/axis", line 3549, in <module>
    o.mainloop()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1035, in mainloop
    self.tk.mainloop(n)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1432, in __call__
    def __call__(self, *args):
KeyboardInterrupt
Shutting down and cleaning up LinuxCNC...
Attachments:

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

More
22 Aug 2025 21:57 #333783 by cmorley
Replied by cmorley on topic Displaying Active Work Coordinate System
You have commented out the line that defines self.stat:
class HandlerClass:
    def __init__(self, halcomp,builder,useropts):
        self.builder = builder
        self.halcomp = halcomp
#        self.stat = linuxcnc.stat()

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
23 Aug 2025 01:10 #333785 by Todd Zuercher
Replied by Todd Zuercher on topic Displaying Active Work Coordinate System
I had noticed that just after I posted it, but I thought I tried uncommenting it and it I didn't think it seemed to make any difference. (Error messages were still the same and the Label didn't change.)

But I thought I had better test again before posting a reply. I loaded up a 2.7 Wheezy live cd image in a VM and ran a simulation with this GladeVCP files (and that line uncommented, and it works! I don't know maybe I forgot to save after uncommenting that line earlier today. But I'll have to wait until Monday to try it out on the real machine at work.

Thanks alot for your help.

PS any ideas on these other "error" messages that show up in the terminal but with no noticeable effect on functionality.
File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 99, in _f
    return f(self, *a, **kw)
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 461, in on_activate
    ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)
AttributeError: 'EMC_Action_MDI' object has no attribute 'stat'
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 99, in _f
    return f(self, *a, **kw)
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 461, in on_activate
    ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)
AttributeError: 'EMC_Action_MDI' object has no attribute 'stat'
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 99, in _f
    return f(self, *a, **kw)
  File "/usr/lib/pymodules/python2.7/gladevcp/hal_actions.py", line 461, in on_activate
    ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)

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

More
23 Aug 2025 23:48 - 23 Aug 2025 23:51 #333830 by cmorley
Replied by cmorley on topic Displaying Active Work Coordinate System
Glad you got it to work.
It errors for timing reasons it seems, the function get called before all the initiation is done.
After initiation then there is no more errors.
I ran your panel in master and it's the same.

You can quiet the message by changing the code in hal_actions.py
def on_activate(self, w):
    try:
        ensure_mode(self.stat, self.linuxcnc, linuxcnc.MODE_MDI)
        template = HalTemplate(self.command)
        cmd = template.substitute(FloatComp(self.hal))
        self.linuxcnc.mdi(cmd)
    except Exception as e:
        pass
        #print(self.get_name(),e)

 
Last edit: 23 Aug 2025 23:51 by cmorley.
The following user(s) said Thank You: Todd Zuercher

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
25 Aug 2025 01:25 #333876 by Todd Zuercher
Replied by Todd Zuercher on topic Displaying Active Work Coordinate System
I had assumed it was something I had wrong in my .py file. I'm not bothered by them if they are not really a problem.

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

Moderators: HansU
Time to create page: 0.074 seconds
Powered by Kunena Forum