auto-sync
This commit is contained in:
parent
079c5029e7
commit
c967e5e46c
|
@ -13,9 +13,19 @@ Pid::Pid(float pFactor, float iFactor, float dFactor) {
|
||||||
this->pFactor = pFactor;
|
this->pFactor = pFactor;
|
||||||
this->iFactor = iFactor;
|
this->iFactor = iFactor;
|
||||||
this->dFactor = dFactor;
|
this->dFactor = dFactor;
|
||||||
|
|
||||||
|
integration = 0;
|
||||||
|
prevError = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pid::getValue(float input) {
|
float Pid::getValue(float target, float input, float dTime) {
|
||||||
return 0;
|
float error = target - input;
|
||||||
|
|
||||||
|
float pTerm = pFactor * error;
|
||||||
|
integration += iFactor * dTime * error;
|
||||||
|
float dTerm = dFactor / dTime * (error - prevError);
|
||||||
|
|
||||||
|
prevError = error;
|
||||||
|
return pTerm + integration + dTerm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,16 @@ class Pid {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Pid(float pFactor, float iFactor, float dFactor);
|
Pid(float pFactor, float iFactor, float dFactor);
|
||||||
float getValue(float input);
|
float getValue(float target, float input, float dTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float pFactor;
|
float pFactor;
|
||||||
float iFactor;
|
float iFactor;
|
||||||
float dFactor;
|
float dFactor;
|
||||||
|
|
||||||
|
float integration;
|
||||||
|
float prevError;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PID_H_ */
|
#endif /* PID_H_ */
|
||||||
|
|
Loading…
Reference in New Issue