emg

Dependencies:   HIDScope MODSERIAL mbed-dsp mbed TouchButton

Fork of test by BMT M9 Groep01

Files at this revision

API Documentation at this revision

Comitter:
s1340735
Date:
Tue Oct 28 10:18:53 2014 +0000
Parent:
29:52a0d241e1b0
Child:
33:bc0abe29bad1
Commit message:
calibratie shizzle

Changed in this revision

TouchButton.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TouchButton.lib	Tue Oct 28 10:18:53 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/virajjayaweera/code/TouchButton/#2afd6e977c5b
--- a/main.cpp	Mon Oct 27 12:51:12 2014 +0000
+++ b/main.cpp	Tue Oct 28 10:18:53 2014 +0000
@@ -2,6 +2,8 @@
 #include "HIDScope.h"
 #include "MODSERIAL.h"
 #include "arm_math.h"
+#include "mbed.h"
+#include "TouchButton.h"
 
 MODSERIAL pc(USBTX,USBRX);
 
@@ -10,23 +12,40 @@
 AnalogIn emgB(PTB1); //biceps
 AnalogIn emgT(PTB2); //tricep
 
+DigitalOut myled1(LED1);//red
+DigitalOut myled2(LED2);//green
+DigitalOut myled3(LED3);//blue
+
+/* FRDM-KL25Z built-in touch slider
+*************************
+*     *     *     *     *
+*  1  *  2  *  3  *  4  *
+*     *     *     *     *
+*************************
+* key 1 will light Red LED
+* key 2 will light Green LED
+* key 3 will light Blue LED
+* key 4 will light White LED (R+G+B)
+*/
 
 //*** OBJECTS ***
 //bicep
-uint16_t emg_valueB;
-float emg_value_f32B;
-float filtered_emgB;
+uint16_t emg_valueB, emg_valueB_calibratie;
+float emg_value_f32B, emg_value_f32B_calibratie;
+float filtered_emgB, filtered_emgB_calibratie;
 float drempelwaardeB1, drempelwaardeB2, drempelwaardeB3;//B1=snelheidsstand 1, B2=snelheidsstand 2, B3=snelheidsstand 3
 int yB1, yB2, yB3;
+float MOVAVG_B_caliratie;
 float B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, MOVAVG_B; //moving average objects
 float B30, B31, B32, B33, B34, B35, B36, B37, B38, B39, B40, B41, B42, B43, B44, B45, B46, B47, B48, B49, B50, B51, B52, B53, B54, B55, B56, B57, B58, B59;
 int snelheidsstand;
 //tricep
-uint16_t emg_valueT;
-float emg_value_f32T;
-float filtered_emgT;
+uint16_t emg_valueT, emg_valueT_calibratie;
+float emg_value_f32T, emg_value_f32T_calibratie;
+float filtered_emgT, filtered_emgT_calibratie;
 float drempelwaardeT;
 int yT1, yT2;
+float MOVAVG_T_calibratie;
 float T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,MOVAVG_T; //moving average objects
 float MOVAVG_Positie1, MOVAVG_Positie2;
 int positie;
@@ -184,7 +203,7 @@
     B2=B1;
     B1=B0;
 
-//sturen naar scherm
+    //sturen naar scherm
     pc.printf("%f\r\n",MOVAVG_B);
 
     //naar HID Scope
@@ -194,123 +213,212 @@
 }
 
 
-// *** MAIN ***
-int main()
+// *** TRICEPS EN BICEPS CALIBRATIE ***
+void Calibratie_Triceps()
 {
-    pc.baud(115200);
+    //triceps drempelwaarde calibreren
 
-    //bepaling van positie met triceps 1
-    Ticker log_timerT1;
+    Ticker log_timerT;
 
     arm_biquad_cascade_df1_init_f32(&notchT,1,notch_const,notch_states);
     arm_biquad_cascade_df1_init_f32(&lowpassT,1,lowpass_const,lowpass_states);
     arm_biquad_cascade_df1_init_f32(&highpassT,1,highpass_const,highpass_states);
 
-    log_timerT1.attach(Triceps, 0.005);
-    wait(30);
-    log_timerT1.detach();
-
-    MOVAVG_T=MOVAVG_Positie1;
-
-    // positie van batje met behulp van Triceps
-    drempelwaardeT=0.1;
+    log_timerT.attach(Triceps, 0.005);
+    wait(3);
+    log_timerT.detach();
+}
 
-    if (MOVAVG_Positie1>= drempelwaardeT) {
-        yT1=1;
-    } else {
-        yT1=0;
-    }
-
-    pc.printf("Triceps eerste meting is klaar.\n");
-    wait(3);
-
-    //bepaling van positie met tricep 2
-    Ticker log_timerT2;
+void Calibratie_Biceps()
+{
+    Ticker log_timerB;
 
     arm_biquad_cascade_df1_init_f32(&notchT,1,notch_const,notch_states);
     arm_biquad_cascade_df1_init_f32(&lowpassT,1,lowpass_const,lowpass_states);
     arm_biquad_cascade_df1_init_f32(&highpassT,1,highpass_const,highpass_states);
 
-    log_timerT2.attach(Triceps, 0.005);
-    wait(5);
-    log_timerT2.detach();
+    log_timerB.attach(Biceps, 0.005);
+    wait(3);
+    log_timerB.detach();
+}
+
+// *** MAIN ***
+int main()
+{
+    pc.baud(115200);
+
+    TouchButton TButton;
+
+    int key=0;
+
+    key = TButton.PresedButton();
+
+    pc.printf("key 1 calibratie triceps/n");
+    pc.printf("key 2 caliratie biceps/n");
+    pc.printf("key 3 START/n");
 
-    MOVAVG_T=MOVAVG_Positie2;
+    wait(10);
+
+    while(true) {
+        if (key==0) {
+            myled1 = 1;
+            myled2 = 1;
+            myled3 = 1;
+
+            pc.printf("calibratie tricep aan\n");
+            Calibratie_Triceps();
+            drempelwaardeT=MOVAVG_T-1;
+            pc.printf("drempelwaarde triceps is %f\r\n", drempelwaardeT);
+            wait(5);
+
+            pc.printf("calibratie tricep klaar\n");
+
+        } else if (key==1) {
+            myled1 = 1;
+            myled2 = 1;
+            myled3 = 0;
+            wait(0.1);
 
-    if (MOVAVG_Positie2 >= drempelwaardeT) {
-        yT2=1;
-    } else {
-        yT2=0;
-    }
+            pc.printf("calibratie bicep snelheid 1 aan\n");
+            Calibratie_Biceps();
+            drempelwaardeB1=MOVAVG_B-1;
+            pc.printf("drempelwaarde snelheid 1 is %f\r\n", drempelwaardeB1);
+            wait(5);
+
+            pc.printf("calibratie bicep snelheid 2 aan\n");
+            Calibratie_Biceps();
+            drempelwaardeB2=MOVAVG_B-1;
+            pc.printf("drempelwaarde snelheid 2 is %f\r\n", drempelwaardeB2);
+            wait(5);
+
+            pc.printf("calibratie bicep snelheid 2 aan\n");
+            Calibratie_Biceps();
+            drempelwaardeB2=MOVAVG_B-1;
+            pc.printf("drempelwaarde snelheid 3 is %f\r\n", drempelwaardeB3);
+            wait(5);
+
+            pc.printf("caliratie biceps is klaar/n");
 
-    pc.printf("Triceps tweede meting is klaar.\n");
+        } else if (key==2) {
+            myled1 = 1;
+            myled2 = 0;
+            myled3 = 1;
+            wait(0.1);
+
+            pc.printf("eerst positie dan snelheid aangeven/n");
+
+            //bepaling van positie met triceps 1
+            Ticker log_timerT1;
+
+            arm_biquad_cascade_df1_init_f32(&notchT,1,notch_const,notch_states);
+            arm_biquad_cascade_df1_init_f32(&lowpassT,1,lowpass_const,lowpass_states);
+            arm_biquad_cascade_df1_init_f32(&highpassT,1,highpass_const,highpass_states);
+
+            log_timerT1.attach(Triceps, 0.005);
+            wait(10);
+            log_timerT1.detach();
+
+            MOVAVG_T=MOVAVG_Positie1;
+
+            // positie van batje met behulp van Triceps
+
+            if (MOVAVG_Positie1>= drempelwaardeT) {
+                yT1=1;
+            } else {
+                yT1=0;
+            }
 
-    //*** INPUT MOTOR 2 ***
-    positie=yT1+yT2;
+            pc.printf("Triceps eerste meting is klaar.\n");
+            wait(5);
+
+            //bepaling van positie met tricep 2
+            Ticker log_timerT2;
+
+            arm_biquad_cascade_df1_init_f32(&notchT,1,notch_const,notch_states);
+            arm_biquad_cascade_df1_init_f32(&lowpassT,1,lowpass_const,lowpass_states);
+            arm_biquad_cascade_df1_init_f32(&highpassT,1,highpass_const,highpass_states);
+
+            log_timerT2.attach(Triceps, 0.005);
+            wait(5);
+            log_timerT2.detach();
+
+            MOVAVG_T=MOVAVG_Positie2;
+
+            if (MOVAVG_Positie2 >= drempelwaardeT) {
+                yT2=1;
+            } else {
+                yT2=0;
+            }
+
+            pc.printf("Triceps tweede meting is klaar.\n");
+
+            //*** INPUT MOTOR 2 ***
+            positie=yT1+yT2;
+
+            //controle positie op scherm
+            if (positie==0) {
+                pc.printf("Motor 2 blijft op stand 1\n");
+            } else {
+                if (positie==1) {
+                    pc.printf("Motor 2 gaat naar stand 2\n");
+                } else {
+                    if (positie==2) {
+                        pc.printf("Motor 2 gaat naar stand 3\n");
+                    }
+                }
+            }
+
+            wait(5);
+
+            Ticker log_timerB;
 
-    //controle positie op scherm
-    if (positie==0) {
-        pc.printf("Motor 2 blijft op stand 1\n");
-    } else {
-        if (positie==1) {
-            pc.printf("Motor 2 gaat naar stand 2\n");
+            arm_biquad_cascade_df1_init_f32(&notchB,1,notch_const,notch_states);
+            arm_biquad_cascade_df1_init_f32(&lowpassB,1,lowpass_const,lowpass_states);
+            arm_biquad_cascade_df1_init_f32(&highpassB,1,highpass_const,highpass_states);
+
+            log_timerB.attach(Biceps,0.005);
+            wait(5);
+            log_timerB.detach();
+
+            //bepaling van snelheidsstand met biceps
+
+            if (MOVAVG_B >= drempelwaardeB1) {
+                yB1=1;
+                if (MOVAVG_B >= drempelwaardeB2) {
+                    yB2=1;
+                    if (MOVAVG_B >= drempelwaardeB3) {
+                        yB3=1;
+                    } else {
+                        yB3=0;
+                    }
+                } else {
+                    yB2=0;
+                }
+            } else {
+                yB1=0;
+            }
+
+            //*** INPUT MOTOR 1 ***
+            snelheidsstand=yB1+yB2+yB3;
+
+            //controle snelheidsstand op scherm
+            if (snelheidsstand==0) {
+                pc.printf("Motor 1 beweegt niet\n");
+            } else {
+                if (snelheidsstand==1) {
+                    pc.printf("Motor 1 beweegt met snelheid 1\n");
+                } else {
+                    if (snelheidsstand==2) {
+                        pc.printf("Motor 1 beweegt met snelheid 2\n");
+                    } else {
+                        if (snelheidsstand==3) {
+                            pc.printf("Motor 1 beweegt met snelheid 3\n");
+                        }
+                    }
+                }
+            }
         } else {
-            if (positie==2) {
-                pc.printf("Motor 2 gaat naar stand 3\n");
-            }
+            pc.printf("voer eerst een calibratie uit\n");
         }
     }
-
-    wait(5);
-
-    Ticker log_timerB;
-
-    arm_biquad_cascade_df1_init_f32(&notchB,1,notch_const,notch_states);
-    arm_biquad_cascade_df1_init_f32(&lowpassB,1,lowpass_const,lowpass_states);
-    arm_biquad_cascade_df1_init_f32(&highpassB,1,highpass_const,highpass_states);
-
-    log_timerB.attach(Biceps,0.005);
-    wait(5);
-    log_timerB.detach();
-
-//bepaling van snelheidsstand met biceps
-    drempelwaardeB1=2;
-    drempelwaardeB2=5;
-    drempelwaardeB3=10;
-
-    if (MOVAVG_B >= drempelwaardeB1) {
-        yB1=1;
-        if (MOVAVG_B >= drempelwaardeB2) {
-            yB2=1;
-            if (MOVAVG_B >= drempelwaardeB3) {
-                yB3=1;
-            } else {
-                yB3=0;
-            }
-        } else {
-            yB2=0;
-        }
-    } else {
-        yB1=0;
-    }
-
-//*** INPUT MOTOR 1 ***
-    snelheidsstand=yB1+yB2+yB3;
-
-//controle snelheidsstand op scherm
-    if (snelheidsstand==0) {
-        pc.printf("Motor 1 beweegt niet\n");
-    } else {
-        if (snelheidsstand==1) {
-            pc.printf("Motor 1 beweegt met snelheid 1\n");
-        } else {
-            if (snelheidsstand==2) {
-                pc.printf("Motor 1 beweegt met snelheid 2\n");
-            } else {
-                if (snelheidsstand==3) {
-                    pc.printf("Motor 1 beweegt met snelheid 3\n");
-                }
-            }
-        }
-    }
-}
\ No newline at end of file
+}