Here is a little subroutine I created today to give live feedback to an operator. Did a pretty good job of improving throughput. Calculates a moving average of the last ten runs. Written for a Super Mini Mill.
I heavily comment my stuff to make it easy to understand for our non CNC machinists.
Code:
%
O40002 (Parts per hour running average)
(Subroutine calcs the number of parts )
(that are being produced per hour )
(This is calculated based on the time taken )
(between calls stored in a)
(10 position ring buffer.)
(** Required Arguments **)
("D" count of parts per run)
(** Macro vars used **)
(670-679 used for ring buffer)
(681 Current position in buffer)
(682 Calculated parts per hour )
(3001 is th HAAS millisec timer)
(Checks to see if buffer position needs to)
(return to zero.)
IF[#681 GT 9] THEN #681 = 0
#[670 + #681] = #3001 (Store timer value)
#681 = #681 + 1 (Increment buffer position)
#3001 = 0 (Reset timer)
#1 = 0 (Loop counter)
#2 = #681 (Ring buffer average starting point)
WHILE[#1 LT 10]DO1
#3=#3 + #[670 + [#2 MOD 10]]
#2 = #2 + 1
#1 = #1 + 1
END1
#4 = #3/10 (Divide by buffer size for average)
#4 = #4/1000 (Convert from milsec)
#4 = #4/#7 (Divide by number of parts/run)
#682 = 3600 / #4 (Store number of parts per hour)
M99
%