![](/media/cache/group/9e3cc099b3b04bca937a1cca1da81b19.jpg.50x50_q85.jpg)
Dit is alleen het EMG gedeelte
Dependencies: mbed HIDScope biquadFilter MODSERIAL FXOS8700Q
Diff: main.cpp
- Revision:
- 29:f51683a6cbbf
- Parent:
- 28:59e8266f4633
- Child:
- 30:bac3b60d6283
diff -r 59e8266f4633 -r f51683a6cbbf main.cpp --- a/main.cpp Mon Oct 28 14:27:21 2019 +0000 +++ b/main.cpp Mon Oct 28 14:40:43 2019 +0000 @@ -180,7 +180,7 @@ // Check filter stability bool checkBQChainStable() { - bool n_stable = bqc1_notch.stable(); + bool n_stable = bqc1_notch.stable(); // Check stability of all BQ Chains bool hp_stable = bqc1_high.stable(); bool l_stable = bqc1_low.stable(); @@ -196,7 +196,7 @@ */ void sampleSignal() { - if (sampleNow == true) { + if (sampleNow == true) { // This ticker only samples if the sample flag is true, to prevent unnecessary computations // Read EMG inputs emg1 = emg1_in.read(); emg2 = emg2_in.read(); @@ -225,7 +225,7 @@ scope.set(3, emg2_env ); scope.send(); - if (calibrateNow) { + if (calibrateNow == true) { // Only add values to EMG vectors if calibration flag is true emg1_cal.push_back(emg1_env); // Add values to calibration vector emg1_cal_size = emg1_cal.size(); emg2_cal.push_back(emg2_env); // Add values to calibration vector @@ -275,7 +275,7 @@ emg3_MVC_stdev = getStdev(emg3_cal, emg3_MVC); // Store MVC stdev globally - emg_MVC_cal_done = true; + 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 @@ -288,7 +288,7 @@ emg3_rest_stdev = getStdev(emg3_cal, emg3_rest); // Store MVC stdev globally - emg_rest_cal_done = true; + 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 @@ -306,18 +306,23 @@ // Do nothing until end condition is met - // State transition guard + // State transition guard. Possible next states: + // 1. emg_cal_MVC (button1 pressed) + // 2. emg_cal_rest (button2 pressed) + // 3. emg_operation (both calibrations have run) if ( button1_pressed ) { - button1_pressed = false; - emg_curr_state = emg_cal_MVC; - emg_state_changed = true; + button1_pressed = false; // Disable button pressed function until next button press + emg_curr_state = emg_cal_MVC; // Set next state + emg_state_changed = true; // Enable entry functions + } else if ( button2_pressed ) { - button2_pressed = false; - emg_curr_state = emg_cal_rest; - emg_state_changed = true; + button2_pressed = false; // Disable button pressed function until next button press + emg_curr_state = emg_cal_rest; // Set next state + emg_state_changed = true; // Enable entry functions + } else if ( emg_MVC_cal_done && emg_rest_cal_done ) { - emg_curr_state = emg_operation; - emg_state_changed = true; + emg_curr_state = emg_operation; // Set next state + emg_state_changed = true; // Enable entry functions } } @@ -339,8 +344,9 @@ emg3_cal.reserve(Fs * Tcal); } - // Allemaal dingen doen tot de end conditions true zijn - + // Do nothing until end condition is met + + // State transition guard if ( timerCalibration.read() >= Tcal ) { // After interval Tcal the calibration step is finished sampleNow = false; // Disable signal sampling in sampleSignal() calibrateNow = false; // Disable calibration sampling @@ -350,8 +356,6 @@ emg_curr_state = emg_wait; // Set next state emg_state_changed = true; // State has changed (to run - - // pc.printf("Calibration step finished"); } } @@ -372,8 +376,8 @@ // Do stuff until end condition is met double emg1_norm = emg1_env * emg1_factor; // Normalize EMG signal with calibrated factor - double emg2_norm = emg2_env * emg2_factor; - double emg3_norm = emg3_env * emg3_factor; + double emg2_norm = emg2_env * emg2_factor; // Idem + double emg3_norm = emg3_env * emg3_factor; // Idem // Set normalized EMG output signal (CAN BE MOVED TO EXTERNAL FUNCTION BECAUSE IT IS REPEATED 3 TIMES) if ( emg1_norm < emg1_th ) { // If below threshold, emg_out = 0 (ignored) @@ -479,12 +483,13 @@ } else { led_r = 0; // LED on } - emg_curr_state = emg_wait; + emg_curr_state = emg_wait; // Start off in EMG Wait state + button1.fall( &button1Press ); // Change to state MVC calibration on button press + button2.fall( &button2Press ); // Change to state rest calibration on button press tickGlobal.attach( &tickGlobalFunc, Ts ); - button1.fall( &button1Press ); // Run MVC calibration on button press - button2.fall( &button2Press ); // Run rest calibration on button press + while(true) {