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
WheelControl/P.h
- Committer:
- mazdo25
- Date:
- 2019-03-09
- Revision:
- 3:01b5e80d842d
- Parent:
- 1:813f4b17ae65
File content as of revision 3:01b5e80d842d:
//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)/(inMax - inMin))*(outMax-outMin))+outMin; //scales temp to the correct output Limits
if (temp > 1.0f ) {temp = 1.0f;}
if (temp < -1.0f) {temp = -1.0f;}
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;
}
};