Dan August
/
EMG2spier
Meting en filter voor 2 spieren
main.cpp@1:fb33955ca402, 2013-10-25 (annotated)
- Committer:
- DanAuhust
- Date:
- Fri Oct 25 09:30:58 2013 +0000
- Revision:
- 1:fb33955ca402
- Parent:
- 0:3a1196d78030
- Child:
- 2:5c6873981eac
error 153 nog oplossen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DanAuhust | 0:3a1196d78030 | 1 | #include "mbed.h" |
DanAuhust | 0:3a1196d78030 | 2 | #include "MODSERIAL.h" |
DanAuhust | 0:3a1196d78030 | 3 | |
DanAuhust | 0:3a1196d78030 | 4 | //Define objects |
DanAuhust | 0:3a1196d78030 | 5 | AnalogIn emg_biceps(PTB0); //Analog input |
DanAuhust | 0:3a1196d78030 | 6 | AnalogIn emg_triceps(PTB1); |
DanAuhust | 0:3a1196d78030 | 7 | // AnalogIn emg_flexoren(PTB2); |
DanAuhust | 0:3a1196d78030 | 8 | // AnalogIn emg_extensoren(PTB3); |
DanAuhust | 0:3a1196d78030 | 9 | PwmOut red(LED_RED); // sig_out biceps |
DanAuhust | 0:3a1196d78030 | 10 | PwmOut blue(LED_BLUE); // sig_out triceps |
DanAuhust | 0:3a1196d78030 | 11 | // PwmOut green(LED_GREEN); |
DanAuhust | 0:3a1196d78030 | 12 | |
DanAuhust | 0:3a1196d78030 | 13 | Ticker timer; |
DanAuhust | 0:3a1196d78030 | 14 | MODSERIAL pc(USBTX,USBRX,64,1024); |
DanAuhust | 0:3a1196d78030 | 15 | |
DanAuhust | 0:3a1196d78030 | 16 | #define MAXCOUNT 40 |
DanAuhust | 0:3a1196d78030 | 17 | #define inertia 4 |
DanAuhust | 0:3a1196d78030 | 18 | |
DanAuhust | 0:3a1196d78030 | 19 | #define gain_biceps 1 |
DanAuhust | 0:3a1196d78030 | 20 | #define threshold_biceps 0.04 |
DanAuhust | 0:3a1196d78030 | 21 | #define border_biceps 0.1125 //25% van .57 - .12 |
DanAuhust | 0:3a1196d78030 | 22 | |
DanAuhust | 0:3a1196d78030 | 23 | #define gain_triceps 1 |
DanAuhust | 0:3a1196d78030 | 24 | #define threshold_triceps 0.1 |
DanAuhust | 0:3a1196d78030 | 25 | #define border_triceps 0.1237 //25% van .605 - .11 = .12375 |
DanAuhust | 0:3a1196d78030 | 26 | |
DanAuhust | 0:3a1196d78030 | 27 | #define NUM0 0.8841 // constante |
DanAuhust | 0:3a1196d78030 | 28 | #define NUM1 -3.53647 // z^-1 |
DanAuhust | 0:3a1196d78030 | 29 | #define NUM2 5.3046 // z^-2etc. |
DanAuhust | 0:3a1196d78030 | 30 | #define NUM3 -3.5364 |
DanAuhust | 0:3a1196d78030 | 31 | #define NUM4 0.8841 |
DanAuhust | 0:3a1196d78030 | 32 | |
DanAuhust | 0:3a1196d78030 | 33 | #define DEN0 1 // constante |
DanAuhust | 0:3a1196d78030 | 34 | #define DEN1 -3.7538 |
DanAuhust | 0:3a1196d78030 | 35 | #define DEN2 5.2912 |
DanAuhust | 0:3a1196d78030 | 36 | #define DEN3 -3.3189 |
DanAuhust | 0:3a1196d78030 | 37 | #define DEN4 0.7816 |
DanAuhust | 0:3a1196d78030 | 38 | |
DanAuhust | 0:3a1196d78030 | 39 | //filter functie definieren. filter(signal_number) |
DanAuhust | 0:3a1196d78030 | 40 | //signal_number=1 --> biceps filteren |
DanAuhust | 0:3a1196d78030 | 41 | //signal_number=2 --> triceps filteren |
DanAuhust | 0:3a1196d78030 | 42 | //signal_number=3 --> flexoren filteren |
DanAuhust | 0:3a1196d78030 | 43 | //signal_number=4 --> extensoren filteren |
DanAuhust | 0:3a1196d78030 | 44 | |
DanAuhust | 0:3a1196d78030 | 45 | float filter(int signal_number){ |
DanAuhust | 0:3a1196d78030 | 46 | //static variables keep their values between function calls |
DanAuhust | 0:3a1196d78030 | 47 | //the assignents are only executed the first iteration. |
DanAuhust | 0:3a1196d78030 | 48 | |
DanAuhust | 0:3a1196d78030 | 49 | //variabelen biceps definieren |
DanAuhust | 1:fb33955ca402 | 50 | float in0_biceps =0; |
DanAuhust | 1:fb33955ca402 | 51 | static float in1_biceps =0, in2_biceps = 0, in3_biceps = 0, in4_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 52 | static float out0_biceps = 0, out1_biceps = 0 , out2_biceps = 0, out3_biceps = 0, out4_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 53 | |
DanAuhust | 0:3a1196d78030 | 54 | // variabelen triceps definieren |
DanAuhust | 0:3a1196d78030 | 55 | static float in0_triceps = 0, in1_triceps = 0, in2_triceps = 0, in3_triceps = 0, in4_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 56 | static float out0_triceps = 0, out1_triceps = 0, out2_triceps = 0, out3_triceps = 0, out4_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 57 | |
DanAuhust | 0:3a1196d78030 | 58 | //variabelen flexoren definieren |
DanAuhust | 0:3a1196d78030 | 59 | static float in0_flexoren = 0, in1_flexoren = 0, in2_flexoren = 0, in3_flexoren = 0, in4_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 60 | static float out0_flexoren = 0, out1_flexoren = 0, out2_flexoren = 0, out3_flexoren = 0, out4_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 61 | |
DanAuhust | 0:3a1196d78030 | 62 | //variablen extensoren definieren |
DanAuhust | 0:3a1196d78030 | 63 | static float in0_extensoren = 0, in1_extensoren = 0, in2_extensoren = 0, in3_extensoren = 0, in4_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 64 | static float out0_extensoren = 0, out1_extensoren = 0, out2_extensoren = 0, out3_extensoren = 0, out4_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 65 | |
DanAuhust | 0:3a1196d78030 | 66 | //overige variabelen definieren |
DanAuhust | 0:3a1196d78030 | 67 | // verwijder static waar mogelijk, maakt programma iets sneller |
DanAuhust | 0:3a1196d78030 | 68 | static float count_biceps = 0, count_triceps = 0, count_extensoren = 0, count_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 69 | static float square_biceps = 0, square_triceps = 0, square_flexoren = 0, square_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 70 | static float sum_biceps = 0, sum_triceps = 0, sum_flexoren = 0, sum_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 71 | static float mean_biceps = 0.1, mean_triceps = 0.1, mean_flexoren = 0.1, mean_extensoren = 0.1; |
DanAuhust | 1:fb33955ca402 | 72 | static float emg_biceps, emg_triceps, emg_flexoren, emg_extensoren; // output ruwe EMG |
DanAuhust | 0:3a1196d78030 | 73 | static float sig_in_biceps, sig_in_triceps, sig_in_extensoren, sig_in_flexoren; // naam gewijzigd, output StDev |
DanAuhust | 0:3a1196d78030 | 74 | static float sig_out_biceps, sig_out_triceps, sig_out_extensoren, sig_out_flexoren; |
DanAuhust | 1:fb33955ca402 | 75 | float emg_abs, sig_out, deltaV; |
DanAuhust | 1:fb33955ca402 | 76 | static float sig_prev_biceps = 0, sig_prev_triceps = 0, sig_prev_extensoren = 0, sig_prev_flexoren = 0; |
DanAuhust | 1:fb33955ca402 | 77 | static int stat0_biceps, stat0_triceps, stat0_extensoren, stat0_flexoren; |
DanAuhust | 1:fb33955ca402 | 78 | static int stat1_biceps = 0, stat1_triceps = 0, stat1_extensoren = 0, stat1_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 79 | |
DanAuhust | 0:3a1196d78030 | 80 | switch (signal_number){ |
DanAuhust | 0:3a1196d78030 | 81 | case 1: |
DanAuhust | 0:3a1196d78030 | 82 | //biceps filteren |
DanAuhust | 0:3a1196d78030 | 83 | in4_biceps = in3_biceps; in3_biceps = in2_biceps; in2_biceps = in1_biceps; in1_biceps = in0_biceps; |
DanAuhust | 0:3a1196d78030 | 84 | in0_biceps = emg_biceps.read(); |
DanAuhust | 1:fb33955ca402 | 85 | out4_biceps = out3_biceps; out3_biceps = out2_biceps; out2_biceps = out1_biceps; out1_biceps = out0_biceps; |
DanAuhust | 0:3a1196d78030 | 86 | out0_biceps = (NUM0*in0_biceps + NUM1*in1_biceps + NUM2*in2_biceps + NUM3*in3_biceps + NUM4*in4_biceps - DEN1*out1_biceps - DEN2*out2_biceps - DEN3*out3_biceps - DEN4*out4_biceps ) / DEN0; |
DanAuhust | 0:3a1196d78030 | 87 | |
DanAuhust | 0:3a1196d78030 | 88 | //std deviatie bepalen, om de N metingen |
DanAuhust | 0:3a1196d78030 | 89 | emg_abs = fabs(out0_biceps); |
DanAuhust | 0:3a1196d78030 | 90 | sum_biceps += out0_biceps; |
DanAuhust | 0:3a1196d78030 | 91 | square_biceps += (emg_abs - mean_biceps)*(emg_abs - mean_biceps); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 92 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 93 | count_biceps += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 94 | if (count_biceps >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 95 | { sig_in_biceps = sqrt(square_biceps/count_biceps); |
DanAuhust | 0:3a1196d78030 | 96 | mean_biceps = sum_biceps/count_biceps; |
DanAuhust | 0:3a1196d78030 | 97 | count_biceps = 0; square_biceps = 0; sum_biceps = 0; // en neem de RMS als er genoeg zijn geteld, stuur die door, en reset sqaure en count |
DanAuhust | 0:3a1196d78030 | 98 | // nieuw: |
DanAuhust | 1:fb33955ca402 | 99 | deltaV = sig_in_biceps - sig_prev_biceps; |
DanAuhust | 0:3a1196d78030 | 100 | if (sig_in_biceps <= threshold_biceps) // threshold |
DanAuhust | 0:3a1196d78030 | 101 | { stat0_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 102 | if (stat1_biceps == 1) |
DanAuhust | 0:3a1196d78030 | 103 | sig_out_biceps = sig_prev_biceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 104 | else sig_out_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 105 | } |
DanAuhust | 0:3a1196d78030 | 106 | else if ( deltaV >= border_biceps ) // stijging |
DanAuhust | 0:3a1196d78030 | 107 | { stat0_biceps = 1; |
DanAuhust | 0:3a1196d78030 | 108 | if (stat1_biceps == -1) |
DanAuhust | 0:3a1196d78030 | 109 | sig_out_biceps = sig_prev_biceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 110 | else sig_out_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 111 | } |
DanAuhust | 0:3a1196d78030 | 112 | else if ( deltaV <= -border_biceps ) // daling |
DanAuhust | 0:3a1196d78030 | 113 | { stat0_biceps = -1; |
DanAuhust | 0:3a1196d78030 | 114 | if (stat1_biceps == 1) |
DanAuhust | 0:3a1196d78030 | 115 | sig_out_biceps = sig_prev_biceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 116 | else sig_out_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 117 | } |
DanAuhust | 0:3a1196d78030 | 118 | else { stat0_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 119 | sig_out_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 120 | } |
DanAuhust | 0:3a1196d78030 | 121 | sig_prev_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 122 | stat1_biceps = stat0_biceps; |
DanAuhust | 0:3a1196d78030 | 123 | sig_out = sig_out_biceps; |
DanAuhust | 0:3a1196d78030 | 124 | red = sig_out_biceps; |
DanAuhust | 0:3a1196d78030 | 125 | } |
DanAuhust | 0:3a1196d78030 | 126 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 127 | break; |
DanAuhust | 0:3a1196d78030 | 128 | case 2: |
DanAuhust | 0:3a1196d78030 | 129 | //triceps filteren |
DanAuhust | 0:3a1196d78030 | 130 | in4_triceps = in3_triceps; in3_triceps = in2_triceps; in2_triceps = in1_triceps; in1_triceps = in0_triceps; |
DanAuhust | 0:3a1196d78030 | 131 | in0_triceps = emg_triceps.read(); |
DanAuhust | 0:3a1196d78030 | 132 | out4_triceps = out3_triceps; out3_triceps = out2_triceps; out2_triceps = out1_triceps; out1_triceps = out0_triceps; |
DanAuhust | 0:3a1196d78030 | 133 | out0_biceps = (NUM0*in0_triceps + NUM1*in1_triceps + NUM2*in2_triceps + NUM3*in3_triceps + NUM4*in4_triceps - DEN1*out1_triceps - DEN2*out2_triceps - DEN3*out3_triceps - DEN4*out4_triceps ) / DEN0; |
DanAuhust | 0:3a1196d78030 | 134 | |
DanAuhust | 0:3a1196d78030 | 135 | //std deviatie bepalen om de N metingen |
DanAuhust | 0:3a1196d78030 | 136 | emg_abs = fabs(out0_triceps); |
DanAuhust | 0:3a1196d78030 | 137 | sum_triceps += out0_triceps; |
DanAuhust | 0:3a1196d78030 | 138 | square_triceps += (emg_abs - mean_triceps)*(emg_abs - mean_triceps); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 139 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 140 | count_triceps += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 141 | |
DanAuhust | 0:3a1196d78030 | 142 | if (count_triceps >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 143 | { sig_in_triceps = sqrt(square_triceps/count_triceps); |
DanAuhust | 0:3a1196d78030 | 144 | mean_triceps = sum_triceps/count_triceps; |
DanAuhust | 0:3a1196d78030 | 145 | count_triceps = 0; square_triceps = 0; sum_triceps = 0;// en neem de RMS als er genoeg zijn geteld, stuur die door, en reset sqaure en count |
DanAuhust | 1:fb33955ca402 | 146 | deltaV = sig_in_triceps - sig_prev_triceps; |
DanAuhust | 0:3a1196d78030 | 147 | if (sig_in_triceps <= threshold_triceps) // threshold |
DanAuhust | 0:3a1196d78030 | 148 | { stat0_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 149 | if (stat1_triceps == 1) |
DanAuhust | 0:3a1196d78030 | 150 | sig_out_triceps = sig_prev_triceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 151 | else sig_out_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 152 | } |
DanAuhust | 0:3a1196d78030 | 153 | else if ( deltaV >= border_triceps ) // stijging |
DanAuhust | 0:3a1196d78030 | 154 | { stat0_triceps = 1; |
DanAuhust | 0:3a1196d78030 | 155 | if (stat1_triceps == -1) |
DanAuhust | 0:3a1196d78030 | 156 | sig_out_triceps = sig_prev_triceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 157 | else sig_out_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 158 | } |
DanAuhust | 0:3a1196d78030 | 159 | else if ( deltaV <= -border_triceps ) // daling |
DanAuhust | 0:3a1196d78030 | 160 | { stat0_triceps = -1; |
DanAuhust | 0:3a1196d78030 | 161 | if (stat1_triceps == 1) |
DanAuhust | 0:3a1196d78030 | 162 | sig_out_triceps = sig_prev_triceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 163 | else sig_out_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 164 | } |
DanAuhust | 0:3a1196d78030 | 165 | else { stat0_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 166 | sig_out_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 167 | } |
DanAuhust | 0:3a1196d78030 | 168 | sig_prev_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 169 | stat1_triceps = stat0_triceps; |
DanAuhust | 0:3a1196d78030 | 170 | sig_out = sig_out_triceps; |
DanAuhust | 0:3a1196d78030 | 171 | blue = sig_out_triceps; |
DanAuhust | 0:3a1196d78030 | 172 | } |
DanAuhust | 0:3a1196d78030 | 173 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 174 | break; |
DanAuhust | 0:3a1196d78030 | 175 | case 3: |
DanAuhust | 0:3a1196d78030 | 176 | //flexoren filteren |
DanAuhust | 0:3a1196d78030 | 177 | in4_flexoren = in3_flexoren; in3_flexoren = in2_flexoren; in2_flexoren = in1_flexoren; in1_flexoren = in0_flexoren; |
DanAuhust | 0:3a1196d78030 | 178 | in0_flexoren = emg_flexoren.read(); |
DanAuhust | 0:3a1196d78030 | 179 | out4_flexoren = out3_flexoren; out3_flexoren = out2_flexoren; out2_flexoren = out1_flexoren; out1_flexoren = out0_flexoren; |
DanAuhust | 0:3a1196d78030 | 180 | out0_flexoren = (NUM0*in0_flexoren + NUM1*in1_flexoren + NUM2*in2_flexoren + NUM3*in3_flexoren + NUM4*in4_flexoren - DEN1*out1_flexoren - DEN2*out2_flexoren - DEN3*out3_flexoren - DEN4*out4_flexoren) / DEN0; |
DanAuhust | 0:3a1196d78030 | 181 | |
DanAuhust | 0:3a1196d78030 | 182 | //std deviatie bepalen om de N metingen |
DanAuhust | 0:3a1196d78030 | 183 | emg_abs = fabs(out0_flexoren); |
DanAuhust | 0:3a1196d78030 | 184 | sum_flexoren += out0_flexoren; |
DanAuhust | 0:3a1196d78030 | 185 | square_flexoren += (emg_abs - mean_flexoren)*(emg_abs - mean_flexoren); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 186 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 187 | count_flexoren += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 188 | if (count_flexoren >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 189 | { sig_in_flexoren = sqrt(square_flexoren/count_flexoren); |
DanAuhust | 0:3a1196d78030 | 190 | mean_flexoren = sum_flexoren/count_flexoren; |
DanAuhust | 0:3a1196d78030 | 191 | count_flexoren = 0; square_flexoren = 0; sum_flexoren = 0; // en neem de RMS als er genoeg zijn geteld, stuur die door, en reset sqaure en count |
DanAuhust | 0:3a1196d78030 | 192 | |
DanAuhust | 0:3a1196d78030 | 193 | sig_out = sig_out_flexoren; |
DanAuhust | 0:3a1196d78030 | 194 | } |
DanAuhust | 0:3a1196d78030 | 195 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 196 | break; |
DanAuhust | 0:3a1196d78030 | 197 | case 4: |
DanAuhust | 0:3a1196d78030 | 198 | //extensoren filteren |
DanAuhust | 0:3a1196d78030 | 199 | in4_extensoren = in3_extensoren; in3_extensoren = in2_extensoren; in2_extensoren = in1_extensoren; in1_extensoren = in0_extensoren; |
DanAuhust | 0:3a1196d78030 | 200 | in0_extensoren = emg_extensoren.read(); |
DanAuhust | 0:3a1196d78030 | 201 | out4_extensoren = out3_extensoren; out3_extensoren = out2_extensoren; out2_extensoren = out1_extensoren; out1_extensoren = out0_extensoren; |
DanAuhust | 0:3a1196d78030 | 202 | out0_extensoren = (NUM0*in0_extensoren + NUM1*in1_extensoren + NUM2*in2_extensoren + NUM3*in3_extensoren + NUM4*in4_extensoren - DEN1*out1_extensoren - DEN2*out2_extensoren - DEN3*out3_extensoren - DEN4*out4_extensoren) / DEN0; |
DanAuhust | 0:3a1196d78030 | 203 | |
DanAuhust | 0:3a1196d78030 | 204 | //std deviatie bepalen om de 50 metingen |
DanAuhust | 0:3a1196d78030 | 205 | emg_abs = fabs(out0_extensoren); |
DanAuhust | 0:3a1196d78030 | 206 | sum_extensoren += out0_extensoren; |
DanAuhust | 0:3a1196d78030 | 207 | square_extensoren += (emg_abs - mean_extensoren)*(emg_abs - mean_extensoren); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 208 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 209 | count_extensoren += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 210 | if (count_extensoren >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 211 | { sig_in_extensoren = sqrt(square_extensoren/count_extensoren); |
DanAuhust | 0:3a1196d78030 | 212 | mean_extensoren = sum_extensoren/count_extensoren; |
DanAuhust | 0:3a1196d78030 | 213 | count_extensoren = 0; square_extensoren = 0; sum_extensoren = 0; // en neem de RMS als er genoeg zijn geteld, stuur die door, en reset sqaure en count |
DanAuhust | 0:3a1196d78030 | 214 | |
DanAuhust | 0:3a1196d78030 | 215 | sig_out=sig_out_extensoren; |
DanAuhust | 0:3a1196d78030 | 216 | } |
DanAuhust | 0:3a1196d78030 | 217 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 218 | break; |
DanAuhust | 0:3a1196d78030 | 219 | } |
DanAuhust | 0:3a1196d78030 | 220 | |
DanAuhust | 0:3a1196d78030 | 221 | return sig_out; |
DanAuhust | 0:3a1196d78030 | 222 | |
DanAuhust | 0:3a1196d78030 | 223 | } |
DanAuhust | 0:3a1196d78030 | 224 | |
DanAuhust | 0:3a1196d78030 | 225 | void looper() |
DanAuhust | 0:3a1196d78030 | 226 | { |
DanAuhust | 0:3a1196d78030 | 227 | static float biceps, triceps, extensoren, flexoren, emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 228 | |
DanAuhust | 0:3a1196d78030 | 229 | emg_filter_test = filter(1); |
DanAuhust | 0:3a1196d78030 | 230 | if (emg_filter_test != -1) biceps = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 231 | emg_filter_test = filter(2); |
DanAuhust | 0:3a1196d78030 | 232 | if (emg_filter_test != -1) triceps = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 233 | /*emg_filter_test = filter(3); |
DanAuhust | 0:3a1196d78030 | 234 | if (emg_filter_test != -1) flexoren = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 235 | emg_filter_test = filter(4); |
DanAuhust | 0:3a1196d78030 | 236 | if (emg_filter_test != -1) extensoren = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 237 | */ |
DanAuhust | 0:3a1196d78030 | 238 | } |
DanAuhust | 0:3a1196d78030 | 239 | |
DanAuhust | 0:3a1196d78030 | 240 | int main() |
DanAuhust | 0:3a1196d78030 | 241 | { |
DanAuhust | 0:3a1196d78030 | 242 | /*setup baudrate. Choose the same in your program on PC side*/ |
DanAuhust | 0:3a1196d78030 | 243 | pc.baud(115200); |
DanAuhust | 0:3a1196d78030 | 244 | /*set the period for the PWM to the red LED*/ |
DanAuhust | 0:3a1196d78030 | 245 | red.period_ms(80); // periode pwm = 2*Fs , blijkbaar. |
DanAuhust | 0:3a1196d78030 | 246 | blue.period_ms(80); |
DanAuhust | 0:3a1196d78030 | 247 | |
DanAuhust | 0:3a1196d78030 | 248 | |
DanAuhust | 0:3a1196d78030 | 249 | /**Here you attach the 'void looper(void)' function to the Ticker object0 |
DanAuhust | 0:3a1196d78030 | 250 | * The looper() function will be called every 0.001 seconds. |
DanAuhust | 0:3a1196d78030 | 251 | * Please mind that the parentheses after looper are omitted when using attach. |
DanAuhust | 0:3a1196d78030 | 252 | */ |
DanAuhust | 0:3a1196d78030 | 253 | timer.attach(looper, 0.001); |
DanAuhust | 0:3a1196d78030 | 254 | while(1) // Loop |
DanAuhust | 0:3a1196d78030 | 255 | { |
DanAuhust | 1:fb33955ca402 | 256 | // zie 'encoder' , timer bepaalt wanneer een if in de while-loop berekeningen doet voor de motor. |
DanAuhust | 0:3a1196d78030 | 257 | |
DanAuhust | 0:3a1196d78030 | 258 | } |
DanAuhust | 0:3a1196d78030 | 259 | } |