asdfasdf
Dependencies: HIDScope MODSERIAL PID QEI biquadFilter mbed
Fork of cpfromralph by
Diff: main.cpp
- Revision:
- 22:68ab712b62b2
- Parent:
- 21:136a1ab8163c
- Child:
- 23:e5db011bd410
diff -r 136a1ab8163c -r 68ab712b62b2 main.cpp --- a/main.cpp Wed Nov 02 09:39:07 2016 +0000 +++ b/main.cpp Wed Nov 02 12:55:41 2016 +0000 @@ -8,10 +8,12 @@ AnalogIn emg2_in( A1 ); Ticker sample_timer; -HIDScope scope( 4 ); +HIDScope scope( 3 ); DigitalOut red(LED_RED); DigitalOut blue(LED_BLUE); DigitalOut green(LED_GREEN); +DigitalOut emg1_out( D8 ); +DigitalOut emg2_out( D9 ); MODSERIAL pc(USBTX, USBRX); @@ -19,56 +21,51 @@ double emg1; double emg1highfilter; double emg1notchfilter; -double emg1abs +double emg1abs; double emg1lowfilter; +double emgpeak; double emg2; double emg2highfilter; double emg2notchfilter; -double emg2abs +double emg2abs; double emg2lowfilter; // Filter settings BiQuad filterhigh(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01); -BiQuad filternotch(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01) -BiQuad filterlow(8.883e-01,1.7671,8.835e-01,1.7227,8.114e-01) +BiQuad filternotch(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01); +BiQuad filterlow(1.439e-02,2.794e-02,1.397e-02,-1.7229,7.788e-01); +BiQuad filterpeak(1.0878,-1.950,8.771e-01,-1.95032,9.5499e-01); // Filtering void filter() { - emg1=emg1_in.read(); - emg1highfilter=filterhigh.step(emg1); - emg1notchfilter=filternotch.step(emg1highfilter); - emg1abs=fabs(emg1notchfilter); - emg1lowfilter=filterlow(emg1abs); + emg1 = emg1_in.read(); + emg1highfilter = filterhigh.step(emg1); + emg1notchfilter = filternotch.step(emg1highfilter); + emg1abs = fabs(emg1notchfilter); + emg1lowfilter = filterlow.step(emg1abs); + emgpeak = filterpeak.step(emg1lowfilter); - emg2=emg2_in.read(); - emg2highfilter=filterhigh.step(emg2); - emg2notchfilter=filternotch.step(emg2highfilter); - emg2abs=fabs(emg2notchfilter); - emg2lowfilter=filterlow(emg2abs); + emg2 = emg2_in.read(); + emg2highfilter = filterhigh.step(emg2); + emg2notchfilter = filternotch.step(emg2highfilter); + emg2abs = fabs(emg2notchfilter); + emg2lowfilter = filterlow.step(emg2abs); -void sample() -{ /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ scope.set(0, emg1_in.read() ); - scope.set(1, emg1lowfilter.read() ); - scope.set(2, emg2_in.read() ); - scope.set() emg2lowfilter.read() ); - /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) - * Ensure that enough channels are available (HIDScope scope( 2 )) - * Finally, send all channels to the PC at once */ + scope.set(1, emg1lowfilter ); + scope.set(2, emgpeak ); + /* Finally, send all channels to the PC at once */ scope.send(); /* To indicate that the function is working, the LED is toggled */ - led = !led; + green = !green; } int main() { - /**Attach the 'sample' function to the timer 'sample_timer'. - * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz - */ - sample_timer.attach(&sample, 0.001); - /*empty loop, sample() is executed periodically*/ + sample_timer.attach(&filter, 0.001); + while(1) {} } \ No newline at end of file