Hacky solution to show estimated completion time for loaded program

16 Jan 2022 18:02 - 16 Jan 2022 18:05 #232038 by kimdanielarthur
I wanted to show the estimated and running time for program in my gladevcp UI panel. Ignoring the fact that the estimated time may be off by quite a bit.

Given that there the "file->properties" dialogue in the Axis UI that shows the estimated time I wanted to expose the same calculated time to my gladevcp panel.

Since the gladevcp python file is in a seperate procesa and I could not find a way to access needed information through available python librares (linuxcnc, hal, halgui and so on) my slightly hacky workaround was to:
1. Use the USER_COMMAND_FILE that has access to Axis objects to interact with gcode-data and reuse the same code that populates the estimated time for "file-properties" panel
2. Monitor if a new file has been loaded through user_live_update() function. (I could not find anywhere to add an eventlistener...)
3. Write the estimated time for program to a temporary file when a new file has been loaded by Axis GUI
4. On the other side in my gladevcp python script - Listen to file changes through a gllib.timeout_add_seconds() function called every second
5. Load time estimate from temporary file in step 2
6. Display in my gladevcp

In my USER_COMMAND_FILE python file:
lastLoadedFile = ""
def user_live_update():
    global lastLoadedFile
    if loaded_file:
        if loaded_file <> lastLoadedFile:
            runTime = calculateRunTime(loaded_file)
            print("New file loaded: " + loaded_file + " - " + str(runTime) + " seconds")
            lastLoadedFile = loaded_file
            f = open("/home/pi/ektefilewatcher", "w")
            f.write (loaded_file + "\r\n")
            f.write (str(runTime) + "\r\n")
#logic copied from axis.py in linuxcnc source
def calculateRunTime(loaded_file):
    runTime = ""
    if not loaded_file:
        return 0
        mf = vars.max_speed.get()
        return (sum(dist(l[1][:3], l[2][:3])/min(mf, l[3]) for l in o.canon.feed) +
            sum(dist(l[1][:3], l[2][:3])/min(mf, l[3])  for l in o.canon.arcfeed) +
            sum(dist(l[1][:3], l[2][:3])/mf  for l in o.canon.traverse) +
In my gladevcp python file
def __init__(self, halcomp,builder,useropts):
        self.builder = builder
        self.isRunning = False
        self.runTime = 0
        self.estimatedTime = 0
        self.lastFile = ""
        glib.timeout_add_seconds(1, self.on_timer_tick)

def on_timer_tick(self, userdata=None):
        currentFile = s.file
        if(currentFile != self.lastFile):
            f = open("/home/pi/ektefilewatcher", "r")
            watchedFile = f.readline().strip()
            fileTime = float(f.readline())
            if(watchedFile == currentFile ):
                print("got new file time: " + currentFile + " - " + str(fileTime) )
                self.lastFile = currentFile
                self.estimatedTime = fileTime
                self.builder.get_object("ekte_filetiming_display").set_label("" + self.getTime(self.estimatedTime))
        return True

This is a very rounad about way of doing it, but atleast I got what I wanted. Does anyone know of a easier way to do this?
Last edit: 16 Jan 2022 18:05 by kimdanielarthur. Reason: wrong code pasted

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

16 Jan 2022 20:48 #232064 by chris@cnc

[code]This is a very rounad about way of doing it, but atleast I got what I wanted. Does anyone know of a easier way to do this?

I have no idea.
I search over one year to pick up the estimated run time. But i can't find anything how this time is calculated and not understand your code. Basically reason I'm a mechanic. I use axis and PYVCP panel. 
How do calculating the time, and it's possible to import in pyvcp? In the end, I want to do a real-time calculation.
("estimated run time" - "halui.program.is-running") to see actual estimated program end time. Sure, this time is not true but more than nothing and in case of 4h runtime are 15 min doesn't matter. It's more or less good to know when to be back.

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

17 Jan 2022 07:44 #232098 by kimdanielarthur
Yes its nice to see it, even though it is accurate. We are many people at workshop that use CNC and it is good to be able to get a rough idea of timing.

In order to get the solution I am using to work you need to have python scripts set up for both axis and your pyvcp. do you have that already? They way I have done it is not elegant and requires some manual coding and not just using pins, so I think it is best if you have done a little bit of python?

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

Moderators: mhaberler
Time to create page: 0.106 seconds
Powered by Kunena Forum