change at hidscope

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of a_check_emg_filtered_emg by Daniqe Kottelenberg

Revision:
26:38dc21b9ba7d
Parent:
25:58f351d9fcc4
--- a/main.cpp	Fri Oct 28 07:19:58 2016 +0000
+++ b/main.cpp	Fri Oct 28 08:10:07 2016 +0000
@@ -8,26 +8,35 @@
 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
-Ticker      switch_function;         //ticker
-HIDScope    scope(5);               //open 3 channels in hidscope
-MODSERIAL pc(USBTX, USBRX);            //pc connection
+DigitalIn   button_calibration_biceps (SW3);                //button to start calibration biceps
+DigitalIn   button_calibration_triceps (SW2);               // button to start calibration tricps
+
+Ticker      sample_timer;               //ticker
+Ticker      switch_function;            //ticker
+Ticker      calibration_ticker          //ticker
+HIDScope    scope(5);                   //open 3 channels in hidscope
+MODSERIAL pc(USBTX, USBRX);             //pc connection
 
 //motors
 DigitalOut richting_motor1(D4);
 PwmOut pwm_motor1(D5);
 DigitalOut richting_motor2(D7);
 PwmOut pwm_motor2(D6);
+
+//digital out
+
 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
 int    switch_signal_leftarm=0;             // switching between motors. 
-double cut_off_value_biceps =0.06;              //gespecificeerd door floortje
-double cut_off_value_triceps=-0.03;             //gespecificeerd door floortje
-double signal_right_arm;
-int n = 0; //start van de teller wordt op nul gesteld
+double cut_off_value_biceps =0.06;          //gespecificeerd door floortje
+double cut_off_value_triceps=-0.03;         //gespecificeerd door floorte
+double signal_right_arm;                    //signal right arm
+double max_biceps;                          //calibration maximum biceps
+double max_triceps;                         //calibration maximum triceps
+int n = 0;                                  //start van de teller wordt op nul gesteld, om te kunnen switchen
  
 //biceps  arm 1, right arm
 double emg_biceps_right;
@@ -148,6 +157,27 @@
         scope.send();                       //send all the signals to the scope
                 }
 
+//calibration function
+void calibration(){
+            if(button_calibration==0)
+            {
+            for(int n =0; n<2000;n++)                                                  //read for 5000 samples as calibration
+                {
+            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);      //highpass
+            emg_abs_biceps_right=fabs(emg_filtered_high_biceps_right);              //fabs because float
+            emg_filtered_biceps_right=filterlow.step(emg_abs_biceps_right);         //lowpass to envelope
+                        
+            if (emg_filtered_biceps_right > max_right_biceps)                    //determine what the highest reachable emg signal is
+                {
+            max_right_biceps = emg_filtered_biceps_right;
+                }
+                }
+            cut_off_value=0.2*max_right_biceps; 
+            pc.printf(" change of cv %f ",cut_off_value );   
+            }
+                }
+
 //program
 
 int main()