![](/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:
- 20:07723b8348e3
- Parent:
- 19:f0875bc3b72f
diff -r f0875bc3b72f -r 07723b8348e3 main.cpp --- a/main.cpp Fri May 01 11:54:11 2015 +0000 +++ b/main.cpp Fri May 01 12:24:34 2015 +0000 @@ -18,6 +18,9 @@ DigitalIn Up(p15); DigitalIn Down(p12); +float setpoint = 7000; //Frequentie +float step_freq = 1; + // Filter arm_biquad_casd_df1_inst_f32 lowpass_pot; @@ -29,14 +32,29 @@ float lowpass_pot_states[4]; //globale variabele float filtered_pot; +float filtered_average_pot; float pot_value1_f32; -// EMG looper + +//Gemiddelde van de waarde nemen +/*void average_pot(float filtered_pot,float *average) +{ + static float total=0; + static float number=0; + total = total + filtered_pot; + number = number + 1; + if ( number == 50) { + *average = total/50; + total = 0; + number = 0; + } +}*/ + void looper() { /*variable to store value in*/ - // uint16_t pot_value1; + // uint16_t pot_value1; - + /*put raw emg value both in red and in emg_value*/ //pot_value1 = Pot1.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) pot_value1_f32 = Pot1.read() - 0.500; @@ -44,43 +62,42 @@ //process emg biceps arm_biquad_cascade_df1_f32(&lowpass_pot, &pot_value1_f32, &filtered_pot, 1 ); + //average_pot(filtered_pot,&filtered_average_pot); } - int main() { - Ticker log_timer; - //set up filters. Use external array for constants - arm_biquad_cascade_df1_init_f32(&lowpass_pot, 1 , lowpass_const, lowpass_pot_states); - log_timer.attach(looper, 0.01); - - Enable = 0; - float setpoint = 7000; //Frequentie - float step_freq = 1; - MS1 = 1; - MS2 = 0; - MS3 = 0; - //float p1; - //p1 = pot_value1_f32 - 0.500; +void looper_motor() +{ + float new_step_freq; + new_step_freq = (setpoint*pot_value1_f32*2); + step_freq = abs(new_step_freq); //Geeft een frequentie in 100 stappen. + Step.period(1.0/step_freq); +} +int main() +{ + Ticker log_timer; + //set up filters. Use external array for constants + arm_biquad_cascade_df1_init_f32(&lowpass_pot, 1 , lowpass_const, lowpass_pot_states); + log_timer.attach(looper, 0.01); + + Ticker looptimer; + looptimer.attach(looper_motor, 0.01); + + MS1 = 1; + MS2 = 0; + MS3 = 0; + Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. + Step.write(0.5); // Duty cycle van 50% - Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. - Step.write(0.5); // Duty cycle van 50% - // Dir = Pot1; // Dir 1 is naar boven, Dir 0 naar onder. - Enable = 1; - while (1) { + while (1) { - if (pot_value1_f32 < 0) { //Directie controle. - Dir = 0; - } else if (pot_value1_f32 > 0) { - Dir = 1; - } - // p1 = Pot1.read() - 0.500; //Offset creëren [-0.500;0.500] - - float new_step_freq; - new_step_freq = (setpoint*pot_value1_f32*2); - step_freq = abs(new_step_freq); //Geeft een frequentie in 100 stappen. - Step.period(1.0/step_freq); - //wait(0.01); //Hier nog ticker inbouwen - lcd.printf("Spd %.0f Hz p1 %.2f \n", step_freq, pot_value1_f32); //snelheid meting op lcd, zonder decimalen + if (pot_value1_f32 < 0) { //Directie controle. + Dir = 0; + } else if (pot_value1_f32 > 0) { + Dir = 1; + } + wait(0.01); + lcd.printf("Spd %.0f Hz p1 %.4f \n", step_freq, pot_value1_f32); //snelheid meting op lcd, zonder decimalen - } + } } \ No newline at end of file