Switches 2.0

Dependencies:   mbed QEI HIDScope BiQuad4th_order biquadFilter MODSERIAL FastPWM

Revision:
10:cbcb35182ef1
Parent:
9:0e838367ab6a
diff -r 0e838367ab6a -r cbcb35182ef1 main.cpp
--- a/main.cpp	Fri Nov 01 10:23:02 2019 +0000
+++ b/main.cpp	Tue Nov 05 13:23:20 2019 +0000
@@ -85,10 +85,10 @@
 
 Ticker ticker_calibration;   // Ticker to send the EMG signals to screen
 
-volatile double emg1_cal = 0.8;
+volatile double emg1_cal = 0.8;      // Initial value of the calibrated first emg
 volatile double emg1_filtered;      //measured value of the first emg
 volatile double emg2_filtered;      //measured value of the second emg
-volatile double emg2_cal = 0.8;
+volatile double emg2_cal = 0.8;     // Initial value of the calibrated second emg
 
 double speedy = 3;
 double speedx = 3;
@@ -249,20 +249,19 @@
 
 void EMGcalibration()
 {
-    Timer tijd;
-    tijd.start(); 
-    ticker_calibration.attach(&sample, 0.002);  
+    Timer tijd;                                 // Timer for the duration of the calibration stage
+    tijd.start();                               // Start of the timer
+    ticker_calibration.attach(&sample, 0.002);  // Ticker for reading EMG-signals is attached to the function that filters the emg-signals
     do {
-        //ticker_calibration.attach(&sample, 0.002);
-        if(emg1_cal < emg1_filtered) {
-            emg1_cal = emg1_filtered ;
-            pc.printf("EMG_cal : %g \n\r",emg1_cal);
+        if(emg1_cal < emg1_filtered) {                  // Initial calibration value is compaired to the current EMG value.
+            emg1_cal = emg1_filtered ;                  // When the current EMG value is higher than the calibration value, then the calibration 
+            pc.printf("EMG_cal : %g \n\r",emg1_cal);    // value becomes the current EMG value.
         }
-        if(emg2_cal < emg2_filtered) {
+        if(emg2_cal < emg2_filtered) {                  // The same is true for the second EMG signal
             emg2_cal = emg2_filtered ;
         }
         pc.printf("emg1: %f\n\r", emg1_filtered);
-    } while(tijd.read()<10);
+    } while(tijd.read()<10);                            // After ten seconds the calibration of the EMG-signals stop
 }
 
 
@@ -280,15 +279,15 @@
 
 void moveWithEMG()
 {
-    if(emg1_filtered >= 0.5*emg1_cal) {
-        speedy = 3;
+    if(emg1_filtered >= 0.5*emg1_cal) {                     // When the current value of EMG1 is higher than half of the calibration value,
+        speedy = 3;                                         // the speed in Y direction becomes 3. Otherwise the speed stays 0.
         pc.printf("emg1: %f", emg1_filtered);
     } else {
         speedy = 0;
     }
 
-    if(emg2_filtered >= 0.5*emg2_cal) {
-        speedx = 3;
+    if(emg2_filtered >= 0.5*emg2_cal) {                     // When the current value of EMG2 is higher than half of the calibration value,
+        speedx = 3;                                         // the speed in X direction becomes 3. Otherwise the speed stays 0.
         pc.printf("emg1: %f\n\r", emg2_filtered);
     } else {
         speedx = 0;
@@ -444,18 +443,14 @@
 
 void sample()
 {
-    emg1_filtered = FilterDesign(emg0.read());
-    emg2_filtered = FilterDesign(emg1.read());
+    emg1_filtered = FilterDesign(emg0.read());                  // The first emg signal is put in the filter and the filtered values are saved
+    emg2_filtered = FilterDesign(emg1.read());                  // The second emg signal is put in the filter and the filtered values are saved
+    
     /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
     scope.set(0, emg1_filtered ) ;
     scope.set(1, emg2_filtered );
-    /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
-    *  Ensure that enough channels are available (HIDScope scope( 2 ))
-    *  Finally, send all channels to the PC at once */
-    scope.send();
-    /* To indicate that the function is working, the LED is toggled */
-    //pc.printf("%f", emg1_filtered)
-    //led = !led;
+    
+    scope.send();                   // Finally, the values are send and can be used in other functions.
 }
 
 void moveWithSpeed(double *xStart, double *yStart, double xSpeed, double ySpeed)