![](/media/cache/group/9e3cc099b3b04bca937a1cca1da81b19.jpg.50x50_q85.jpg)
Dit is alleen het EMG gedeelte
Dependencies: mbed HIDScope biquadFilter MODSERIAL FXOS8700Q
Diff: main.cpp
- Revision:
- 32:b9b9c50f5429
- Parent:
- 31:b5188b6d45db
- Child:
- 33:90404e64d844
--- a/main.cpp Mon Oct 28 16:34:03 2019 +0000 +++ b/main.cpp Tue Oct 29 13:12:58 2019 +0000 @@ -15,7 +15,7 @@ */ // PC serial connection -HIDScope scope( 4 ); +HIDScope scope( 4 ); MODSERIAL pc(USBTX, USBRX); // LED @@ -136,6 +136,18 @@ ------ HELPER FUNCTIONS ------ */ +// Return max value of vector +double getMax(const vector<double> &vect) +{ + double curr_max = 0.0; + int vect_n = vect.size(); + + for (int i = 0; i < vect_n; i++) { + if (vect[i] < curr_max) { curr_max = vect[i]; }; + } + return curr_max; +} + // Return mean of vector double getMean(const vector<double> &vect) { @@ -261,14 +273,14 @@ { switch( emg_curr_state ) { case emg_cal_MVC: - emg1_MVC = getMean(emg1_cal); // Store MVC globally - emg1_MVC_stdev = getStdev(emg1_cal, emg1_MVC); // Store MVC stdev globally + emg1_MVC = getMax(emg1_cal); // Store max value of MVC globally + // emg1_MVC_stdev = getStdev(emg1_cal, emg1_MVC); // Store MVC stdev globally - emg2_MVC = getMean(emg2_cal); // Store MVC globally - emg2_MVC_stdev = getStdev(emg2_cal, emg2_MVC); // Store MVC stdev globally + emg2_MVC = getMax(emg2_cal); // Store max value of MVC globally + // emg2_MVC_stdev = getStdev(emg2_cal, emg2_MVC); // Store MVC stdev globally - emg3_MVC = getMean(emg3_cal); // Store MVC globally - emg3_MVC_stdev = getStdev(emg3_cal, emg3_MVC); // Store MVC stdev globally + emg3_MVC = getMax(emg3_cal); // Store max value of MVC globally + // emg3_MVC_stdev = getStdev(emg3_cal, emg3_MVC); // Store MVC stdev globally emg_MVC_cal_done = true; // To set up transition guard to operation mode @@ -298,6 +310,7 @@ // Entry function if ( emg_state_changed == true ) { emg_state_changed = false; // Disable entry functions + button1.fall( &button1Press ); // Change to state MVC calibration on button1 press button2.fall( &button2Press ); // Change to state rest calibration on button2 press } @@ -344,8 +357,8 @@ calibrateNow = true; // Enable calibration vector functionality in sampleSignal() emg1_cal.reserve(Fs * Tcal); // Initialize vector lengths to prevent memory overflow - emg2_cal.reserve(Fs * Tcal); - emg3_cal.reserve(Fs * Tcal); + emg2_cal.reserve(Fs * Tcal); // Idem + emg3_cal.reserve(Fs * Tcal); // Idem } // Do stuff until end condition is met @@ -353,7 +366,7 @@ scope.set(0, emg1 ); // One notch filtered EMG to check 50Hz disturbance scope.set(1, emg1_env ); scope.set(2, emg2_env ); - scope.set(3, emg2_env ); + scope.set(3, emg3_env ); scope.send();