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: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: controller_copy.cpp
- Revision:
- 40:82addb417220
diff -r 5e2e95c322da -r 82addb417220 controller_copy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/controller_copy.cpp Mon Oct 14 11:46:35 2019 +0000 @@ -0,0 +1,25 @@ +//Gains +double e = 1.02; +double Ts = 0.92; + + double K_p = 1;//Position gain + double K_i = 1;//Integral gain + double K_d = 1;//Diverentiation gain + + //static double u_i = 0; + static double e_Prev = 0; + +double ControllerPID(double e, double Ts) +{ + double u_p = K_p*e; //Position action + double u_i = K_i*(e*Ts+u_i); //Integral action + double u_d = K_d*((e-e_Prev)/Ts); //Diverential action + + e_Prev = e; //Write error to previous error + + double u; + + u = u_p + u_i + u_d; + + return u; +} \ No newline at end of file