Remco Dasselaar / Mbed 2 deprecated TotalControlEmg2

Dependencies:   HIDScope MODSERIAL QEI TextLCD mbed

Fork of TotalControlEmg2 by Remco Dasselaar

Files at this revision

API Documentation at this revision

Comitter:
Bartvaart
Date:
Mon Oct 12 10:14:18 2015 +0000
Parent:
17:cfe44346645c
Child:
19:6c0245063b96
Commit message:
Lijkt te werken, moet nog getest worden met echte metingen

Changed in this revision

Filterdesigns.cpp Show annotated file Show diff for this revision Revisions of this file
Filterdesigns.h Show annotated file Show diff for this revision Revisions of this file
Kalibratie.cpp Show annotated file Show diff for this revision Revisions of this file
Mode.cpp Show annotated file Show diff for this revision Revisions of this file
Mode.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Filterdesigns.cpp	Fri Oct 09 11:27:58 2015 +0000
+++ b/Filterdesigns.cpp	Mon Oct 12 10:14:18 2015 +0000
@@ -38,16 +38,16 @@
 
 // constante variabelen:
 
-double gem = 0.4557; // gemiddelde waarde emgsignaal
+//double gem = 0.4557; // gemiddelde waarde emgsignaal
 
 double y=0;
 
-double Filterdesigns(double u)
+double Filterdesigns(double u, double ymin)
 {
     //u = input waarde
     //y = output waarde
     
-    u = u - gem; // gemiddelde bepalen
+    u = u - ymin; // zorgen dat bij geen signaal u = 0
     
     // Op deze manier worden de waardes ingelezen in Filter. Zorg dus voor dezelfde volgorde, zodat de waardes goed uitgelezen worden!:
     // Filter(double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2, const double gain)
--- a/Filterdesigns.h	Fri Oct 09 11:27:58 2015 +0000
+++ b/Filterdesigns.h	Mon Oct 12 10:14:18 2015 +0000
@@ -1,3 +1,3 @@
 #include "mbed.h"
 
-double Filterdesigns(double u);
\ No newline at end of file
+double Filterdesigns(double u, double ymin);
\ No newline at end of file
--- a/Kalibratie.cpp	Fri Oct 09 11:27:58 2015 +0000
+++ b/Kalibratie.cpp	Mon Oct 12 10:14:18 2015 +0000
@@ -20,10 +20,11 @@
 
     LedGreen.write(0); //Led aan
     double ymax = 0;
+    double gem = 0; // omdat y min nog niet is gedefinieerd moet er daarvoor in de plaats een waarde 0 worden doorgestuurd naar het programma Filterdesigns. Omdat het onduidelijk is dezse ymin te gaan noemen in een bestand waar ymin ook wordt bepaald heet deze in dit geval gem
 
     while(Timermax <= 5) { //Als timer onder de 5 seconden is dit uitvoeren
         double u = emg2.read();
-        double y = Filterdesigns(u);
+        double y = Filterdesigns(u, gem);
         if (y > ymax) { //Als de gemeten waarde groter is dan de opgeslagen waarde wordt dit de nieuwe opgeslagen waarde
             ymax = y;
         } 
@@ -42,10 +43,11 @@
 
     LedRed.write(0);
     double ymin = 10;
+    double gem = 0;
 
     while(Timermin <= 5) {
         double u = emg2.read();
-        double y = Filterdesigns(u);
+        double y = Filterdesigns(u, gem);
         
         if (y < ymin) {
             ymin = y;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mode.cpp	Mon Oct 12 10:14:18 2015 +0000
@@ -0,0 +1,19 @@
+#include "Mode.h"
+
+double mode;
+
+int Mode(double y, double ymax, double thresholdlow, double thresholdmid, double thresholdhigh)
+{   
+    
+    if ( y <= thresholdlow){
+        mode = 1;
+        }
+    if (y > thresholdmid && mode == 1){
+        mode = 2;
+        }
+    if (y > thresholdhigh && mode == 1){
+        mode = 3;
+        }
+
+    return mode;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mode.h	Mon Oct 12 10:14:18 2015 +0000
@@ -0,0 +1,3 @@
+#include "mbed.h"
+
+int Mode(double y, double ymax, double thresholdlow, double thresholdmid, double thresholdhigh);
\ No newline at end of file
--- a/main.cpp	Fri Oct 09 11:27:58 2015 +0000
+++ b/main.cpp	Mon Oct 12 10:14:18 2015 +0000
@@ -3,9 +3,10 @@
 #include "Filterdesigns.h"
 #include "Kalibratie.h"
 #include "MODSERIAL.h" //bugfix
+#include "Mode.h"
 
 AnalogIn    emg(A0); //Analog input van emg kabels
-HIDScope    scope(2); //2 scopes
+HIDScope    scope(3); //3 scopes
 Ticker      EMGticker;
 MODSERIAL   pc(USBTX, USBRX); //bugfix
 DigitalOut  LedBlue(LED3);
@@ -16,26 +17,42 @@
 
 bool readymax = 0;
 bool readymin = 0;
+double ymin;
+double ymax;
+double thresholdlow;
+double thresholdmid;
+double thresholdhigh;
+
+void EMGkalibratie(){
+    LedBlue = 1;
+    Init();
+    ymax = KalibratieMax(readymax);
+    ymin = KalibratieMin(readymin);
+    
+    // bepalen van thresholds voor aan/uit
+    thresholdlow = 0.2; // standaardwaarde
+    thresholdmid = 0.5 * ymax; // afhankelijk van max output gebruiker
+    thresholdhigh = 0.8 * ymax;
+    }
 
 void EMGfilter(){
     //uitlezen emg signaal
     double u = emg.read();
-    double y = Filterdesigns(u);
-//    pc.printf("%f \n",y); //bugfix
+    double y = Filterdesigns(u, ymin);
+    //pc.printf("%f \n",y); //bugfix
     // Plotten in HIDscope
+    int mode = Mode(y, ymax, thresholdlow, thresholdmid, thresholdhigh); //bepaald welk signaal de motor krijgt (aan, uit, middel)
     scope.set(0,u); //ongefilterde waarde naar scope 1
     scope.set(1,y); //gefilterde waarde naar scope 2
+    scope.set(2,mode); 
     scope.send(); //stuur de waardes naar HIDscope
     }
     
 
 int main(){
-    LedBlue = 1;
-    Init();
-    double ymax = KalibratieMax(readymax);
-    double ymin = KalibratieMin(readymin);
     
-    pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
+    EMGkalibratie();
+    //pc.printf("ymax = %f en ymin = %f \n",ymax, ymin); //bugfix
     
     while(readymax == 1 && readymin == 1){
         LedBlue = 0;