![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
4 directional EMG control of the XY table. Made during my bachelor end assignment.
Dependencies: C12832_lcd HIDScope mbed-dsp mbed
Diff: main.cpp
- Revision:
- 27:c7b1851c9bb7
- Parent:
- 26:b88ff19ff5dc
- Child:
- 28:593929bbdb98
diff -r b88ff19ff5dc -r c7b1851c9bb7 main.cpp --- a/main.cpp Mon May 11 15:37:58 2015 +0000 +++ b/main.cpp Mon May 18 09:52:02 2015 +0000 @@ -3,8 +3,6 @@ #include "arm_math.h" #include "HIDScope.h" -#define P_GAIN 0.998 - //Motor control DigitalOut Dir(p21); PwmOut Step(p22); @@ -28,7 +26,7 @@ C12832_LCD lcd; //Variables for motor control -float setpoint = 7000; //Frequentie +float setpoint = 6500; //Frequentie float step_freq = 1; @@ -36,8 +34,10 @@ arm_biquad_casd_df1_inst_f32 lowpass_pot; arm_biquad_casd_df1_inst_f32 lowpass_step; -//lowpass filter settings: Fc = 0.5 Hz, Fs = 100 Hz, Gain = -3 dB -float lowpass_const[] = {0.06089863257570727, 0, 0, 0.9391013674242927, 0}; +//lowpass filter settings: Fc = 1 Hz, Fs = 100 Hz, Gain = -3 dB onepole-lp +float lowpass_const[] = {0.0201, 0.0402 , 0.0201, 1.5610, -0.6414}; +//Lowpass filter potmeter: Fc = 0.5 Hz, Fs = 500 Hz, +//float lowpass_const[] = {0.000009825916403675327, 0.000019651832807350654, 0.000009825916403675327, 1.991114207740345, -0.9911535114059596}; //lowpass for step_freq: Fc = 2 Hz, Fs = 100, Gain = 6 dB //float lowpass1_const[] = {0.007820199259120319, 0.015640398518240638, 0.007820199259120319, 1.7347238224240125, -0.7660046194604936}; @@ -94,19 +94,20 @@ arm_biquad_cascade_df1_f32(&lowpass_pot, &pot_value1_f32, &filtered_pot, 1 ); } + void looper_motor() { float new_step_freq; - new_step_freq = (setpoint*pot_value1_f32*2); + new_step_freq = (setpoint*filtered_pot*2); step_freq = abs(new_step_freq); //Gives the PWM frequenty to the motor. //arm_biquad_cascade_df1_f32(&lowpass_step, &step_freq, &filtered_step, 1); - if (step_freq < 700) { + if (step_freq < 850) { Enable = 1; } else { Enable = 0; } - Step.period(1.0/step_freq); + Step.period(1.0/(100 + step_freq)); } int main() @@ -122,28 +123,27 @@ emgtimer.attach(looper_emg, 0.002);*/ Ticker looptimer; - //arm_biquad_cascade_df1_init_f32(&lowpass_step, 1, lowpass1_const, lowpass1_step_states); looptimer.attach(looper_motor, 0.01); MS1 = 1; MS2 = 0; MS3 = 0; - Step.period(1./step_freq); + //Step.period(1/step_freq); Step.write(0.5); // Duty cycle van 50% while (1) { - if (pot_value1_f32 < 0) { //Directie controle. + if (filtered_pot < 0) { //Directie controle. Dir = 0; } else { Dir = 1; } - - lcd.printf("Raw %.4f Hz Filt %.4f \n", Pot1.read(), filtered_pot); //snelheid meting op lcd + Step.write(0.5); + lcd.printf("Freq %.0f Hz Filt %.4f \n", step_freq, filtered_pot); //snelheid meting op lcd //pc.printf(" %.4f \n", Pot1.read()); //lcd.printf("filt %.3f raw %.3f \n", filtered_biceps, emg0.read()); //pc.printf("Spd %.0f Hz p1 %.4f \n", step_freq, pot_value1_f32); //snelheid meting op lcd - wait(0.01); + wait(0.002); }