Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BX-car by
Diff: controller.cpp
- Revision:
- 9:33b99cb45e99
- Parent:
- 8:8e49e21d80a2
- Child:
- 10:d2401a243e8d
diff -r 8e49e21d80a2 -r 33b99cb45e99 controller.cpp --- a/controller.cpp Sun Jun 22 15:29:20 2014 +0000 +++ b/controller.cpp Tue Jun 24 10:06:54 2014 +0000 @@ -2,15 +2,17 @@ #include "controller.h" -PID::PID(float Kc, float tauI, float tauD, float interval) { +PID::PID(float in_min,float in_max,float out_min,float out_max,float Kc, float tauI, float tauD, float interval) { usingFeedForward = false; //inAuto = false; //Default the limits to the full range of I/O. //Make sure to set these to more appropriate limits for your application. - setInputLimits(10.0, 118.0); - setOutputLimits(0.0,1.0); + + //BX tune + setInputLimits(in_min,in_max); + setOutputLimits(out_min,out_max); tSample_ = interval; @@ -230,11 +232,11 @@ //controllerOutput_ = Kc_ * error + tauR_ * accError_ + tauD_ * dMeas; //Make sure the computed output is within output constraints. - if (controllerOutput_ < -1.0) { - controllerOutput_ = -1.0; + if (controllerOutput_ < outMin_) { + controllerOutput_ = outMin_; } - else if (controllerOutput_ > 1.0) { - controllerOutput_ = 1.0; + else if (controllerOutput_ >outMax_ ) { + controllerOutput_ = outMax_; } //Remember this output for the windup check next time. @@ -244,7 +246,7 @@ //Scale the output from percent span back out to a real world number. - return (controllerOutput_ * 90); + return (controllerOutput_ ); }