working-est copy with class-based code. still open loop
Fork of analoghalls6 by
Diff: pidcontroller.cpp
- Revision:
- 9:d3b70c15baa9
- Parent:
- 1:1f58bdcf2956
- Child:
- 10:b4abecccec7a
--- a/pidcontroller.cpp Wed Mar 04 15:33:32 2015 +0000 +++ b/pidcontroller.cpp Fri Mar 06 19:12:53 2015 +0000 @@ -12,10 +12,10 @@ } float PidController::Update(float ref, float in) { - float error = ref - in; + float error = in - ref; _integral += error; - if (_integral > _out_max) _integral = _out_max; - if (_integral < _out_min) _integral = _out_min; + 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;