Werkend aansturingsscript voor 2 motoren, incl werkende program switch. Motoren oscilleren nog iets. Vuur mechanisme ontbreekt nog.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of frdm_Motor_V2_3 by
Diff: main.cpp
- Revision:
- 21:cd7eb62183da
- Parent:
- 20:f5091e29cd26
- Child:
- 23:6b7695ffadcb
diff -r f5091e29cd26 -r cd7eb62183da main.cpp --- a/main.cpp Fri Oct 02 17:22:17 2015 +0000 +++ b/main.cpp Fri Oct 02 18:15:24 2015 +0000 @@ -18,9 +18,12 @@ PwmOut motor2speed(D5); //Tickers -Ticker ScopeTime; -Ticker myControllerTicker; -Ticker PrintTime; +Ticker t1, t2, t3, t4; +volatile bool fn1_go = false, fn2_go = false, fn3_go = false, fn4_go = false; +void fn1_activate(){ fn1_go = true; }; //Activates the go−flag +void fn2_activate(){ fn2_go = true; }; +void fn3_activate(){ fn3_go = true; }; +void fn4_activate(){ fn4_go = true; }; //Startwaarden double reference; @@ -88,7 +91,6 @@ void motor2_Controller() { reference = m2_ref; // Setpoint - double pulses = Encoder.getPulses(); 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); @@ -111,30 +113,50 @@ LedG.write(1); pc.baud(115200); pc.printf("Tot aan loop werkt\n"); + - ScopeTime.attach_us(&ScopeSend, 10e4); - myControllerTicker.attach( &motor2_Controller, 0.01f ); // 100 Hz - PrintTime.attach(&PCPrintf,0.1f); + t1.attach( &fn1_activate, 0.01f); // Function@100hz + t2.attach( &fn2_activate, 0.001f); // Function@ 1khz + t3.attach( &fn3_activate, 0.2f); // Function@ 5hz + t4.attach( &fn3_activate, 0.02f); // Function@ 50hz + while(true) { char c = pc.getc(); + if(fn1_go) + { + fn1_go = false; + motor2_Controller(); + } + if(fn2_go) + { + fn2_go = false; + ScopeSend(); + } + if(fn3_go) + { + fn3_go = false; + PCPrintf(); + } + if(c == 'e') //Ga 1 programma omhoog { - count = count + 1; + count = count + 1; if(count > 2) - { - count = 2; - } - + { + count = 2; + } } + if(c == 'd') //Ga 1 programma omlaag { count = count - 1; if(count < 0) - { - count = 0; - } - } + { + count = 0; + } + } + if(count == 0) //Motor 1 control {