![](/media/cache/group/9e3cc099b3b04bca937a1cca1da81b19.jpg.50x50_q85.jpg)
De hele robot in 1 keer bam
Dependencies: mbed QEI Servo HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@16:7acbcc4aa35c, 2019-10-22 (annotated)
- Committer:
- Jellehierck
- Date:
- Tue Oct 22 10:25:22 2019 +0000
- Revision:
- 16:7acbcc4aa35c
- Parent:
- 15:421d3d9c563b
- Child:
- 17:e4e7b1fbb263
Started work in EMG substate machine. We first need to draw the substate machine on paper
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IsaRobin | 0:6972d0e91af1 | 1 | //c++ script for filtering of measured EMG signals |
IsaRobin | 0:6972d0e91af1 | 2 | #include "mbed.h" //Base library |
IsaRobin | 0:6972d0e91af1 | 3 | #include "HIDScope.h" // to see if program is working and EMG is filtered properly |
Jellehierck | 2:d3e9788ab1b3 | 4 | // #include "QEI.h"// is needed for the encoder |
Jellehierck | 8:ea3de43c9e8b | 5 | #include "MODSERIAL.h"// in order for connection with the pc |
Jellehierck | 2:d3e9788ab1b3 | 6 | #include "BiQuad.h" |
Jellehierck | 2:d3e9788ab1b3 | 7 | // #include "FastPWM.h" |
Jellehierck | 2:d3e9788ab1b3 | 8 | // #include "Arduino.h" //misschien handig omdat we het EMG arduino board gebruiken (?) |
Jellehierck | 2:d3e9788ab1b3 | 9 | // #include "EMGFilters.h" |
IsaRobin | 0:6972d0e91af1 | 10 | #include <vector> // For easy array management |
Jellehierck | 7:7a088536f1c9 | 11 | #include <numeric> // For manipulating array data |
IsaRobin | 0:6972d0e91af1 | 12 | |
Jellehierck | 15:421d3d9c563b | 13 | /* |
Jellehierck | 15:421d3d9c563b | 14 | ------ DEFINE MBED CONNECTIONS ------ |
Jellehierck | 15:421d3d9c563b | 15 | */ |
IsaRobin | 0:6972d0e91af1 | 16 | |
Jellehierck | 15:421d3d9c563b | 17 | // PC serial connection |
Jellehierck | 15:421d3d9c563b | 18 | HIDScope scope( 5 ); |
Jellehierck | 15:421d3d9c563b | 19 | MODSERIAL pc(USBTX, USBRX); |
IsaRobin | 0:6972d0e91af1 | 20 | |
Jellehierck | 4:09a01d2db8f7 | 21 | // LED |
Jellehierck | 6:5437cc97e1e6 | 22 | DigitalOut led_g(LED_GREEN); |
Jellehierck | 6:5437cc97e1e6 | 23 | DigitalOut led_r(LED_RED); |
Jellehierck | 8:ea3de43c9e8b | 24 | DigitalOut led_b(LED_BLUE); |
Jellehierck | 8:ea3de43c9e8b | 25 | |
Jellehierck | 8:ea3de43c9e8b | 26 | // Buttons |
Jellehierck | 8:ea3de43c9e8b | 27 | InterruptIn button1(D11); |
Jellehierck | 8:ea3de43c9e8b | 28 | InterruptIn button2(D10); |
Jellehierck | 12:70f0710400c2 | 29 | InterruptIn button3(SW3); |
Jellehierck | 4:09a01d2db8f7 | 30 | |
Jellehierck | 16:7acbcc4aa35c | 31 | // EMG Substates |
Jellehierck | 16:7acbcc4aa35c | 32 | enum EMG_States = { emg_wait, emg_cal_MVC, emg_cal_rest, emg_scale, emg_operation }; // Define EMG substates |
Jellehierck | 16:7acbcc4aa35c | 33 | EMG_States emg_curr_state; // Initialize EMG substate variable |
Jellehierck | 16:7acbcc4aa35c | 34 | |
Jellehierck | 15:421d3d9c563b | 35 | // Global variables for EMG reading |
Jellehierck | 15:421d3d9c563b | 36 | AnalogIn emg1_in (A1); // Right biceps, x axis |
Jellehierck | 15:421d3d9c563b | 37 | AnalogIn emg2_in (A2); // Left biceps, y axis |
Jellehierck | 15:421d3d9c563b | 38 | AnalogIn emg3_in (A3); // Third muscle, TBD |
Jellehierck | 15:421d3d9c563b | 39 | |
IsaRobin | 0:6972d0e91af1 | 40 | double emg1; |
Jellehierck | 12:70f0710400c2 | 41 | double emg1_MVC; |
Jellehierck | 12:70f0710400c2 | 42 | double emg1_MVC_stdev; |
Jellehierck | 12:70f0710400c2 | 43 | double emg1_rest; |
Jellehierck | 12:70f0710400c2 | 44 | double emg1_rest_stdev; |
Jellehierck | 7:7a088536f1c9 | 45 | vector<double> emg1_cal; |
Jellehierck | 7:7a088536f1c9 | 46 | |
Jellehierck | 15:421d3d9c563b | 47 | double emg2; |
Jellehierck | 15:421d3d9c563b | 48 | double emg2_MVC; |
Jellehierck | 15:421d3d9c563b | 49 | double emg2_MVC_stdev; |
Jellehierck | 15:421d3d9c563b | 50 | double emg2_rest; |
Jellehierck | 15:421d3d9c563b | 51 | double emg2_rest_stdev; |
Jellehierck | 15:421d3d9c563b | 52 | vector<double> emg2_cal; |
IsaRobin | 0:6972d0e91af1 | 53 | |
Jellehierck | 15:421d3d9c563b | 54 | double emg3; |
Jellehierck | 15:421d3d9c563b | 55 | double emg3_MVC; |
Jellehierck | 15:421d3d9c563b | 56 | double emg3_MVC_stdev; |
Jellehierck | 15:421d3d9c563b | 57 | double emg3_rest; |
Jellehierck | 15:421d3d9c563b | 58 | double emg3_rest_stdev; |
Jellehierck | 15:421d3d9c563b | 59 | vector<double> emg3_cal; |
Jellehierck | 15:421d3d9c563b | 60 | |
Jellehierck | 15:421d3d9c563b | 61 | // Initialize tickers and timeouts |
Jellehierck | 4:09a01d2db8f7 | 62 | Ticker tickSample; |
Jellehierck | 15:421d3d9c563b | 63 | Ticker tickSampleCalibration; |
Jellehierck | 7:7a088536f1c9 | 64 | Timeout timeoutCalibrationMVC; |
Jellehierck | 12:70f0710400c2 | 65 | Timeout timeoutCalibrationRest; |
Jellehierck | 4:09a01d2db8f7 | 66 | |
Jellehierck | 15:421d3d9c563b | 67 | /* |
Jellehierck | 15:421d3d9c563b | 68 | ------ GLOBAL VARIABLES ------ |
Jellehierck | 15:421d3d9c563b | 69 | */ |
Jellehierck | 11:042170a9b93a | 70 | const double Fs = 500; // Sampling frequency (s) |
Jellehierck | 11:042170a9b93a | 71 | const double Tcal = 10.0f; // Calibration duration (s) |
Jellehierck | 15:421d3d9c563b | 72 | int trim_cal = 1; // Trim transient behaviour of calibration (s) |
Jellehierck | 4:09a01d2db8f7 | 73 | |
Jellehierck | 15:421d3d9c563b | 74 | // Calculate global variables |
Jellehierck | 15:421d3d9c563b | 75 | const double Ts = 1/Fs; // Sampling time (s) |
Jellehierck | 15:421d3d9c563b | 76 | int trim_cal_i = trim_cal * Fs - 1; // Determine iterator of transient behaviour trim |
Jellehierck | 15:421d3d9c563b | 77 | |
Jellehierck | 15:421d3d9c563b | 78 | // Notch biquad filter coefficients (iirnotch Q factor 35 @50Hz) from MATLAB: |
Jellehierck | 15:421d3d9c563b | 79 | BiQuad bq_notch( 0.995636295063941, -1.89829218816065, 0.995636295063941, 1, -1.89829218816065, 0.991272590127882); // b01 b11 b21 a01 a11 a21 |
Jellehierck | 11:042170a9b93a | 80 | BiQuadChain bqc_notch; |
Jellehierck | 1:059cca298369 | 81 | |
Jellehierck | 15:421d3d9c563b | 82 | // Highpass biquad filter coefficients (butter 4th order @10Hz cutoff) from MATLAB |
Jellehierck | 15:421d3d9c563b | 83 | BiQuad bq_H1(0.922946103200875, -1.84589220640175, 0.922946103200875, 1, -1.88920703055163, 0.892769008131025); // b01 b11 b21 a01 a11 a21 |
Jellehierck | 15:421d3d9c563b | 84 | BiQuad bq_H2(1, -2, 1, 1, -1.95046575793011, 0.954143234875078); // b02 b12 b22 a02 a12 a22 |
Jellehierck | 15:421d3d9c563b | 85 | BiQuadChain bqc_high; |
IsaRobin | 0:6972d0e91af1 | 86 | |
Jellehierck | 15:421d3d9c563b | 87 | // Lowpass biquad filter coefficients (butter 4th order @5Hz cutoff) from MATLAB: |
Jellehierck | 15:421d3d9c563b | 88 | BiQuad bq_L1(5.32116245737504e-08, 1.06423249147501e-07, 5.32116245737504e-08, 1, -1.94396715039462, 0.944882378004138); // b01 b11 b21 a01 a11 a21 |
Jellehierck | 15:421d3d9c563b | 89 | BiQuad bq_L2(1, 2, 1, 1, -1.97586467534468, 0.976794920438162); // b02 b12 b22 a02 a12 a22 |
Jellehierck | 15:421d3d9c563b | 90 | BiQuadChain bqc_low; |
Jellehierck | 2:d3e9788ab1b3 | 91 | |
Jellehierck | 15:421d3d9c563b | 92 | /* |
Jellehierck | 15:421d3d9c563b | 93 | ------ HELPER FUNCTIONS ------ |
Jellehierck | 15:421d3d9c563b | 94 | */ |
Jellehierck | 15:421d3d9c563b | 95 | |
Jellehierck | 15:421d3d9c563b | 96 | // Return mean of vector |
Jellehierck | 8:ea3de43c9e8b | 97 | double getMean(const vector<double> &vect) |
Jellehierck | 7:7a088536f1c9 | 98 | { |
Jellehierck | 8:ea3de43c9e8b | 99 | double sum = 0.0; |
Jellehierck | 8:ea3de43c9e8b | 100 | int vect_n = vect.size(); |
Jellehierck | 8:ea3de43c9e8b | 101 | |
Jellehierck | 8:ea3de43c9e8b | 102 | for ( int i = 0; i < vect_n; i++ ) { |
Jellehierck | 8:ea3de43c9e8b | 103 | sum += vect[i]; |
Jellehierck | 8:ea3de43c9e8b | 104 | } |
Jellehierck | 8:ea3de43c9e8b | 105 | return sum/vect_n; |
Jellehierck | 8:ea3de43c9e8b | 106 | } |
Jellehierck | 8:ea3de43c9e8b | 107 | |
Jellehierck | 15:421d3d9c563b | 108 | // Return standard deviation of vector |
Jellehierck | 8:ea3de43c9e8b | 109 | double getStdev(const vector<double> &vect, const double vect_mean) |
Jellehierck | 8:ea3de43c9e8b | 110 | { |
Jellehierck | 8:ea3de43c9e8b | 111 | double sum2 = 0.0; |
Jellehierck | 8:ea3de43c9e8b | 112 | int vect_n = vect.size(); |
Jellehierck | 8:ea3de43c9e8b | 113 | |
Jellehierck | 8:ea3de43c9e8b | 114 | for ( int i = 0; i < vect_n; i++ ) { |
Jellehierck | 8:ea3de43c9e8b | 115 | sum2 += pow( vect[i] - vect_mean, 2 ); |
Jellehierck | 8:ea3de43c9e8b | 116 | } |
Jellehierck | 8:ea3de43c9e8b | 117 | double output = sqrt( sum2 / vect_n ); |
Jellehierck | 8:ea3de43c9e8b | 118 | return output; |
Jellehierck | 7:7a088536f1c9 | 119 | } |
Jellehierck | 7:7a088536f1c9 | 120 | |
Jellehierck | 15:421d3d9c563b | 121 | // Check filter stability |
Jellehierck | 6:5437cc97e1e6 | 122 | bool checkBQChainStable() |
Jellehierck | 6:5437cc97e1e6 | 123 | { |
Jellehierck | 11:042170a9b93a | 124 | bool n_stable = bqc_notch.stable(); |
Jellehierck | 11:042170a9b93a | 125 | bool hp_stable = bqc_high.stable(); |
Jellehierck | 6:5437cc97e1e6 | 126 | bool l_stable = bqc_low.stable(); |
Jellehierck | 6:5437cc97e1e6 | 127 | |
Jellehierck | 11:042170a9b93a | 128 | if (n_stable && hp_stable && l_stable) { |
Jellehierck | 6:5437cc97e1e6 | 129 | return true; |
Jellehierck | 6:5437cc97e1e6 | 130 | } else { |
Jellehierck | 6:5437cc97e1e6 | 131 | return false; |
Jellehierck | 6:5437cc97e1e6 | 132 | } |
Jellehierck | 6:5437cc97e1e6 | 133 | } |
Jellehierck | 6:5437cc97e1e6 | 134 | |
Jellehierck | 15:421d3d9c563b | 135 | /* |
Jellehierck | 15:421d3d9c563b | 136 | ------ TICKER FUNCTIONS ------ |
Jellehierck | 15:421d3d9c563b | 137 | */ |
Jellehierck | 11:042170a9b93a | 138 | /* |
Jellehierck | 6:5437cc97e1e6 | 139 | // Read samples, filter samples and output to HIDScope |
Jellehierck | 2:d3e9788ab1b3 | 140 | void sample() |
Jellehierck | 2:d3e9788ab1b3 | 141 | { |
Jellehierck | 4:09a01d2db8f7 | 142 | // Read EMG inputs |
Jellehierck | 2:d3e9788ab1b3 | 143 | emg1 = emg1_in.read(); |
Jellehierck | 2:d3e9788ab1b3 | 144 | emg2 = emg2_in.read(); |
Jellehierck | 2:d3e9788ab1b3 | 145 | emg3 = emg3_in.read(); |
Jellehierck | 4:09a01d2db8f7 | 146 | |
Jellehierck | 4:09a01d2db8f7 | 147 | // Output raw EMG input |
Jellehierck | 4:09a01d2db8f7 | 148 | scope.set(0, emg1 ); |
Jellehierck | 6:5437cc97e1e6 | 149 | |
Jellehierck | 5:3d65f89e3755 | 150 | // Filter notch and highpass |
Jellehierck | 5:3d65f89e3755 | 151 | double emg1_n_hp = bqc_notch_high.step( emg1 ); |
Jellehierck | 6:5437cc97e1e6 | 152 | |
Jellehierck | 5:3d65f89e3755 | 153 | // Rectify |
Jellehierck | 5:3d65f89e3755 | 154 | double emg1_rectify = fabs( emg1_n_hp ); |
Jellehierck | 6:5437cc97e1e6 | 155 | |
Jellehierck | 5:3d65f89e3755 | 156 | // Filter lowpass (completes envelope) |
Jellehierck | 5:3d65f89e3755 | 157 | double emg1_env = bqc_low.step( emg1_rectify ); |
Jellehierck | 4:09a01d2db8f7 | 158 | |
Jellehierck | 4:09a01d2db8f7 | 159 | // Output EMG after filters |
Jellehierck | 5:3d65f89e3755 | 160 | scope.set(1, emg1_env ); |
Jellehierck | 4:09a01d2db8f7 | 161 | scope.send(); |
Jellehierck | 2:d3e9788ab1b3 | 162 | } |
Jellehierck | 11:042170a9b93a | 163 | */ |
IsaRobin | 0:6972d0e91af1 | 164 | |
Jellehierck | 7:7a088536f1c9 | 165 | void sampleCalibration() |
Jellehierck | 7:7a088536f1c9 | 166 | { |
Jellehierck | 7:7a088536f1c9 | 167 | // Read EMG inputs |
Jellehierck | 7:7a088536f1c9 | 168 | emg1 = emg1_in.read(); |
Jellehierck | 7:7a088536f1c9 | 169 | emg2 = emg2_in.read(); |
Jellehierck | 7:7a088536f1c9 | 170 | emg3 = emg3_in.read(); |
Jellehierck | 7:7a088536f1c9 | 171 | |
Jellehierck | 7:7a088536f1c9 | 172 | // Output raw EMG input |
Jellehierck | 7:7a088536f1c9 | 173 | scope.set(0, emg1 ); |
Jellehierck | 10:97a79aa10a56 | 174 | |
Jellehierck | 10:97a79aa10a56 | 175 | double emg1_n = bqc_notch.step( emg1 ); // Filter notch |
Jellehierck | 11:042170a9b93a | 176 | scope.set(1, emg1_n); |
Jellehierck | 10:97a79aa10a56 | 177 | double emg1_hp = bqc_high.step( emg1_n ); // Filter highpass |
Jellehierck | 15:421d3d9c563b | 178 | scope.set(2, emg1_hp); |
Jellehierck | 11:042170a9b93a | 179 | double emg1_rectify = fabs( emg1_hp ); // Rectify |
Jellehierck | 15:421d3d9c563b | 180 | scope.set(3, emg1_rectify); |
Jellehierck | 7:7a088536f1c9 | 181 | double emg1_env = bqc_low.step( emg1_rectify ); // Filter lowpass (completes envelope) |
Jellehierck | 7:7a088536f1c9 | 182 | |
Jellehierck | 7:7a088536f1c9 | 183 | // Output EMG after filters |
Jellehierck | 15:421d3d9c563b | 184 | scope.set(4, emg1_env ); |
Jellehierck | 7:7a088536f1c9 | 185 | scope.send(); |
Jellehierck | 7:7a088536f1c9 | 186 | |
Jellehierck | 7:7a088536f1c9 | 187 | emg1_cal.push_back(emg1_env); |
Jellehierck | 7:7a088536f1c9 | 188 | } |
Jellehierck | 7:7a088536f1c9 | 189 | |
Jellehierck | 15:421d3d9c563b | 190 | /* |
Jellehierck | 15:421d3d9c563b | 191 | ------ EMG CALIBRATION FUNCTIONS ------ |
Jellehierck | 15:421d3d9c563b | 192 | */ |
Jellehierck | 15:421d3d9c563b | 193 | |
Jellehierck | 15:421d3d9c563b | 194 | // Finish up calibration of MVC |
Jellehierck | 7:7a088536f1c9 | 195 | void calibrationMVCFinished() |
Jellehierck | 7:7a088536f1c9 | 196 | { |
Jellehierck | 15:421d3d9c563b | 197 | tickSampleCalibration.detach(); // Stop calibration ticker to remove interrupt |
Jellehierck | 15:421d3d9c563b | 198 | emg1_MVC = getMean(emg1_cal); // Store MVC globally |
Jellehierck | 15:421d3d9c563b | 199 | emg1_MVC_stdev = getStdev(emg1_cal, emg1_MVC); // Store MVC stde globally |
Jellehierck | 15:421d3d9c563b | 200 | emg1_cal.clear(); // Empty vector to prevent memory overflow |
Jellehierck | 15:421d3d9c563b | 201 | led_b = 1; // Turn off calibration led |
Jellehierck | 7:7a088536f1c9 | 202 | } |
Jellehierck | 7:7a088536f1c9 | 203 | |
Jellehierck | 15:421d3d9c563b | 204 | // Run calibration of MVC |
Jellehierck | 7:7a088536f1c9 | 205 | void calibrationMVC() |
Jellehierck | 7:7a088536f1c9 | 206 | { |
Jellehierck | 15:421d3d9c563b | 207 | timeoutCalibrationMVC.attach( &calibrationMVCFinished, Tcal); // Stop MVC calibration after interval |
Jellehierck | 15:421d3d9c563b | 208 | tickSampleCalibration.attach( &sampleCalibration, Ts ); // Start sample ticker |
Jellehierck | 15:421d3d9c563b | 209 | led_b = 0; // Turn on calibration led |
Jellehierck | 7:7a088536f1c9 | 210 | } |
Jellehierck | 7:7a088536f1c9 | 211 | |
Jellehierck | 15:421d3d9c563b | 212 | // Finish up calibration in rest |
Jellehierck | 12:70f0710400c2 | 213 | void calibrationRestFinished() |
Jellehierck | 12:70f0710400c2 | 214 | { |
Jellehierck | 15:421d3d9c563b | 215 | tickSampleCalibration.detach(); // Stop calibration ticker to remove interrupt |
Jellehierck | 15:421d3d9c563b | 216 | emg1_rest = getMean(emg1_cal); // Store rest globally |
Jellehierck | 15:421d3d9c563b | 217 | emg1_rest_stdev = getStdev(emg1_cal, emg1_rest);// Store rest stdev globally |
Jellehierck | 15:421d3d9c563b | 218 | emg1_cal.clear(); // Empty vector to prevent memory overflow |
Jellehierck | 15:421d3d9c563b | 219 | led_b = 1; // Turn off calibration led |
Jellehierck | 12:70f0710400c2 | 220 | } |
Jellehierck | 12:70f0710400c2 | 221 | |
Jellehierck | 16:7acbcc4aa35c | 222 | // Run calibration in rest |
Jellehierck | 12:70f0710400c2 | 223 | void calibrationRest() |
Jellehierck | 12:70f0710400c2 | 224 | { |
Jellehierck | 15:421d3d9c563b | 225 | timeoutCalibrationRest.attach( &calibrationRestFinished, Tcal); // Stop rest calibration after interval |
Jellehierck | 15:421d3d9c563b | 226 | tickSampleCalibration.attach( &sampleCalibration, Ts ); // Start sample ticker |
Jellehierck | 15:421d3d9c563b | 227 | led_b = 0; // Turn on calibration led |
Jellehierck | 12:70f0710400c2 | 228 | } |
Jellehierck | 12:70f0710400c2 | 229 | |
Jellehierck | 15:421d3d9c563b | 230 | // Determine scale factors for operation mode |
Jellehierck | 12:70f0710400c2 | 231 | void makeScale() |
Jellehierck | 12:70f0710400c2 | 232 | { |
Jellehierck | 15:421d3d9c563b | 233 | double margin_percentage = 10; // Set up % margin for rest |
Jellehierck | 15:421d3d9c563b | 234 | double factor1 = 1 / emg1_MVC; // Factor to normalize MVC |
Jellehierck | 15:421d3d9c563b | 235 | double emg1_th = emg1_rest * factor1 + margin_percentage/100; // Set normalized rest threshold |
Jellehierck | 12:70f0710400c2 | 236 | |
Jellehierck | 12:70f0710400c2 | 237 | pc.printf("Factor: %f TH: %f\r\n", factor1, emg1_th); |
Jellehierck | 12:70f0710400c2 | 238 | } |
Jellehierck | 7:7a088536f1c9 | 239 | |
Jellehierck | 16:7acbcc4aa35c | 240 | /* |
Jellehierck | 16:7acbcc4aa35c | 241 | ------ EMG SUBSTATE MACHINE ------ |
Jellehierck | 16:7acbcc4aa35c | 242 | */ |
Jellehierck | 16:7acbcc4aa35c | 243 | |
Jellehierck | 16:7acbcc4aa35c | 244 | |
Jellehierck | 16:7acbcc4aa35c | 245 | |
Jellehierck | 5:3d65f89e3755 | 246 | void main() |
Jellehierck | 4:09a01d2db8f7 | 247 | { |
Jellehierck | 15:421d3d9c563b | 248 | pc.baud(115200); // MODSERIAL rate |
Jellehierck | 8:ea3de43c9e8b | 249 | pc.printf("Starting\r\n"); |
Jellehierck | 15:421d3d9c563b | 250 | |
Jellehierck | 15:421d3d9c563b | 251 | // tickSample.attach(&sample, Ts); // Initialize sample ticker |
Jellehierck | 6:5437cc97e1e6 | 252 | |
Jellehierck | 6:5437cc97e1e6 | 253 | // Create BQ chains to reduce computations |
Jellehierck | 10:97a79aa10a56 | 254 | bqc_notch.add( &bq_notch ); |
Jellehierck | 10:97a79aa10a56 | 255 | bqc_high.add( &bq_H1 ).add( &bq_H2 ); |
Jellehierck | 5:3d65f89e3755 | 256 | bqc_low.add( &bq_L1 ).add( &bq_L2 ); |
Jellehierck | 4:09a01d2db8f7 | 257 | |
Jellehierck | 15:421d3d9c563b | 258 | led_b = 1; // Turn blue led off at startup |
Jellehierck | 15:421d3d9c563b | 259 | led_g = 1; // Turn green led off at startup |
Jellehierck | 15:421d3d9c563b | 260 | led_r = 1; // Turn red led off at startup |
Jellehierck | 8:ea3de43c9e8b | 261 | |
Jellehierck | 6:5437cc97e1e6 | 262 | // If any filter chain is unstable, red led will light up |
Jellehierck | 6:5437cc97e1e6 | 263 | if (checkBQChainStable) { |
Jellehierck | 6:5437cc97e1e6 | 264 | led_r = 1; // LED off |
Jellehierck | 6:5437cc97e1e6 | 265 | } else { |
Jellehierck | 6:5437cc97e1e6 | 266 | led_r = 0; // LED on |
Jellehierck | 6:5437cc97e1e6 | 267 | } |
Jellehierck | 6:5437cc97e1e6 | 268 | |
Jellehierck | 15:421d3d9c563b | 269 | button1.fall( &calibrationMVC ); // Run MVC calibration on button press |
Jellehierck | 15:421d3d9c563b | 270 | button2.fall( &calibrationRest ); // Run rest calibration on button press |
Jellehierck | 15:421d3d9c563b | 271 | button3.fall( &makeScale ); // Create scale factors and close calibration at button press |
Jellehierck | 8:ea3de43c9e8b | 272 | |
Jellehierck | 4:09a01d2db8f7 | 273 | while(true) { |
Jellehierck | 7:7a088536f1c9 | 274 | |
Jellehierck | 6:5437cc97e1e6 | 275 | // Show that system is running |
Jellehierck | 8:ea3de43c9e8b | 276 | // led_g = !led_g; |
Jellehierck | 12:70f0710400c2 | 277 | pc.printf("EMG MVC: %f stdev: %f\r\nEMG Rest: %f stdev: %f\r\n", emg1_MVC, emg1_MVC_stdev, emg1_rest, emg1_rest_stdev); |
Jellehierck | 4:09a01d2db8f7 | 278 | wait(0.5); |
Jellehierck | 4:09a01d2db8f7 | 279 | } |
Jellehierck | 4:09a01d2db8f7 | 280 | } |