EMG and motor script together, Not fully working yet,

Dependencies:   Encoder QEI biquadFilter mbed

Revision:
2:2c4ee76dc830
Parent:
1:6aac013b0ba3
Child:
3:59b504840b95
--- a/main.cpp	Wed Oct 25 11:00:20 2017 +0000
+++ b/main.cpp	Wed Oct 25 13:32:29 2017 +0000
@@ -104,24 +104,27 @@
     emgBRcomplete = bqLow1.step(emgBRrectified);     //Low-pass
     
     
-    /*Getting threshold value for Right Biceps, a value of 30% of 
+    /*Getting threshold value for Right Biceps, a value of 20% of 
     Maximum Voluntary Contraction is chosen as threshold value */
     if (countBR < numsamples) {
         emgBRsum = emgBRsum + emgBRcomplete;
         countBR++;
+        led_R = 0;
+        led_B = 0;
+        led_G = 1;
         }
     
     emgBRmeanMVC = emgBRsum / numsamples;
     
-    thresholdBR = emgBRmeanMVC * 0.3;
-   
-   
+    thresholdBR = emgBRmeanMVC * 0.25;
+    
     //Filtering steps for the Left Biceps EMG
     emgBLfiltered = bqChain2.step( emgBL.read() );    //Notch+High-pass
     emgBLrectified = fabs( emgBLfiltered );           //Rectification
     emgBLcomplete = bqLow2.step( emgBLrectified );    //Low-pass
     
-    /*Getting threshold value for Left Biceps, a value of 30% of 
+    
+    /*Getting threshold value for Left Biceps, a value of 20% of 
     Maximum Voluntary Contraction is chosen as threshold value */
     if (countBL < numsamples) {
         emgBLsum = emgBLsum + emgBLcomplete;
@@ -130,7 +133,9 @@
     
     emgBLmeanMVC = emgBLsum / numsamples;
     
-    thresholdBL = emgBLmeanMVC * 0.3;
+    thresholdBL = emgBLmeanMVC * 0.25;
+        
+    //pc.printf("ThresholdBR = %0.3f, ThresholdBL = %0.3f \n", thresholdBR,thresholdBL);
 }
 
 // Function to make the BiQuadChain for the Notch and High pass filter for both filters
@@ -151,9 +156,10 @@
     pc.printf("Xin is %i\n",Xin);
     led_G=0;
     led_R=1;
-    wait(0.5);
+    wait(0.2);
     led_G=1;
     led_R=0;
+    wait(0.5);
 }  
 
 
@@ -161,6 +167,7 @@
 int tellerX(){
     led_G=1; 
     led_B=1;
+    led_R=0;
         while(true){
     //button.fall(ledtX);          //This has to be replaced by EMG   
     if (emgBRcomplete > thresholdBR){
@@ -170,6 +177,9 @@
     huidigetijdX=t.read();
     if (huidigetijdX>2){
         led_R=1;                //Go to the next program (couting values for Y)
+        if (emgBRcomplete > thresholdBR){
+        0;                 // dit is wat je uiteindelijk wil dat er staat
+        }
         return 0;
         }
     }  
@@ -186,9 +196,10 @@
     pc.printf("Yin is %i\n",Yin);
     led_G=0;
     led_B=1;
-    wait(0.5);
+    wait(0.2);
     led_G=1;
     led_B=0;
+    wait(0.5);
 }  
 
 // Couting system for values of Y
@@ -196,6 +207,7 @@
     t.reset();
     led_G=1;
     led_B=0; 
+    led_R=1;
     while(true){
     //button.fall(ledtY);         //See comments at X   
     if (emgBRcomplete > thresholdBR){
@@ -205,7 +217,11 @@
     huidigetijdY=t.read();
     if (huidigetijdY>2){
         led_B=1; 
-        button.fall(0);   // Wat is deze?
+        if (emgBRcomplete > thresholdBR){
+        0;                 // dit is wat je uiteindelijk wil dat er staat
+        }
+        
+        //button.fall(0);   // Wat is deze?
         return 0;      // ga door naar het volgende programma 
         }
     }
@@ -266,7 +282,7 @@
     }
 
 void calcdelta2() {    
-    delta2 = (countb - Encoder2.getPulses());                                                 //  <------- de reden dat de delta negatief is
+    delta2 = (countb - Encoder2.getPulses());                                                 //  <------- de reden dat de delta negatief is (jitse)
     }
 
 double referenceVelocity1; 
@@ -494,17 +510,20 @@
 {
     pc.baud(115200);
     getbqChain();
-    sample_timer.attach(&EMG_sample, 0.002);
-    tellerX();
-    tellerY();
-    calculator();
-    controlmotor1.attach(&MeasureAndControl1, 0.01);
-    calculatedelta1.attach(&calcdelta1, 0.01);
-    printdata1.attach(&readdata1, 0.5); 
-    controlmotor2.attach(&MeasureAndControl2, 0.01);
-    calculatedelta2.attach(&calcdelta2, 0.01);
-    printdata2.attach(&readdata2, 0.5); 
-    //zakker();
-        
+    while(true){
+        sample_timer.attach(&EMG_sample, 0.002);
+        wait(2.5f);
+        tellerX();
+        tellerY();
+        calculator();
+        controlmotor1.attach(&MeasureAndControl1, 0.01);
+        calculatedelta1.attach(&calcdelta1, 0.01);
+        printdata1.attach(&readdata1, 0.5); 
+        controlmotor2.attach(&MeasureAndControl2, 0.01);
+        calculatedelta2.attach(&calcdelta2, 0.01);
+        printdata2.attach(&readdata2, 0.5); 
+        //zakker();
+        wait(5.0f);
+        }
     return 0;
 }
\ No newline at end of file