Total Machine time

  • anfänger
  • anfänger's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
11 Aug 2020 11:31 - 18 Aug 2020 20:17 #177884 by anfänger
[solved ]Total Machine time was created by anfänger
Hi,

I have some maintainance schedules for my machine (50 hours for some filters and 2000 hours for greasing ways and spindles)
So I would like to have a timer that’s counting as long as the machine is powered on but does not loose the information when powered of. Can I use time for this or will it loose its information with shutdown?
I am using 2.8 with qtpyvcp / Probe basic

Thanks Patrick
Last edit: 18 Aug 2020 20:17 by anfänger.

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

More
12 Aug 2020 12:00 #178032 by RotarySMP
Replied by RotarySMP on topic Total Machine time
I don't know how to do it, but LinuxCNC records the machine position to a file one shut down, and reads it in on start up, so you must be able to add what you want.
Mark

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

  • anfänger
  • anfänger's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
12 Aug 2020 12:15 #178033 by anfänger
Replied by anfänger on topic Total Machine time
This I already do. I know I had one in my debug tab in gmocappy but I can‘t find my old files to check how i it was done and i i can transfer this to probe basic.

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

More
15 Aug 2020 01:37 #178221 by Himarc3D
Replied by Himarc3D on topic Total Machine time
You get it running now ?
check this threads if not;

forum.linuxcnc.org/10-advanced-configura...e-studdies-ugh#44268

www.forum.linuxcnc.org/21-axis/12553-axis-log

I think every program language these days have library for CSV support.
If you dont need to be very specific maybe you can try Tuptime, its in Python and have CSV support...the code is open and maybe you can change it for your need or just start automatically LCNC and use Tuptime (system uptime) and consider it is the machine uptime...
The linuxCNC machine position at start up and shutdown will log even if you dont use the machine, if so its similar to Tuptime.
I need check the LCNC log file to see what happen if for example the machine loose power, the log will be there for power failure?
im still learning Linux, cron job, grep, ps etc so many things...very powerful CLI in Linux and system config file is all in .txt, very nice!

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

  • anfänger
  • anfänger's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
16 Aug 2020 17:35 - 18 Aug 2020 20:16 #178417 by anfänger
Replied by anfänger on topic Total Machine time
And yes linux is awesome. My only problem with linuxcnc is that I can't write python code. But I can use bash and perl. So the timelpg.py script (in the Time Studies thread ) should give me enough to make something out of it.
Last edit: 18 Aug 2020 20:16 by anfänger.

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

  • anfänger
  • anfänger's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
18 Aug 2020 20:17 - 20 Aug 2020 17:59 #178625 by anfänger
Replied by anfänger on topic Total Machine time
If someone is interested this code which seems to work.
#!/usr/bin/python

import time
import hal

fname = "timelog.txt"
sumlog = "time.txt"

delta_t = 1 # seconds poll interval, hold inputs at least this long
f = open(fname,mode="a+") # a: append or create if file doesnt exist
h = hal.component("timelog")
h.newpin("active",hal.HAL_BIT,hal.HAL_IN)
h.newpin("seconds",hal.HAL_U32,hal.HAL_OUT)
h.newpin("minutes",hal.HAL_U32,hal.HAL_OUT)
h.newpin("hours",hal.HAL_U32,hal.HAL_OUT)
h.ready()

try:
        f2= open(sumlog,mode="r+")
        runtime=float(f2.readline())
        f2.close()
except:
        f2= open(sumlog,mode="w+")
        runtime=0.0
        f2.write(str(runtime))
        #f3.flush()
        f2.truncate()
        f2.close()


m, s = divmod(runtime, 60)
hr, m = divmod(m, 60)
#print(hr,m,s)
h["seconds"]=s
h["minutes"]=m
h["hours"]=hr
old_start_pin_value = False
t_start = time.time()
t_begin = time.time()

msg = ("Begin %s\n" % time.ctime())
f.write(msg)
f.flush()
started = False
while True:
    time.sleep(delta_t)
    #print h["active"]
    start_pin_value = h["active"]
    if start_pin_value != old_start_pin_value:
        print("changed")
        if started:
            started = False
            print("timer off")
            t_now = time.time()
            msg = ("Stop:  %s Elapsed: %f\n" % (time.ctime(),t_now - t_start))
            f.write(msg)
            f.flush()
            runtime=seconds
            savetime=str(seconds)
            print savetime
            f2= open(sumlog,mode="w+")
            f2.write(savetime)
            #f3.flush()
            f2.truncate()
            f2.close()
        else:
            started = True
            print("timer on")
            msg = ("Start: %s\n" %time.ctime())
            f.write(msg)
            f.flush()
            t_start = time.time()
            f2= open(sumlog,"r")
            runtime=float(f2.readline())
            f2.close()
            print runtime

    if start_pin_value: 
        seconds= runtime+(time.time() - t_start)
        m, s = divmod(seconds, 60)
        hr, m = divmod(m, 60)
        h["seconds"]=s
        h["minutes"]=m
        h["hours"]=hr
    old_start_pin_value = start_pin_value
Last edit: 20 Aug 2020 17:59 by anfänger. Reason: Edited code
The following user(s) said Thank You: RogEnk

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

More
20 Aug 2020 07:57 #178805 by Himarc3D
Replied by Himarc3D on topic Total Machine time
Glad you figure it out. Looks like i need learn Python too...the minimum.

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

  • anfänger
  • anfänger's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
20 Aug 2020 08:08 #178806 by anfänger
Replied by anfänger on topic Total Machine time
Me too :dry:

Next thing is the remote control of my air compressor.
I installed the Shelly yesterday :side:

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

More
21 Aug 2020 10:25 #178915 by Mike_Eitel
Replied by Mike_Eitel on topic Total Machine time
How do you intend to connect the shelly.
What i found is that it should be possible to use plcopen to convert the Shelly into a ModBusTCP remoteIO. Using arduino ide. Did that for an oak device, was not too difficult.
Mike

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

  • anfänger
  • anfänger's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
21 Aug 2020 10:39 - 21 Aug 2020 10:40 #178916 by anfänger
Replied by anfänger on topic Total Machine time
They have an http api you can use I wrote a python hal module for me:

forum.linuxcnc.org/38-general-linuxcnc-q...uxcnc?start=0#178821

You can actually also analyse the feedback from the Shelly if you want and do a lot more, but for me this is enough.
Last edit: 21 Aug 2020 10:40 by anfänger.

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

Time to create page: 0.102 seconds
Powered by Kunena Forum