This commit is contained in:
rusefi 2017-06-02 22:28:12 -04:00
parent 3fea210652
commit 6b61023b6d
2 changed files with 8 additions and 10 deletions

View File

@ -50,11 +50,11 @@ float Pid::getValue(float target, float input, float dTime) {
* If we have exceeded the ability of the controlled device to hit target, the I factor will keep accumulating and approach infinity.
* Here we limit the I-term #353
*/
if (iTerm > pid->maxValue - (pTerm + dTerm + pid->offset))
iTerm = pid->maxValue - (pTerm + dTerm + pid->offset);
if (iTerm > pid->maxValue)
iTerm = pid->maxValue;
if (iTerm < pid->minValue - (pTerm + dTerm + pid->offset))
iTerm = pid->minValue - (pTerm + dTerm + pid->offset);
if (iTerm < pid->minValue)
iTerm = pid->minValue;
float result = pTerm + iTerm + dTerm + pid->offset;
if (result > pid->maxValue) {

View File

@ -57,14 +57,12 @@ void testPidController(void) {
assertEqualsM("target=50, input=0 iTerm", 0, pid.iTerm);
assertEqualsM("target=50, input=70", 0, pid.getValue(/*target*/50, /*input*/70));
assertEqualsM("target=50, input=70 iTerm", 20, pid.iTerm);
assertEqualsM("target=50, input=70 iTerm", 0, pid.iTerm);
assertEqualsM("target=50, input=70 #2", 0, pid.getValue(/*target*/50, /*input*/70));
// WOW, we are getting non-zero iTerm while iFactor is zero?!
assertEqualsM("target=50, input=70 iTerm #2", 20, pid.iTerm);
assertEqualsM("target=50, input=70 iTerm #2", 0, pid.iTerm);
// and now we inherit this iTerm even for cases where targer==input?! NOT RIGHT
assertEqualsM("target=50, input=50", 20, pid.getValue(/*target*/50, /*input*/50));
assertEqualsM("target=50, input=50 iTerm", 20, pid.iTerm);
assertEqualsM("target=50, input=50", 0, pid.getValue(/*target*/50, /*input*/50));
assertEqualsM("target=50, input=50 iTerm", 0, pid.iTerm);
}