Marijke Zondag / Mbed 2 deprecated Project_script_gedeelte

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of Milestone_sample by Marijke Zondag

Revision:
29:c72e49a3edbb
Parent:
28:4534a096b677
Child:
30:12b2107dc139
--- a/main.cpp	Wed Oct 24 17:56:55 2018 +0000
+++ b/main.cpp	Wed Oct 24 18:32:51 2018 +0000
@@ -13,8 +13,9 @@
 AnalogIn emg0_in            (A0);                   //First raw EMG signal input
 AnalogIn emg1_in            (A1);                   //Second raw EMG signal input
 AnalogIn emg2_in            (A2);                   //Third raw EMG signal input
+DigitalOut myled            (LED_GREEN);            //Led to test if the code works
 
-MODSERIAL pc(USBTX, USBRX);                         //Serial communication to see if the code works step by step
+//MODSERIAL pc(USBTX, USBRX);                       //Serial communication to see if the code works step by step, turn on if hidscope is off
 
 HIDScope    scope( 6 );                             //HIDScope set to 3x2 channels for 3 muscles
 
@@ -27,13 +28,12 @@
 const float T   = 0.002f;                           //Ticker period
 
 //EMG filter
-double emg0_filt, emg1_filt, emg2_filt;                                                             //Variables for filtered EMG data channel 0, 1 and 2
+double emg0_filt, emg1_filt, emg2_filt;                                                          //Variables for filtered EMG data channel 0, 1 and 2
 double emg0_raw, emg1_raw, emg2_raw;
 const int windowsize = 150;                                                                      //Size of the array over which the moving average (MovAg) is calculated. (random number)
 double sum, sum1, sum2, sum3;                                                                    //variables used to sum elements in array
 double StoreArray0[windowsize], StoreArray1[windowsize], StoreArray2[windowsize];                //Empty arrays to calculate MoveAg
-double movAg0, movAg1, movAg2;                                                                     //outcome of MovAg (moet dit een array zijn??)
-
+double movAg0, movAg1, movAg2;                                                                   //outcome of MovAg (moet dit een array zijn??)
 
 //Biquad                                                                                         //Variables for the biquad band filters (alle 3 dezelfde maar je kan niet 3x 'emg0band' aanroepen ofzo)
 BiQuadChain emg0filter;
@@ -61,36 +61,36 @@
     /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
     scope.set(0,emg0_raw);
     scope.set(1,emg0_filt);
-    //scope.set(1,movAg0);      //als moving average werkt
+    //scope.set(1,movAg0);          //als moving average werkt
     scope.set(2,emg1_raw);
     scope.set(3,emg1_filt);
-    //scope.set(3,movAg1);      //als moving average werkt
+    //scope.set(3,movAg1);          //als moving average werkt
     scope.set(4,emg2_raw);
     scope.set(5,emg2_filt);
-    //scope.set(5,movAg2);      //als moving average werkt
+    //scope.set(5,movAg2);          //als moving average werkt
 
     scope.send();                   //Send data to HIDScope server
 }
 
 void EMGFilter0()
 {   
-    double emg0_raw      = emg0_in.read();                  //give name to raw EMG0 data
+    double emg0_raw      = emg0_in.read();                      //give name to raw EMG0 data
     double emg0_filt_x   = emg0filter.step(emg0_raw);           //Use biquad chain to filter raw EMG data
-    double emg0_filt     = abs(emg0_filt_x);                   //rectifier. LET OP: volgorde filter: band-notch-rectifier. Eerst band-rect-notch, stel er komt iets raars uit, dan Notch uit de biquad chain halen en aparte chain voor aanmaken.
+    double emg0_filt     = abs(emg0_filt_x);                    //rectifier. LET OP: volgorde filter: band-notch-rectifier. Eerst band-rect-notch, stel er komt iets raars uit, dan Notch uit de biquad chain halen en aparte chain voor aanmaken.
 }
 
 void EMGFilter1()
 {
-    double emg1_raw      = emg1_in.read();                  //give name to raw EMG1 data
+    double emg1_raw      = emg1_in.read();                      //give name to raw EMG1 data
     double emg1_filt_x   = emg1filter.step(emg1_raw);           //Use biquad chain to filter raw EMG data
-    double emg1_filt     = abs(emg1_filt_x);                   //rectifier. LET OP: volgorde filter: band-notch-rectifier. Eerst band-rect-notch.
+    double emg1_filt     = abs(emg1_filt_x);                    //rectifier. LET OP: volgorde filter: band-notch-rectifier. Eerst band-rect-notch.
 }
 
 void EMGFilter2()
 {
-    double emg2_raw      = emg2_in.read();                  //Give name to raw EMG1 data
+    double emg2_raw      = emg2_in.read();                      //Give name to raw EMG1 data
     double emg2_filt_x   = emg2filter.step(emg2_raw);           //Use biquad chain to filter raw EMG data
-    double emg2_filt     = abs(emg2_filt_x);                   //Rectifier. LET OP: volgorde filter: band-notch-rectifier.
+    double emg2_filt     = abs(emg2_filt_x);                    //Rectifier. LET OP: volgorde filter: band-notch-rectifier.
 }
  
 void MovAg()                                         //Calculate moving average (MovAg), klopt nog niet!!
@@ -102,7 +102,7 @@
         StoreArray2[i] = StoreArray2[i-1];
     }
     
-    StoreArray0[0] = emg0_filt;                    //Stores the latest datapoint of the filtered signal in the first element of the array
+    StoreArray0[0] = emg0_filt;                      //Stores the latest datapoint of the filtered signal in the first element of the array
     StoreArray1[0] = emg1_filt;
     StoreArray2[0] = emg2_filt;
     
@@ -133,21 +133,17 @@
 
 int main()
 {         
-        pc.baud(115200);
-        pc.printf("hello\n\r");                                                                 //Check, does it work?
+        //pc.baud(115200);
+        //pc.printf("Hello World!\r\n");                                                          //Serial communication only works if hidscope is turned off.
+        myled == 0;                                                                               //Does the code work?
         
         emg0filter.add( &emg0band1 ).add( &emg0band2 ).add( &emg0band3 ).add( &notch1 );        //attach biquad elements to chain
         emg1filter.add( &emg1band1 ).add( &emg1band2 ).add( &emg1band3 ).add( &notch2 );
         emg2filter.add( &emg2band1 ).add( &emg2band2 ).add( &emg2band3 ).add( &notch3 );
 
-        while(true)
-        {
-
         filter_tick.attach(&emg_filtered,T);        //EMG signals filtered every T sec.
         MovAg_tick.attach(&MovAg,T);                //Moving average calculation every T sec.
         HIDScope_tick.attach(&HIDScope_sample,T);   //EMG signals raw + filtered to HIDScope every T sec.
-
-        pc.printf("\n\r Moving average EMG 3 is: %d \n\r",movAg2);
         
-        }
+        while(1){}
 }