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.
Dependencies: QEI biquadFilter mbed HIDScope
Diff: PID_controler.h
- Revision:
- 1:fafea1d00d0c
- Child:
- 2:f68fd7b1c655
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PID_controler.h Thu Nov 01 09:42:53 2018 +0000 @@ -0,0 +1,20 @@ +double PID_controller(double error, double Kp, double Ki, double Kd, double Ts) +{ + static double error_integral = 0; + static double error_prev = error; + static BiQuad LowPassFilter(0.0640, 0.1279, 0.0640, -1.1683, 0.4241); + + //proportional part + double u_k = Kp * error; + + //Integral part + error_integral = error_integral + error * Ts; + double u_i = Ki * error_integral; + + // Derivative part + double error_derivative = (error - error_prev)/Ts; + double filtered_error_derivative = LowPassFilter.step(error_derivative); + double u_d = Kd * filtered_error_derivative; + error_prev = error; + return ((u_k + u_i + u_d)/10000); +} \ No newline at end of file