Dit is alleen het EMG gedeelte

Dependencies:   mbed HIDScope biquadFilter MODSERIAL FXOS8700Q

Files at this revision

API Documentation at this revision

Comitter:
Jellehierck
Date:
Wed Oct 30 18:48:23 2019 +0000
Parent:
36:ec2bb2a02856
Commit message:
Program after implementing in state machine;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Oct 29 16:23:41 2019 +0000
+++ b/main.cpp	Wed Oct 30 18:48:23 2019 +0000
@@ -8,7 +8,6 @@
 // #include "Arduino.h" //misschien handig omdat we het EMG arduino board gebruiken (?)
 // #include "EMGFilters.h"
 #include <vector> // For easy array management
-#include <numeric> // For manipulating array data
 
 /*
 ------ DEFINE MBED CONNECTIONS ------
@@ -87,8 +86,6 @@
 int emg3_dir = 1;
 
 // Initialize tickers and timeouts
-Ticker tickSample;
-Ticker tickSampleCalibration;
 Ticker tickGlobal; // Set global ticker
 Timer timerCalibration;
 
@@ -97,11 +94,9 @@
 */
 const double Fs = 500; // Sampling frequency (s)
 const double Tcal = 10.0f; // Calibration duration (s)
-int trim_cal = 1; // Trim transient behaviour of calibration (s)
 
 // Calculate global variables
 const double Ts = 1/Fs; // Sampling time (s)
-int trim_cal_i = trim_cal * Fs - 1; // Determine iterator of transient behaviour trim
 
 // Notch biquad filter coefficients (iirnotch Q factor 35 @50Hz) from MATLAB:
 BiQuad bq1_notch( 0.995636295063941,  -1.89829218816065,   0.995636295063941,  1, -1.89829218816065,   0.991272590127882); // b01 b11 b21 a01 a11 a21
@@ -300,30 +295,6 @@
     }
 }
 */
-
-// Finish up calibration
-void calibrationFinished()
-{
-    switch( emg_curr_state ) {
-        case emg_cal_MVC:
-            emg1_MVC = getMax(emg1_cal); // Store max value of MVC globally
-            emg2_MVC = getMax(emg2_cal); // Store max value of MVC globally
-            emg3_MVC = getMax(emg3_cal); // Store max value of MVC globally
-
-            emg_MVC_cal_done = true; // To set up transition guard to operation mode
-            break;
-        case emg_cal_rest:
-            emg1_rest = getMean(emg1_cal); // Store rest EMG globally
-            emg2_rest = getMean(emg2_cal); // Store rest EMG globally
-            emg3_rest = getMean(emg3_cal); // Store rest EMG globally
-            emg_rest_cal_done = true; // To set up transition guard to operation mode
-            break;
-    }
-    vector<double>().swap(emg1_cal); // Empty vector to prevent memory overflow
-    vector<double>().swap(emg2_cal); // Empty vector to prevent memory overflow
-    vector<double>().swap(emg3_cal); // Empty vector to prevent memory overflow
-}
-
 // EMG Waiting state
 void do_emg_wait()
 {
@@ -394,7 +365,25 @@
         sampleNow = false; // Disable signal sampling in sampleSignal()
         calibrateNow = false; // Disable calibration sampling
 
-        calibrationFinished(); // Process calibration data
+        switch( emg_curr_state ) {
+            case emg_cal_MVC:
+                emg1_MVC = getMax(emg1_cal); // Store max value of MVC globally
+                emg2_MVC = getMax(emg2_cal); // Store max value of MVC globally
+                emg3_MVC = getMax(emg3_cal); // Store max value of MVC globally
+
+                emg_MVC_cal_done = true; // To set up transition guard to operation mode
+                break;
+            case emg_cal_rest:
+                emg1_rest = getMean(emg1_cal); // Store rest EMG globally
+                emg2_rest = getMean(emg2_cal); // Store rest EMG globally
+                emg3_rest = getMean(emg3_cal); // Store rest EMG globally
+                emg_rest_cal_done = true; // To set up transition guard to operation mode
+                break;
+        }
+        vector<double>().swap(emg1_cal); // Empty vector to prevent memory overflow
+        vector<double>().swap(emg2_cal); // Empty vector to prevent memory overflow
+        vector<double>().swap(emg3_cal); // Empty vector to prevent memory overflow
+
         led_b = 1; // Turn off calibration led
 
         emg_curr_state = emg_wait; // Set next state
@@ -415,8 +404,8 @@
         emg2_th = emg2_rest * emg2_factor + margin_percentage/100; // Set normalized rest threshold
         emg3_factor = 1 / emg3_MVC; // Factor to normalize MVC
         emg3_th = emg3_rest * emg3_factor + margin_percentage/100; // Set normalized rest threshold
-        
-        
+
+
         // ------- TO DO: MAKE SURE THESE BUTTONS DO NOT BOUNCE (e.g. with button1.rise() ) ------
         //button1.fall( &toggleEMG1Dir ); // Change to state MVC calibration on button1 press
         //button2.fall( &toggleEMG2Dir ); // Change to state rest calibration on button2 press