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:
- 28:593929bbdb98
- Parent:
- 27:c7b1851c9bb7
- Child:
- 29:83f005c637be
diff -r c7b1851c9bb7 -r 593929bbdb98 main.cpp --- a/main.cpp Mon May 18 09:52:02 2015 +0000 +++ b/main.cpp Tue May 19 15:16:50 2015 +0000 @@ -20,7 +20,7 @@ //Potmeter and EMG AnalogIn Pot1(p19); AnalogIn emg0(p17); -//HIDScope scope(2); +HIDScope scope(2); //lcd C12832_LCD lcd; @@ -34,12 +34,12 @@ arm_biquad_casd_df1_inst_f32 lowpass_pot; arm_biquad_casd_df1_inst_f32 lowpass_step; -//lowpass filter settings: Fc = 1 Hz, Fs = 100 Hz, Gain = -3 dB onepole-lp +//lowpass filter potmeter: Fcn = 0.1 Hz, Fs = 100 Hz 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}; +//lowpass filter potmeter: Fcn = 0.05 Hz, Fs = 500 +//float lowpass_const[] = {0.0055, 0.0111, 0.0055, 1.7786, -0.8008}; //EMG filter arm_biquad_casd_df1_inst_f32 lowpass_biceps; @@ -54,7 +54,6 @@ float lowpass_biceps_states[4]; float highnotch_biceps_states[8]; float lowpass_pot_states[4]; -float lowpass1_step_states[4]; //global variabels float filtered_biceps; @@ -83,7 +82,7 @@ /*send value to PC. */ //scope.set(0,emg_value1); //Raw EMG signal biceps //scope.set(1,filtered_biceps); //Filtered signal - //scope.send(); + // scope.send(); } void looper_pot() { @@ -92,6 +91,9 @@ //process input arm_biquad_cascade_df1_f32(&lowpass_pot, &pot_value1_f32, &filtered_pot, 1 ); + scope.set(0, filtered_pot); + scope.set(1, Pot1.read()); + scope.send(); } @@ -100,7 +102,7 @@ float new_step_freq; 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 < 850) { Enable = 1; @@ -117,10 +119,10 @@ arm_biquad_cascade_df1_init_f32(&lowpass_pot, 1 , lowpass_const, lowpass_pot_states); log_timer.attach(looper_pot, 0.01); - /*Ticker emgtimer; + Ticker emgtimer; arm_biquad_cascade_df1_init_f32(&lowpass_biceps, 1 , lowpass_const, lowpass_biceps_states); arm_biquad_cascade_df1_init_f32(&highnotch_biceps, 2 , highnotch_const, highnotch_biceps_states); - emgtimer.attach(looper_emg, 0.002);*/ + emgtimer.attach(looper_emg, 0.005); Ticker looptimer; looptimer.attach(looper_motor, 0.01); @@ -140,10 +142,10 @@ } 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()); + //pc.printf(" %.4f \n", filtered_pot); //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.002); + wait(0.01); }