PID Control Version 1

Dependencies:   MODSERIAL biquadFilter mbed

Files at this revision

API Documentation at this revision

Comitter:
JorineOosting
Date:
Tue Oct 30 09:16:27 2018 +0000
Commit message:
PID control Version1;

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
biquadFilter.lib Show annotated file Show diff for this revision Revisions of this file
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 d2af5cdc35ff MODSERIAL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Tue Oct 30 09:16:27 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/JorineOosting/code/MODSERIAL/#05131df90d24
diff -r 000000000000 -r d2af5cdc35ff biquadFilter.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/biquadFilter.lib	Tue Oct 30 09:16:27 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tomlankhorst/code/biquadFilter/#26861979d305
diff -r 000000000000 -r d2af5cdc35ff main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 30 09:16:27 2018 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "BiQuad.h"
+
+//Gebaseerd op PES Lecture 5
+
+//void BiQuad::PIDF( double Kp, double Ki, double Kd, double N, double Ts  ) {
+ 
+//    double b0, b1, b2, bd, a1, a2;
+ 
+//    a1 = -4.0/(N*Ts+2.0);
+//    a2 = -(N*Ts-2.0)/(N*Ts+2.0);
+ 
+//   bd = ( N*Ts+2.0 );
+ 
+//    b0 = ( 4.0*Kp + 4.0*Kd*N + 2.0*Ki*Ts + 2.0*Kp*N*Ts + Ki*N*Ts*Ts )/(2.0*bd);
+//    b1 = ( Ki*N*Ts*Ts - 4.0*Kp - 4.0*Kd*N )/bd;
+//    b2 = ( 4.0*Kp + 4.0*Kd*N - 2*Ki*Ts - 2*Kp*N*Ts + Ki*N*Ts*Ts )/(2.0*bd);
+ 
+//    set( b0, b1, b2, a1, a2 );
+
+//};
+
+    double Kp  = 17.5;                          //Zelf variëren
+    double Ki = 1.02;                           //Zelf variëren
+    double Kd = 23.2;                           //Zelf variëren
+    double yref;                                
+    double y; 
+    double error = yref-y;
+    double Ts = 0.0025;                         //Tijdstap van de Ticker 
+
+int main()
+{
+
+    // double N
+    double PID_control(error);                  //Waarom is dit een variabele? 
+    {
+        static double error_i =0;
+        static double error_prev = error;
+        static BiQuad LowPassFilter(0.6389 1.2779 0.6389 1.143 0.4128); //b0,b1,b2,a0,a1: coëfficiënten moeten berekend worden met butter in MATLAB.
+                                                                             //Coëfficiënten zijn afhankelijk van cutoff frequency en sampling frequency
+        //Proportional part:
+        double u_p = Kp*error;
+    
+        //Integral part:
+        error_i = error_i + error*Ts;           //Berekenen integraal error
+        double u_i = Ki*error_i;
+        
+        //Derivative part:
+        double error_d = (error-error_prev)/Ts;
+        double f_error_d = LowPassFilter.step(error_d); //Filtered derivative error
+        double u_d = Kd*f_error_d;
+        error_prev = error;
+    
+        //Sum all parts and return it
+        double u_tot = u_p + u_i + u_d;         //Niet zeker of dit handig is
+        return u_tot;
+    }
+     // if loop toevoegen om de grenzen van de motor aan te geven 
+     // grenswaarden voor de hoeken uitlezen mbv de encoder
+}
+   
+    
\ No newline at end of file
diff -r 000000000000 -r d2af5cdc35ff mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 30 09:16:27 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file