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.
Dependencies: mbed
Diff: PID2.h
- Revision:
- 6:477382219bcf
- Parent:
- 5:f1613df66ceb
- Child:
- 9:cefa177c1353
--- a/PID2.h Mon Mar 25 22:42:31 2019 +0000
+++ b/PID2.h Tue Mar 26 16:19:47 2019 +0000
@@ -35,15 +35,15 @@
if (currVal < inMin_) {inMin_ = currVal;}
controlAction = prevControlAction - (PrevErr*Kp_) + (Kp_*currErr)+ (Ki_*Ts*currErr) + ((Kd_/Ts)*(currErr - PrevErr - PrevErr + PrevPrevErr));
-
- if (controlAction > inMax_) {controlAction = inMax_;}
- if (controlAction < inMin_) {controlAction = inMin_;}
prevControlAction = controlAction;
PrevPrevErr = PrevErr;
PrevErr = currErr;
//scale the control Action to the correct output limits and output
- return ((((controlAction)- inMin_)/(inMax_ - inMin_)) * (*outMax_ - *outMin_)) + *outMin_;
+ controlAction = ((((controlAction)- inMin_)/(inMax_ - inMin_)) * (*outMax_ - *outMin_)) + *outMin_;
+
+ if (controlAction > *outMax_) {return *outMax_;} else if (controlAction < *outMin_) {return *outMin_;} else {return controlAction;}
+
}
void setSetPoint(float _sP)
@@ -55,6 +55,10 @@
{
if (inMin > inMax) {return;}
+ PrevErr = scaler(inMax_,inMin_,inMin,inMax,PrevErr);
+ PrevPrevErr = scaler(inMax_,inMin_,inMin,inMax,PrevPrevErr);
+ prevControlAction = scaler(inMax_,inMin_,inMin,inMax,prevControlAction);
+
inMin_ = inMin;
inMax_ = inMax;
}
@@ -77,6 +81,11 @@
return prevControlAction;
}
+ float returnOutMax()
+ {
+ return *outMax_;
+ }
+
};
//(((temp-inMin)/(inMax - inMin))*(outMax-outMin))+outMin
\ No newline at end of file