![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
motor met PID controller, aangestuurd via pc.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of frdm_Motor_V2 by
Diff: main.cpp
- Revision:
- 14:baebaef79aa6
- Parent:
- 13:a6770307a5d2
- Child:
- 15:7fbee317af2d
diff -r a6770307a5d2 -r baebaef79aa6 main.cpp --- a/main.cpp Tue Sep 29 16:48:08 2015 +0000 +++ b/main.cpp Tue Sep 29 16:58:52 2015 +0000 @@ -18,6 +18,7 @@ double Aantal_pulses; double reference; double position; +double m2_ref; void ScopeSend()//Functie die de gegevens voor de scope uitleest en doorstuurt { @@ -33,7 +34,7 @@ const double m2_Ts = 0.01; // Controller gain -const double m2_Kp = 0.07,m2_Ki = 0.005, m2_Kd = 0.005; +const double m2_Kp = 0.07,m2_Ki = 0.005, m2_Kd = 0.001; double m2_err_int = 0, m2_prev_err = 0; //Derivative filter coeffs @@ -69,7 +70,7 @@ // Motor control void motor2_Controller() { - reference = potmeter2.read()*360; + reference = m2_ref; position = Encoder.getPulses()*360/(0.5*128*131); // Aantal Degs double P2 = PID( reference - position, m2_Kp, m2_Ki, m2_Kd, m2_Ts, m2_err_int, m2_prev_err, m2_f_v1, m2_f_v2, m2_f_a1, m2_f_a2, m2_f_b0, m2_f_b1, m2_f_b2); @@ -94,8 +95,16 @@ myControllerTicker.attach( &motor2_Controller, 0.01f ); // 100 Hz while(true) { + char c = pc.getc(); + if(c == 'r') + { + m2_ref = m2_ref + 5; + } + if(c == 'f') + { + m2_ref = m2_ref - 5; + } pc.printf("position = %f aantal degs = %f \n",reference,position); - wait(0.2f); } } \ No newline at end of file