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 PID by
Revision 3:0f1bc3b0d050, committed 2015-05-19
- Comitter:
- miczyg
- Date:
- Tue May 19 16:39:18 2015 +0000
- Parent:
- 1:709ed452cc4c
- Commit message:
- Wzmocnienie, period itd ok, wersja P dzia?aj?ca.
Changed in this revision
PID.cpp | Show annotated file Show diff for this revision Revisions of this file |
PID.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/PID.cpp Thu May 14 12:28:08 2015 +0000 +++ b/PID.cpp Tue May 19 16:39:18 2015 +0000 @@ -24,7 +24,7 @@ * THE SOFTWARE. * * @section DESCRIPTION - * + * * A PID controller is a widely used feedback controller commonly found in * industry. * @@ -49,7 +49,8 @@ */ #include "PID.h" -PID::PID(float Kc, float tauI, float tauD, float interval) { +PID::PID(float Kc, float tauI, float tauD, float interval) +{ usingFeedForward = false; inAuto = false; @@ -72,12 +73,13 @@ accError_ = 0.0; bias_ = 0.0; - + realOutput_ = 0.0; } -void PID::setInputLimits(float inMin, float inMax) { +void PID::setInputLimits(float inMin, float inMax) +{ //Make sure we haven't been given impossible values. if (inMin >= inMax) { @@ -101,7 +103,8 @@ } -void PID::setOutputLimits(float outMin, float outMax) { +void PID::setOutputLimits(float outMin, float outMax) +{ //Make sure we haven't been given impossible values. if (outMin >= outMax) { @@ -124,7 +127,8 @@ } -void PID::setTunings(float Kc, float tauI, float tauD) { +void PID::setTunings(float Kc, float tauI, float tauD) +{ //Verify that the tunings make sense. if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) { @@ -156,10 +160,11 @@ Kc_ = Kc; tauR_ = tempTauR; tauD_ = tauD / tSample_; - + } -void PID::reset(void) { +void PID::reset(void) +{ float scaledBias = 0.0; @@ -177,7 +182,8 @@ } -void PID::setMode(int mode) { +void PID::setMode(int mode) +{ //We were in manual, and we just got set to auto. //Reset the controller internals. @@ -189,7 +195,8 @@ } -void PID::setInterval(float interval) { +void PID::setInterval(float interval) +{ if (interval > 0) { //Convert the time-based tunings to reflect this change. @@ -201,26 +208,30 @@ } -void PID::setSetPoint(float sp) { +void PID::setSetPoint(float sp) +{ setPoint_ = sp; } -void PID::setProcessValue(float pv) { +void PID::setProcessValue(float pv) +{ processVariable_ = pv; } -void PID::setBias(float bias){ +void PID::setBias(float bias) +{ bias_ = bias; usingFeedForward = 1; } -float PID::compute() { +float PID::compute() +{ //Pull in the input and setpoint, and scale them into percent span. scaledPV = (processVariable_ - inMin_) / inSpan_; @@ -275,50 +286,63 @@ } -float PID::getInMin() { +float PID::getInMin() +{ return inMin_; } -float PID::getInMax() { +float PID::getInMax() +{ return inMax_; } -float PID::getOutMin() { +float PID::getOutMin() +{ return outMin_; } -float PID::getOutMax() { +float PID::getOutMax() +{ return outMax_; } -float PID::getInterval() { +float PID::getInterval() +{ return tSample_; } -float PID::getPParam() { +float PID::getPParam() +{ return pParam_; } -float PID::getIParam() { +float PID::getIParam() +{ return iParam_; } -float PID::getDParam() { +float PID::getDParam() +{ return dParam_; } + +void PID::resetAccError() +{ + accError_ = 0; +} \ No newline at end of file
--- a/PID.h Thu May 14 12:28:08 2015 +0000 +++ b/PID.h Tue May 19 16:39:18 2015 +0000 @@ -163,8 +163,9 @@ float getPParam(); float getIParam(); float getDParam(); - -//private: + void resetAccError(); + +private: bool usingFeedForward; bool inAuto;