PID control with a lowpass filter to make the motor follow pot1
Dependencies: HIDScope QEI mbed
Fork of PID_control_with_lowpass by
Diff: main.cpp
- Revision:
- 6:60227fd3b30f
- Parent:
- 5:43e34b6d66af
- Child:
- 7:dbc066a7bb66
diff -r 43e34b6d66af -r 60227fd3b30f main.cpp --- a/main.cpp Mon Sep 28 09:27:22 2015 +0000 +++ b/main.cpp Mon Sep 28 11:23:06 2015 +0000 @@ -11,6 +11,7 @@ //ingangen AnalogIn pot1(A2); +IntertuptIn changecontrollervalue(PTA4); //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) @@ -65,6 +66,7 @@ return y; } ///////////////////////////////////////////////////////////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; @@ -88,7 +90,6 @@ return Kp * e + Ki * motor1_error_int + Kd * e_der; } - ///////////////////////////////////////////////////////////GO-FLAGS AND ACTIVATION FUNCTIONS/////////////////////////////// //go flags volatile bool scopedata_go=false, pid_control_go=false; @@ -152,8 +153,20 @@ scopedata(); scopedata_go=false; } + //intterrupt in to change controller values + if (changecontrollervalues==0) { + motor1_speed_control=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.scanf("%f", &motor1_pid_kd); + } + } return 0; //gives warning: unreachable - } \ No newline at end of file