test

Dependencies:   HIDScope MODSERIAL mbed-dsp mbed

Fork of emg_filter2 by BMT M9 Groep01

Files at this revision

API Documentation at this revision

Comitter:
s1340735
Date:
Mon Oct 20 17:59:08 2014 +0000
Parent:
59:fa8d6909d8ac
Commit message:
test

Changed in this revision

EMGfilter.cpp Show annotated file Show diff for this revision Revisions of this file
emg_mk.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r fa8d6909d8ac -r 7b5ca1a4d7c3 EMGfilter.cpp
--- a/EMGfilter.cpp	Mon Oct 20 13:07:38 2014 +0000
+++ b/EMGfilter.cpp	Mon Oct 20 17:59:08 2014 +0000
@@ -3,9 +3,6 @@
 #include "MODSERIAL.h"
 #include "arm_math.h"
 
-
-// ****** emg filter shizzle ******
-
 //Define objects
 AnalogIn    emgB(PTB0); //Analog input bicep
 AnalogIn    emgT(PTB1); //Analog input tricep
@@ -20,7 +17,7 @@
 
 MODSERIAL pc(USBTX,USBRX);
 
-HIDScope scope(4);//uitgang scherm
+HIDScope scope(2);//uitgang scherm
 
 arm_biquad_casd_df1_inst_f32 lowpass;
 //constants for 50Hz lowpass
@@ -51,35 +48,38 @@
 
 // Calibratie
 
-pc.printf("Calibratie drempelwaarde Triceps stand 1\n");
-wait(0.5);
+void Calibratie()
 {
-    int i;
-    int j=19;
-
-    for (i = 0, i<=j; i ++) {
-        /*variable to store value in*/
-        uint16_t emg_valueT1i_C;
+    pc.printf("Calibratie drempelwaarde Triceps stand 1\n");
+    wait(0.5);
+    {
+        int i;
+        int j=19;
 
-        float emg_value_f32T1i_C;
-        /*put raw emg value both in red and in emg_value*/
-        emg_valueT1i_C = emgT1i_C.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V)
-        emg_value_f32T1i_C = emgT1i_C.read();
+        for (i=0, i<=j; i++) {
+            /*variable to store value in*/
+            uint16_t emg_valueT1i_C;
 
-        //process emg
-        arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32T1i_C, &filtered_emgT1i_C, 1 );
-        filtered_emgT1i_C = fabs(filtered_emgT1i_C);
-        arm_biquad_cascade_df1_f32(&lowpass, &filtered_emgT1i_C, &filtered_emgT1i_C, 1 );
+            float emg_value_f32T1i_C;
+            /*put raw emg value both in red and in emg_value*/
+            emg_valueT1i_C = emgT1i_C.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V)
+            emg_value_f32T1i_C = emgT1i_C.read();
+
+            //process emg
+            arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32T1i_C, &filtered_emgT1i_C, 1 );
+            filtered_emgT1i_C = fabs(filtered_emgT1i_C);
+            arm_biquad_cascade_df1_f32(&lowpass, &filtered_emgT1i_C, &filtered_emgT1i_C, 1 );
+        }
     }
 }
-// Mean Triceps stand 1
-
 
-float MeanT1=filtered_emgT10_C*0.05+filtered_emgT11_C*0.05+filtered_emgT12_C*0.05+filtered_emgT13_C*0.05+filtered_emgT14_C*0.05+filtered_emgT15_C*0.05+filtered_emgT16_C*0.05+filtered_emgT17_C*0.05+filtered_emgT18_C*0.05+filtered_emgT19_C*0.05+filtered_emgT110_C*0.05+filtered_emgT111_C*0.05+filtered_emgT112_C*0.05+filtered_emgT113_C*0.05+filtered_emgT114_C*0.05+filtered_emgT115_C*0.05+filtered_emgT116_C*0.05+filtered_emgT117_C*0.05+filtered_emgT118_C*0.05+filtered_emgT119_C*0.05;
-
+// Mean Triceps stand 1
+void MeanTriceps()
+{
 
+    float MeanT1=filtered_emgT10_C*0.05+filtered_emgT11_C*0.05+filtered_emgT12_C*0.05+filtered_emgT13_C*0.05+filtered_emgT14_C*0.05+filtered_emgT15_C*0.05+filtered_emgT16_C*0.05+filtered_emgT17_C*0.05+filtered_emgT18_C*0.05+filtered_emgT19_C*0.05+filtered_emgT110_C*0.05+filtered_emgT111_C*0.05+filtered_emgT112_C*0.05+filtered_emgT113_C*0.05+filtered_emgT114_C*0.05+filtered_emgT115_C*0.05+filtered_emgT116_C*0.05+filtered_emgT117_C*0.05+filtered_emgT118_C*0.05+filtered_emgT119_C*0.05;
 
-
+}
 
 //BICEP EMG LEZEN
 void looperB()
@@ -118,6 +118,7 @@
         B1=B0;
     }
 }
+
 // Triceps EMG lezen
 void looperT()
 {
@@ -158,7 +159,7 @@
 
 int main()
 {
-    Ticker log_timer,;
+    Ticker log_timer,; //bicep logtimer
     //set up filters. Use external array for constants
     arm_biquad_cascade_df1_init_f32(&lowpass,1 , lowpass_const, lowpass_states);
     arm_biquad_cascade_df1_init_f32(&highpass,1 ,highpass_const, highpass_states);
@@ -168,16 +169,28 @@
     * Please mind that the parentheses after looper are omitted when using attach.
     */
     log_timer.attach(looperB, 0.005);//??
+    while(1) { //Loop
+        /*Empty!*/
+        /*Everything is handled by the interrupt routine now!*/
+    }
+    
+        Ticker log_timer,; //bicep logtimer
+    //set up filters. Use external array for constants
+    arm_biquad_cascade_df1_init_f32(&lowpass,1 , lowpass_const, lowpass_states);
+    arm_biquad_cascade_df1_init_f32(&highpass,1 ,highpass_const, highpass_states);
+
+    /**Here you attach the 'void looper(void)' function to the Ticker object
+    * The looper() function will be called every 0.01 seconds.
+    * Please mind that the parentheses after looper are omitted when using attach.
+    */
     log_timer.attach(looperT, 0.005);//??
     while(1) { //Loop
         /*Empty!*/
         /*Everything is handled by the interrupt routine now!*/
     }
+    
 }
 
-//filtered_emgB
-//filtered_emgT
-
 void AntwoordT()
 {
     drempelwaardeT1=4.99;
@@ -215,46 +228,47 @@
     }
 }
 
-    void AntwoordB() {
-        drempelwaardeB1=4.99;
-        drempelwaardeB2=6;
-        drempelwaardeB3=10;
-        int yB1;
-        int yB2;
-        int yB3;
+void AntwoordB()
+{
+    drempelwaardeB1=4.99;
+    drempelwaardeB2=6;
+    drempelwaardeB3=10;
+    int yB1;
+    int yB2;
+    int yB3;
 
-        if (MOVAVG_B > drempelwaardeB1) {
-            yB1=1;
-            if (MOVAVG_B > drempelwaardeB2) {
-                yB2=1;
-                if (MOVAVG_B > drempelwaardeB3) {
-                    yB3=1;
-                } else {
-                    yB3=0;
-                }
+    if (MOVAVG_B > drempelwaardeB1) {
+        yB1=1;
+        if (MOVAVG_B > drempelwaardeB2) {
+            yB2=1;
+            if (MOVAVG_B > drempelwaardeB3) {
+                yB3=1;
             } else {
-                yB2=0;
+                yB3=0;
             }
         } else {
-            yB1=0;
-        }
-
-        int snelheidsstand;
-
-        snelheidsstand=yB1+yB2+yB3;
-        if (snelheidsstand==1) {
-            pc.printf("Motor 1 beweegt met snelheid 1\n");
-        } else {
-            pc.printf("Motor 1 beweegt niet met snelheid 1\n");
+            yB2=0;
         }
-        if (snelheidsstand==2) {
-            pc.printf("Motor 1 beweegt met snelheid 2\n");
-        } else {
-            pc.printf("Motor 1 beweegt niet met snelheid 2\n");
-        }
-        if (snelheidsstand==3) {
-            pc.printf("Motor 1 beweegt met snelheid 3\n");
-        } else {
-            pc.printf("Motor 1 beweegt niet met snelheid 3\n");
-        }
+    } else {
+        yB1=0;
+    }
+
+    int snelheidsstand;
+
+    snelheidsstand=yB1+yB2+yB3;
+    if (snelheidsstand==1) {
+        pc.printf("Motor 1 beweegt met snelheid 1\n");
+    } else {
+        pc.printf("Motor 1 beweegt niet met snelheid 1\n");
     }
+    if (snelheidsstand==2) {
+        pc.printf("Motor 1 beweegt met snelheid 2\n");
+    } else {
+        pc.printf("Motor 1 beweegt niet met snelheid 2\n");
+    }
+    if (snelheidsstand==3) {
+        pc.printf("Motor 1 beweegt met snelheid 3\n");
+    } else {
+        pc.printf("Motor 1 beweegt niet met snelheid 3\n");
+    }
+}
diff -r fa8d6909d8ac -r 7b5ca1a4d7c3 emg_mk.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emg_mk.cpp	Mon Oct 20 17:59:08 2014 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "HIDScope.h"
+#include "MODSERIAL.h"
+#include "arm_math.h"
+
+
+HIDScope scope(2);
+
+AnalogIn emgB(PTB0);
+
+float (filtered_emgB);
+float drempelwaardeB1, drempelwaardeB2, drempelwaardeB3;
+int yB1, yB2, yB3;
+
+int main()
+{
+    float ruw_emgB;
+    while (true) {
+        ruw_emgB = emgB.read();
+        filtered_emgB = filter(ruw_emgB);
+
+        scope.set(0,ruw_emgB);
+        scope.set(1,filtered_emgB);
+        scope.send();
+
+        if (filtered_emgB >= drempelwaardeB1) {
+            yB1=1;
+        ...
\ No newline at end of file