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.
Revision 0:cbabd9031b37, committed 2018-10-15
- Comitter:
- Rhein
- Date:
- Mon Oct 15 09:41:49 2018 +0000
- Commit message:
- PES_Lecture5_Assignment
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r cbabd9031b37 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Oct 15 09:41:49 2018 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+
+DigitalOut gpo(D0);
+DigitalOut led(LED_RED);
+DigitalOut motor_dir(D7);
+
+double Kp = 17.5;
+double Ki = 1.02;
+double Kd = 23.2;
+double Ts = 0.01; //Sample time in seconds
+
+ double GetReferenceVelocity() //Determine reference value
+ {
+ const float maxVelocity = 8.4;
+ double referenceVelocity;
+
+ if (botton1)
+ {
+ referenceVelocity = PotMeterIn * maxVelocity;
+ }
+ else
+ {
+ referenceVelocity = -1*PotMeterIn * maxVelocity;
+ }
+ return referenceVelocity;
+
+ }
+
+ double GetActualPosition() // measure plant output
+ {
+ double pos_rad = - (pos_counts - pos_offset_counts) / (double)counts_per_rad;
+ return pos_rad;
+ }
+
+ double PID_controller(double error)
+ {
+ static double error_integral = 0;
+ static double error_prev = error;
+ static Biquad LowpassFilter(0.0640,0.1279,0.0640,-1.1683,0.4241);
+
+ //P part
+ double u_k = Kp * e;
+
+ //I part
+ error_integral = error_integral + error * Ts;
+ double u_i = Ki * error_integral;
+
+ //D part
+ double error_derivative = (error - error_prev)/Ts;
+ double filtered_error_derivatice = LowPassFilter.step(error_derivative);
+ double u_d = Kd * filtered_error_derivative;
+ error_prev = error;
+
+ return u_k + u_i + u_d;
+ }
\ No newline at end of file
diff -r 000000000000 -r cbabd9031b37 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Oct 15 09:41:49 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file