Created
January 1, 2015 19:59
-
-
Save murilopontes/4de021e6ec194db510e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PID_classic { | |
private: | |
float error_bak = 0; | |
float error = 0; | |
float error_integration = 0; | |
float error_derivate = 0; | |
public: | |
float target =0; // user target value | |
float system_feedback = 0; // system sensor | |
float system_action = 0; | |
float KP = 1; | |
float KD = 1; | |
float KI = 1; | |
float prevent_windump_factor=0.99; | |
void act(){ | |
//backup previous error | |
error_bak=error; | |
//calculate new error | |
error = target - system_feedback; | |
//Differentiation error | |
error_derivate = error - error_bak; | |
//Integration error | |
error_integration = error_integration*(prevent_windump_factor) + error; | |
//calculate | |
system_action = KP * error + KD * error_derivate + KI * error_integration; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment