Werkcollege opgave 23 september BMT K9

Dependencies:   Encoder HIDScope MODSERIAL mbed QEI biquadFilter

Committer:
ThomasBNL
Date:
Tue Oct 20 11:15:38 2015 +0000
Revision:
39:9fa091753592
Parent:
38:be38b9318849
Child:
40:7f928b465f8d
Child:
42:b5186a54d839
EMG filters aangepast HIDscope werkt nog steeds niet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bscheltinga 0:fe3896c6eeb0 1 #include "mbed.h"
bscheltinga 12:0a079e86348e 2 #include "HIDScope.h"
bscheltinga 0:fe3896c6eeb0 3 #include "MODSERIAL.h"
bscheltinga 13:04e10692e239 4 #include "biquadFilter.h" //Filter direct form II
bscheltinga 0:fe3896c6eeb0 5
bscheltinga 26:1090acf98efc 6 // [DEFINE INPUTS] //
sigert 37:6c04c15d9bbe 7 DigitalOut debug_led_red(LED_RED); // Debug LED
sigert 37:6c04c15d9bbe 8 DigitalOut debug_led_green(LED_GREEN); // Debug LED
sigert 37:6c04c15d9bbe 9 DigitalOut debug_led_blue(LED_BLUE); // Debug LED
ThomasBNL 36:f29a36683b1a 10
sigert 37:6c04c15d9bbe 11 const double off=1; // Led off
sigert 37:6c04c15d9bbe 12 const double on=0; // Led on
bscheltinga 21:594915ba2bf9 13
bscheltinga 26:1090acf98efc 14 // [DEFINE CONSTANTS] //
ThomasBNL 27:85e5d36bb6c5 15 HIDScope scope(3); // Aantal HIDScope kanalen
bscheltinga 18:68067ffd169e 16 MODSERIAL pc(USBTX,USBRX);
bscheltinga 20:d5f5c60adc43 17 Ticker control_tick;
ThomasBNL 27:85e5d36bb6c5 18 Ticker T1;
bscheltinga 15:7870f7912904 19
bscheltinga 26:1090acf98efc 20 // [BIQUAD FILTERS] //
ThomasBNL 27:85e5d36bb6c5 21 int Fs = 512; // sampling frequency
ThomasBNL 36:f29a36683b1a 22 const double low_b0 = 0.05892937945281792;
ThomasBNL 36:f29a36683b1a 23 const double low_b1 = 0.11785875890563584;
ThomasBNL 36:f29a36683b1a 24 const double low_b2 = 0.05892937945281792;
ThomasBNL 36:f29a36683b1a 25 const double low_a1 = -1.205716572226748;
sigert 37:6c04c15d9bbe 26 const double low_a2 = 0.44143409003801976; //Notch 1 LOW: VIA online biquad calculator Lowpass 520-48-0.7071-6
bscheltinga 15:7870f7912904 27
ThomasBNL 36:f29a36683b1a 28 const double high_b0 = 0.6389437261127494;
ThomasBNL 36:f29a36683b1a 29 const double high_b1 = -1.2778874522254988;
ThomasBNL 36:f29a36683b1a 30 const double high_b2 = 0.6389437261127494;
ThomasBNL 36:f29a36683b1a 31 const double high_a1 = -1.1429772843080923;
ThomasBNL 39:9fa091753592 32 const double high_a2 = 0.41279762014290533; // NOTCH 2 HIGH: VIA online biquad calculator Highpass 520-52-0.7071-6
bscheltinga 22:14abcfdd1554 33
ThomasBNL 39:9fa091753592 34 const double high_b0_HP = 0.84855234544818812;
ThomasBNL 39:9fa091753592 35 const double high_b1_HP = -1.6970469089637623;
ThomasBNL 39:9fa091753592 36 const double high_b2_HP = 0.8485234544818812;
ThomasBNL 39:9fa091753592 37 const double high_a1_HP = -1.6564788473046559;
ThomasBNL 39:9fa091753592 38 const double high_a2_HP = 0.7376149706228688; // HIGHPASS : NOG OPZOEKEN!! : >25Hz? sample rate 512Hz
sigert 37:6c04c15d9bbe 39
ThomasBNL 39:9fa091753592 40 const double low_b0_LP = 0.0013067079602315681;
ThomasBNL 39:9fa091753592 41 const double low_b1_LP = 0.0026134159204631363;
ThomasBNL 39:9fa091753592 42 const double low_b2_LP = 0.0013067079602315681;
ThomasBNL 39:9fa091753592 43 const double low_a1_LP = -1.9238184798980429;
ThomasBNL 39:9fa091753592 44 const double low_a2_LP = 0.9290453117389691; // LOWPASS : NOG OPZOEKEN!! <5-10 Hz? sample rate 512Hz
sigert 37:6c04c15d9bbe 45 //
ThomasBNL 36:f29a36683b1a 46 //Left bicep
sigert 37:6c04c15d9bbe 47 biquadFilter highpassfilter_1(high_a1_HP, high_a2_HP, high_b0_HP, high_b1_HP, high_b2_HP);// moeten nog waardes voor gemaakt worden? (>25Hz doorlaten)
sigert 37:6c04c15d9bbe 48 biquadFilter notchL1(high_a1, high_a2, high_b0, high_b1, high_b2);// moeten nog waardes voor gemaakt worden (>52Hz doorlaten)
ThomasBNL 36:f29a36683b1a 49 biquadFilter notchL2(low_a1, low_a2, low_b0, low_b1, low_b2);// moeten nog waardes voor gemaakt worden (<48Hz doorlaten)
sigert 37:6c04c15d9bbe 50 biquadFilter lowpassfilter_1(low_a1_LP, low_a2_LP, low_b0_LP, low_b1_LP, low_b2_LP);
bscheltinga 0:fe3896c6eeb0 51
ThomasBNL 36:f29a36683b1a 52 // Right bicep
sigert 37:6c04c15d9bbe 53 biquadFilter highpassfilter_2(high_a1_HP, high_a2_HP, high_b0_HP, high_b1_HP, high_b2_HP);// moeten nog waardes voor gemaakt worden?
sigert 37:6c04c15d9bbe 54 biquadFilter notchR1(high_a1, high_a2, high_b0, high_b1, high_b2); // moeten nog waardes voor gemaakt worden
ThomasBNL 36:f29a36683b1a 55 biquadFilter notchR2(low_a1, low_a2, low_b0, low_b1, low_b2); // moeten nog waardes voor gemaakt worden
sigert 37:6c04c15d9bbe 56 biquadFilter lowpassfilter_2(low_a1_LP, low_a2_LP, low_b0_LP, low_b1_LP, low_b2_LP);// moeten nog waardes voor gemaakt worden?
bscheltinga 20:d5f5c60adc43 57
ThomasBNL 27:85e5d36bb6c5 58
ThomasBNL 36:f29a36683b1a 59 AnalogIn input1(A0); // EMG: Two AnalogIn EMG inputs
ThomasBNL 36:f29a36683b1a 60 AnalogIn input2(A1); // EMG: Two AnalogIn EMG inputs
ThomasBNL 36:f29a36683b1a 61
ThomasBNL 36:f29a36683b1a 62 // __________________________
ThomasBNL 36:f29a36683b1a 63 // : [EMG variables] :
ThomasBNL 36:f29a36683b1a 64 // :__________________________:
ThomasBNL 36:f29a36683b1a 65 //
ThomasBNL 36:f29a36683b1a 66
ThomasBNL 36:f29a36683b1a 67 volatile bool control_go = false; // EMG:
ThomasBNL 36:f29a36683b1a 68 volatile bool sample = false;
ThomasBNL 36:f29a36683b1a 69 volatile bool sample_error = false;
ThomasBNL 36:f29a36683b1a 70 volatile bool sample_error_strike = false;
ThomasBNL 36:f29a36683b1a 71
ThomasBNL 36:f29a36683b1a 72 double Sample_EMG_L_1, Sample_EMG_L_2, Sample_EMG_L_3, Sample_EMG_L_4, Sample_EMG_L_5, Sample_EMG_L_6, Sample_EMG_L_7, Sample_EMG_L_8, Sample_EMG_L_9, Sample_EMG_L_10, moving_average_left;
ThomasBNL 36:f29a36683b1a 73 double Sample_EMG_R_1, Sample_EMG_R_2, Sample_EMG_R_3, Sample_EMG_R_4, Sample_EMG_R_5, Sample_EMG_R_6, Sample_EMG_R_7, Sample_EMG_R_8, Sample_EMG_R_9, Sample_EMG_R_10, moving_average_right;
ThomasBNL 36:f29a36683b1a 74
ThomasBNL 36:f29a36683b1a 75 double minimum_L; double maximum_L;
ThomasBNL 36:f29a36683b1a 76 double EMG_L_min; double EMG_L_max;
ThomasBNL 36:f29a36683b1a 77 double minimum_R; double maximum_R;
ThomasBNL 36:f29a36683b1a 78 double EMG_R_min; double EMG_R_max;
ThomasBNL 36:f29a36683b1a 79 double EMG_left_Bicep; double EMG_Right_Bicep; // input variables
ThomasBNL 36:f29a36683b1a 80 double EMG_Left_Bicep_filtered_notch_1;double EMG_Right_Bicep_filtered_notch_1;
ThomasBNL 36:f29a36683b1a 81 double EMG_Left_Bicep_filtered_notch_2;double EMG_Right_Bicep_filtered_notch_2;
ThomasBNL 36:f29a36683b1a 82 double EMG_Left_Bicep_filtered; double EMG_Right_Bicep_filtered; // output variables
ThomasBNL 36:f29a36683b1a 83
ThomasBNL 36:f29a36683b1a 84
ThomasBNL 36:f29a36683b1a 85 double n=0; double c=0; double k=0; double p=0; double er=0;
ThomasBNL 36:f29a36683b1a 86
ThomasBNL 36:f29a36683b1a 87 // FUNCTIONS
ThomasBNL 36:f29a36683b1a 88 void ControlGo();
ThomasBNL 36:f29a36683b1a 89 void take_sample();
ThomasBNL 36:f29a36683b1a 90 void Filter();
ThomasBNL 36:f29a36683b1a 91 void sample_filter();
ThomasBNL 36:f29a36683b1a 92 void countdown_from_5();
ThomasBNL 36:f29a36683b1a 93 void calibration();
sigert 37:6c04c15d9bbe 94 void red();void blue();void green();void white();void yellow();void cyan();void purple(); void black();
sigert 37:6c04c15d9bbe 95
ThomasBNL 36:f29a36683b1a 96
ThomasBNL 36:f29a36683b1a 97 //==========================//
ThomasBNL 27:85e5d36bb6c5 98 // [MAIN FUNCTION] //
ThomasBNL 36:f29a36683b1a 99 //==========================//
ThomasBNL 27:85e5d36bb6c5 100 int main()
ThomasBNL 27:85e5d36bb6c5 101 {
ThomasBNL 27:85e5d36bb6c5 102 control_tick.attach(&ControlGo, (float)1/Fs);
sigert 38:be38b9318849 103 pc.baud(115200);
sigert 38:be38b9318849 104 double n=0;
ThomasBNL 36:f29a36683b1a 105 // calibration(); // calibreer min en max positie
ThomasBNL 27:85e5d36bb6c5 106 while(1)
ThomasBNL 27:85e5d36bb6c5 107 {
ThomasBNL 27:85e5d36bb6c5 108 if(control_go)
ThomasBNL 27:85e5d36bb6c5 109 {
sigert 38:be38b9318849 110 n++;
sigert 38:be38b9318849 111 pc.printf("n %f",n);
ThomasBNL 27:85e5d36bb6c5 112 sample_filter();
sigert 38:be38b9318849 113 scope.set(0,n); //left bicep unfiltered
ThomasBNL 36:f29a36683b1a 114 scope.set(1,EMG_Left_Bicep_filtered); //Filtered signal
ThomasBNL 36:f29a36683b1a 115 scope.set(2,moving_average_left); //
ThomasBNL 27:85e5d36bb6c5 116 scope.send();
ThomasBNL 27:85e5d36bb6c5 117 control_go = 0;
ThomasBNL 27:85e5d36bb6c5 118 }
sigert 37:6c04c15d9bbe 119 yellow();
ThomasBNL 27:85e5d36bb6c5 120 } // while end
ThomasBNL 27:85e5d36bb6c5 121 } // main end
ThomasBNL 36:f29a36683b1a 122
ThomasBNL 36:f29a36683b1a 123 // --------------------------------------------------------------------------------------------------------
ThomasBNL 36:f29a36683b1a 124 // [FUNCTIONS] //
ThomasBNL 36:f29a36683b1a 125 void ControlGo() //Control flag
ThomasBNL 36:f29a36683b1a 126 {
ThomasBNL 36:f29a36683b1a 127 control_go = true;
ThomasBNL 36:f29a36683b1a 128 }
ThomasBNL 36:f29a36683b1a 129
ThomasBNL 36:f29a36683b1a 130 void sample_filter()
ThomasBNL 36:f29a36683b1a 131 {
ThomasBNL 36:f29a36683b1a 132 Filter();
ThomasBNL 36:f29a36683b1a 133 take_sample();
ThomasBNL 36:f29a36683b1a 134 if(sample)
ThomasBNL 36:f29a36683b1a 135 {
ThomasBNL 36:f29a36683b1a 136 sample=false;
ThomasBNL 36:f29a36683b1a 137 Sample_EMG_L_1 = EMG_Left_Bicep_filtered; Sample_EMG_R_1 = EMG_Right_Bicep_filtered;
ThomasBNL 36:f29a36683b1a 138
ThomasBNL 36:f29a36683b1a 139 Sample_EMG_L_10= Sample_EMG_L_9; Sample_EMG_R_10= Sample_EMG_R_9;
ThomasBNL 36:f29a36683b1a 140 Sample_EMG_L_9 = Sample_EMG_L_8; Sample_EMG_R_9 = Sample_EMG_R_8;
ThomasBNL 36:f29a36683b1a 141 Sample_EMG_L_8 = Sample_EMG_L_7; Sample_EMG_R_8 = Sample_EMG_R_7;
ThomasBNL 36:f29a36683b1a 142 Sample_EMG_L_7 = Sample_EMG_L_6; Sample_EMG_R_7 = Sample_EMG_R_6;
ThomasBNL 36:f29a36683b1a 143 Sample_EMG_L_6 = Sample_EMG_L_5; Sample_EMG_R_6 = Sample_EMG_R_5;
ThomasBNL 36:f29a36683b1a 144 Sample_EMG_L_5 = Sample_EMG_L_4; Sample_EMG_R_5 = Sample_EMG_R_4;
ThomasBNL 36:f29a36683b1a 145 Sample_EMG_L_4 = Sample_EMG_L_3; Sample_EMG_R_4 = Sample_EMG_R_3;
ThomasBNL 36:f29a36683b1a 146 Sample_EMG_L_3 = Sample_EMG_L_2; Sample_EMG_R_3 = Sample_EMG_R_2;
ThomasBNL 36:f29a36683b1a 147 Sample_EMG_L_2 = Sample_EMG_L_1; Sample_EMG_R_2 = Sample_EMG_R_1;
ThomasBNL 36:f29a36683b1a 148 }
ThomasBNL 36:f29a36683b1a 149 moving_average_left=Sample_EMG_L_1*0.1+Sample_EMG_L_2*0.1+Sample_EMG_L_3*0.1+Sample_EMG_L_4*0.1+Sample_EMG_L_5*0.1+Sample_EMG_L_6*0.1+Sample_EMG_L_7*0.1+Sample_EMG_L_8*0.1+Sample_EMG_L_9*0.1+Sample_EMG_L_10*0.1;
ThomasBNL 36:f29a36683b1a 150 moving_average_right=Sample_EMG_R_1*0.1+Sample_EMG_R_2*0.1+Sample_EMG_R_3*0.1+Sample_EMG_R_4*0.1+Sample_EMG_R_5*0.1+Sample_EMG_R_6*0.1+Sample_EMG_R_7*0.1+Sample_EMG_R_8*0.1+Sample_EMG_R_9*0.1+Sample_EMG_R_10*0.1;
ThomasBNL 36:f29a36683b1a 151 n++;
ThomasBNL 36:f29a36683b1a 152 }
ThomasBNL 36:f29a36683b1a 153
ThomasBNL 36:f29a36683b1a 154 void take_sample() // Take a sample every 25th sample
ThomasBNL 36:f29a36683b1a 155 {
ThomasBNL 36:f29a36683b1a 156 if(n==25)
ThomasBNL 36:f29a36683b1a 157 {
ThomasBNL 36:f29a36683b1a 158 sample = true; n=0;
ThomasBNL 36:f29a36683b1a 159 }
ThomasBNL 36:f29a36683b1a 160
ThomasBNL 36:f29a36683b1a 161 if(er==5)
ThomasBNL 36:f29a36683b1a 162 {
ThomasBNL 36:f29a36683b1a 163 sample_error = true; er=0;
ThomasBNL 36:f29a36683b1a 164 }
ThomasBNL 36:f29a36683b1a 165
ThomasBNL 36:f29a36683b1a 166 sample_error_strike = true;
ThomasBNL 36:f29a36683b1a 167 }
ThomasBNL 36:f29a36683b1a 168
ThomasBNL 36:f29a36683b1a 169 // [FILTER FUNCTIONS] //
ThomasBNL 36:f29a36683b1a 170 // [EMG] //
ThomasBNL 36:f29a36683b1a 171
ThomasBNL 36:f29a36683b1a 172 void Filter() // Unfiltered EMG (input) -> highpass filter -> rectify -> lowpass filter -> Filtered EMG (output)
ThomasBNL 36:f29a36683b1a 173 {
ThomasBNL 36:f29a36683b1a 174 EMG_left_Bicep = input1; EMG_Right_Bicep = input2;
ThomasBNL 36:f29a36683b1a 175
ThomasBNL 36:f29a36683b1a 176 EMG_Left_Bicep_filtered = highpassfilter_1.step(EMG_left_Bicep); EMG_Right_Bicep_filtered = highpassfilter_2.step(EMG_Right_Bicep);
ThomasBNL 36:f29a36683b1a 177 EMG_Left_Bicep_filtered = fabs(EMG_Left_Bicep_filtered); EMG_Right_Bicep_filtered = fabs(EMG_Right_Bicep_filtered);
ThomasBNL 36:f29a36683b1a 178
ThomasBNL 36:f29a36683b1a 179 EMG_Left_Bicep_filtered_notch_1 = notchL1.step(EMG_Left_Bicep_filtered); EMG_Right_Bicep_filtered_notch_1 = notchR1.step(EMG_Right_Bicep_filtered);
ThomasBNL 36:f29a36683b1a 180 EMG_Left_Bicep_filtered_notch_2 = notchL2.step(EMG_Left_Bicep_filtered_notch_1); EMG_Right_Bicep_filtered_notch_2 = notchR2.step(EMG_Right_Bicep_filtered_notch_1);
ThomasBNL 36:f29a36683b1a 181
ThomasBNL 36:f29a36683b1a 182 EMG_Left_Bicep_filtered = lowpassfilter_1.step(EMG_Left_Bicep_filtered_notch_2); EMG_Right_Bicep_filtered = lowpassfilter_2.step(EMG_Right_Bicep_filtered_notch_2);
ThomasBNL 36:f29a36683b1a 183 }
ThomasBNL 36:f29a36683b1a 184
ThomasBNL 36:f29a36683b1a 185 void countdown_from_5() // Countdown from 5 till 0 inside Putty (interface)
ThomasBNL 36:f29a36683b1a 186 {
ThomasBNL 36:f29a36683b1a 187 wait(1); pc.printf("5 \n\r"); wait(1); pc.printf("4 \n\r"); wait(1); pc.printf("3 \n\r"); wait(1); pc.printf("2 Ready \n\r");
ThomasBNL 36:f29a36683b1a 188 wait(1); pc.printf("1 Set \n\r"); wait(1); pc.printf("Go \n\r");
ThomasBNL 36:f29a36683b1a 189 }
ThomasBNL 36:f29a36683b1a 190
ThomasBNL 36:f29a36683b1a 191 void calibration()
ThomasBNL 36:f29a36683b1a 192 {
ThomasBNL 36:f29a36683b1a 193
ThomasBNL 36:f29a36683b1a 194
ThomasBNL 36:f29a36683b1a 195 // [MINIMUM VALUE BICEPS CALIBRATION] //
ThomasBNL 36:f29a36683b1a 196
ThomasBNL 36:f29a36683b1a 197 pc.printf("Start minimum calibration in 5 seconds \n\r");
ThomasBNL 36:f29a36683b1a 198 pc.printf("Keep your biceps as relaxed as possible \n\r");
ThomasBNL 36:f29a36683b1a 199
ThomasBNL 36:f29a36683b1a 200 countdown_from_5();
ThomasBNL 36:f29a36683b1a 201 c=0;
ThomasBNL 36:f29a36683b1a 202
ThomasBNL 36:f29a36683b1a 203 while(c<2560) // 512Hz -> 2560 is equal to five seconds
ThomasBNL 36:f29a36683b1a 204 {
ThomasBNL 36:f29a36683b1a 205 Filter(); // Filter EMG signal
ThomasBNL 36:f29a36683b1a 206 minimum_L=EMG_Left_Bicep_filtered+minimum_L; // Take previous sample EMG_Left_Bicep_filtered and add the new value
ThomasBNL 36:f29a36683b1a 207 minimum_R=EMG_Right_Bicep_filtered+minimum_R;
ThomasBNL 36:f29a36683b1a 208 // scope.set(0,EMG_left_Bicep);
ThomasBNL 36:f29a36683b1a 209 // scope.set(1,EMG_Left_Bicep_filtered);
ThomasBNL 36:f29a36683b1a 210 // scope.set(2,minimum_L);
ThomasBNL 36:f29a36683b1a 211 // scope.send();
ThomasBNL 36:f29a36683b1a 212 c++; // Every sample c is increased by one until the statement c<2560 is false
ThomasBNL 36:f29a36683b1a 213 wait(0.001953125); // wait one sample
ThomasBNL 36:f29a36683b1a 214 }
ThomasBNL 36:f29a36683b1a 215
ThomasBNL 36:f29a36683b1a 216 pc.printf("Finished minimum calibration \n\r");
ThomasBNL 36:f29a36683b1a 217
ThomasBNL 36:f29a36683b1a 218 EMG_L_min=minimum_L/2560; // Divide the summation by the number of measurements (2560 measurements) to get a mean value over 5 seconds
ThomasBNL 36:f29a36683b1a 219 EMG_R_min=minimum_R/2560;
ThomasBNL 36:f29a36683b1a 220
ThomasBNL 36:f29a36683b1a 221 pc.printf("EMG_L_min = %f \n\r EMG_R_min = %f \n\r", EMG_L_min, EMG_R_min);
ThomasBNL 36:f29a36683b1a 222
ThomasBNL 36:f29a36683b1a 223 wait (3); //cooldown
ThomasBNL 36:f29a36683b1a 224
ThomasBNL 36:f29a36683b1a 225
ThomasBNL 36:f29a36683b1a 226 // [MAXIMUM VALUE BICEPS CALIBRATION] //
ThomasBNL 36:f29a36683b1a 227
ThomasBNL 36:f29a36683b1a 228
ThomasBNL 36:f29a36683b1a 229 pc.printf("start maximum calibration in 5 seconds (start contraction at 3) \n\r");
ThomasBNL 36:f29a36683b1a 230
ThomasBNL 36:f29a36683b1a 231 countdown_from_5();
ThomasBNL 36:f29a36683b1a 232 c=0;
ThomasBNL 36:f29a36683b1a 233
ThomasBNL 36:f29a36683b1a 234 while(c<2560) // 512Hz -> 2560 is equal to five seconds
ThomasBNL 36:f29a36683b1a 235 {
ThomasBNL 36:f29a36683b1a 236 Filter(); // Filter EMG signal
ThomasBNL 36:f29a36683b1a 237 maximum_L=EMG_Left_Bicep_filtered+maximum_L; // Take previous sample EMG_Left_Bicep_filtered and add the new value
ThomasBNL 36:f29a36683b1a 238 maximum_R=EMG_Right_Bicep_filtered+maximum_R;
ThomasBNL 36:f29a36683b1a 239 c++; // Every sample c is increased by one until the statement c<2560 is false
ThomasBNL 36:f29a36683b1a 240 wait(0.001953125);
ThomasBNL 36:f29a36683b1a 241 }
ThomasBNL 36:f29a36683b1a 242
ThomasBNL 36:f29a36683b1a 243 pc.printf("Finished minimum calibration \n\r");
ThomasBNL 36:f29a36683b1a 244
ThomasBNL 36:f29a36683b1a 245 EMG_L_max=maximum_L/2560; // Divide the summation by the number of measurements (2560 measurements) to get a mean value over 5 seconds
ThomasBNL 36:f29a36683b1a 246 EMG_R_max=maximum_R/2560;
ThomasBNL 36:f29a36683b1a 247
ThomasBNL 36:f29a36683b1a 248 pc.printf("EMG_L_max = %f \n\r EMG_R_max = %f \n\r", EMG_L_max, EMG_R_max);
ThomasBNL 36:f29a36683b1a 249
ThomasBNL 36:f29a36683b1a 250 wait (3); //cooldown
ThomasBNL 36:f29a36683b1a 251
ThomasBNL 36:f29a36683b1a 252
ThomasBNL 36:f29a36683b1a 253 // [MAXIMUM VALUE BICEPS CALIBRATION] //
ThomasBNL 36:f29a36683b1a 254 // Calculate threshold percentages //
ThomasBNL 36:f29a36683b1a 255
ThomasBNL 36:f29a36683b1a 256 const float Threshold_Bicep_Left_1=((EMG_L_max-EMG_L_min)*0.2)+EMG_L_min;; //(waarde waarop het gemeten EMG signaal 20% van max het maximale is); // LEFT
ThomasBNL 36:f29a36683b1a 257 const float Threshold_Bicep_Left_2=((EMG_L_max-EMG_L_min)*0.6)+EMG_L_min; //(waarde waarop het gemeten EMG signaal 60% van max het maximale is);
ThomasBNL 36:f29a36683b1a 258 const float Threshold_Bicep_Right_1=((EMG_R_max-EMG_R_min)*0.2)+EMG_R_min; //(waarde waarop het gemeten EMG signaal 20% van max het maximale is); // RIGHT
ThomasBNL 36:f29a36683b1a 259 const float Threshold_Bicep_Right_2=((EMG_R_max-EMG_R_min)*0.6)+EMG_R_min; //(waarde waarop het gemeten EMG signaal 60% van max het maximale is);
ThomasBNL 36:f29a36683b1a 260
ThomasBNL 36:f29a36683b1a 261 pc.printf("left 1: %f left 2: %f right 1: %f right 2: %f \n\r", Threshold_Bicep_Left_1, Threshold_Bicep_Left_2, Threshold_Bicep_Right_1, Threshold_Bicep_Right_2);
ThomasBNL 36:f29a36683b1a 262
ThomasBNL 36:f29a36683b1a 263 }
ThomasBNL 36:f29a36683b1a 264
sigert 37:6c04c15d9bbe 265 void red() { debug_led_red=on; debug_led_blue=off; debug_led_green=off; }
sigert 37:6c04c15d9bbe 266 void blue() { debug_led_red=off; debug_led_blue=on; debug_led_green=off; }
sigert 37:6c04c15d9bbe 267 void green() { debug_led_red=off; debug_led_blue=off; debug_led_green=on; }
sigert 37:6c04c15d9bbe 268 void white() { debug_led_red=on; debug_led_blue=on; debug_led_green=on; }
sigert 37:6c04c15d9bbe 269 void yellow() { debug_led_red=on; debug_led_blue=off; debug_led_green=on; }
sigert 37:6c04c15d9bbe 270 void cyan() { debug_led_red=off; debug_led_blue=on; debug_led_green=on; }
sigert 37:6c04c15d9bbe 271 void purple() { debug_led_red=on; debug_led_blue=on; debug_led_green=off; }
sigert 37:6c04c15d9bbe 272 void black() { debug_led_red=off; debug_led_blue=off; debug_led_green=off; }
ThomasBNL 36:f29a36683b1a 273