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 10:43:22 2014 +0000
Parent:
23:8d9a623dd713
Child:
25:ec41b972b250
Commit message:
Starting to implement enum and switches in the script (rewriting script)

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 09:20:24 2014 +0000
+++ b/Project_main.cpp	Fri Oct 03 10:43:22 2014 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "MODSERIAL.h"
 #include "HIDScope.h"
+#define TIMEB4NEXTCHOICE 2
 
 //Define objects
 AnalogIn    emg0(PTB1); //Analog input
@@ -37,7 +38,7 @@
     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)
-        pc.printf("%u\n",emg_value);
+        //pc.printf("%u\n",emg_value);
     scope.set(0,emg_value);
     scope.set(1,emgfloat.read());
     scope.send();
@@ -59,6 +60,12 @@
     * Please mind that the parentheses after looper are omitted when using attach.
     */
     log_timer.attach(looper, 0.001);
+    
+    enum Direction {LEFT, MID, RIGHT,UNSET};
+    Direction direc = UNSET;
+    enum Force {WEAK, NORMAL, STRONG,UNSET};
+    Force force = UNSET;
+    
     goto directionchoice;
     while(1) { //Loop keuze DIRECTION
         directionchoice:
@@ -67,10 +74,14 @@
                 red=0;
                 green=1;
                 blue=1;
-                for (int lag=0; lag<50; lag++) {
+                for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
-                        direction = 1;
-                        pc.printf("A");
+                        direc = LEFT;
+                        blue = 0;
+                        green = 0;
+                        red=1;
+                        pc.printf("LEFT");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
                         goto forcechoice;
                     } else {
                         wait(0.1);
@@ -81,10 +92,14 @@
                 red =1;
                 green=0;
                 blue=1;
-                for (int lag=0; lag<50; lag++) {
+                for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
-                        direction = 2;
-                        pc.printf("B");
+                        direction = MID;
+                        blue = 0;
+                        green = 1;
+                        red=0;
+                        pc.printf("MID");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie                        
                         goto forcechoice;
                     } else {
                         wait(0.1);
@@ -95,10 +110,14 @@
                 red=1;
                 green=1;
                 blue=0;
-                for (int lag=0; lag<50; lag++) {
+                for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         direction = 3;
+                        blue = 1;
+                        green = 0;
+                        red=0;
                         pc.printf("C");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie                        
                         goto forcechoice;
                     } else {
                         wait(0.1);
@@ -114,10 +133,14 @@
                 red=0;
                 green=1;
                 blue=1;
-                for (int lag=0; lag<50; lag++) {
+                for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
                         force = 1;
-                        pc.printf("A");
+                        blue = 0;
+                        green = 0;
+                        red=1;
+                        pc.printf("D");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie                        
                         goto choicesmade;
                     } else {
                         wait(0.1);
@@ -128,10 +151,14 @@
                 red =1;
                 green=0;
                 blue=1;
-                for (int lag=0; lag<50; lag++) {
+                for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         force = 2;
-                        pc.printf("B");
+                        blue = 0;
+                        green = 1;
+                        red=0;
+                        pc.printf("E");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie                        
                         goto choicesmade;
                     } else {
                         wait(0.1);
@@ -142,10 +169,14 @@
                 red=1;
                 green=1;
                 blue=0;
-                for (int lag=0; lag<50; lag++) {
+                for (int lag=0; lag<20; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         force = 3;
-                        pc.printf("C");
+                        blue = 1;
+                        green = 0;
+                        red=0;
+                        pc.printf("F");
+                        wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie                        
                         goto choicesmade;
                     } else {
                         wait(0.1);