EMG test for robot is working (to get thresholds)
Dependencies: HIDScope biquadFilter mbed
Fork of EMG_prog_robot by
Diff: main.cpp
- Revision:
- 2:c32de830a7d9
- Parent:
- 1:dea6b70cd991
- Child:
- 3:35103d6e7d2a
diff -r dea6b70cd991 -r c32de830a7d9 main.cpp --- a/main.cpp Tue Nov 01 17:04:39 2016 +0000 +++ b/main.cpp Wed Nov 02 09:32:11 2016 +0000 @@ -18,10 +18,11 @@ double EMGright, EMGleft, inR; int EMGgain=1; //set initial conditions -double biceps_l = 0; -double biceps_r = 0; +//double biceps_l = 0; +//double biceps_r = 0; double outRenvelope, outLenvelope; -double T; +int T=4; + void filter_timer_act(){filter_timer_go=true;}; @@ -44,8 +45,10 @@ BiQuad bq2L(9.8239e-01,-1.9648e+00,9.8239e-01,-1.9645e+00,9.6508e-01); // Low pass Butterworth filter 2nd order, Fc = 8; BiQuad bq3L(5.6248e-05,1.1250e-04,5.6248e-05,-1.9787e+00,9.7890e-01); + // In the following: R is used for right arm, L is used for left arm! -void FilteredSample() + +void FilteredSample(int &Tout) { double inLout = emg0.read(); double inRout = emg1.read(); @@ -58,15 +61,15 @@ double outLrect = fabs(outLfilter1); double envelopeL = bcq2L.step(outLrect); - biceps_l = (double) outLenvelope * EMGgain; //emg0.read(); //velocity or reference position change, EMG with a gain - biceps_r = (double) outRenvelope * EMGgain; //emg1.read(); + 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){ //both arms activated: stamp moves down //pc.printf("Stamp down\n\r"); //pc.printf("right: %f\n\r",biceps_r); //pc.printf("left: %f\n\r",biceps_l); //wait(0.5); - T = -1; + Tout = -1; led1=!led1;//blink purple led2=!led2; } @@ -76,7 +79,7 @@ //pc.printf("right: %f\n\r",biceps_r); //pc.printf("left: %f\n\r",biceps_l); //wait(0.5); - T = -2; + Tout = -2; led2=1;//off led1=0;//on red } @@ -86,7 +89,7 @@ //pc.printf("right: %f\n\r",biceps_r); //pc.printf("left: %f\n\r",biceps_l); //wait(0.5); - T = 2; + Tout = 2; led2=0;//on blue led1=1;//off } @@ -96,7 +99,7 @@ led2 = 1; //off //pc.printf("Nothing...\n\r"); //wait(0.5); - T = 0; + Tout = 5; } /*pc.printf("EMG right = %f\n\r",inRout); @@ -108,11 +111,11 @@ scope.set(1, inLout); scope.set(2, envelopeR); scope.set(3, envelopeL); - scope.set(4, T); + scope.set(4, Tout); scope.send(); // To indicate that the function is working, the LED is toggled*/ - led2 = !led2; + //led2 = !led2; } /*void sendValues( double outRenvelope, double outLenvelope){ @@ -181,7 +184,7 @@ { if (filter_timer_go){ filter_timer_go=false; - FilteredSample();} + FilteredSample(T);} /*if (send_timer_go){ send_timer_go=false; sendValues(outRenvelope, outLenvelope);}*/