Motor control

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
7:20a802dfe664
Parent:
6:1c0b6e55e900
Child:
8:c6c94d55b088
--- a/main.cpp	Fri Oct 11 12:33:42 2019 +0000
+++ b/main.cpp	Fri Oct 11 13:02:43 2019 +0000
@@ -35,9 +35,9 @@
 double potValue;
 double pi2= 6.283185;
 float e; //e = error
-float Kp;
-float Ki=1;
-float Kd=21.5;
+float Kp=0.45;
+float Ki=0;
+float Kd;
 float u_k;
 float u_i;
 float u_d;
@@ -70,7 +70,7 @@
     static BiQuad LowPassFilter(0.0640,0.1279,0.0640,-1.1683,0.4241);
     
     //Proportional part:
-    Kp=20*potmeter2.read();
+    Kd=0.5*potmeter2.read();
     u_k=Kp*e;
     
     //Integral part
@@ -141,11 +141,11 @@
     button2.fall(&toggleMotor);
     while (true) {
 
-        pc.printf("Potmeter: %d Kp: %f\r\n", potValue,Kp);
-        pc.printf("Counts: %i   DeltaCounts: %i\r\n", counts, deltaCounts);
+        //pc.printf("Potmeter: %d \r\n", potValue,);
+        //pc.printf("Counts: %i   DeltaCounts: %i\r\n", counts, deltaCounts);
         pc.printf("Angle:  %f   Omega:       %f\r\n", angle, omega);
         pc.printf("U1: %f   Error:  %f     \r\n",u1, e);
-        
+        pc.printf("Kp: %f   Kd: %f   Ki:    %f \r\n", Kp, Kd, Ki);
         
         wait(0.5);
     }