EMG filtering; highpass, notch, abs, moving average
Dependencies: HIDScope MODSERIAL- mbed-dsp mbed
Revision 29:7523e4a8e000, committed 2014-10-06
- Comitter:
- Hooglugt
- Date:
- Mon Oct 06 12:42:02 2014 +0000
- Parent:
- 26:9b43d9cb1fb2
- Child:
- 30:5e5098b0cca6
- Commit message:
- Script netter en beetje commentaar toegevoegd
Changed in this revision
MODSERIAL.lib | Show annotated file Show diff for this revision Revisions of this file |
Project_main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MODSERIAL.lib Fri Oct 03 12:40:15 2014 +0000 +++ b/MODSERIAL.lib Mon Oct 06 12:42:02 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Sissors/code/MODSERIAL/#f6cba765d331 +http://mbed.org/users/Sissors/code/MODSERIAL/#2e4e3795a093
--- a/Project_main.cpp Fri Oct 03 12:40:15 2014 +0000 +++ b/Project_main.cpp Mon Oct 06 12:42:02 2014 +0000 @@ -1,59 +1,56 @@ #include "mbed.h" #include "MODSERIAL.h" #include "HIDScope.h" -#define TIMEB4NEXTCHOICE 2 -#define TIMEBETWEENBLINK 20 + +#define TIMEB4NEXTCHOICE 1 // 1s keuzelampje blijft aan +#define TIMEBETWEENBLINK 10 // 1s voor volgende blink //Define objects -AnalogIn emg0(PTB1); //Analog input -PwmOut emgfloat(PTD4);//Float voor EMG-waarde -PwmOut red(LED_RED); //PWM output +AnalogIn emg0(PTB1); //Analog input biceps +AnalogIn emg1(PTB2); //Analog input triceps + +PwmOut emg_bifloat(PTD4); //Float voor EMG-waarde biceps, VRAAG: waarom we hier een PwmOut voor gebruiken +PwmOut emg_trifloat(PTA4); //Float voor EMG-waarde triceps + +PwmOut red(LED_RED); PwmOut green(LED_GREEN); PwmOut blue(LED_BLUE); + int direction = 0; int force = 0; Ticker log_timer; MODSERIAL pc(USBTX,USBRX); -HIDScope scope(2); +HIDScope scope(4); -/** Looper function -* functions used for Ticker and Timeout should be of type void <name>(void) -* i.e. no input arguments, no output arguments. -* if you want to change a variable that you use in other places (for example in main) -* you will have to make that variable global in order to be able to reach it both from -* the function called at interrupt time, and in the main function. -* To make a variable global, define it under the includes. -* variables that are changed in the interrupt routine (written to) should be made -* 'volatile' to let the compiler know that those values may change outside the current context. -* i.e.: "volatile uint16_t emg_value;" instead of "uint16_t emg_value" -* in the example below, the variable is not re-used in the main function, and is thus declared -* local in the looper function only. -**/ -void looper() +void looper() //nieuwe looper maken, die om een nog te bepalen tijdseenheid de emgtrifloat checked en anders nieuwe goto maakt naar vorige selectiekeuze { - /*variable to store value in*/ - uint16_t emg_value; - /*put raw emg value both in emgfloat and in emg_value*/ - emgfloat.write(emg0.read()); // read float value (0..1 = 0..3.3V) - emg_value = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V) - /*send value to PC. Line below is used to prevent buffer overrun */ - if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30) + /*put raw emg value of biceps both in emg_bifloat and in emg_bivalue*/ + emg_bifloat.write(emg0.read()); // read float value (0..1 = 0..3.3V) biceps + uint16_t emg_bivalue; + emg_bivalue = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V) biceps + + /*put raw emg value of triceps both in emg_trifloat and in emg_trivalue*/ + emg_trifloat.write(emg1.read()); // read float value (0..1 = 0..3.3V) triiceps + uint16_t emg_trivalue; + emg_trivalue = emg1.read_u16(); // read direct ADC result (0..4096 = 0..3.3V) biceps + + /*send value to PC. Line below is used to prevent buffer overrun */ //VRAAG: praktisch nut hiervan? behalve dat het een heleboel spul uitprint + if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30) { //pc.printf("%u\n",emg_value); - scope.set(0,emg_value); - scope.set(1,emgfloat.read()); + } + scope.set(0,emg_bivalue); + scope.set(1,emg_bifloat.read()); + scope.set(2,emg_trivalue); + scope.set(3,emg_trifloat.read()); scope.send(); - /**When not using the LED, the above could also have been done this way: - * pc.printf("%u\n", emg0.read_u16()); - */ } - - int main() { pc.baud(115200); //baudrate instellen - emgfloat.period_ms(2); //sets period for the PWM to the emgfloat PTD4 + emg_bifloat.period_ms(2); //sets period for the PWM to the emgfloat PTD4 + emg_trifloat.period_ms(2); log_timer.attach(looper, 0.001); // The looper() function will be called every 0.001 seconds (with the ticker object) goto directionchoice; // goes to first while(1) for the deciding the direction @@ -66,11 +63,11 @@ green=1; blue=1; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emgfloat.read()>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat.read()>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter direction = 1; + red=1; + green = 0; blue = 0; - green = 0; - red=1; pc.printf("links "); wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie goto forcechoice; // goes to second while(1) for the deciding the force @@ -84,11 +81,11 @@ green=0; blue=1; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emgfloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter direction = 2; + red=0; + green = 1; blue = 0; - green = 1; - red=0; pc.printf("mid "); wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om paars lampje aan te zetten ter controle selectie goto forcechoice; @@ -102,11 +99,11 @@ green=1; blue=0; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emgfloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter direction = 3; + red=0; + green = 0; blue = 1; - green = 0; - red=0; pc.printf("rechts "); wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie goto forcechoice; @@ -125,11 +122,11 @@ green=1; blue=1; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emgfloat.read()>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat.read()>0.8) { // 0.8 klopt niet als grenswaarde. #nofilter force = 1; + red=1; + green = 0; blue = 0; - green = 0; - red=1; pc.printf("zwak "); wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie goto choicesmade; @@ -143,11 +140,11 @@ green=0; blue=1; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emgfloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter force = 2; + red=0; + green = 1; blue = 0; - green = 1; - red=0; pc.printf("normaal "); wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om paars lampje aan te zetten ter controle selectie goto choicesmade; @@ -161,11 +158,11 @@ green=1; blue=0; for (int lag=0; lag<TIMEBETWEENBLINK; lag++) { - if(emgfloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter + if(emg_bifloat.read()>0.8) { //0.8 klopt niet als grenswaarde. #nofilter force = 3; + red=0; + green = 0; blue = 1; - green = 0; - red=0; pc.printf("sterk "); wait(TIMEB4NEXTCHOICE); // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie goto choicesmade;