Filter emg 7-10-15 v1

Dependencies:   HIDScope mbed MODSERIAL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Kalibratie.cpp Source File

Kalibratie.cpp

00001 #include "Kalibratie.h"
00002 #include "Filterdesigns.h"
00003 //#include "MODSERIAL.h" //bugfix
00004 
00005 //AnalogIn    emg2(A0); //Analog input van emg kabels niet meer nodig
00006 //MODSERIAL   pc2(USBTX, USBRX); //bugfix
00007 DigitalOut  LedGreen(LED2);
00008 DigitalOut  LedRed(LED1);
00009 
00010 int samples = 100;
00011 
00012 void Init()
00013 {
00014     LedGreen = 1;
00015     LedRed = 1;
00016 }
00017 
00018 double KalibratieMax(bool &readymax, AnalogIn emg)  //Kalibratie van de maximum waarde
00019 {
00020     //pc2.baud(115200);
00021     LedGreen.write(0); //Led aan
00022     double ymax = 0;
00023 
00024     for(int i = 1; i <= samples; i++) { //Als timer onder de 5 seconden is dit uitvoeren
00025         double u = emg.read();
00026         double y = Filterdesigns(u);
00027         
00028         if (y > ymax && i >= samples / 10) { //Als de gemeten waarde groter is dan de opgeslagen waarde wordt dit de nieuwe opgeslagen waarde
00029             ymax = y;
00030         } 
00031         else {}
00032         //pc2.printf("y = %f en ymax = %f \n",y,ymax); //bugfix
00033         wait(0.05);
00034     }
00035     
00036     LedGreen.write(1); //Led aan
00037     readymax = 1; // Zodat systeem weet wanneer kalibratie voltooid is
00038     return ymax;
00039 }
00040 
00041 double KalibratieMin(bool &readymin, AnalogIn emg)  //Kalibratie van de minimum waarde
00042 {
00043     //pc2.baud(115200);
00044     LedRed.write(0);
00045     double ymin = 10;
00046 
00047     for(int i = 1; i <= samples; i++) {
00048         double u = emg.read();
00049         double y = Filterdesigns(u);
00050         
00051         if (y < ymin && i >= samples / 10) {
00052             ymin = y;
00053         } 
00054         else {}
00055         //pc2.printf("y = %f en ymin = %f \n",y,ymin); //bugfix
00056         wait(0.05);
00057     }
00058     
00059     LedRed.write(1);
00060     readymin = 1;
00061     return ymin;
00062 }