from greg
Fork of PID by
Revision 5:43a44c2880a3, committed 2013-09-26
- Comitter:
- oprospero
- Date:
- Thu Sep 26 05:18:54 2013 +0000
- Parent:
- 4:e3cc82bee208
- Child:
- 6:d3d95134e5a5
- Commit message:
- set
Changed in this revision
PID.cpp | Show annotated file Show diff for this revision Revisions of this file |
PID.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/PID.cpp Mon Jul 29 19:58:42 2013 +0000 +++ b/PID.cpp Thu Sep 26 05:18:54 2013 +0000 @@ -21,6 +21,7 @@ { integralError = 0.0f; previousError = 0.0f; + errorTrim = 0.0f; } float PID::correct(const float currentPosition, @@ -41,11 +42,23 @@ } else if (integralError > windupGainGuard) { integralError = windupGainGuard; } - + + + float currentderivativeError = (currentError - previousError); +// if(currentderivativeError > 0 && currentError > 0){ +// errorTrim += currentderivativeError * 0.001; +// }else if (currentderivativeError < 0 && currentError < 0){ +// errorTrim += currentderivativeError * 0.001; +// } +// +// currentError += errorTrim; + + + // Calculate the correction, based on the tuning values proportionalControl = proportionalGain * currentError; integralControl = integralError * integralGain; - derivativeControl = derivativeGain * ((currentError - previousError) / dt); + derivativeControl = derivativeGain * (currentderivativeError / dt); // Save current error for next call to correction previousError = currentError;
--- a/PID.h Mon Jul 29 19:58:42 2013 +0000 +++ b/PID.h Thu Sep 26 05:18:54 2013 +0000 @@ -12,6 +12,7 @@ * * @author UWB Quadcopter group */ + class PID { @@ -52,6 +53,7 @@ float previousError; float integralError; + float errorTrim; };