Skip to content

Commit 6b4127a

Browse files
committed
code cleanup
1 parent d8e1e98 commit 6b4127a

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

src/MycilaPID.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)