working-est copy with class-based code. still open loop
Fork of analoghalls6 by
Diff: pidcontroller.cpp
- Revision:
- 10:b4abecccec7a
- Parent:
- 9:d3b70c15baa9
--- a/pidcontroller.cpp Fri Mar 06 19:12:53 2015 +0000 +++ b/pidcontroller.cpp Sun Mar 08 00:45:28 2015 +0000 @@ -11,9 +11,10 @@ _out_min = out_min; } -float PidController::Update(float ref, float in) { - float error = in - ref; - _integral += error; +float PidController::Update(float ref, float in) { //starts positive, integrator is adding up the error to get there. cranking throttle makes it go negative. that makes sense. + float error = ref - in; + //_integral += error; + _integral = 0.0f; if (_integral*_ki > _out_max) _integral = _out_max/_ki; if (_integral*_ki < _out_min) _integral = _out_min/_ki; float deriv = _last_in - in;