Combination code of movement and emg code with small changes for 2 motors.

Dependencies:   HIDScope MODSERIAL QEI biquadFilter mbed

Fork of EMG_converter_code by Gerlinde van de Haar

Revision:
3:a69f041108d4
Parent:
2:83659da3e5fe
Child:
4:fd29407c3115
diff -r 83659da3e5fe -r a69f041108d4 main.cpp
--- a/main.cpp	Mon Oct 26 13:22:32 2015 +0000
+++ b/main.cpp	Mon Oct 26 14:05:37 2015 +0000
@@ -1,13 +1,15 @@
 #include "mbed.h"
 #include "HIDScope.h"
 #include "biquadFilter.h"        // Require the HIDScope library
-
+#include "MODSERIAL.h"
 //Define objects
 AnalogIn    emg(A0); //Analog of EMG input
 Ticker      sample_timer;
 HIDScope    scope(2);        // Instantize a 2-channel HIDScope object
 DigitalIn button1(PTA4);//test button for starting motor 1
 DigitalOut led1(LED_RED);
+DigitalOut led2(LED_BLUE);
+MODSERIAL pc(USBTX,USBRX);
 /*The biquad filters required to transform the EMG signal into an usable signal*/
 biquadFilter filterhigh1(-1.1430, 0.4128, 0.6389, -1.2779, 0.6389);
 biquadFilter filterlow1(1.9556, 0.9565, 0.9780, 1.9561, 0.9780);
@@ -25,10 +27,10 @@
  */
 void filter(){
         emg_value = emg.read();//read the emg value from the elektrodes
-        signalpart1 = filterhigh1.step(emg_value);//Highpass filter for removing offset and artifacts
-        signalpart2 = abs(signalpart1);//rectify the filtered signal
-        signalpart3 = filterlow1.step(signalpart2);//low pass filter to envelope the emg
-        signalpart4 = notch.step(signalpart3);//notch filter to remove 50Hz signal
+        signalpart1 = notch.step(emg_value);//Highpass filter for removing offset and artifacts
+        signalpart2 = filterhigh1.step(signalpart1);//rectify the filtered signal
+        signalpart3 = abs(signalpart2);//low pass filter to envelope the emg
+        signalpart4 = filterlow1.step(signalpart3);//notch filter to remove 50Hz signal
         signalfinal = filterlow2.step(signalpart4);//2nd low pass filter to envelope the emg
         onoffsignal=signalfinal/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person
         scope.set(0,emg_value);//set emg signal to scope in channel 1
@@ -42,20 +44,22 @@
         }
     return maxcal;
 }
-const int button_pressed = 0;
-bool caldone =0;
+
 int main()
 {
-    
-    if(button1.read() == button_pressed){//as long as the button is pressed record the emg signal
-    led1.write(!led1.read());
-    }   /* double signalmeasure=emg.read();//read the emg values to check for max
-        if(signalmeasure > maxcal){
-            maxcal = signalmeasure;
-            }
-            caldone=1; */
-    
-    if(caldone==1){
-        sample_timer.attach(&filter, 0.002);//continously execute the EMG reader and filter
-        }
+    led1.write(1);
+    led2.write(1);
+    sample_timer.attach(&filter, 0.002);//continously execute the EMG reader and filter
+        while(1){
+                   pc.baud(115200);
+                   pc.printf("%f \n", onoffsignal);
+            if(onoffsignal==0.02){
+             led1.write(0);
+             led2.write(1);
+             }
+             else if(onoffsignal == 0.05){
+                 led1.write(1);
+                 led2.write(0);
+             }
+        }     
 }
\ No newline at end of file