Numero Uno / EMG

Dependents:   PID_VelocityExample TheProgram Passief_stuurprogramma Actief_stuurprogramma

Revision:
9:7da462802e5f
Parent:
7:8ce86cc65126
Child:
10:9f27d04c6183
--- a/EMG.h	Thu Oct 15 12:05:39 2015 +0000
+++ b/EMG.h	Fri Oct 23 09:21:17 2015 +0000
@@ -38,7 +38,8 @@
 InterruptIn cali_button(PTA4); // initialize interrupt button for calibration stuff
 double cali_fact1 = 8;
 double cali_fact2 = 8; // calibration factor to normalize filter output to a scale of 0 - 1
-
+double cali_fact3 = 8;
+double cali_fact4 = 8;
 
 void sample_filter()
 {
@@ -62,8 +63,8 @@
 void calibrate() // function to calibrate the emg signals from the user. It takes 5 seconds of measurements of maximum output, then takes the max and normalizes to that.
 {
     outofboundsled=0;
-    cali_fact1 = 1; cali_fact2 = 1;
-    double cali_max1 = 0; double cali_max2 = 0;
+    cali_fact1 = 1; cali_fact2 = 1; cali_fact3 = 1; cali_fact4 = 1; 
+    double cali_max1 = 0; double cali_max2 = 0; double cali_max3 = 0; double cali_max4 = 0;
     for(int i = 0; i < 5*Fs; i++)
     {
         sample_filter();
@@ -73,7 +74,9 @@
         }
         wait(1/(float)Fs);
    }
+   outofboundsled=1;
    wait(1); // seperated calibration of muscles, including a wait period of a second between the calibration of each thing.
+   outofboundsled=0;
    for(int i = 0; i < 5*Fs; i++)
     {
         sample_filter();
@@ -83,8 +86,34 @@
         }
         wait(1/(float)Fs);
    }
+   outofboundsled=1;
+   wait(1);
+   outofboundsled=0;
+    for(int i = 0; i < 5*Fs; i++)
+    {
+        sample_filter();
+        if(y3 > cali_max3)
+        {
+            cali_max3 = y3;
+        }
+        wait(1/(float)Fs);
+    }
+    outofboundsled=1;
+    wait(1);
+    outofboundsled=0;
+    for(int i = 0; i < 5*Fs; i++)
+    {
+        sample_filter();
+        if(y4 > cali_max4)
+        {
+            cali_max4 = y4;
+        }
+        wait(1/(float)Fs);
+    }
    cali_fact1 = 1.0/cali_max1;
    cali_fact2 = 1.0/cali_max2;
+   cali_fact3 = 1.0/cali_max3;
+   cali_fact4 = 1.0/cali_max4;
    calibrate_go = 0;
    outofboundsled=1;
 }