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:
- 15:3fa780990a6a
- Parent:
- 12:f7acda4545ba
- Child:
- 16:7ada30380595
diff -r 5cc3e028d8a3 -r 3fa780990a6a controller.cpp --- a/controller.cpp Mon Jun 30 02:26:43 2014 +0000 +++ b/controller.cpp Mon Jun 30 02:54:45 2014 +0000 @@ -18,7 +18,7 @@ tSample_ = interval;// init is 10 - setTunings(Kc, tauI, tauD); + setTunings(Kp, Ki, Kd); setPoint_ = 0.0; processVariable_ = 0.0; @@ -88,25 +88,25 @@ -void PID::setTunings(float Kc, float tauI, float tauD) { +void PID::setTunings(float Kp, float Ki, float Kd) { //Verify that the tunings make sense. - if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) { + if (Kp == 0.0 || Ki < 0.0 || Kd < 0.0) { return; } //Store raw values to hand back to user on request. - pParam_ = Kc; - iParam_ = tauI; - dParam_ = tauD; + pParam_ = Kp; + iParam_ = Ki; + dParam_ = Kd; float tempTauR; - if (tauI == 0.0) { + if (Ki == 0.0) { tempTauR = 0.0; } else { - tempTauR = (1.0 / tauI) * tSample_; + tempTauR = (1.0 / Ki) * tSample_; } //For "bumpless transfer" we need to rescale the accumulated error. @@ -115,13 +115,13 @@ //accError_ = 0.0; //} //else { - accError_ *= (Kc_ * tauR_) / (Kc * tempTauR); + accError_ *= (Kp_ * tauR_) / (Kp * tempTauR); //} //} - Kc_ = Kc; + Kp_ = Kp; tauR_ = tempTauR; - tauD_ = tauD / tSample_; + Kd_ = Kd / tSample_; } @@ -162,7 +162,7 @@ //Convert the time-based tunings to reflect this change. tauR_ *= (interval / tSample_); accError_ *= (tSample_ / interval); - tauD_ *= (interval / tSample_); + Kd_ *= (interval / tSample_); tSample_ = interval; } @@ -194,7 +194,7 @@ float centerL = L; float centerB = sp; // center of black float error = centerB - centerR; - if(error < -8 && error >8){ + if(error > -8 && error <8){ return 0.085; } else if((error < -8 && error > -20)||(error > 8 && error < 40)){