EMG filtering; highpass, notch, abs, moving average

Dependencies:   HIDScope MODSERIAL- mbed-dsp mbed

Files at this revision

API Documentation at this revision

Comitter:
Hooglugt
Date:
Fri Oct 03 12:27:01 2014 +0000
Parent:
24:c6073b9efd5b
Child:
26:9b43d9cb1fb2
Commit message:
alles in for/while loops met if en else statements - alle mogelijkheden met ints en geen enums of switches

Changed in this revision

Project_main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Project_main.cpp	Fri Oct 03 10:43:22 2014 +0000
+++ b/Project_main.cpp	Fri Oct 03 12:27:01 2014 +0000
@@ -39,7 +39,7 @@
     /*send value to PC. Line below is used to prevent buffer overrun */
     if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30)
         //pc.printf("%u\n",emg_value);
-    scope.set(0,emg_value);
+        scope.set(0,emg_value);
     scope.set(1,emgfloat.read());
     scope.send();
     /**When not using the LED, the above could also have been done this way:
@@ -51,38 +51,28 @@
 
 int main()
 {
-    /*setup baudrate. Choose the same in your program on PC side*/
-    pc.baud(115200);
-    /*set the period for the PWM to the emgfloat PTD4*/
-    emgfloat.period_ms(2);
-    /**Here you attach the 'void looper(void)' function to the Ticker object
-    * The looper() function will be called every 0.001 seconds.
-    * Please mind that the parentheses after looper are omitted when using attach.
-    */
-    log_timer.attach(looper, 0.001);
+    pc.baud(115200); //baudrate instellen
+    emgfloat.period_ms(2); //sets period for the PWM to the emgfloat PTD4
+    log_timer.attach(looper, 0.001); // The looper() function will be called every 0.001 seconds (with the ticker object)
     
-    enum Direction {LEFT, MID, RIGHT,UNSET};
-    Direction direc = UNSET;
-    enum Force {WEAK, NORMAL, STRONG,UNSET};
-    Force force = UNSET;
+    goto directionchoice; // goes to first while(1) for the deciding the direction
     
-    goto directionchoice;
     while(1) { //Loop keuze DIRECTION
-        directionchoice:
+directionchoice:
         for(int i=1; i<4; i++) {
             if(i==1) {           //red
                 red=0;
                 green=1;
                 blue=1;
                 for (int lag=0; lag<20; lag++) {
-                    if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
-                        direc = LEFT;
+                    if(emgfloat.read()>0.8) {                   // 0.8 klopt niet als grenswaarde. #nofilter
+                        direction = 1;
                         blue = 0;
                         green = 0;
                         red=1;
-                        pc.printf("LEFT");
-                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
-                        goto forcechoice;
+                        pc.printf("A");
+                        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
                     } else {
                         wait(0.1);
                     }
@@ -94,12 +84,12 @@
                 blue=1;
                 for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
-                        direction = MID;
+                        direction = 2;
                         blue = 0;
                         green = 1;
                         red=0;
-                        pc.printf("MID");
-                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie                        
+                        pc.printf("B");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie
                         goto forcechoice;
                     } else {
                         wait(0.1);
@@ -117,17 +107,17 @@
                         green = 0;
                         red=0;
                         pc.printf("C");
-                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie                        
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie
                         goto forcechoice;
                     } else {
                         wait(0.1);
                     }
                 }
             }
-        }      
+        }
     }
     while(1) { //Loop keuze FORCE
-    forcechoice:
+forcechoice:
         for(int i=1; i<4; i++) {
             if(i==1) {           //red
                 red=0;
@@ -140,7 +130,7 @@
                         green = 0;
                         red=1;
                         pc.printf("D");
-                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie                        
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
                         goto choicesmade;
                     } else {
                         wait(0.1);
@@ -158,7 +148,7 @@
                         green = 1;
                         red=0;
                         pc.printf("E");
-                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie                        
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie
                         goto choicesmade;
                     } else {
                         wait(0.1);
@@ -176,7 +166,7 @@
                         green = 0;
                         red=0;
                         pc.printf("F");
-                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie                        
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie
                         goto choicesmade;
                     } else {
                         wait(0.1);
@@ -185,8 +175,41 @@
             }
         }
     }
-    choicesmade:
+choicesmade:
+
+    if(direction == 0 || force == 0) {
+        pc.printf("error");
+    }
+    if(direction == 1 && force == 1) {            // links zwak
+        pc.printf("links zwak");
+    }
+    if(direction == 1 && force == 2) {            // links normaal
+        pc.printf("links normaal");
+    }
+    if(direction == 1 && force == 3) {            // links sterk
+        pc.printf("links sterk");
+    }
+    if(direction == 2 && force == 1) {            // mid zwak
+        pc.printf("mid zwak");
+    }
+    if(direction == 2 && force == 2) {            // mid normaal
+        pc.printf("mid normaal");
+    }
+    if(direction == 2 && force == 3) {            // mid sterk
+        pc.printf("mid sterk");
+    }
+    if(direction == 3 && force == 1) {            // rechts zwak
+        pc.printf("rechts zwak");
+    }
+    if(direction == 3 && force == 2) {            // rechts normaal
+        pc.printf("rechts normaal");
+    }
+    if(direction == 3 && force == 3) {            // rechts sterk
+        pc.printf("rechts sterk");
+    }
+
     red = 0;
     green = 0;
     blue = 0;
-    }
\ No newline at end of file
+
+}
\ No newline at end of file