This commit is contained in:
parent
de78eaaa06
commit
4284c47e0c
|
@ -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.
|
* 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
|
* Here we limit the I-term #353
|
||||||
*/
|
*/
|
||||||
if (iTerm > pid->maxValue - (pTerm + dTerm + pid->offset))
|
if (iTerm > pid->maxValue)
|
||||||
iTerm = pid->maxValue - (pTerm + dTerm + pid->offset);
|
iTerm = pid->maxValue;
|
||||||
|
|
||||||
if (iTerm < pid->minValue - (pTerm + dTerm + pid->offset))
|
if (iTerm < pid->minValue)
|
||||||
iTerm = pid->minValue - (pTerm + dTerm + pid->offset);
|
iTerm = pid->minValue;
|
||||||
|
|
||||||
float result = pTerm + iTerm + dTerm + pid->offset;
|
float result = pTerm + iTerm + dTerm + pid->offset;
|
||||||
if (result > pid->maxValue) {
|
if (result > pid->maxValue) {
|
||||||
|
|
|
@ -57,14 +57,12 @@ void testPidController(void) {
|
||||||
assertEqualsM("target=50, input=0 iTerm", 0, pid.iTerm);
|
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", 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));
|
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", 0, pid.iTerm);
|
||||||
assertEqualsM("target=50, input=70 iTerm #2", 20, pid.iTerm);
|
|
||||||
|
|
||||||
// and now we inherit this iTerm even for cases where targer==input?! NOT RIGHT
|
assertEqualsM("target=50, input=50", 0, pid.getValue(/*target*/50, /*input*/50));
|
||||||
assertEqualsM("target=50, input=50", 20, pid.getValue(/*target*/50, /*input*/50));
|
assertEqualsM("target=50, input=50 iTerm", 0, pid.iTerm);
|
||||||
assertEqualsM("target=50, input=50 iTerm", 20, pid.iTerm);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue