Bayley Wang
/
priustroller
Prius IPM controller
Fork of analoghalls5_5 by
Diff: meta/pidcontroller.cpp
- Revision:
- 25:0003b824dd7d
- Parent:
- 24:f1ff9c7256b5
--- a/meta/pidcontroller.cpp Mon Mar 09 11:33:14 2015 +0000 +++ b/meta/pidcontroller.cpp Tue Mar 10 17:47:08 2015 +0000 @@ -13,13 +13,18 @@ float PidController::Update(float ref, float in) { float error = ref - in; + _integral += error; + if (_integral * _ki > _out_max) _integral = _out_max / _ki; if (_integral * _ki < _out_min) _integral = _out_min / _ki; + float deriv = _last_in - in; _last_in = in; float tmp = _ki * _integral + _kp * error + _kd * deriv; + if (tmp > _out_max) tmp = _out_max; if (tmp < _out_min) tmp = _out_min; + return tmp; } \ No newline at end of file