Remco Dasselaar / Mbed 2 deprecated TotalControlEmg2

Dependencies:   HIDScope MODSERIAL QEI TextLCD mbed

Fork of TotalControlEmg2 by Remco Dasselaar

Revision:
18:eec0880fcded
Parent:
17:cfe44346645c
Child:
19:6c0245063b96
diff -r cfe44346645c -r eec0880fcded main.cpp
--- a/main.cpp	Fri Oct 09 11:27:58 2015 +0000
+++ b/main.cpp	Mon Oct 12 10:14:18 2015 +0000
@@ -3,9 +3,10 @@
 #include "Filterdesigns.h"
 #include "Kalibratie.h"
 #include "MODSERIAL.h" //bugfix
+#include "Mode.h"
 
 AnalogIn    emg(A0); //Analog input van emg kabels
-HIDScope    scope(2); //2 scopes
+HIDScope    scope(3); //3 scopes
 Ticker      EMGticker;
 MODSERIAL   pc(USBTX, USBRX); //bugfix
 DigitalOut  LedBlue(LED3);
@@ -16,26 +17,42 @@
 
 bool readymax = 0;
 bool readymin = 0;
+double ymin;
+double ymax;
+double thresholdlow;
+double thresholdmid;
+double thresholdhigh;
+
+void EMGkalibratie(){
+    LedBlue = 1;
+    Init();
+    ymax = KalibratieMax(readymax);
+    ymin = KalibratieMin(readymin);
+    
+    // bepalen van thresholds voor aan/uit
+    thresholdlow = 0.2; // standaardwaarde
+    thresholdmid = 0.5 * ymax; // afhankelijk van max output gebruiker
+    thresholdhigh = 0.8 * ymax;
+    }
 
 void EMGfilter(){
     //uitlezen emg signaal
     double u = emg.read();
-    double y = Filterdesigns(u);
-//    pc.printf("%f \n",y); //bugfix
+    double y = Filterdesigns(u, ymin);
+    //pc.printf("%f \n",y); //bugfix
     // Plotten in HIDscope
+    int mode = Mode(y, ymax, thresholdlow, thresholdmid, thresholdhigh); //bepaald welk signaal de motor krijgt (aan, uit, middel)
     scope.set(0,u); //ongefilterde waarde naar scope 1
     scope.set(1,y); //gefilterde waarde naar scope 2
+    scope.set(2,mode); 
     scope.send(); //stuur de waardes naar HIDscope
     }
     
 
 int main(){
-    LedBlue = 1;
-    Init();
-    double ymax = KalibratieMax(readymax);
-    double ymin = KalibratieMin(readymin);
     
-    pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
+    EMGkalibratie();
+    //pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
     
     while(readymax == 1 && readymin == 1){
         LedBlue = 0;