Floris Hoek / Mbed 2 deprecated template_biorobotics_Group_18

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
15:5f9450964075
Parent:
14:1343966a79e8
Child:
17:3b463660aa42
Child:
18:4a6be1893d7f
--- a/main.cpp	Fri Oct 25 08:32:53 2019 +0000
+++ b/main.cpp	Fri Oct 25 08:44:57 2019 +0000
@@ -113,12 +113,12 @@
 float rms_deque(std::deque<float> deque) {
     float sum = 0;
     for (int i = 0; i < deque.size(); i++) {
-        sum = sum + pow(deque[i],2);
+        sum = sum + pow(deque[i],2);        // Square the entries of the deque and add them to sum
     }
-    return pow(sum,0.5f);
+    return pow(sum,0.5f);                   // Return the square root of the sum (and thus the RMS)
 }
 
-void measure_data(float &rms_0, float &rms_1, float &rms_2, float &rms_3, bool determine_max) {
+void measure_data(float &rms_0, float &rms_1, float &rms_2, float &rms_3) {
     float b0 = 0.0f;  // Coefficients from the following formula:
     float b1 = 0.0f;  //
     float b2 = 0.0f;  //        b0 + b1 z^-1 + b2 z^-2
@@ -161,17 +161,17 @@
     rms_2 = rms_deque(deque_f_y2);    // 
     rms_3 = rms_deque(deque_f_y3);
     
-    if (determine_max == true) {
+    if (MyState == EMG_CALIBRATION) {
         
-        det_max(rms_0, max_rms0);
+        det_max(rms_0, max_rms0);       // Determine the maximum RMS value of the EMG signals during the EMG_CALIBRATION state
         det_max(rms_1, max_rms1);
         det_max(rms_2, max_rms2);
         det_max(rms_3, max_rms3);
         
     }
-    else if (determine_max == false) {
-        rms_0 = rms_0/max_rms0;
-        rms_1 = rms_1/max_rms1;
+    else if ((int)MyState > 4) {
+        rms_0 = rms_0/max_rms0;     // Normalise the RMS value by dividing by the maximum RMS value
+        rms_1 = rms_1/max_rms1;     // This is done during the states with a value higher than 4, as this is when you start the playable game mode
         rms_2 = rms_2/max_rms2;
         rms_3 = rms_3/max_rms3;
     }
@@ -179,13 +179,13 @@
 }
 
 void det_max(float rms, float &max_rms) {
-    max_rms = max_rms < rms ? rms : max_rms;
+    max_rms = max_rms < rms ? rms : max_rms; // if max_rms is smaller than rms, set rms as new max_rms, otherwise keep max_rms
 }
 
 void emgcalibration() {
     float rms0, rms1, rms2, rms3;           // RMS values of the different EMG signals
 
-    measure_data(rms0, rms1, rms2, rms3, true);   // Calculate RMS values
+    measure_data(rms0, rms1, rms2, rms3);   // Calculate RMS values
     
     float duration = 10.0f;                 // Duration of the emgcalibration function, in this case 10 seconds
     int rounds = (duration / timeinterval); // Determine the amount of times this function has to run to run for the duration time