Ah, so you're trying to work around the self-imposed limitation of not having predictable behavior from the OS. ;-)
Yes, that's what I was refering to.
Without pasting in the lengthy argument, I'll try to explain it to you:
You are saying that you don't know how often you're process will be executed, but you do know *when* it gets executed. You're dealing with that fact by scaling your input numbers with the elapsed time between invocations. You will not sample your input signals (your encoder speed) in a regular interval, but you will assume that they stayed constant during the time between your last and current sample.
This is not a model that can be tackled by traditional signal-analysis techniques, so I had to transform your system to one that, given the same input will produce the same output, but operates on a regular sample interval.
To do that, first I had to 'fill in' your signal with the missing values in the data points where you didn't make a sampling. That's where I've used your assumption that the input signal didn't change, so I've used the previously known sample. This is the signal, I've called 'W': the signal that you operated on with values filled in to the points that you've missed it in such a manner that your algorithm would produce the same output for both the original irregular, and this 'W' signal. (Here I mean that your program would produce the same outputs at any given point in time, if it was called at regular intervals for 'W' or at irregular intervals for the original input values.)
For the arguments I made I also needed the 'actual' input (encoder speed) signal even at the locations where you didn't sample it. (Here I mean time locations where you didn't sample because your porcess wasn't invoked at that instance of time. I know you sample every time you're called but sometime this call is missing. That's what introduces the irregularity that I'm trying to model here.) This is the signal I've called 'S'. These two signals are somewhat different, since the assumption that the signal didn't change when you didn't look at it obviously somewhat incorrect. This incorrectness in my model is measured by the signal 'N'. If your assumption is correct, than values of 'N' are small, if youre assumtion is incorrect, the values are large. In any rate 'N' is not constant zero.
These changes made the ground where normal control theory could be applied: from now on both the input and output signals are simple discrete time signals, and your PID loop also operates on a regular intervals. Still the system produces the same command signal at its output as your original algorithm would. Again, this was needed to be able to make arguments and to quantify the effects on the whole system of your solution to the inablity to sample at regular intervals.
After this setup I've examined what error will be introduced in the controlled system by this additional 'N' signal. Note again, that this 'N' signal is the product - and in this sense the representation - of the irregular sampling of your design. So, by estimating the error introduced to the controlled system (motor shaft rotation speed) by this 'N' signal, I'm trying to calculate the effect of the unregularity of the sampling.
I came up with the result of:
Total_Rotation_noise = Motor(PID(N)) / (1+Motor(PID(N)))
This is with the assumption that the feedback circuit is ideal. Now, I can't tell you if this signal is important, all I can tell you is it's non-zero. Well, actually I can tell you one more thing.
Your system's response for a control input ('C') will be the following:
Total_Rotation_controlled = Motor(PID(C)) / (1+Motor(PID(C)))
Of course if your control loop is working correctly than:
Total_Rotation_controlled ~= C
In other words a good control loop does its best to keep the output value as close as the control input as possible. However note that this is the same equation as the previous one, for the noise. This means that your control loop will do its best to copy the noise 'N' to the output as well. What I'm trying to point out here is that you introduce this noise at the worst possible point to the system: you will apply your whole closed-loop transfer function to it and not the open-loop one.
Hope it cleared things up.
Regards, Andras Tantos