auto-sync
This commit is contained in:
parent
16c8f53d2b
commit
842d45477f
|
@ -9,10 +9,12 @@
|
|||
|
||||
#include "pid.h"
|
||||
|
||||
Pid::Pid(float pFactor, float iFactor, float dFactor) {
|
||||
Pid::Pid(float pFactor, float iFactor, float dFactor, float minResult, float maxResult) {
|
||||
this->pFactor = pFactor;
|
||||
this->iFactor = iFactor;
|
||||
this->dFactor = dFactor;
|
||||
this->minResult = minResult;
|
||||
this->maxResult = maxResult;
|
||||
|
||||
integration = 0;
|
||||
prevError = 0;
|
||||
|
@ -26,6 +28,16 @@ float Pid::getValue(float target, float input, float dTime) {
|
|||
float dTerm = dFactor / dTime * (error - prevError);
|
||||
|
||||
prevError = error;
|
||||
return pTerm + integration + dTerm;
|
||||
|
||||
float result = pTerm + integration + dTerm;
|
||||
if (result > maxResult) {
|
||||
integration -= result - maxResult;
|
||||
result = maxResult;
|
||||
} else if (result < minResult) {
|
||||
integration += minResult - result;
|
||||
result = minResult;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,15 @@
|
|||
class Pid {
|
||||
|
||||
public:
|
||||
Pid(float pFactor, float iFactor, float dFactor);
|
||||
Pid(float pFactor, float iFactor, float dFactor, float minResult, float maxResult);
|
||||
float getValue(float target, float input, float dTime);
|
||||
|
||||
private:
|
||||
float pFactor;
|
||||
float iFactor;
|
||||
float dFactor;
|
||||
float minResult;
|
||||
float maxResult;
|
||||
|
||||
float integration;
|
||||
float prevError;
|
||||
|
|
Loading…
Reference in New Issue