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: WheelControl/P.h
- Revision:
- 1:813f4b17ae65
- Child:
- 3:01b5e80d842d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WheelControl/P.h Sun Mar 03 00:54:07 2019 +0000
@@ -0,0 +1,59 @@
+//CURRENTLY EMPTY BUT I MAY JUST MAKE A NEW CLASS FOR THE P CONTROL
+class P
+{
+ private:
+ float inMin;
+ float inMax;
+ float control;
+
+ float outMin;
+ float outMax;
+
+ float gain;
+
+
+ public:
+ P(float G)
+ {
+ gain = G;
+ inMin = 0.0f;
+ inMax = 3.3f;
+ outMin = 0.0f;
+ outMax = 1.0f;
+ control = 0;
+ }
+
+ void setInputLimits(float inMin_, float inMax_)
+ {
+ if (inMin_ > inMax_) {return;} //cant be true can it
+ inMin = inMin_;
+ inMax = inMax_;
+ }
+
+ void setOutputLimits(float outMin_, float outMax_)
+ {
+ if (outMin_ > outMax_) {return;}
+ outMin = outMin_;
+ outMax = outMax_;
+ }
+
+ float compute(float curVal_)
+ {
+ float temp = ((control-curVal_)*gain)+curVal_; //amplify difference by gain and add to current value
+ temp = (((temp-inMin)/(inMin - inMin))*(outMax-outMin))+outMin; //scales temp to the correct output Limits
+ return temp; //return the scaled value
+ }
+
+ void setControl(float wantedVal_)
+ {
+ if (wantedVal_ > inMax) {control = inMax;}
+ else if (wantedVal_ <inMin) {control = inMin;}
+ else {control = wantedVal_;}
+ }
+
+ float returnControl(void)
+ {
+ return control;
+ }
+
+};
\ No newline at end of file