20171016_PID_controller_working

Dependencies:   MODSERIAL QEI biquadFilter mbed

Fork of 20171013_PI_controller_working_tryingtoaddPID by V D

Files at this revision

API Documentation at this revision

Comitter:
vd
Date:
Tue Oct 17 16:22:41 2017 +0000
Parent:
2:02b385b96543
Commit message:
working PID and printing works too;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 02b385b96543 -r 7e616fcf471d main.cpp
--- a/main.cpp	Sun Oct 15 21:19:11 2017 +0000
+++ b/main.cpp	Tue Oct 17 16:22:41 2017 +0000
@@ -23,13 +23,13 @@
 Ticker controller;
 
 const double pi = 3.1415926535897;
-const double M1_TS = 0.01; // (was 0.0001) 0.001 and 0.01 work without biquad filter.
+const double M1_TS = 0.01; // (was 0.0001) 0.001 and 0.01 work without biquad filter. // // Sample time (motor - timestep)
 
 //verplaatst
 const float RAD_PER_PULSE = (2*pi)/4200;
 const float CONTROLLER_TS = 0.01;     //TIME INTERVAL/ hZ
 
-const float M1_KP = 10, M1_KI = 1.0, M1_KD = 0.5; //was KP=10 KI=0.5 KD=0.5
+const float M1_KP = 10, M1_KI = 0.5, M1_KD = 0.5; //was KP=10 KI=0.5 KD=0.5
 double m1_err_int = 0, m1_prev_err = 0 ;
 const double M1_F_A1 = 1.0 , M1_F_A2  = 2.0 , M1_F_B0  = 1.0 , M1_F_B1  = 3.0 , M1_F_B2  = 4.0 ;
 double m1_f_v1  = 0  , m1_f_v2  = 0 ;
@@ -44,7 +44,7 @@
 }
 */
 
-/*
+/* Stukje code dat hier stond maar is verplaatst naar line 29:
 const float RAD_PER_PULSE = (2*pi)/4200;
 const float CONTROLLER_TS = 0.001;     //TIME INTERVAL/ hZ
 
@@ -63,7 +63,7 @@
 double PID(double e, const double Kp, const double Ki, const double Kd, double Ts, double &e_int, double &e_prev, double &f_v1, double &f_v2, const double f_a1, const double f_a2, const double f_b0, const double f_b1, const double f_b2){
 
 // Derivative
-double e_der = (e - e_prev)/Ts;
+double e_der = (e - e_prev)/Ts; // Ts = motor1-timestep
 
 
 // biquad part, see slide
@@ -201,6 +201,7 @@
 
 */
 
+
 int main(){
     pc.baud(9600);
     //controller.attach(&m1_Controller, CONTROLLER_TS);            --> P one
@@ -215,7 +216,9 @@
     //float motor1 = PID(reference - position, M1_KP, M1_KI, M1_KD, M1_TS, m1_err_int, m1_prev_err, m1_f_v1, m1_f_v2, M1_F_A1, M1_F_A2, M1_F_B0, M1_F_B1, M1_F_B2);
     double motor1 = PID(reference - position, M1_KP, M1_KI, M1_KD, M1_TS, m1_err_int, m1_prev_err, m1_f_v1, m1_f_v2, M1_F_A1, M1_F_A2, M1_F_B0, M1_F_B1, M1_F_B2);
 
-        pc.printf("\r value motor1: %f. reference Pot: %f. Position: %f \n", motor1, reference, position);           
+        pc.printf("\r value motor1: %f. reference Pot: %f. Position: %f \n", motor1, reference, position);     
+                  
     }
 }
 
+// Voor Mac: screen /dev/tty.usbmodem1422 9600