even versimpelen
Dependencies: HIDScope MODSERIAL PID QEI biquadFilter mbed
Fork of cpfromralph1 by
Diff: main.cpp
- Revision:
- 25:07187cf76863
- Parent:
- 24:26659f1de039
- Child:
- 26:c9ba45bdd5c9
diff -r 26659f1de039 -r 07187cf76863 main.cpp --- a/main.cpp Thu Nov 03 13:40:17 2016 +0000 +++ b/main.cpp Thu Nov 03 14:58:42 2016 +0000 @@ -4,13 +4,12 @@ #include "MODSERIAL.h" //Define objects - AnalogIn emg1_in( A0 ); + AnalogIn emg1_in( A0 ); /* read out the signal */ AnalogIn emg2_in( A1 ); AnalogIn emg3_in( A2 ); DigitalIn max_reader1( SW2 ); DigitalIn max_reader3( SW3 ); - Ticker main_timer; Ticker max_read1; Ticker max_read3; @@ -49,11 +48,11 @@ double max3; double maxpart3; -// Filter settings +// BiQuad Filter Settings // Right Biceps BiQuad filterhigh1(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01); /* Filter at 10 Hz */ BiQuad filternotch1(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01); /* Filter at 50 Hz */ - BiQuad filterpeak1(1.0033,-1.984,9.852e-01,-1.9838,9.8855e-01); /* Gain peak at 11 Hz */ + BiQuad filterpeak1(1.0033,-1.984,9.852e-01,-1.9838,9.8855e-01); /* 4dB Gain peak at 11 Hz */ BiQuad filterlow1(1.368e-03,2.737e-03,1.369e-03,-1.9219,9.274e-01); /* Filter at 15 Hz */ // Left Biceps BiQuad filterhigh2(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01); @@ -67,20 +66,20 @@ BiQuad filterlow3(1.368e-03,2.737e-03,1.369e-03,-1.9219,9.274e-01); // -// Finding max values for correct motor switch +// Finding max values for correct motor switch if the button is pressed void get_max1(){ if (max_reader1==0){ green = !green; red = 1; blue = 1; - for(int n=0;n<2000;n++){ - - emg1 = emg1_in.read(); - emg1highfilter = filterhigh1.step(emg1); - emg1notchfilter = filternotch1.step(emg1highfilter); - emg1abs = fabs(emg1notchfilter); - emg1lowfilter = filterlow1.step(emg1abs); - emg1peak = filterpeak1.step(emg1lowfilter); + + for(int n=0;n<2000;n++){ /* measure 2000 samples and filter it */ + emg1 = emg1_in.read(); /* read out emg */ + emg1highfilter = filterhigh1.step(emg1); /* high pass filtered */ + emg1notchfilter = filternotch1.step(emg1highfilter); /* notch filtered */ + emg1abs = fabs(emg1notchfilter); /* take the absolute value */ + emg1lowfilter = filterlow1.step(emg1abs); /* low pass filtered */ + emg1peak = filterpeak1.step(emg1lowfilter); /* 4dB gain peak */ if (max1<emg1peak){ max1 = emg1peak; @@ -90,8 +89,8 @@ wait(0.2f); green = 1; } - maxpart1 = 0.28*max1; - maxpart2 = 0.18*max1; + maxpart1 = 0.25*max1; + maxpart2 = 0.15*max1; } void get_max3(){ @@ -116,7 +115,7 @@ wait(0.2f); red = 1; } - maxpart3 = 0.28*max3; + maxpart3 = 0.25*max3; } // Filtering & Scope @@ -178,13 +177,13 @@ scope.set(3, emg3peak ); scope.set(4, maxpart3 ); - scope.send(); + scope.send(); /* send everything to the HID scope */ } int main(){ - main_timer.attach(&filter, 0.001); - max_read1.attach(&get_max1, 2); + main_timer.attach(&filter, 0.001); /* set frequency for the filters at 1000Hz */ + max_read1.attach(&get_max1, 2); /* set the frequency of the calibration loop at 0.5Hz */ max_read3.attach(&get_max3, 2); while(1) {} } \ No newline at end of file