![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Filter emg 7-10-15 v1
Dependencies: HIDScope mbed MODSERIAL
Kalibratie.cpp@24:38cd27737a43, 2016-10-12 (annotated)
- Committer:
- Bartvaart
- Date:
- Wed Oct 12 15:31:14 2016 +0000
- Revision:
- 24:38cd27737a43
- Parent:
- 22:c1811e60bfce
andries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bartvaart | 16:8f175d2a472f | 1 | #include "Kalibratie.h" |
Bartvaart | 17:cfe44346645c | 2 | #include "Filterdesigns.h" |
Bartvaart | 22:c1811e60bfce | 3 | //#include "MODSERIAL.h" //bugfix |
Bartvaart | 17:cfe44346645c | 4 | |
Bartvaart | 24:38cd27737a43 | 5 | //AnalogIn emg2(A0); //Analog input van emg kabels niet meer nodig |
Bartvaart | 22:c1811e60bfce | 6 | //MODSERIAL pc2(USBTX, USBRX); //bugfix |
Bartvaart | 22:c1811e60bfce | 7 | DigitalOut LedGreen(LED2); |
Bartvaart | 22:c1811e60bfce | 8 | DigitalOut LedRed(LED1); |
Bartvaart | 22:c1811e60bfce | 9 | |
Bartvaart | 22:c1811e60bfce | 10 | int samples = 100; |
Bartvaart | 17:cfe44346645c | 11 | |
Bartvaart | 17:cfe44346645c | 12 | void Init() |
Bartvaart | 17:cfe44346645c | 13 | { |
Bartvaart | 17:cfe44346645c | 14 | LedGreen = 1; |
Bartvaart | 17:cfe44346645c | 15 | LedRed = 1; |
Bartvaart | 17:cfe44346645c | 16 | } |
Bartvaart | 17:cfe44346645c | 17 | |
Bartvaart | 24:38cd27737a43 | 18 | double KalibratieMax(bool &readymax, AnalogIn emg) //Kalibratie van de maximum waarde |
Bartvaart | 17:cfe44346645c | 19 | { |
Bartvaart | 22:c1811e60bfce | 20 | //pc2.baud(115200); |
Bartvaart | 17:cfe44346645c | 21 | LedGreen.write(0); //Led aan |
Bartvaart | 17:cfe44346645c | 22 | double ymax = 0; |
Bartvaart | 16:8f175d2a472f | 23 | |
Bartvaart | 22:c1811e60bfce | 24 | for(int i = 1; i <= samples; i++) { //Als timer onder de 5 seconden is dit uitvoeren |
Bartvaart | 24:38cd27737a43 | 25 | double u = emg.read(); |
Bartvaart | 20:11e1244ad2ad | 26 | double y = Filterdesigns(u); |
Bartvaart | 22:c1811e60bfce | 27 | |
Bartvaart | 22:c1811e60bfce | 28 | if (y > ymax && i >= samples / 10) { //Als de gemeten waarde groter is dan de opgeslagen waarde wordt dit de nieuwe opgeslagen waarde |
Bartvaart | 17:cfe44346645c | 29 | ymax = y; |
Bartvaart | 17:cfe44346645c | 30 | } |
Bartvaart | 22:c1811e60bfce | 31 | else {} |
Bartvaart | 22:c1811e60bfce | 32 | //pc2.printf("y = %f en ymax = %f \n",y,ymax); //bugfix |
Bartvaart | 22:c1811e60bfce | 33 | wait(0.05); |
Bartvaart | 17:cfe44346645c | 34 | } |
Bartvaart | 19:6c0245063b96 | 35 | |
Bartvaart | 17:cfe44346645c | 36 | LedGreen.write(1); //Led aan |
Bartvaart | 17:cfe44346645c | 37 | readymax = 1; // Zodat systeem weet wanneer kalibratie voltooid is |
Bartvaart | 17:cfe44346645c | 38 | return ymax; |
Bartvaart | 17:cfe44346645c | 39 | } |
Bartvaart | 17:cfe44346645c | 40 | |
Bartvaart | 24:38cd27737a43 | 41 | double KalibratieMin(bool &readymin, AnalogIn emg) //Kalibratie van de minimum waarde |
Bartvaart | 17:cfe44346645c | 42 | { |
Bartvaart | 22:c1811e60bfce | 43 | //pc2.baud(115200); |
Bartvaart | 17:cfe44346645c | 44 | LedRed.write(0); |
Bartvaart | 17:cfe44346645c | 45 | double ymin = 10; |
Bartvaart | 17:cfe44346645c | 46 | |
Bartvaart | 22:c1811e60bfce | 47 | for(int i = 1; i <= samples; i++) { |
Bartvaart | 24:38cd27737a43 | 48 | double u = emg.read(); |
Bartvaart | 20:11e1244ad2ad | 49 | double y = Filterdesigns(u); |
Bartvaart | 17:cfe44346645c | 50 | |
Bartvaart | 22:c1811e60bfce | 51 | if (y < ymin && i >= samples / 10) { |
Bartvaart | 17:cfe44346645c | 52 | ymin = y; |
Bartvaart | 17:cfe44346645c | 53 | } |
Bartvaart | 22:c1811e60bfce | 54 | else {} |
Bartvaart | 22:c1811e60bfce | 55 | //pc2.printf("y = %f en ymin = %f \n",y,ymin); //bugfix |
Bartvaart | 22:c1811e60bfce | 56 | wait(0.05); |
Bartvaart | 17:cfe44346645c | 57 | } |
Bartvaart | 17:cfe44346645c | 58 | |
Bartvaart | 17:cfe44346645c | 59 | LedRed.write(1); |
Bartvaart | 17:cfe44346645c | 60 | readymin = 1; |
Bartvaart | 17:cfe44346645c | 61 | return ymin; |
Bartvaart | 17:cfe44346645c | 62 | } |