comparison core/Pid.cpp @ 152:8f98b32d0e23 ClockSync

Last commit on this branch for a while. Overall not very succesful
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 05 Oct 2015 13:06:14 +0100
parents 134bff10e561
children
comparison
equal deleted inserted replaced
151:e9c9404e3d1f 152:8f98b32d0e23
11 integralError = 0; 11 integralError = 0;
12 pastError = 0; 12 pastError = 0;
13 error = 0; 13 error = 0;
14 differentialError = 0; 14 differentialError = 0;
15 kp = 5; 15 kp = 5;
16 ki = 2; 16 ki = 2;// 2;
17 kd = 0.8; 17 kd = 0.8; //0.8;
18 gain = 1;
18 idleTimeout = 0; 19 idleTimeout = 0;
19 timeoutCount = 0; 20 timeoutCount = 0;
20 output = 0; 21 output = 0;
21 // printf("----------%f %f %f %f %f %f\n", kp, error, ki, integralError, kd, differentialError); 22 // printf("----------%f %f %f %f %f %f\n", kp, error, ki, integralError, kd, differentialError);
22 } 23 }
30 pastError = error; 31 pastError = error;
31 error = anError; 32 error = anError;
32 ts = 1; //TODO: this should be passed as a parameter, unless setError() gets always called at constant intervals 33 ts = 1; //TODO: this should be passed as a parameter, unless setError() gets always called at constant intervals
33 updateIntegralError(); 34 updateIntegralError();
34 updateDifferentialError(); 35 updateDifferentialError();
35 output= kp * error + ki * integralError + kd * differentialError; 36 output = gain * (kp * error + ki * integralError + kd * differentialError);
36 // printf("%f %f %f %f %f %f %f\n", output, kp, error, ki, integralError, kd, differentialError); 37 // printf("%f %f %f %f %f %f %f\n", output, kp, error, ki, integralError, kd, differentialError);
37 return output; 38 return output;
38 } 39 }
39 float Pid::getOutput(){ 40 float Pid::getOutput(){
40 return output; 41 return output;
41 } 42 }
42 43 void Pid::setProportionalGain(float proportionalGain){
43 44 kp = proportionalGain;
45 }
46 void Pid::setDerivativeGain(float derivativeGain){
47 kd = derivativeGain;
48 }
49 void Pid::setIntegralGain(float integralGain){
50 ki = integralGain;
51 }
52 void Pid::setGlobalGain(float globalGain){
53 gain = globalGain;
54 }
55 float Pid::getProportionalGain(){
56 return kp;
57 }
58 float Pid::getDerivativeGain(){
59 return kd;
60 }
61 float Pid::getIntegralGain(){
62 return ki;
63 }
64 float Pid::getGlobalGain(){
65 return gain;
66 }
67 float Pid::getIntegralError(){
68 return integralError;
69 }