EMG calibration worked with Sabine

Dependencies:   BiQuad4th_order Biquad HIDScope MODSERIAL biquadFilter mbed

Fork of emg_calibration by Silvie van den Bogaard

Files at this revision

API Documentation at this revision

Comitter:
Mirjam
Date:
Wed Oct 31 20:47:07 2018 +0000
Parent:
2:a4148186b3e3
Commit message:
Test met ledjes (werkt niet voor EMG 2)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a4148186b3e3 -r 274fb751b92d main.cpp
--- a/main.cpp	Wed Oct 31 19:59:10 2018 +0000
+++ b/main.cpp	Wed Oct 31 20:47:07 2018 +0000
@@ -10,13 +10,17 @@
 
 AnalogIn emg1_raw(A0);
 AnalogIn emg2_raw(A1);
-DigitalOut led(LED_RED);
+DigitalOut ledr(LED_RED);
+DigitalOut ledg(LED_GREEN);
+enum states {CALIBRATING,MOVE};
+states currentState = CALIBRATING;
 
 //global variables
 double emg1_cal = 0.00000; //measured value of the first emg
 double emg2_cal = 0.00000; //measured value of the second emg
 double EMG_calibrated_max_1 = 0.00000; //final calibration value of EMG1
 double EMG_calibrated_max_2 = 0.00000; //final calibration value of EMG2
+const float threshold_EMG = 0.1;         // threshold op 25 procent van maximale waarde 
 
 void ReadEMG()
 {
@@ -43,11 +47,45 @@
     pc.baud(115200);
     // Attach the 'ReadEMG' function to the timer 'sample'. Frequency is 50 Hz.
     sample.attach(&ReadEMG, 0.02f);
+    ledr = 1;
+    ledg = 1;
+    
     
     while (true) {
-        led = 0;
-        EMG_calibration();
-        led = 1;
-        pc.printf("Final: EMG1 = %f, EMG2 = %f \r\n",EMG_calibrated_max_1,EMG_calibrated_max_2);
+        switch(currentState){
+            case CALIBRATING:
+            ledr = 0;
+            ledg = 1;
+            EMG_calibration();
+            pc.printf("Final: EMG1 = %f, EMG2 = %f \r\n",EMG_calibrated_max_1,EMG_calibrated_max_2);
+            currentState = MOVE;
+            break;
+            
+            case MOVE:
+            ledr = 1;
+            ledg = 1;
+            if (emg2_cal > (threshold_EMG*EMG_calibrated_max_2)){
+                ledr = 0;
+                }
+            /*
+            if (emg1_cal >= (threshold_EMG*EMG_calibrated_max_1) && emg2_cal >= (threshold_EMG*EMG_calibrated_max_2)){
+                ledg = 0;
+                ledr = 0;
+                }
+            else if (emg2_cal >= (threshold_EMG*EMG_calibrated_max_2) && emg1_cal < (threshold_EMG*EMG_calibrated_max_1)){
+                ledr = 0;
+                ledg = 1;
+                }
+            else if (emg1_cal >= (threshold_EMG*EMG_calibrated_max_1) && emg2_cal < (threshold_EMG*EMG_calibrated_max_2)){
+                ledg = 0;
+                ledr = 1;
+                }
+            else {
+                ledr = 1;
+                ledg = 1;
+                }   
+            */
+            break;
+            }
     }
 }
\ No newline at end of file