Page 1 of 1

Drawing a graph of any signal in the production statistics

Posted: Thu Jul 28, 2016 3:40 am
by siggboy
So there was the question in this thread (29735) of how to show the accumulator charge over time, as a graph.

And zebediah49 had the great idea of creating a PWM signal from the input (accumulator level in this case), then use the PWM signal to toggle a power switch to create a power usage graph of an isolated power network. That graph basically traces the original input signal.

That's a bit awkward for actual use, because you need to be close to the (isolated) power network to be able to click on a power pole and inspect the graph.

Then I had the idea "why not use the production graph?" After all, there is one item that you can produce and consume endlessly: Oil Barrels.
oil-contraption.gif
oil-contraption.gif (1.87 MiB) Viewed 7447 times
The combinators at the top create the PWM signal (Zebediah's idea). It's simply a looping counter and a decider that outputs a "1" when the reference signal is greater than the counter value. So, the output goes between "1" and "0", and the periods of "1" are longer, the higher your reference signal is.

So it turns an arbitrary input signal into a PWM "encoding" of it. Then you can use the PWM signal to control something else, for example a pump.

The two assemblers just produce and consume oil barrels endlessly. There are 10 barrels in the loop, which is enough to keep the machines working as long as the oil is flowing. The Fast Inserters are also fast enough.

So the bottleneck is the oil, which we use to slow down the production. The three pumps transport up to 90 oil/second, the assemblers could theoretically process ~93 oil/second. So, if we're slowing down the pumps, we already slow down the machines.

The PWM signal is simply used as the pump control, so the pumps can be regulated from 0% to 100%, with some granularity, and the resulting Oil Barrel consumption/production immediately follows. Because the machines are sped up to 300% and feeding directly into eachother, the contraption reacts really fast to any change of the pump speed.

When creating the PWM signal, I'm using a clock with a cycle of 10 ticks, so the period of the PWM signal is 10 ticks, and the inputs can take values from 0 to 10 (an accumulator readout would have to be divided by 10 to be compatible).

I've created a small solar array with a dummy load, and put it through two day/night cycles, here's how it looks in the production graph (for the second cycle I've removed a few accus to make them drain to zero):
accu-cycle.png
accu-cycle.png (350.45 KiB) Viewed 7447 times
Of course you could graph all others sorts of long-term trends with this: train throughput, coal bunker at the power plant, oil storage...

The only downside is that you can't transport oil in barrels anymore, as that would ruin the graph. Rail Tanker I guess :). Of course, if all the liquids become barreable, then you could everything except oil, and even have multiple graphs of different things.

And the production statistics are available anywhere, anytime, and can show very long-term trends up to 50h.
blueprint

Re: Drawing a graph of any signal in the production statistics

Posted: Thu Jul 28, 2016 9:13 am
by Qon
I love everything about it, except not being able to barrel if I use this! q:

It won't work very well with extremely fast switching signals but for measuring things that happen in game it should be able to handle most things I believe.

Re: Drawing a graph of any signal in the production statistics

Posted: Thu Jul 28, 2016 9:25 am
by siggboy
Qon wrote:It won't work very well with extremely fast switching signals
Yes, but that has nothing to do with the contraption itself, but only with the PWM sampling. If your signal changes too rapidly you get aliasing in the sampling and the PWM signal is worthless. In the setup above the sampling rate is 10 ticks, so anything that changes slower than that should be fine. Maybe it's even 5 ticks (Nyquist rate), but I'm not really sure if that applies to PWM. Probably it does. I forgot most of what I ever knew about signal processing.

Edit: I think the Nyquist rate applies, which would be 20 ticks, so the signal must not change faster than that to capture everything in the PWM signal. It would be interesting to test this. It's probably not going to be possible with the contraption though.