Skip to content

Commit a0eb0d6

Browse files
author
David Forrest
committed
1 parent 9b4ca0e commit a0eb0d6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

PID_v1.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,15 @@ bool PID::Compute()
8282
/*Compute Rest of PID Output*/
8383
output += outputSum - kd * dInput;
8484

85-
if(output > outMax) output = outMax;
86-
else if(output < outMin) output = outMin;
87-
*myOutput = output;
85+
if(output > outMax){
86+
outputSum -= output - outMax; // backcalculate integral to feasability
87+
output = outMax;
88+
}
89+
else if(output < outMin) {
90+
outputSum += outMin - output; // backcalculate integral to feasability
91+
output = outMin;
92+
}
93+
*myOutput = output;
8894

8995
/*Remember some variables for next time*/
9096
lastInput = input;

0 commit comments

Comments
 (0)