teg wrote:Normally PID algorithm doesn't work like that. P (proportional part) just reacts to current error. It doesn't affect to past (as I part) or to future (as D part).
When I=0 and D=0, PID controller works as a P-controller and output should be error * proportional band.
Correct, and since in your example, there is still error, there will still be correction. It is reacting to current error by further changing the output, and will continue to do so until current error diminishes.
With a proportional controller offset (deviation from set-point) is present. Integral action (and only integral!) was included in controllers to eliminate this offset.
Now your PID-controller will eliminate this offset without integral, which is incorrect.
I disagree. Previous error will not be taken into account, only previous valve position. IF there is RPM error, then the P term should affect an immediate change, which it does. As the error gets smaller, it'll affect less and less of a change, but should still affect a change.
Say my error is 800 rpm, and I have the values P = 50, I = 0, D = 0.
Also, say my target rpm is 800, and I'm at 1600 rpms, and my duty is 70%, my open duty is 80%, and closed duty is 10%.
So with a P of 50, I want to make a change to duty that should affect a 400 rpm change...
I want ((Kp + Ki - Kd) * (open duty - closed duty)) / (rpm) or
((-400 + 0 - 0) * (70)) / 1600)
or
-17.5 (-17 since we're an integer-only processor)
now, my current duty is 70, so 70 + -17 = 53.
OK, so now lets say that the rpm dropped where we wanted, and our error is now 400, we go through the same thing again...
We end up with 53 - 8, and get a new duty of 45.
And so on... The proportional value comes from the current error. As long as there is error, and the calculated value that comes from the P term is not resulting in a 0 correction, (meaning as long as the error is large enough) we correct.
It works exactly as it should... I HAVE to store the previous valve position so as to correct by a certain relative amount. I'm not storing previous corrections, but making a relative change to the current duty. IACmotor_pos is the current valve duty.
If there is currently error, and the error is large enough, the P term should affect a change... once error gets small enough that P no longer has an effect, the error sum will eventually build up, and be large enough that when multiplied by the I term, then divided by 100, we'll end up with something non-zero which will affect a change.
P causes immediate change, I causes change as error builds up, D causes change based on the current rate of change (future).
The IACmotor_pos is the actual position of the valve. I'm not incorporating previous error by using that and adding to it, I'm changing the valve position by a relative amount. Basically, if you change it by 2 %, and you have 100 error, then change it another 2%, and still have 100 error, you should continue changing it until the error goes away. Most often, a change in valve position will result in a change in rpm, which will cause the position to stay where it is when error gets small enough.
It is working exactly as it should.
Ken