nu met gains, threshold en eerst opvullen

Dependencies:   MODSERIAL mbed

Fork of EMGStdevV3 by Jorick Leferink

Files at this revision

API Documentation at this revision

Comitter:
DanAuhust
Date:
Tue Nov 05 09:51:59 2013 +0000
Parent:
5:7644d6b16ceb
Commit message:
Geheel werken versie, biceps op andere arm nog wel testen.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Nov 05 08:38:03 2013 +0000
+++ b/main.cpp	Tue Nov 05 09:51:59 2013 +0000
@@ -109,7 +109,7 @@
 
         case 4:
             //n = sizeof(keeper_extensoren)/sizeof(float);
-            keeper_triceps[count_extensoren]=value;
+            keeper_extensoren[count_extensoren]=value;
             count_extensoren++;
             if ( count_extensoren >= n)
                 count_extensoren = 0;
@@ -127,27 +127,27 @@
    } // einde if
    else
             {startcount+=1;
-            switch(sig_number){
+            switch(number){
             case 1:
-                keeper_biceps[count_biceps]=input;
+                keeper_biceps[count_biceps]=value;
                 count_biceps++;
                 if(count_biceps >= n)
                     count_biceps=0;
                 break;
             case 2:
-                keeper_triceps[count_triceps]=input;
+                keeper_triceps[count_triceps]=value;
                 count_triceps++;
                 if(count_triceps >= n)
                     count_triceps=0;
                 break;
             case 3:
-                keeper_flexoren[count_flexoren]=input;
+                keeper_flexoren[count_flexoren]=value;
                 count_flexoren++;
                 if(count_flexoren >= n)
                     count_flexoren=0;
                 break;
             case 4:
-                keeper_extensoren[count_extensoren]=input;
+                keeper_extensoren[count_extensoren]=value;
                 count_extensoren++;
                 if(count_extensoren >= n)
                     count_extensoren=0;
@@ -212,12 +212,12 @@
             out0_biceps = (NUM0*in0_biceps + NUM1*in1_biceps + NUM2*in2_biceps + NUM3*in3_biceps + NUM4*in4_biceps - DEN1*out1_biceps - DEN2*out2_biceps - DEN3*out3_biceps - DEN4*out4_biceps ) / DEN0;                      
             
             //signaal filteren op 5Hz LOWPASS
-            in4_3_biceps = in3_3_biceps; in3_3_biceps = in2_3_biceps; in2_3_biceps = in1_3_biceps; in1_3_biceps = in0_3_biceps;
+            /*in4_3_biceps = in3_3_biceps; in3_3_biceps = in2_3_biceps; in2_3_biceps = in1_3_biceps; in1_3_biceps = in0_3_biceps;
             in0_3_biceps = abs(out0_biceps); // ruw - offset -> filter 1 -> stdev (-> filter 3)
             out4_3_biceps = out3_3_biceps; out3_3_biceps = out2_3_biceps; out2_3_biceps = out1_3_biceps; out1_3_biceps = out0_3_biceps;           
             out0_3_biceps = (NUM0_3*in0_3_biceps + NUM1_3*in1_3_biceps + NUM2_3*in2_3_biceps + NUM3_3*in3_3_biceps + NUM4_3*in4_3_biceps - DEN1_3*out1_3_biceps - DEN2_3*out2_3_biceps - DEN3_3*out3_3_biceps - DEN4_3*out4_3_biceps ) / DEN0_3;
-
-            sig_out = out0_3_biceps;
+*/
+            sig_out = out0_biceps;
             break;
 
         case 2:
@@ -228,12 +228,12 @@
             out0_triceps = (NUM0*in0_triceps + NUM1*in1_triceps + NUM2*in2_triceps + NUM3*in3_triceps + NUM4*in4_triceps - DEN1*out1_triceps - DEN2*out2_triceps - DEN3*out3_triceps - DEN4*out4_triceps ) / DEN0;                      
 
             //signaal filteren op 5Hz LOWPASS
-            in4_3_triceps = in3_3_triceps; in3_3_triceps = in2_3_triceps; in2_3_triceps = in1_3_triceps; in1_3_triceps = in0_3_triceps;
+            /*in4_3_triceps = in3_3_triceps; in3_3_triceps = in2_3_triceps; in2_3_triceps = in1_3_triceps; in1_3_triceps = in0_3_triceps;
             in0_3_triceps = abs(out0_triceps);
             out4_3_triceps = out3_3_triceps; out3_3_triceps = out2_3_triceps; out2_3_triceps = out1_3_triceps; out1_3_triceps = out0_3_triceps;           
             out0_3_triceps = (NUM0_3*in0_3_triceps + NUM1_3*in1_3_triceps + NUM2_3*in2_3_triceps + NUM3_3*in3_3_triceps + NUM4_3*in4_3_triceps - DEN1_3*out1_3_triceps - DEN2_3*out2_3_triceps - DEN3_3*out3_3_triceps - DEN4_3*out4_3_triceps ) / DEN0_3;    
-
-            sig_out = out0_3_triceps;
+*/
+            sig_out = out0_triceps;
             break;
 
         case 3:
@@ -244,12 +244,12 @@
             out0_flexoren = (NUM0*in0_flexoren + NUM1*in1_flexoren + NUM2*in2_flexoren + NUM3*in3_flexoren + NUM4*in4_flexoren - DEN1*out1_flexoren - DEN2*out2_flexoren - DEN3*out3_flexoren - DEN4*out4_flexoren ) / DEN0;                      
 
             //signaal filteren op 5Hz LOWPASS
-            in4_3_flexoren = in3_3_flexoren; in3_3_flexoren = in2_3_flexoren; in2_3_flexoren = in1_3_flexoren; in1_3_flexoren = in0_3_flexoren;
+            /*in4_3_flexoren = in3_3_flexoren; in3_3_flexoren = in2_3_flexoren; in2_3_flexoren = in1_3_flexoren; in1_3_flexoren = in0_3_flexoren;
             in0_3_flexoren = abs(out0_flexoren);
             out4_3_flexoren = out3_3_flexoren; out3_3_flexoren = out2_3_flexoren; out2_3_flexoren = out1_3_flexoren; out1_3_flexoren = out0_3_flexoren;           
             out0_3_flexoren = (NUM0_3*in0_3_flexoren + NUM1_3*in1_3_flexoren + NUM2_3*in2_3_flexoren + NUM3_3*in3_3_flexoren + NUM4_3*in4_3_flexoren - DEN1_3*out1_3_flexoren - DEN2_3*out2_3_flexoren - DEN3_3*out3_3_flexoren - DEN4_3*out4_3_flexoren ) / DEN0_3;    
-
-            sig_out = out0_3_flexoren;
+*/
+            sig_out = out0_flexoren;
             break;
 
         case 4:
@@ -260,12 +260,12 @@
             out0_extensoren = (NUM0*in0_extensoren + NUM1*in1_extensoren + NUM2*in2_extensoren + NUM3*in3_extensoren + NUM4*in4_extensoren - DEN1*out1_extensoren - DEN2*out2_extensoren - DEN3*out3_extensoren - DEN4*out4_extensoren ) / DEN0;                      
 
             //signaal filteren op 5Hz LOWPASS
-            in4_3_extensoren = in3_3_extensoren; in3_3_extensoren = in2_3_extensoren; in2_3_extensoren = in1_3_extensoren; in1_3_extensoren = in0_3_extensoren;
+            /*in4_3_extensoren = in3_3_extensoren; in3_3_extensoren = in2_3_extensoren; in2_3_extensoren = in1_3_extensoren; in1_3_extensoren = in0_3_extensoren;
             in0_3_extensoren = abs(out0_extensoren);
             out4_3_extensoren = out3_3_extensoren; out3_3_extensoren = out2_3_extensoren; out2_3_extensoren = out1_3_extensoren; out1_3_extensoren = out0_3_extensoren;           
             out0_3_extensoren = (NUM0_3*in0_3_extensoren + NUM1_3*in1_3_extensoren + NUM2_3*in2_3_extensoren + NUM3_3*in3_3_extensoren + NUM4_3*in4_3_extensoren - DEN1_3*out1_3_extensoren - DEN2_3*out2_3_extensoren - DEN3_3*out3_3_extensoren - DEN4_3*out4_3_extensoren ) / DEN0_3;    
-
-            sig_out = out0_3_extensoren;
+*/
+            sig_out = out0_extensoren;
             break;
     }
     return sig_out;
@@ -282,64 +282,38 @@
 
     emg_value_biceps = std_dev(filter(1),1);
     emg_value_triceps = std_dev(filter(2),2); 
-    emg_value_extensoren = std_dev(filter(3),3);
-    emg_value_flexoren = std_dev(filter(4),4);
+    emg_value_flexoren = std_dev(filter(3),3);
+    emg_value_extensoren = std_dev(filter(4),4);
 
+ 
     if(emg_value_biceps < 4.5)
         emg_value_biceps=0;
     else if (emg_value_biceps > 13)
          emg_value_biceps = 13;
-    //emg_value_biceps =  emg_value_biceps;
+    emg_value_biceps = 1.5 * emg_value_biceps;
+
+    if(emg_value_triceps < 5)
+        emg_value_triceps=0;
+    else if (emg_value_triceps > 10)
+         emg_value_triceps = 10;
+    emg_value_triceps = emg_value_triceps;
     
-    if(emg_value_triceps < 2.5)
-        emg_value_biceps=0;
-    else if (emg_value_biceps > 10)
-         emg_value_biceps = 10;
-    //emg_value_triceps =  emg_value_triceps;
-    
-    if(emg_value_flexoren < 2)
+    if(emg_value_flexoren < 3) // was 2, wordt 3
         emg_value_flexoren=0;
     else if (emg_value_flexoren > 8)
          emg_value_flexoren = 8;
-    emg_value_flexoren = 2*emg_value_flexoren;
-    
+    emg_value_flexoren = 1.5*emg_value_flexoren; // was 2, wordt 1.5
+        
     if(emg_value_extensoren < 5)
         emg_value_extensoren=0;
     else if (emg_value_extensoren > 13)
          emg_value_extensoren = 13;
+
+    dy = emg_value_biceps - emg_value_triceps;
+    dx = (emg_value_flexoren - emg_value_extensoren); // was gain 2, wordt 1
  
-dy = emg_value_biceps - emg_value_triceps;
-dx = 2*(emg_value_flexoren - emg_value_extensoren);
-    if(emg_value_biceps < 4.5)
-        emg_value_biceps=0;
-    else if (emg_value_biceps > 13)
-         emg_value_biceps = 13;
-    //emg_value_biceps =  emg_value_biceps;
-    
-    if(emg_value_triceps < 2.5)
-        emg_value_biceps=0;
-    else if (emg_value_biceps > 10)
-         emg_value_biceps = 10;
-    //emg_value_triceps =  emg_value_triceps;
-    
-    if(emg_value_flexoren < 2)
-        emg_value_flexoren=0;
-    else if (emg_value_flexoren > 8)
-         emg_value_flexoren = 8;
-    emg_value_flexoren = 2*emg_value_flexoren;
-    
-    if(emg_value_extensoren < 5)
-        emg_value_extensoren=0;
-    else if (emg_value_extensoren > 13)
-         emg_value_extensoren = 13;
- 
-    dy = emg_value_biceps - emg_value_triceps;
-    dx = 2*(emg_value_flexoren - emg_value_extensoren);
-
-    dy = emg_value_biceps-emg_value_triceps;
-    dx = emg_value_extensoren - emg_value_flexoren;    
     if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30)
-        pc.printf("%.6f\n",dy);
+        pc.printf("%.6f\n",dx);
     /**When not using the LED, the above could also have been done this way:
     * pc.printf("%.6\n", emg0.read());
     */