Hacky solution to show estimated completion time for loaded program

More
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")
            f.close()
#logic copied from axis.py in linuxcnc source
def calculateRunTime(loaded_file):
    runTime = ""
    if not loaded_file:
        return 0
    else:
        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) +
            o.canon.dwell_time
            )
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):
        s.poll()
        currentFile = s.file
        if(currentFile != self.lastFile):
            f = open("/home/pi/ektefilewatcher", "r")
            watchedFile = f.readline().strip()
            fileTime = float(f.readline())
            f.close()
            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?
Attachments:
Last edit: 16 Jan 2022 18:05 by kimdanielarthur. Reason: wrong code pasted

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

More
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?
[/code]


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.

More
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.

More
23 Jan 2023 19:19 #262760 by jpa
(Cross-posting to this topic because the Axis Modifications topic is a bit long and not read by everyone.)

I made this snippet to add G-code progress & remaining time estimate to the Axis status bar:
github.com/HacklabJKL/sergei_cnc2/commit...7983c7956d92219af00f



Like the estimate in File -> Properties this does not take acceleration into account, so it will typically estimate a bit shorter time and run negative at the end of the G-code. It does take into account the current feedrate overrides, and updates in real time even if they are changed in the middle of the job.

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

More
23 Jan 2023 19:39 - 23 Jan 2023 19:40 #262763 by HansU
I did this github.com/hansu/linuxcnc/blob/gremlin/s...mlin/gremlin_test.py some time ago
to get that information, not sure if it is more accurate than your solution.
Just run that script with a running LinuxCNC 2.8 to test it.
It is basically an adapted version of github.com/LinuxCNC/linuxcnc/blob/master...f/gremlin/gremlin.py

Only the extents show different values, because the offset is not incorporated here, but inside Axis it is (or the other way around).
Last edit: 23 Jan 2023 19:40 by HansU.

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

More
18 May 2023 11:44 #271606 by kang2k
Please help edit this module. My machine have 3 axis, XZA, and this script exit with error in line "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) +"

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

More
18 May 2023 14:34 #271611 by HansU
You can now use the 'graphics-gcode-properties' message from the GStat module: linuxcnc.org/docs/2.9/html/gui/gstat.html

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

Moderators: mhaberlerHansU
Time to create page: 0.278 seconds
Powered by Kunena Forum