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:
1:9913e3886643
Parent:
0:1883d922ada8
Child:
2:83659da3e5fe
--- a/main.cpp	Wed Oct 21 15:23:36 2015 +0000
+++ b/main.cpp	Fri Oct 23 08:36:59 2015 +0000
@@ -11,33 +11,44 @@
 biquadFilter filterlow1(1.9556, 0.9565, 0.9780, 1.9561, 0.9780);
 biquadFilter notch(-1.1978e-16, 0.9561, 0.9780, -1.1978e-16, 0.9780);
 biquadFilter filterlow2(-1.9645, 0.9651, 1.5515e-4, 3.1030e-4, 1.5515e-4);
-
+double emg_value;
+double signalpart1;
+double signalpart2;
+double signalpart3;
+double signalpart4;
+double signalfinal;
+        
 /* 
  */
 void filter()
 {
-    /* Sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */
-    double emg_value = emg.read();
-        double signalpart1 = filterhigh1.step(emg_value);//Highpass filter for removing offset and artifacts
-        double signalpart2 = abs(signalpart1);//rectify the filtered signal
-        double signalpart3 = filterlow1.step(signalpart2);//low pass filter to envelope the emg
-        double signalpart4 = notch.step(signalpart3);//notch filter to remove 50Hz signal
-        double signalfinal = filterlow2.step(signalpart4);//2nd low pass filter to envelope the emg
-        scope.set(0,emg_value);//emg_value
-        scope.set(1,signalfinal);
-        /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
-    /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */
-    /* Finally, send all channels to the PC at once */
-    scope.send();
+        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
+        signalfinal = filterlow2.step(signalpart4);//2nd low pass filter to envelope the emg
+        scope.set(0,emg_value);//set emg signal to scope in channel 1
+        scope.set(1,signalfinal);//set filtered signal to scope in channel 2
+    scope.send();//send the signals to the scope
 }
 
 int main()
 {
-    /**Attach the 'sample' function to the timer 'sample_timer'.
-    * this ensures that 'sample' is executed every... 0.002 seconds
-    */
-    sample_timer.attach(&filter, 0.002);
-
-    /*empty loop, sample() is executed periodically*/
-    while(1) {}
+    int caldone=0;
+    double maxValue = 0;//define the max value to start with
+    while(1){
+    while(PTC6){//as long as the button is pressed record the emg signal
+        double signalmeasure=emg.read();//read the emg values to check for max
+        if(signalmeasure > maxValue){
+            maxValue = signalmeasure;
+            }
+            caldone=1;
+        }
+    double maxcal=maxValue;
+    if(caldone==1){
+        sample_timer.attach(&filter, 0.002);//continously execute the EMG reader and filter
+        double onoffsignal=signalfinal/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person
+}
+}
 }
\ No newline at end of file