PID control with a lowpass filter to make the motor follow pot1

Dependencies:   HIDScope QEI mbed

Fork of PID_control_with_lowpass by Jasper Gerth

Files at this revision

API Documentation at this revision

Comitter:
Gerth
Date:
Mon Sep 28 11:36:56 2015 +0000
Parent:
6:60227fd3b30f
Commit message:
now with the serial connection value change working;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Sep 28 11:23:06 2015 +0000
+++ b/main.cpp	Mon Sep 28 11:36:56 2015 +0000
@@ -11,7 +11,8 @@
 
 //ingangen
 AnalogIn pot1(A2);
-IntertuptIn changecontrollervalue(PTA4);
+InterruptIn changecontrollervalues(PTA4);
+Serial pc(USBTX, USBRX);
 
 //uitgangen
 DigitalOut motor1_direction(D7);// draairichting motor 1 (1 is CW encoder als je daar op kijkt en CW shaft als je daar op kijkt)
@@ -68,9 +69,9 @@
 ///////////////////////////////////////////////////////////CONTROLLERS//////////////////////////////////////////////////////////
 
 //DIT ZIJN ZOMAAR WAARDEN, AANPASSEN DUS WAARDES BEREKENEN MET MATLAB
-const float motor1_pid_kp=0.5;
-const float motor1_pid_ki=0.01;
-const float motor1_pid_kd=0.01;
+float motor1_pid_kp=0.5;
+float motor1_pid_ki=0.01;
+float motor1_pid_kd=0.01;
 
 double motor1_error_int=0;
 double motor1_error_prev=0;
@@ -155,18 +156,16 @@
         }
         //intterrupt in to change controller values
         if (changecontrollervalues==0) {
-            motor1_speed_control=0;
+            motor1_speed_control.write(0);
             pc.printf("KP is now %f, enter new value\n",motor1_pid_kp);
             pc.scanf("%f", &motor1_pid_kp);
 
             pc.printf("KI is now %f, enter new value\n",motor1_pid_ki);
             pc.scanf("%f", &motor1_pid_ki);
 
-            pc.printf("KP is now %f, enter new value\n",motor1_pid_kd);
+            pc.printf("KD is now %f, enter new value\n",motor1_pid_kd);
             pc.scanf("%f", &motor1_pid_kd);
         }
-
-
     }
     return 0; //gives warning: unreachable
 }
\ No newline at end of file