Oud verslag voor Biquad.

Dependencies:   Biquad HIDScope QEI angleandposition controlandadjust mbed

Fork of includeair by Jasper Gerth

Revision:
3:48438eea184e
Parent:
2:c7707856d137
Child:
4:bf7765b0f612
--- a/main.cpp	Tue Oct 13 12:41:12 2015 +0000
+++ b/main.cpp	Tue Oct 13 13:42:16 2015 +0000
@@ -7,7 +7,7 @@
 //info out
 HIDScope scope(4);
 Ticker scope_ticker;
-const float scope_frequency=500;
+const double scope_frequency=500;
 Serial pc(USBTX,USBRX);
 
 ////////////////ENCODERS
@@ -21,7 +21,7 @@
 float Ki=0.01;
 float Kd=0.001;
 Ticker control_ticker;
-const float control_frequency=25;
+const double control_frequency=25;
 
 double error1_int=0;// storage variables for the errors
 double error2_int=0;
@@ -31,16 +31,18 @@
 InterruptIn valuechangebutton(PTC6);//button to change controller constants
 
 //safetyandthreshold
-AnalogIn safety(A3);//pot 2, used for the safety cutoff value for the pwm
-AnalogIn threshold(A2);//pot1, used to adjust threshold if signal differs per person
+AnalogIn safety_pot(A3);//pot 2, used for the safety cutoff value for the pwm
+AnalogIn threshold_pot(A2);//pot1, used to adjust threshold if signal differs per person
 
 Ticker safetyandthreshold_ticker; // ticker to read potmeters
-const float safetyandthreshold_frequency=1; // frequency for the ticker
+const double safetyandthreshold_frequency=1; // frequency for the ticker
+
+float threshold_value=1;
 
 ////////////////////////////////FILTER
 #include "filtervalues.h"
 Ticker filter_ticker;
-const float filter_frequency=500;
+const double filter_frequency=500;
 Biquad myfilter1;
 Biquad myfilter2;
 
@@ -51,11 +53,18 @@
 double filteredsignal2=0;
 double filter_extragain=1;
 
+/////////////////READSIGNAL
+Ticker readsignal_ticker;
+const double readsignal_frequency=25;
+
+DigitalOut led(D4);
+
 //////////////////////GO FLAGS AND ACTIVATION FUNCTIONS
 volatile bool scopedata_go=false,
               control_go=false,
               filter_go=false,
-              safetyandthreshold_go=false;
+              safetyandthreshold_go=false,
+              readsignal_go=false;
 
 void scopedata_activate()
 {
@@ -73,20 +82,25 @@
 {
     safetyandthreshold_go=true;
 }
+void readsignal_activate()
+{
+    readsignal_go=true;
+}
 
 
 ////////////////////////FUNCTIONS
 //gather data and send to scope
 void scopedata()
 {
-    scope.set(0,encoder1.getPulses());
-    scope.set(1,encoder2.getPulses());
-}
+    scope.set(0,emg1_input.read());
+    scope.set(1,filteredsignal1);
+    scope.send();
+    }
 //read potmeters and adjust the safetyfactor and threshold
 void safetyandthreshold()
 {
-    mycontroller.cutoff((ceil (10*safety.read()) )/10); // adjust the safetyfactor rounded to 1 decimal
-    ///////////////////////NEED AN IDEA FOR THE THRESHOLD!!!!!!!!!!!!!!!!!!!!
+    mycontroller.cutoff((ceil (10*safety_pot.read()) )/10); // adjust the safetyfactor value between 0 and 1 rounded to 1 decimal
+    threshold_value=((ceil (10*threshold_pot.read()) )/10); // adjust the threshold value between 0 and 1 rounded to 1 decimal
 }
 /////filter
 void filtereverything()
@@ -132,18 +146,16 @@
     //filter_timer.stop();
 }
 
-void control(){
+void control()
+{
     ///call desired controller here
-    }
+}
 
 //adjust controller values when sw2 is pressed
 void valuechange()
 {
-    pc.printf("Extra gain is now %f, enter new value\n",filter_extragain);
-    pc.scanf("%f",&filter_extragain);
-    
-    /*mycontroller.STOP();
-    pc.printf("KP is now %f, enter new value\n",Kp);
+    mycontroller.STOP();
+    /*pc.printf("KP is now %f, enter new value\n",Kp);
     pc.scanf("%f", &Kp);
 
     pc.printf("KI is now %f, enter new value\n",Ki);
@@ -151,7 +163,19 @@
 
     pc.printf("KD is now %f, enter new value\n",Kd);
     pc.scanf("%f", &Kd);*/
+
+    pc.printf("Extra gain is now %f, enter new value\n",filter_extragain);
+    pc.scanf("%f",&filter_extragain);
 }
+void readsignal()
+{
+    if (filteredsignal1>=threshold_value) {
+        led=1;
+    } else {
+        led=0;
+    }
+}
+
 
 int main()
 {
@@ -160,6 +184,7 @@
     filter_ticker.attach(&filter_activate,1.0/filter_frequency);
     control_ticker.attach(&control_activate,1.0/control_frequency);
     scope_ticker.attach(&scopedata_activate,1.0/scope_frequency);
+    readsignal_ticker.attach(&readsignal_activate, 1.0/readsignal_frequency);
 
     while(1) {
         if (scopedata_go==true) {
@@ -178,6 +203,10 @@
             control();
             control_go=false;
         }
-         valuechangebutton.fall(&valuechange);
+        if (readsignal_go==true) {
+            readsignal();
+            readsignal_go=false;
+        }
+        valuechangebutton.fall(&valuechange);
     }
 }
\ No newline at end of file