EMG measurement in HIDScope working!
Dependencies: HIDScope biquadFilter mbed
Revision 3:35103d6e7d2a, committed 2016-11-02
- Comitter:
- Marieke
- Date:
- Wed Nov 02 10:48:31 2016 +0000
- Parent:
- 2:c32de830a7d9
- Commit message:
- Script EMG: 2 channels in Hidscope working!
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c32de830a7d9 -r 35103d6e7d2a main.cpp --- a/main.cpp Wed Nov 02 09:32:11 2016 +0000 +++ b/main.cpp Wed Nov 02 10:48:31 2016 +0000 @@ -3,8 +3,8 @@ #include "HIDScope.h" //#define SERIAL_BAUD 115200 // baud rate for serial communication -// Serial communication with PC -Serial pc(USBTX,USBRX); +//Serial communication with PC +//Serial pc(USBTX,USBRX); AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); HIDScope scope( 5 ); @@ -15,13 +15,15 @@ volatile bool filter_timer_go=false,send_timer_go=false; -double EMGright, EMGleft, inR; +//double EMGright, EMGleft, inR; int EMGgain=1; //set initial conditions //double biceps_l = 0; //double biceps_r = 0; -double outRenvelope, outLenvelope; +//double outRenvelope, outLenvelope; int T=4; +double threshold_l=0.025; +double threshold_r = 0.025; @@ -61,35 +63,38 @@ double outLrect = fabs(outLfilter1); double envelopeL = bcq2L.step(outLrect); - double biceps_l = (double) outLenvelope * EMGgain; //emg0.read(); //velocity or reference position change, EMG with a gain - double biceps_r = (double) outRenvelope * EMGgain; //emg1.read(); - if (biceps_l > 0.04 && biceps_r > 0.04){ + double biceps_l = (double) envelopeL * EMGgain; //emg0.read(); //velocity or reference position change, EMG with a gain + double biceps_r = (double) envelopeR * EMGgain; //emg1.read(); + if (biceps_l > threshold_l && biceps_r > threshold_r){ //both arms activated: stamp moves down - //pc.printf("Stamp down\n\r"); - //pc.printf("right: %f\n\r",biceps_r); + //pc.printf("Stamp down "); + //pc.printf("right: %f ",biceps_r); //pc.printf("left: %f\n\r",biceps_l); //wait(0.5); Tout = -1; + //pc.printf("T=%d\n\r",T); led1=!led1;//blink purple led2=!led2; } - else if (biceps_l > 0.04 && biceps_r <= 0.04){ + else if (biceps_l > threshold_l && biceps_r <= threshold_r){ //arm 1 activated, move left - //pc.printf("Move left\n\r"); - //pc.printf("right: %f\n\r",biceps_r); + //pc.printf("Move left "); + //pc.printf("right: %f ",biceps_r); //pc.printf("left: %f\n\r",biceps_l); //wait(0.5); Tout = -2; + //pc.printf("T=%d\n\r",T); led2=1;//off led1=0;//on red } - else if (biceps_l <= 0.04 && biceps_r > 0.04){ + else if (biceps_l <= threshold_l && biceps_r > threshold_r){ //arm 1 activated, move right - //pc.printf("Move right\n\r"); - //pc.printf("right: %f\n\r",biceps_r); + //pc.printf("Move right "); + //pc.printf("right: %f ",biceps_r); //pc.printf("left: %f\n\r",biceps_l); //wait(0.5); Tout = 2; + //pc.printf("T=%d\n\r",T); led2=0;//on blue led1=1;//off } @@ -97,9 +102,11 @@ //wait(0.2); led1 = 1; led2 = 1; //off - //pc.printf("Nothing...\n\r"); + //pc.printf("Nothing... "); //wait(0.5); Tout = 5; + //pc.printf("right: %f ",biceps_r); + //pc.printf("left: %f\n\r",biceps_l); } /*pc.printf("EMG right = %f\n\r",inRout); @@ -113,11 +120,13 @@ scope.set(3, envelopeL); scope.set(4, Tout); + scope.send(); // To indicate that the function is working, the LED is toggled*/ //led2 = !led2; } + /*void sendValues( double outRenvelope, double outLenvelope){ biceps_l = (double) outLenvelope * EMGgain; //emg0.read(); //velocity or reference position change, EMG with a gain