Test code to calibrate EMG - MVC measurement

Dependencies:   HIDScope MODSERIAL mbed

Fork of emgCalibration by Martijn Kern

Files at this revision

API Documentation at this revision

Comitter:
Vigilance88
Date:
Fri Oct 16 12:14:39 2015 +0000
Parent:
4:329e1022cbd3
Commit message:
fixed serial com

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 16 11:58:25 2015 +0000
+++ b/main.cpp	Fri Oct 16 12:14:39 2015 +0000
@@ -10,16 +10,18 @@
 AnalogIn emg3(A2); // 3e board
 AnalogIn emg4(A3); // bovenste board
 
+Ticker sample_timer; // naam van de emg-ticker
 DigitalOut red(LED_RED);
 DigitalOut green(LED_GREEN);
 DigitalOut blue(LED_BLUE);
 
-
-Ticker sample_timer; // naam van de emg-ticker
+int const window=150;                      //30 samples
+int i=0;                        //buffer index
+double bicepsbuffer [window];
 
 //HIDScope scope(4);  // aantal kanalen voor je HIDScope
 
-
+double avg1=0;
 int muscle;
 double tijd;
 double y5;
@@ -101,16 +103,16 @@
 void start_sampling(void)
 {
     sample_timer.attach(&sample_filter,0.002);   //500 Hz EMG 
-    green=0.5; blue=0.5;
-    pc.printf("|-- started sampling --| \r\n");
+    blue=0; green=0;
+    pc.printf("||- started sampling -|| \r\n");
 }
 
 //stop sampling
 void stop_sampling(void)
 {
     sample_timer.detach();
-    green=1; blue=1;
-    pc.printf("|-- stopped sampling --| \r\n");
+    blue=1; green=1;
+    pc.printf("||- stopped sampling -|| \r\n");
 }
      
 void calibrate_emg()
@@ -163,19 +165,20 @@
 int main()
 {
    pc.baud(115200);
+   red=1; green=1; blue=1;
    Ticker timer;
-   red=1; green=1; blue=1;
    
-   pc.printf("Robot Started \r\n");
+   pc.printf("|-- Robot Started --| \r\n");
    pc.printf("Testcode calibration \r\n");
    wait(1);
    pc.printf("+ means current sample is higher than stored MVC\r\n");
    pc.printf("- means current sample is lower than stored MVC\r\n");
    wait(3);
+   pc.printf(" Biceps is first. "); wait(1);
    pc.printf(" Press any key to begin... "); wait(1);
    char input;
    input=pc.getc();
-   pc.putc(input); 
+   pc.putc(input);
    pc.printf(" \r\n  Starting in 3... \r\n"); wait(1);
    pc.printf(" \r\n  Starting in 2... \r\n"); wait(1);
    pc.printf(" \r\n  Starting in 1... \r\n"); wait(1);
@@ -185,15 +188,36 @@
    timer.attach(&calibrate_emg,0.002);
    wait(5);
    timer.detach();
-   
-   pc.printf("\r\n Muscle MVC = %f \r\n",bicepsMVC);
+   pc.printf("\r\n MVC = %f \r\n",bicepsMVC);
    
    pc.printf("Calibrate_emg() exited \r\n");
    pc.printf("Measured time: %f seconds \r\n",tijd);
+   tijd=0;
    
-   // repeat for other muscles.
+   // Triceps:
+   pc.printf(" Triceps is next "); wait(1);
+   pc.printf(" Press any key to begin... "); wait(1);
+   input=pc.getc();
+   pc.putc(input);
+   pc.printf(" \r\n  Starting in 3... \r\n"); wait(1);
+   pc.printf(" \r\n  Starting in 2... \r\n"); wait(1);
+   pc.printf(" \r\n  Starting in 1... \r\n"); wait(1);
+   start_sampling();
+   muscle=1;
+   timer.attach(&calibrate_emg,0.002);
+   wait(5);
+   timer.detach();
+   pc.printf("\r\n Triceps MVC = %f \r\n",tricepsMVC);
    
-   //stop_sampling();
+   pc.printf("Calibrate_emg() exited \r\n");
+   pc.printf("Measured time: %f seconds \r\n",tijd);
+   tijd=0;
+   
+   //Flexor:
+   
+   //Extensor:
+   
+   stop_sampling();
    while (true){   
         
         wait(1);