![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
final version
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of Project_script_union_final by
Diff: main.cpp
- Revision:
- 14:fa09dae67390
- Parent:
- 13:a3d4b4daf5b4
- Child:
- 15:be67b090b64a
--- a/main.cpp Mon Oct 22 08:35:21 2018 +0000 +++ b/main.cpp Mon Oct 22 09:19:09 2018 +0000 @@ -8,8 +8,8 @@ AnalogIn emg1_in (A1); AnalogIn emg2_in (A2); -DigitalIn button1 (D10); //Let op, is deze niet bezet? En 11? Even checken, als er een error komt, kan het hier zitten. -DigitalIn button2 (D11); +InterruptIn button1 (SW2); //Let op, is deze niet bezet? En 11? Even checken, als er een error komt, kan het hier zitten. +InterruptIn button2 (SW3); InterruptIn encoderA (D9); InterruptIn encoderB (D8); @@ -32,17 +32,17 @@ //EMG filter double emgfilter0, emgfilter1, emgfilter2; //Filtered EMG data 0, 1 and 2 -double windowsize = 150; //Size of the array over which the moving average (MovAg) is calculated +const int windowsize = 150; //Size of the array over which the moving average (MovAg) is calculated double sum, sum1, sum2, sum3; //variables used to sum elements in array -double StoreArray0[sizeMovAg] = [], StoreArray1[sizeMoveAg] = [], StoreArray2[sizeMoveAg] = []; //Empty arrays to calculate MoveAg +double StoreArray0[windowsize], StoreArray1[windowsize], StoreArray2[windowsize]; //Empty arrays to calculate MoveAg double movAg0,movAg1,movAg2; //outcome of MovAg //calibration int x = 0; int emg_cal = 0; const int sizeCal = 2000; -double storeCal0[sizeCal] = [], storeCal1[sizeCal] = [], storeCal2[sizeCal] = []; -double meanCal0,meanCal1,meanCal2; +double StoreCal0[sizeCal], StoreCal1[sizeCal], StoreCal2[sizeCal]; +double Mean0,Mean1,Mean2; double Threshold0 = 1, Threshold1 = 1, Threshold2 = 1; @@ -63,6 +63,8 @@ BiQuad emg2band3( 1.00000e+00, -1.99999e+00, 9.99994e-01, -1.93552e+00, 9.39358e-01 ); BiQuad notch1( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01 ); //Notch filter +BiQuad notch2( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01 ); //Notch filter +BiQuad notch3( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01 ); //Notch filter //Tickers @@ -83,7 +85,7 @@ double emg1 = emg1_in.read(); double bandpass1 = emg1band.step(emg1); double absolute1 = fabs(bandpass1); - double notch1 = notch1.step(absolute1); + double notch1 = notch2.step(absolute1); } void EMGFilter2() @@ -91,7 +93,7 @@ double emg2 = emg2_in.read(); double bandpass2 = emg2band.step(emg2); double absolute2 = fabs(bandpass2); - double notch2 = notch1.step(absolute2); + double notch2 = notch3.step(absolute2); } void MovAg() //Calculate moving average (MovAg) @@ -120,7 +122,7 @@ movAg0 = sum1/windowsize; //calculates an average in the array movAg1 = sum2/windowsize; - movAg2 = sum3/sizeMovAg; + movAg2 = sum3/windowsize; } void emg_filtered() //Call all filter functions @@ -324,7 +326,7 @@ { pwmpin2 = 0; } - if(emgfilter2>Thresheld2) + if(emgfilter2>Threshold2) { pwmpin1 = 1; pwmpin2 = 2;