Remco Dasselaar / Mbed 2 deprecated TotalControlEmg2

Dependencies:   HIDScope MODSERIAL QEI TextLCD mbed

Fork of TotalControlEmg2 by Remco Dasselaar

Revision:
19:6c0245063b96
Parent:
18:eec0880fcded
Child:
20:11e1244ad2ad
diff -r eec0880fcded -r 6c0245063b96 main.cpp
--- a/main.cpp	Mon Oct 12 10:14:18 2015 +0000
+++ b/main.cpp	Tue Oct 13 12:28:32 2015 +0000
@@ -10,6 +10,7 @@
 Ticker      EMGticker;
 MODSERIAL   pc(USBTX, USBRX); //bugfix
 DigitalOut  LedBlue(LED3);
+DigitalIn button(PTA4);
 
 //Sample frequentie
 double Fs = 500; //Hz
@@ -23,19 +24,22 @@
 double thresholdmid;
 double thresholdhigh;
 
-void EMGkalibratie(){
+void EMGkalibratie()
+{
     LedBlue = 1;
     Init();
     ymax = KalibratieMax(readymax);
+    wait(1);
     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;
-    }
+    thresholdlow = 0.08; // standaardwaarde
+    thresholdmid = 0.3 * ymax; // afhankelijk van max output gebruiker
+    thresholdhigh = 0.4 * ymax;
+}
 
-void EMGfilter(){
+void EMGfilter()
+{
     //uitlezen emg signaal
     double u = emg.read();
     double y = Filterdesigns(u, ymin);
@@ -44,20 +48,23 @@
     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.set(2,mode);
     scope.send(); //stuur de waardes naar HIDscope
-    }
-    
+}
 
-int main(){
-    
-    EMGkalibratie();
-    //pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
-    
-    while(readymax == 1 && readymin == 1){
-        LedBlue = 0;
+int main()
+{
+    while(1) {
+        if(readymax == 0 || readymin == 0) {
+            EMGkalibratie();
+            pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
+        }
         EMGticker.attach(&EMGfilter, t); //500H
-            while(1){}
+        while(readymax == 1 && readymin == 1) {
+            if(button == 0) {
+                readymax = 0;
+                readymin = 0;
+            }
         }
     }
-    
\ No newline at end of file
+}