change at hidscope

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of a_check_emg_filtered_emg by Daniqe Kottelenberg

Revision:
21:9b8be3dff01a
Parent:
15:bb4a6c7836d8
Child:
22:eb8411807cca
--- a/main.cpp	Mon Oct 24 11:24:50 2016 +0000
+++ b/main.cpp	Tue Oct 25 13:06:23 2016 +0000
@@ -4,42 +4,86 @@
 #include "BiQuad.h"  
 
 //Define objects
-AnalogIn    emg_biceps_right_in( A0 );             //analog in to get EMG in to c++
+AnalogIn    emg_biceps_right_in( A0 );              //analog in to get EMG biceps  (r) in to c++
+AnalogIn    emg_triceps_right_in(A1);               //analog in to get EMG triceps (r) in to c++
+//AnalogIn    emg_biceps_left_in  (A2);               //analog in to get EMG biceps  (l) in to c++
 Ticker      sample_timer;           //ticker
-HIDScope    scope( 3);              //open 3 channels in hidscope
+HIDScope    scope(6);              //open 3 channels in hidscope
 DigitalOut richting_motor1(D4);     //motor1 direction output    
 PwmOut pwm_motor1(D5);              //motor1 velocity  output
-DigitalOut  led(LED_GREEN);
+DigitalOut  led(LED_GREEN);         //led included to check where code is
 
 //define variables
+//other
+int    onoffsignal_rightarm=0;              // on/off signal: 1; biceps activation, 0: nothing, -1, triceps activation
+double cut_off_value_biceps =0.06;              //gespecificeerd door floortje
+double cut_off_value_triceps=-0.06;             //gespecificeerd door floortje
+double signal_right_arm;
+
+//biceps  arm 1, right arm
 double emg_biceps_right;
 double emg_filtered_high_biceps_right;
 double emg_abs_biceps_right;
 double emg_filtered_biceps_right;
-int    onoffsignal=0;
-double cut_off_value=0.08; //gespecifeerd door floortje
+double emg_filtered_high_notch_1_biceps_right;
+double emg_filtered_high_notch_1_2_biceps_right;
 
+//triceps arm 1, right arm
+double emg_triceps_right;
+double emg_filtered_high_triceps_right;
+double emg_abs_triceps_right;
+double emg_filtered_triceps_right;
+double emg_filtered_high_notch_1_triceps_right;
+double emg_filtered_high_notch_1_2_triceps_right;
+
+//before abs filtering
 BiQuad filterhigh(9.5654e-01,-1.9131e+00,9.5654e-01,-1.9112e+00,9.1498e-01);
+BiQuad filternotch1 (9.9115e-01, -1.8853e+00, 9.9115e-01 ,-1.8909e+00  , 9.9103e-01);
+BiQuad filternotch2(1.0000e+00, -1.9022e+00, 1.0000e+00,  -1.8965e+00 , 9.9127e-01);
+
+//after abs filtering
 BiQuad filterlow (6.2942e-06, 1.2588e-05,6.2942e-06,-1.9929e+00,9.9292e-01);
 
-//functions which are called in ticker
+//functions which are called in ticker to sample the analog signal
 void filter(){
+        //biceps right arm read+filtering
         emg_biceps_right=emg_biceps_right_in.read();                            //read the emg value from the elektrodes
         emg_filtered_high_biceps_right= filterhigh.step(emg_biceps_right);
-        emg_abs_biceps_right=fabs(emg_filtered_high_biceps_right); //fabs because float
+        emg_filtered_high_notch_1_biceps_right=filternotch1.step(emg_filtered_high_biceps_right);
+        emg_filtered_high_notch_1_2_biceps_right=filternotch2.step(emg_filtered_high_notch_1_biceps_right);
+        emg_abs_biceps_right=fabs(emg_filtered_high_notch_1_2_biceps_right); //fabs because float
         emg_filtered_biceps_right=filterlow.step(emg_abs_biceps_right);
-        led=!led;
+        
+        //triceps right arm read+filtering
+        emg_triceps_right=emg_triceps_right_in.read();                            //read the emg value from the elektrodes
+        emg_filtered_high_triceps_right= filterhigh.step(emg_triceps_right);
+        emg_filtered_high_notch_1_triceps_right=filternotch1.step(emg_filtered_high_triceps_right);
+        emg_filtered_high_notch_1_2_triceps_right=filternotch2.step(emg_filtered_high_notch_1_triceps_right);
+        emg_abs_triceps_right=fabs(emg_filtered_high_notch_1_2_triceps_right); //fabs because float
+        emg_filtered_triceps_right=filterlow.step(emg_abs_triceps_right);
         
-        if (emg_filtered_biceps_right>cut_off_value)
-        {onoffsignal=1;}
+        //signal substraction of filter biceps and triceps. Biceps +,triceps -
+        signal_right_arm=emg_filtered_biceps_right-emg_filtered_triceps_right;
+               
+        //creating of on/off signal with the created on/off signals, with if statement      
+        if (signal_right_arm>cut_off_value_biceps)
+        {onoffsignal_rightarm=1;}
           
-        else 
-        {onoffsignal=0;}
+        else if (signal_right_arm<cut_off_value_triceps)
+        {
+        onoffsignal_rightarm=-1;
+        }    
+        
+        else
+        {onoffsignal_rightarm=0;}
                       
         //send signals  to scope
-        scope.set(0, emg_biceps_right );           //set emg signal to scope in channel 1
-        scope.set(1, emg_filtered_biceps_right);    
-        scope.set(2, onoffsignal);
+        scope.set(0, emg_filtered_biceps_right);            //set emg signal to scope in channel 0
+        scope.set(1, emg_filtered_triceps_right);           // set emg signal to scope in channel 1
+        scope.set(2, signal_right_arm);                     // set emg signal to scope in channel 2
+        scope.set(3, onoffsignal_rightarm);                          // set emg signal to scope in channel 3
+        scope.set(4, emg_biceps_right);
+        scope.set(5, emg_triceps_right);
         scope.send();                       //send all the signals to the scope
                 }
 
@@ -53,19 +97,25 @@
 
     while(1) 
     {    
-        if (onoffsignal==1)
+        if (onoffsignal_rightarm==1)
         {
-        richting_motor1 = 0;    //motordirection (ccw)
+        richting_motor1 = -1;    //motordirection (ccw)
         pwm_motor1 = 1;         //motorspeed 1  
         
         }
-        else if(onoffsignal==0)
+        else if(onoffsignal_rightarm==-1)
         {
-        richting_motor1 = 0;    //motordirection (ccw)
-        pwm_motor1 = 0;         //motorspeed 0
+        richting_motor1 = 1;    //motordirection (cw)
+        pwm_motor1 = 1;         //motorspeed 1       
+         }
         
-    }
-        
+        else if(onoffsignal_rightarm==0)
+        {
+        richting_motor1 = -1;    //motordirection (ccw)
+        pwm_motor1 = 0;         //motorspeed 0   
+    
+        }
+            
     } 
         
 }
\ No newline at end of file