Hello Guest it is March 28, 2024, 10:18:01 AM

Author Topic: Mach4 Timer Script  (Read 3228 times)

0 Members and 1 Guest are viewing this topic.

Mach4 Timer Script
« on: April 30, 2019, 10:31:01 AM »
I’d like to have a timer start and stop a lub pump after an hour of spindle on time. That would be an accumulated time of spindle on and off time. The scr.StartTimer(#,Time,oneshot) starts the event after the time has expired. The scr.StopTimer(#) seems to cancel the timer before the event. I’d like to start and then pause the timer and then restart. The scr.RestartTimer(#) doesn’t seem to have any effect on the timer. How Is the RestartTimer supposed to work? Thanks for any help.
 
« Last Edit: April 30, 2019, 10:44:25 AM by Tony Bullard »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach4 Timer Script
« Reply #1 on: April 30, 2019, 11:42:38 AM »
I'm not sure about the RestartTimer but think I know how i would handle it.

In the PLC script keep up with spindle on time. If it's on increment a var. Once that var == Time wanted / scan time start a one shot timer for the amount of time I want the lube on, turn the lube output on and reset that var to 1. The timer would just turn the lube output off.
« Last Edit: April 30, 2019, 11:50:21 AM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach4 Timer Script
« Reply #2 on: April 30, 2019, 12:50:43 PM »
This might help if you go with my suggestion.

Code: [Select]
local scrName = scr.GetScreenName()
local inter = scr.GetProperty(scrName, "PLC Interval")
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach4 Timer Script
« Reply #3 on: May 01, 2019, 01:42:50 PM »
Thank you. This looks promising. I've set up a register and functions to get and wright to them. My plc Interval is 50. I run this code in the PLC Script for a test. The functions are in the Screen Load Script.

local val = GetRegister("HurcoTimer")
val = val + 1
WrightRegister("HurcoTimer", val)

I am in demo mode. The PLC Interval seems to be much slower than 50. I get 1000 counts in 62 seconds repeatedly. Any suggestions? thanks.
Re: Mach4 Timer Script
« Reply #4 on: May 01, 2019, 02:43:09 PM »
Hi,
I think the PLC script runs as an interrupt routine. The interrupt interval might be 50 ms but the PC looks to be
taking 12 ms or so to respond to the interrupt and reset the timer which results in a 62 ms delay between script runs.

Relying on the PLC script interval as an accurate timing mechanism is not realistic. In this case does it matter unduly
if the lube pump runs after 1hr spindle time or 1hr 5 min?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Timer Script
« Reply #5 on: May 01, 2019, 03:31:54 PM »
Thank you Craig. No the timing is not critical and I can easily adjust the code to use it for the lub pump. As much as I'd like to do most everything in Mach4 I may just use an Arduino with its millis function for the timed events.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach4 Timer Script
« Reply #6 on: May 01, 2019, 04:51:47 PM »
Yup, Craig is right. And I would not use the PLC loop count if accuracy is critical.

You could do some testing and adjust the script but things could change it (like adding more script to the PLC script itself). Would it ever change enough to matter in most cases? No but each line of code takes time to process.

Any of the following would yield more accurate results I think..... os.date, os.difftime, mc.mcCntlGetRunTime at the expense of added complexity.

All ways would have a rounding error.

Lots of ways to skin this cat. Knowing how good is good enough may be the determining factor.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach4 Timer Script
« Reply #7 on: May 02, 2019, 08:04:28 AM »
Hi,
I've been looking at the provisions of wxTimer. It would appear that could be used.

https://docs.wxwidgets.org/trunk/classwx_timer.html

Thus a Lua statement like:

MyLubeTimer:start(-1)   would cause the previously defined wxTimer called MyLubeTimer to restart from it
previous stop time. Thus the timer would accumulate. Your m3 and m4 macros would each contain such a timer
start statement and your m5 macro would contain a timer stop statement.

In your PLC script you would test the sate of the timer, once 1 hour had accumulated the lube pump would be run.
The timer could then be reset and it would start to accumulate again.

I have yet to complete my experimentations with wxTimer to confirm my idea. If it works as I imagine that would allow
you to track spindle on time to within seconds.

Quote
As much as I'd like to do most everything in Mach4 I may just use an Arduino with its millis function for the timed events.

This adds complexity.......but then so does the programming that Brett has hinted at or the wxTimer idea that I have
outlined. The question is 'does the required accuracy warrant the extra complexity', the operative word is 'required',
not 'wanted' or 'desired' or 'I really want to skite about this' or 'my mother told me I'd go blind doing this'
BUT 'required'.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Timer Script
« Reply #8 on: May 03, 2019, 07:32:13 AM »
  MyLubeTimer:start(10000) starts the timer for 10seconds.

MyLubeTimer:Stop()  stops the timer.

MyLubeTimer:start(-1) restarts MyLubeTimer for 10 seconds. In other words the default valve.
 
I think I'll take another look at the TimerPanel.
Re: Mach4 Timer Script
« Reply #9 on: May 03, 2019, 01:12:40 PM »
Is there a way to use the Time Function # variables in scripts?
From Mach4 Mill Gcode Programing.pdf