3 ms·
Be careful with Arduino libraries. If you are trying to learn something, it's usually better to write your own, or look at really good code. Case in point, PID
by jwr 12y ago
Be careful with Arduino libraries. If you are trying to learn something, it's usually better to write your own, or look at really good code.
Case in point, PIDLibrary, I'm looking at the PIDCompute function, line 57:
ITerm+= (ki * error);
That's not how you deal with I. You are supposed to accumulate (integrate) the error and multiply by Ki only for the final PID addition. You don't want to accumulate your errors multiplied each time by Ki, it makes no sense.
- bradyd 12y agoThat is actually done intentionally to allow for changing of the tuning parameters while the PID is running.[1] The author of the PID library has a full writeup on the design of the algorithm.[2] [1] http://brettbeauregard.com/blog/2011/04/improving-the-beginner%E2%80%99s-pid-tuning-changes/ http://brettbeauregard.com/blog/2011/04/improving-the-beginn... [2] http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ http://brettbeauregard.com/blog/2011/04/improving-the-beginn...