Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: PID.cpp
- Revision:
- 0:88340ec1ec48
- Child:
- 1:09b63bc8f46a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PID.cpp Tue Jul 23 04:16:56 2019 +0000 @@ -0,0 +1,35 @@ +#include "PID.h" + +PID::PID(double INT_TIME){ + time = INT_TIME; + reset(); +} + +void PID::set(double P, double I, double D){ + p = P; + i = I; + d = D; +} + +double PID::con (double error){ + static double pre_err = 0.0; + double result = 0; + + result += error * p; + + integ += (error + pre_err) / 2.0 * time; + result += integ * i; + + result += (error - pre_err) / time; + + pre_err = error; + + return result; +} + +void PID::reset(){ + p = 0.0; + i = 0.0; + d = 0.0; + integ = 0.0; +} \ No newline at end of file