from greg
Fork of PID by
Revision 8:a020a225bc65, committed 2013-12-31
- Comitter:
- oprospero
- Date:
- Tue Dec 31 05:28:01 2013 +0000
- Parent:
- 7:1b1c2ded95f5
- Child:
- 9:244f8204d1fa
- Commit message:
- Added methods to change P and D values
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 Sat Dec 21 08:27:42 2013 +0000 +++ b/PID.cpp Tue Dec 31 05:28:01 2013 +0000 @@ -27,7 +27,7 @@ proportionalControl = integralControl = derivativeControl = 0; } -float PID::correct(const float currentError, const float pGain) +float PID::correct(const float currentError) { // float currentError = 0; // float proportionalControl, integralControl, derivativeControl; @@ -35,7 +35,6 @@ // How far away we are from the target // currentError = targetPosition - currentPosition; - proportionalGain = pGain; // Sum of the errors the controller has incurred over time integralError += currentError; // Cap the sum of errors to prevent excessive correction @@ -57,3 +56,13 @@ return proportionalControl + integralControl + derivativeControl; } + +void PID::updateP(const float pGain) +{ + proportionalGain = pGain; +} + +void PID::updateD(const float dGain) +{ + derivativeGain = dGain; +} \ No newline at end of file
--- a/PID.h Sat Dec 21 08:27:42 2013 +0000 +++ b/PID.h Tue Dec 31 05:28:01 2013 +0000 @@ -43,12 +43,15 @@ * eg. PID can be switched off for manual control) * @return Adjustment to apply to the motors. */ - float correct(const float, const float); + float correct(const float); + + void updateP(const float); + void updateD(const float); private: float proportionalGain; const float integralGain; - const float derivativeGain; + float derivativeGain; const float windupGainGuard; const int dt; float proportionalControl, integralControl, derivativeControl;