I have implemented a PID function using the formula,
correction = Kp * error + Kd * (error - prevError) + kI * (sum of errors)
What should I do to keep my output between 开发者_如何学运维a certain range? say 0-255 If I disregard any value not between 0 to 255 it produces a jiggly behavior?
correction = ...
correction2 = correction;
if(correction < least) {correction2 = least;}
if(correction > most) {correction2 = most;}
Then use correction and correction2 as your output where appropriate.
Don't correct based on correction2 and then wonder why it behaves in an odd way when you reach the edge of least <-> most.
精彩评论