Dan August
/
EMG2spier
Meting en filter voor 2 spieren
main.cpp@0:3a1196d78030, 2013-10-25 (annotated)
- Committer:
- DanAuhust
- Date:
- Fri Oct 25 08:34:03 2013 +0000
- Revision:
- 0:3a1196d78030
- Child:
- 1:fb33955ca402
EMG meting en filter voor 2 spieren
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 | 0:3a1196d78030 | 50 | static float in0_biceps =0 , in1_biceps =0, in2_biceps = 0, in3_biceps = 0, in4_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 51 | static float out0_biceps = 0, out1_biceps = 0 , out2_biceps = 0, out3_biceps = 0, out4_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 52 | |
DanAuhust | 0:3a1196d78030 | 53 | // variabelen triceps definieren |
DanAuhust | 0:3a1196d78030 | 54 | static float in0_triceps = 0, in1_triceps = 0, in2_triceps = 0, in3_triceps = 0, in4_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 55 | static float out0_triceps = 0, out1_triceps = 0, out2_triceps = 0, out3_triceps = 0, out4_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 56 | |
DanAuhust | 0:3a1196d78030 | 57 | //variabelen flexoren definieren |
DanAuhust | 0:3a1196d78030 | 58 | static float in0_flexoren = 0, in1_flexoren = 0, in2_flexoren = 0, in3_flexoren = 0, in4_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 59 | static float out0_flexoren = 0, out1_flexoren = 0, out2_flexoren = 0, out3_flexoren = 0, out4_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 60 | |
DanAuhust | 0:3a1196d78030 | 61 | //variablen extensoren definieren |
DanAuhust | 0:3a1196d78030 | 62 | static float in0_extensoren = 0, in1_extensoren = 0, in2_extensoren = 0, in3_extensoren = 0, in4_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 63 | static float out0_extensoren = 0, out1_extensoren = 0, out2_extensoren = 0, out3_extensoren = 0, out4_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 64 | |
DanAuhust | 0:3a1196d78030 | 65 | //overige variabelen definieren |
DanAuhust | 0:3a1196d78030 | 66 | // verwijder static waar mogelijk, maakt programma iets sneller |
DanAuhust | 0:3a1196d78030 | 67 | static float count_biceps = 0, count_triceps = 0, count_extensoren = 0, count_flexoren = 0; |
DanAuhust | 0:3a1196d78030 | 68 | static float square_biceps = 0, square_triceps = 0, square_flexoren = 0, square_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 69 | static float sum_biceps = 0, sum_triceps = 0, sum_flexoren = 0, sum_extensoren = 0; |
DanAuhust | 0:3a1196d78030 | 70 | static float mean_biceps = 0.1, mean_triceps = 0.1, mean_flexoren = 0.1, mean_extensoren = 0.1; |
DanAuhust | 0:3a1196d78030 | 71 | static float EMG_biceps, EMG_triceps, EMG_flexoren, EMG_extensoren // output ruwe EMG |
DanAuhust | 0:3a1196d78030 | 72 | static float sig_in_biceps, sig_in_triceps, sig_in_extensoren, sig_in_flexoren; // naam gewijzigd, output StDev |
DanAuhust | 0:3a1196d78030 | 73 | static float sig_out_biceps, sig_out_triceps, sig_out_extensoren, sig_out_flexoren; |
DanAuhust | 0:3a1196d78030 | 74 | float emg_abs, sig_out, deltaV |
DanAuhust | 0:3a1196d78030 | 75 | static float sig_prev_biceps = 0, sig_prev_triceps = 0, sig_prev_extensoren = 0, sig_prev_flexoren = 0 |
DanAuhust | 0:3a1196d78030 | 76 | static int stat0_biceps, stat0_triceps, stat0_extensoren, stat0_flexoren |
DanAuhust | 0:3a1196d78030 | 77 | static int stat1_biceps = 0, stat1_triceps = 0, stat1_extensoren = 0, stat1_flexoren = 0 |
DanAuhust | 0:3a1196d78030 | 78 | |
DanAuhust | 0:3a1196d78030 | 79 | switch (signal_number){ |
DanAuhust | 0:3a1196d78030 | 80 | case 1: |
DanAuhust | 0:3a1196d78030 | 81 | //biceps filteren |
DanAuhust | 0:3a1196d78030 | 82 | in4_biceps = in3_biceps; in3_biceps = in2_biceps; in2_biceps = in1_biceps; in1_biceps = in0_biceps; |
DanAuhust | 0:3a1196d78030 | 83 | in0_biceps = emg_biceps.read(); |
DanAuhust | 0:3a1196d78030 | 84 | out4_biceps 2= out3_biceps; out3_biceps = out2_biceps; out2_biceps = out1_biceps; out1_biceps = out0_biceps; |
DanAuhust | 0:3a1196d78030 | 85 | 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 | 86 | |
DanAuhust | 0:3a1196d78030 | 87 | //std deviatie bepalen, om de N metingen |
DanAuhust | 0:3a1196d78030 | 88 | emg_abs = fabs(out0_biceps); |
DanAuhust | 0:3a1196d78030 | 89 | sum_biceps += out0_biceps; |
DanAuhust | 0:3a1196d78030 | 90 | square_biceps += (emg_abs - mean_biceps)*(emg_abs - mean_biceps); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 91 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 92 | count_biceps += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 93 | if (count_biceps >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 94 | { sig_in_biceps = sqrt(square_biceps/count_biceps); |
DanAuhust | 0:3a1196d78030 | 95 | mean_biceps = sum_biceps/count_biceps; |
DanAuhust | 0:3a1196d78030 | 96 | 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 | 97 | // nieuw: |
DanAuhust | 0:3a1196d78030 | 98 | deltaV = sig_in_biceps - sig_prev_biceps |
DanAuhust | 0:3a1196d78030 | 99 | if (sig_in_biceps <= threshold_biceps) // threshold |
DanAuhust | 0:3a1196d78030 | 100 | { stat0_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 101 | if (stat1_biceps == 1) |
DanAuhust | 0:3a1196d78030 | 102 | sig_out_biceps = sig_prev_biceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 103 | else sig_out_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 104 | } |
DanAuhust | 0:3a1196d78030 | 105 | else if ( deltaV >= border_biceps ) // stijging |
DanAuhust | 0:3a1196d78030 | 106 | { stat0_biceps = 1; |
DanAuhust | 0:3a1196d78030 | 107 | if (stat1_biceps == -1) |
DanAuhust | 0:3a1196d78030 | 108 | sig_out_biceps = sig_prev_biceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 109 | else sig_out_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 110 | } |
DanAuhust | 0:3a1196d78030 | 111 | else if ( deltaV <= -border_biceps ) // daling |
DanAuhust | 0:3a1196d78030 | 112 | { stat0_biceps = -1; |
DanAuhust | 0:3a1196d78030 | 113 | if (stat1_biceps == 1) |
DanAuhust | 0:3a1196d78030 | 114 | sig_out_biceps = sig_prev_biceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 115 | else sig_out_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 116 | } |
DanAuhust | 0:3a1196d78030 | 117 | else { stat0_biceps = 0; |
DanAuhust | 0:3a1196d78030 | 118 | sig_out_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 119 | } |
DanAuhust | 0:3a1196d78030 | 120 | sig_prev_biceps = sig_in_biceps; |
DanAuhust | 0:3a1196d78030 | 121 | stat1_biceps = stat0_biceps; |
DanAuhust | 0:3a1196d78030 | 122 | sig_out = sig_out_biceps; |
DanAuhust | 0:3a1196d78030 | 123 | red = sig_out_biceps; |
DanAuhust | 0:3a1196d78030 | 124 | } |
DanAuhust | 0:3a1196d78030 | 125 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 126 | break; |
DanAuhust | 0:3a1196d78030 | 127 | case 2: |
DanAuhust | 0:3a1196d78030 | 128 | //triceps filteren |
DanAuhust | 0:3a1196d78030 | 129 | in4_triceps = in3_triceps; in3_triceps = in2_triceps; in2_triceps = in1_triceps; in1_triceps = in0_triceps; |
DanAuhust | 0:3a1196d78030 | 130 | in0_triceps = emg_triceps.read(); |
DanAuhust | 0:3a1196d78030 | 131 | out4_triceps = out3_triceps; out3_triceps = out2_triceps; out2_triceps = out1_triceps; out1_triceps = out0_triceps; |
DanAuhust | 0:3a1196d78030 | 132 | 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 | 133 | |
DanAuhust | 0:3a1196d78030 | 134 | //std deviatie bepalen om de N metingen |
DanAuhust | 0:3a1196d78030 | 135 | emg_abs = fabs(out0_triceps); |
DanAuhust | 0:3a1196d78030 | 136 | sum_triceps += out0_triceps; |
DanAuhust | 0:3a1196d78030 | 137 | square_triceps += (emg_abs - mean_triceps)*(emg_abs - mean_triceps); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 138 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 139 | count_triceps += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 140 | |
DanAuhust | 0:3a1196d78030 | 141 | if (count_triceps >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 142 | { sig_in_triceps = sqrt(square_triceps/count_triceps); |
DanAuhust | 0:3a1196d78030 | 143 | mean_triceps = sum_triceps/count_triceps; |
DanAuhust | 0:3a1196d78030 | 144 | 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 | 0:3a1196d78030 | 145 | deltaV = sig_in_triceps - sig_prev_triceps |
DanAuhust | 0:3a1196d78030 | 146 | if (sig_in_triceps <= threshold_triceps) // threshold |
DanAuhust | 0:3a1196d78030 | 147 | { stat0_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 148 | if (stat1_triceps == 1) |
DanAuhust | 0:3a1196d78030 | 149 | sig_out_triceps = sig_prev_triceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 150 | else sig_out_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 151 | } |
DanAuhust | 0:3a1196d78030 | 152 | else if ( deltaV >= border_triceps ) // stijging |
DanAuhust | 0:3a1196d78030 | 153 | { stat0_triceps = 1; |
DanAuhust | 0:3a1196d78030 | 154 | if (stat1_triceps == -1) |
DanAuhust | 0:3a1196d78030 | 155 | sig_out_triceps = sig_prev_triceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 156 | else sig_out_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 157 | } |
DanAuhust | 0:3a1196d78030 | 158 | else if ( deltaV <= -border_triceps ) // daling |
DanAuhust | 0:3a1196d78030 | 159 | { stat0_triceps = -1; |
DanAuhust | 0:3a1196d78030 | 160 | if (stat1_triceps == 1) |
DanAuhust | 0:3a1196d78030 | 161 | sig_out_triceps = sig_prev_triceps + deltaV / inertia; |
DanAuhust | 0:3a1196d78030 | 162 | else sig_out_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 163 | } |
DanAuhust | 0:3a1196d78030 | 164 | else { stat0_triceps = 0; |
DanAuhust | 0:3a1196d78030 | 165 | sig_out_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 166 | } |
DanAuhust | 0:3a1196d78030 | 167 | sig_prev_triceps = sig_in_triceps; |
DanAuhust | 0:3a1196d78030 | 168 | stat1_triceps = stat0_triceps; |
DanAuhust | 0:3a1196d78030 | 169 | sig_out = sig_out_triceps; |
DanAuhust | 0:3a1196d78030 | 170 | blue = sig_out_triceps; |
DanAuhust | 0:3a1196d78030 | 171 | } |
DanAuhust | 0:3a1196d78030 | 172 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 173 | break; |
DanAuhust | 0:3a1196d78030 | 174 | case 3: |
DanAuhust | 0:3a1196d78030 | 175 | //flexoren filteren |
DanAuhust | 0:3a1196d78030 | 176 | in4_flexoren = in3_flexoren; in3_flexoren = in2_flexoren; in2_flexoren = in1_flexoren; in1_flexoren = in0_flexoren; |
DanAuhust | 0:3a1196d78030 | 177 | in0_flexoren = emg_flexoren.read(); |
DanAuhust | 0:3a1196d78030 | 178 | out4_flexoren = out3_flexoren; out3_flexoren = out2_flexoren; out2_flexoren = out1_flexoren; out1_flexoren = out0_flexoren; |
DanAuhust | 0:3a1196d78030 | 179 | 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 | 180 | |
DanAuhust | 0:3a1196d78030 | 181 | //std deviatie bepalen om de N metingen |
DanAuhust | 0:3a1196d78030 | 182 | emg_abs = fabs(out0_flexoren); |
DanAuhust | 0:3a1196d78030 | 183 | sum_flexoren += out0_flexoren; |
DanAuhust | 0:3a1196d78030 | 184 | square_flexoren += (emg_abs - mean_flexoren)*(emg_abs - mean_flexoren); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 185 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 186 | count_flexoren += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 187 | if (count_flexoren >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 188 | { sig_in_flexoren = sqrt(square_flexoren/count_flexoren); |
DanAuhust | 0:3a1196d78030 | 189 | mean_flexoren = sum_flexoren/count_flexoren; |
DanAuhust | 0:3a1196d78030 | 190 | 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 | 191 | |
DanAuhust | 0:3a1196d78030 | 192 | sig_out = sig_out_flexoren; |
DanAuhust | 0:3a1196d78030 | 193 | } |
DanAuhust | 0:3a1196d78030 | 194 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 195 | break; |
DanAuhust | 0:3a1196d78030 | 196 | case 4: |
DanAuhust | 0:3a1196d78030 | 197 | //extensoren filteren |
DanAuhust | 0:3a1196d78030 | 198 | in4_extensoren = in3_extensoren; in3_extensoren = in2_extensoren; in2_extensoren = in1_extensoren; in1_extensoren = in0_extensoren; |
DanAuhust | 0:3a1196d78030 | 199 | in0_extensoren = emg_extensoren.read(); |
DanAuhust | 0:3a1196d78030 | 200 | out4_extensoren = out3_extensoren; out3_extensoren = out2_extensoren; out2_extensoren = out1_extensoren; out1_extensoren = out0_extensoren; |
DanAuhust | 0:3a1196d78030 | 201 | 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 | 202 | |
DanAuhust | 0:3a1196d78030 | 203 | //std deviatie bepalen om de 50 metingen |
DanAuhust | 0:3a1196d78030 | 204 | emg_abs = fabs(out0_extensoren); |
DanAuhust | 0:3a1196d78030 | 205 | sum_extensoren += out0_extensoren; |
DanAuhust | 0:3a1196d78030 | 206 | square_extensoren += (emg_abs - mean_extensoren)*(emg_abs - mean_extensoren); //neem absolute waarde, kwadrateer, voeg toe aan vorige square |
DanAuhust | 0:3a1196d78030 | 207 | // voeg rest EMG's toe, variabelen alleen _spier geven als het nodig is. |
DanAuhust | 0:3a1196d78030 | 208 | count_extensoren += 1; // hou bij hoeveel squares er zijn opgeteld |
DanAuhust | 0:3a1196d78030 | 209 | if (count_extensoren >= MAXCOUNT) |
DanAuhust | 0:3a1196d78030 | 210 | { sig_in_extensoren = sqrt(square_extensoren/count_extensoren); |
DanAuhust | 0:3a1196d78030 | 211 | mean_extensoren = sum_extensoren/count_extensoren; |
DanAuhust | 0:3a1196d78030 | 212 | 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 | 213 | |
DanAuhust | 0:3a1196d78030 | 214 | sig_out=sig_out_extensoren; |
DanAuhust | 0:3a1196d78030 | 215 | } |
DanAuhust | 0:3a1196d78030 | 216 | else sig_out = -1; |
DanAuhust | 0:3a1196d78030 | 217 | break; |
DanAuhust | 0:3a1196d78030 | 218 | } |
DanAuhust | 0:3a1196d78030 | 219 | |
DanAuhust | 0:3a1196d78030 | 220 | return sig_out; |
DanAuhust | 0:3a1196d78030 | 221 | |
DanAuhust | 0:3a1196d78030 | 222 | } |
DanAuhust | 0:3a1196d78030 | 223 | |
DanAuhust | 0:3a1196d78030 | 224 | void looper() |
DanAuhust | 0:3a1196d78030 | 225 | { |
DanAuhust | 0:3a1196d78030 | 226 | static float biceps, triceps, extensoren, flexoren, emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 227 | |
DanAuhust | 0:3a1196d78030 | 228 | emg_filter_test = filter(1); |
DanAuhust | 0:3a1196d78030 | 229 | if (emg_filter_test != -1) biceps = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 230 | emg_filter_test = filter(2); |
DanAuhust | 0:3a1196d78030 | 231 | if (emg_filter_test != -1) triceps = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 232 | /*emg_filter_test = filter(3); |
DanAuhust | 0:3a1196d78030 | 233 | if (emg_filter_test != -1) flexoren = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 234 | emg_filter_test = filter(4); |
DanAuhust | 0:3a1196d78030 | 235 | if (emg_filter_test != -1) extensoren = emg_filter_test; |
DanAuhust | 0:3a1196d78030 | 236 | */ |
DanAuhust | 0:3a1196d78030 | 237 | } |
DanAuhust | 0:3a1196d78030 | 238 | |
DanAuhust | 0:3a1196d78030 | 239 | int main() |
DanAuhust | 0:3a1196d78030 | 240 | { |
DanAuhust | 0:3a1196d78030 | 241 | /*setup baudrate. Choose the same in your program on PC side*/ |
DanAuhust | 0:3a1196d78030 | 242 | pc.baud(115200); |
DanAuhust | 0:3a1196d78030 | 243 | /*set the period for the PWM to the red LED*/ |
DanAuhust | 0:3a1196d78030 | 244 | red.period_ms(80); // periode pwm = 2*Fs , blijkbaar. |
DanAuhust | 0:3a1196d78030 | 245 | blue.period_ms(80); |
DanAuhust | 0:3a1196d78030 | 246 | |
DanAuhust | 0:3a1196d78030 | 247 | |
DanAuhust | 0:3a1196d78030 | 248 | /**Here you attach the 'void looper(void)' function to the Ticker object0 |
DanAuhust | 0:3a1196d78030 | 249 | * The looper() function will be called every 0.001 seconds. |
DanAuhust | 0:3a1196d78030 | 250 | * Please mind that the parentheses after looper are omitted when using attach. |
DanAuhust | 0:3a1196d78030 | 251 | */ |
DanAuhust | 0:3a1196d78030 | 252 | timer.attach(looper, 0.001); |
DanAuhust | 0:3a1196d78030 | 253 | while(1) // Loop |
DanAuhust | 0:3a1196d78030 | 254 | { |
DanAuhust | 0:3a1196d78030 | 255 | // blue = sig_out_biceps; |
DanAuhust | 0:3a1196d78030 | 256 | |
DanAuhust | 0:3a1196d78030 | 257 | } |
DanAuhust | 0:3a1196d78030 | 258 | } |