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->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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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_ */
|
||||
|
|
Loading…
Reference in New Issue