![](/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:
- 24:c4c5d30a3938
- Parent:
- 23:4d050e85e863
- Child:
- 25:144eb5822aa7
diff -r 4d050e85e863 -r c4c5d30a3938 main.cpp --- a/main.cpp Fri May 08 12:00:17 2015 +0000 +++ b/main.cpp Fri May 08 13:35:41 2015 +0000 @@ -12,7 +12,7 @@ //Signal to and from computer Serial pc(USBTX, USBRX); -DigitalOut Enable(p14); +DigitalOut Enable(p25); //Microstepping DigitalOut MS1(p27); @@ -22,15 +22,10 @@ //Potmeter and EMG AnalogIn Pot1(p19); AnalogIn emg0(p20); -HIDScope scope(2); +//HIDScope scope(2); //lcd C12832_LCD lcd; -//Joystick control (probably not necessary -BusIn Joystick(p12,p13,p14,p15,p16); -DigitalIn Up(p15); -DigitalIn Down(p12); - //Variables for motor control float setpoint = 7000; //Frequentie float step_freq = 1; @@ -67,28 +62,16 @@ float filtered_step; float pot_value1_f32; -//Averaging (look if necessary) -/*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_emg() { /*variable to store value in*/ - uint16_t emg_value1; + //uint16_t emg_value1; float emg_value1_f32; /*put raw emg value both in red and in emg_value*/ - emg_value1 = emg0.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) + //emg_value1 = emg0.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) emg_value1_f32 = emg0.read(); //process emg biceps @@ -97,9 +80,9 @@ arm_biquad_cascade_df1_f32(&lowpass_biceps, &filtered_biceps, &filtered_biceps, 1 ); /*send value to PC. */ - scope.set(0,emg_value1); //Raw EMG signal biceps - scope.set(1,filtered_biceps); //Filtered signal - scope.send(); + //scope.set(0,emg_value1); //Raw EMG signal biceps + //scope.set(1,filtered_biceps); //Filtered signal + //scope.send(); } void looper_pot() { @@ -116,6 +99,12 @@ new_step_freq = (setpoint*pot_value1_f32*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) { + Enable = 1; } + else { + Enable = 0; + } Step.period(1.0/step_freq); } @@ -125,6 +114,11 @@ //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_pot, 0.01); + + /*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);*/ Ticker looptimer; arm_biquad_cascade_df1_init_f32(&lowpass_step, 1, lowpass1_const, lowpass1_step_states); @@ -133,7 +127,7 @@ MS1 = 1; MS2 = 0; MS3 = 0; - //Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer. + 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% while (1) { @@ -143,10 +137,10 @@ } else { Dir = 1; } - - + lcd.printf("Spd %.0f Hz p1 %.4f \n", step_freq, pot_value1_f32); //snelheid meting op lcd - pc.printf("Spd %.0f Hz p1 %.4f \n", step_freq, pot_value1_f32); //snelheid meting op lcd + pc.printf("filt %f \n", filtered_biceps); + // pc.printf("Spd %.0f Hz p1 %.4f \n", step_freq, pot_value1_f32); //snelheid meting op lcd wait(0.01);