new fork sure

Dependencies:   HIDScope MODSERIAL PID QEI biquadFilter mbed

Fork of cpfromralph by Remi van Veen

Committer:
relvorelvo
Date:
Wed Nov 02 09:39:07 2016 +0000
Revision:
21:136a1ab8163c
Parent:
20:97059009a491
Child:
22:68ab712b62b2
trial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
relvorelvo 21:136a1ab8163c 3 #include "BiQuad.h"
relvorelvo 21:136a1ab8163c 4 #include "MODSERIAL.h"
vsluiter 0:32bb76391d89 5
vsluiter 4:8b298dfada81 6 //Define objects
relvorelvo 21:136a1ab8163c 7 AnalogIn emg1_in( A0 );
relvorelvo 21:136a1ab8163c 8 AnalogIn emg2_in( A1 );
tomlankhorst 19:2bf824669684 9
tomlankhorst 14:f83354387756 10 Ticker sample_timer;
relvorelvo 21:136a1ab8163c 11 HIDScope scope( 4 );
relvorelvo 21:136a1ab8163c 12 DigitalOut red(LED_RED);
relvorelvo 21:136a1ab8163c 13 DigitalOut blue(LED_BLUE);
relvorelvo 21:136a1ab8163c 14 DigitalOut green(LED_GREEN);
relvorelvo 21:136a1ab8163c 15 MODSERIAL pc(USBTX, USBRX);
relvorelvo 21:136a1ab8163c 16
relvorelvo 21:136a1ab8163c 17
relvorelvo 21:136a1ab8163c 18 // EMG variables
relvorelvo 21:136a1ab8163c 19 double emg1;
relvorelvo 21:136a1ab8163c 20 double emg1highfilter;
relvorelvo 21:136a1ab8163c 21 double emg1notchfilter;
relvorelvo 21:136a1ab8163c 22 double emg1abs
relvorelvo 21:136a1ab8163c 23 double emg1lowfilter;
relvorelvo 21:136a1ab8163c 24
relvorelvo 21:136a1ab8163c 25 double emg2;
relvorelvo 21:136a1ab8163c 26 double emg2highfilter;
relvorelvo 21:136a1ab8163c 27 double emg2notchfilter;
relvorelvo 21:136a1ab8163c 28 double emg2abs
relvorelvo 21:136a1ab8163c 29 double emg2lowfilter;
vsluiter 2:e314bb3b2d99 30
relvorelvo 21:136a1ab8163c 31 // Filter settings
relvorelvo 21:136a1ab8163c 32 BiQuad filterhigh(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01);
relvorelvo 21:136a1ab8163c 33 BiQuad filternotch(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01)
relvorelvo 21:136a1ab8163c 34 BiQuad filterlow(8.883e-01,1.7671,8.835e-01,1.7227,8.114e-01)
relvorelvo 21:136a1ab8163c 35
relvorelvo 21:136a1ab8163c 36 // Filtering
relvorelvo 21:136a1ab8163c 37 void filter() {
relvorelvo 21:136a1ab8163c 38 emg1=emg1_in.read();
relvorelvo 21:136a1ab8163c 39 emg1highfilter=filterhigh.step(emg1);
relvorelvo 21:136a1ab8163c 40 emg1notchfilter=filternotch.step(emg1highfilter);
relvorelvo 21:136a1ab8163c 41 emg1abs=fabs(emg1notchfilter);
relvorelvo 21:136a1ab8163c 42 emg1lowfilter=filterlow(emg1abs);
relvorelvo 21:136a1ab8163c 43
relvorelvo 21:136a1ab8163c 44 emg2=emg2_in.read();
relvorelvo 21:136a1ab8163c 45 emg2highfilter=filterhigh.step(emg2);
relvorelvo 21:136a1ab8163c 46 emg2notchfilter=filternotch.step(emg2highfilter);
relvorelvo 21:136a1ab8163c 47 emg2abs=fabs(emg2notchfilter);
relvorelvo 21:136a1ab8163c 48 emg2lowfilter=filterlow(emg2abs);
relvorelvo 21:136a1ab8163c 49
tomlankhorst 14:f83354387756 50 void sample()
vsluiter 2:e314bb3b2d99 51 {
tomlankhorst 19:2bf824669684 52 /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
relvorelvo 21:136a1ab8163c 53 scope.set(0, emg1_in.read() );
relvorelvo 21:136a1ab8163c 54 scope.set(1, emg1lowfilter.read() );
relvorelvo 21:136a1ab8163c 55 scope.set(2, emg2_in.read() );
relvorelvo 21:136a1ab8163c 56 scope.set() emg2lowfilter.read() );
tomlankhorst 19:2bf824669684 57 /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
tomlankhorst 19:2bf824669684 58 * Ensure that enough channels are available (HIDScope scope( 2 ))
tomlankhorst 20:97059009a491 59 * Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 60 scope.send();
tomlankhorst 18:21d8e7a81cf5 61 /* To indicate that the function is working, the LED is toggled */
tomlankhorst 18:21d8e7a81cf5 62 led = !led;
vsluiter 2:e314bb3b2d99 63 }
vsluiter 0:32bb76391d89 64
vsluiter 0:32bb76391d89 65 int main()
tomlankhorst 19:2bf824669684 66 {
tomlankhorst 14:f83354387756 67 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 19:2bf824669684 68 * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
vsluiter 4:8b298dfada81 69 */
relvorelvo 21:136a1ab8163c 70 sample_timer.attach(&sample, 0.001);
tomlankhorst 15:0da764eea774 71
tomlankhorst 14:f83354387756 72 /*empty loop, sample() is executed periodically*/
tomlankhorst 15:0da764eea774 73 while(1) {}
vsluiter 0:32bb76391d89 74 }