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: P.h
- Revision:
- 4:208f5279143a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/P.h Sat Mar 23 19:46:09 2019 +0000
@@ -0,0 +1,81 @@
+
+class P
+{
+ private:
+ float inMin;
+ float inMax;
+
+ float control;
+
+ float outMin;
+ float outMax;
+
+ float gain;
+ float prevCA;
+ float controlAction;
+
+ public:
+ P(float G)
+ {
+ gain = G;
+ outMin = 0.0f;
+ outMax = 1.0f;
+ control = 0;
+ }
+
+ void setInputLimits(int inMin_, int inMax_)
+ {
+ if (inMin_ > inMax_) {return;} //cant be true can it
+ inMin = inMin_;
+ inMax = inMax_;
+ }
+
+ void setInMax(float inMax_)
+ {
+ inMax = inMax_;
+ }
+
+ float returnPrevCA()
+ {
+ return prevCA;
+ }
+
+ void setOutputLimits(float outMin_, float outMax_)
+ {
+ if (outMin_ > outMax_) {return;}
+ outMin = outMin_;
+ outMax = outMax_;
+ }
+
+ float compute(float curVal_)
+ {
+ //if the measured value is greater than the measured amount, then clearly the limits are offfffffffffffffff
+ if (curVal_ > inMax) {inMax=curVal_;}
+ if (curVal_ < inMin) {inMin=curVal_;}
+ controlAction = ((control-curVal_)*gain); //amplify the error by the gain
+ if (controlAction > inMax ) {controlAction = inMax;}
+ if (controlAction < inMin) {controlAction = inMin;}
+ float prevCATemp = prevCA;
+ prevCA = controlAction;
+ controlAction += prevCATemp;
+ return (((controlAction-inMin)/(inMax - inMin))*(outMax-outMin))+outMin; //scales temp to the correct output Limits
+ }
+
+ void setControl(float wantedVal_)
+ {
+ if (wantedVal_ > inMax) {control = inMax;}
+ else if (wantedVal_ < inMin) {control = inMin;}
+ else {control = wantedVal_;}
+ }
+
+ float returnControl(void)
+ {
+ return control;
+ }
+
+ float returnInMax()
+ {
+ return inMax;
+ }
+
+};
\ No newline at end of file