Hamza Yerlikaya
Hamza Yerlikaya

Reputation: 49339

Scaling PID (Proportional Integral Derivative) Output

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?

Upvotes: 0

Views: 1058

Answers (1)

alan2here
alan2here

Reputation: 3327

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.

Upvotes: 0

Related Questions