auto-sync

This commit is contained in:
rusEfi 2014-09-16 01:02:58 -05:00
parent 079c5029e7
commit c967e5e46c
2 changed files with 16 additions and 3 deletions

View File

@ -13,9 +13,19 @@ Pid::Pid(float pFactor, float iFactor, float dFactor) {
this->pFactor = pFactor;
this->iFactor = iFactor;
this->dFactor = dFactor;
integration = 0;
prevError = 0;
}
float Pid::getValue(float input) {
return 0;
float Pid::getValue(float target, float input, float dTime) {
float error = target - input;
float pTerm = pFactor * error;
integration += iFactor * dTime * error;
float dTerm = dFactor / dTime * (error - prevError);
prevError = error;
return pTerm + integration + dTerm;
}

View File

@ -12,13 +12,16 @@ class Pid {
public:
Pid(float pFactor, float iFactor, float dFactor);
float getValue(float input);
float getValue(float target, float input, float dTime);
private:
float pFactor;
float iFactor;
float dFactor;
float integration;
float prevError;
};
#endif /* PID_H_ */