File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -360,25 +360,19 @@ namespace Mycila {
360360 break ;
361361 case ProportionalMode::ON_INPUT:
362362 // proportional on measurement, i.e. accumulate the proportional term based on input changes
363- _pTerm += kp * dError;
363+ _pTerm = _icMode == IntegralCorrectionMode::CLAMP
364+ ? _clamp (_pTerm + kp * dError, -_outputMax, _outputMax)
365+ : _pTerm + kp * dError;
364366 break ;
365367 default :
366368 assert (false );
367369 break ;
368370 }
369371
370372 // calculate integral term and integrate over time
371- _iTerm += ki * error;
372-
373- // clamp integral if needed to prevent windup
374- if (_icMode == IntegralCorrectionMode::CLAMP) {
375- _iTerm = _clamp (_iTerm);
376-
377- // clamp proportional term to max output limit in both directions
378- if (_pMode == ProportionalMode::ON_INPUT) {
379- _pTerm = _clamp (_pTerm, -_outputMax, _outputMax);
380- }
381- }
373+ _iTerm = _icMode == IntegralCorrectionMode::CLAMP
374+ ? _clamp (_iTerm + ki * error)
375+ : _iTerm + ki * error;
382376
383377 // calculate derivative term
384378 _dTerm = kd * dError;
You can’t perform that action at this time.
0 commit comments