Mercurial > hg > beaglert
diff 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 |
line wrap: on
line diff
--- a/core/Pid.cpp Tue Sep 22 04:10:07 2015 +0100 +++ b/core/Pid.cpp Mon Oct 05 13:06:14 2015 +0100 @@ -13,8 +13,9 @@ error = 0; differentialError = 0; kp = 5; - ki = 2; - kd = 0.8; + ki = 2;// 2; + kd = 0.8; //0.8; + gain = 1; idleTimeout = 0; timeoutCount = 0; output = 0; @@ -32,12 +33,37 @@ ts = 1; //TODO: this should be passed as a parameter, unless setError() gets always called at constant intervals updateIntegralError(); updateDifferentialError(); - output= kp * error + ki * integralError + kd * differentialError; + output = gain * (kp * error + ki * integralError + kd * differentialError); // printf("%f %f %f %f %f %f %f\n", output, kp, error, ki, integralError, kd, differentialError); return output; } float Pid::getOutput(){ return output; } - - +void Pid::setProportionalGain(float proportionalGain){ + kp = proportionalGain; +} +void Pid::setDerivativeGain(float derivativeGain){ + kd = derivativeGain; +} +void Pid::setIntegralGain(float integralGain){ + ki = integralGain; +} +void Pid::setGlobalGain(float globalGain){ + gain = globalGain; +} +float Pid::getProportionalGain(){ + return kp; +} +float Pid::getDerivativeGain(){ + return kd; +} +float Pid::getIntegralGain(){ + return ki; +} +float Pid::getGlobalGain(){ + return gain; +} +float Pid::getIntegralError(){ + return integralError; +}