the slap

Dependencies:   Encoder HIDScope MODSERIAL TextLCD mbed-dsp mbed

Fork of The_SLAP_5_1 by Daan

Files at this revision

API Documentation at this revision

Comitter:
Daanmk
Date:
Mon Oct 27 15:16:06 2014 +0000
Parent:
3:81a6009303a9
Child:
5:5383d9a80307
Commit message:
kalibratie variant met IF's

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 27 14:31:43 2014 +0000
+++ b/main.cpp	Mon Oct 27 15:16:06 2014 +0000
@@ -37,8 +37,8 @@
 MODSERIAL pc(USBTX,USBRX,64,1024);
 
 
-float emg0_value_f32,filtered_emg0_notch,filtered_emg0_notch_highpass,filtered_emg0_notch_highpass_lowpass,filtered_emg0_eindsignaal_abs,envelop_emg0,pwm_to_motor1,max_value_biceps; //variable to store value in for biceps 
-float emg1_value_f32,filtered_emg1_notch,filtered_emg1_notch_highpass,filtered_emg1_notch_highpass_lowpass,filtered_emg1_eindsignaal_abs,envelop_emg1,pwm_to_motor2,max_value_triceps; //variable to store value in for triceps 
+float emg0_value_f32,filtered_emg0_notch,filtered_emg0_notch_highpass,filtered_emg0_notch_highpass_lowpass,filtered_emg0_eindsignaal_abs,envelop_emg0,pwm_to_motor1,max_value_biceps,min_value_biceps; //variable to store value in for biceps 
+float emg1_value_f32,filtered_emg1_notch,filtered_emg1_notch_highpass,filtered_emg1_notch_highpass_lowpass,filtered_emg1_eindsignaal_abs,envelop_emg1,pwm_to_motor2,max_value_triceps,min_value_triceps; //variable to store value in for triceps 
 
 arm_biquad_casd_df1_inst_f32 notch_biceps;
 arm_biquad_casd_df1_inst_f32 notch_triceps;
@@ -67,7 +67,7 @@
 float envelop_biceps_states[4];
 float envelop_triceps_states[4];    
 
-enum slapstates {RUST,KALIBRATIE,RICHTEN,SLAAN}; //verschillende stadia definieren voor gebruik in CASES
+enum slapstates {RUST,RUSTMETING,KALIBRATIE,BICEPSMAX,TRICEPSMAX,RICHTEN,SLAAN}; //verschillende stadia definieren voor gebruik in CASES
 uint8_t state=RUST;
 
 volatile bool looptimerflag;
@@ -106,6 +106,7 @@
         emg_timer.attach(emgmeten, TSAMP);
         Ticker looptimer;
         looptimer.attach(setlooptimerflag,TSAMP);
+        Timer tijdtimer;
         arm_biquad_cascade_df1_init_f32(&notch_biceps,1 , notch_const, notch_biceps_states);
         arm_biquad_cascade_df1_init_f32(&highpass_biceps,1 ,highpass_const,highpass_biceps_states);
         arm_biquad_cascade_df1_init_f32(&lowpass_biceps,1 ,lowpass_const,lowpass_biceps_states);
@@ -127,34 +128,79 @@
                 lcd.locate(0,0);         
                 lcd.printf("Kalibratie");   //regel 1 LCD scherm
                 lcd.locate(0,1);
-                lcd.printf("STAP 1: BICEPS");             //regel 2 LCD scherm
+                lcd.printf("1:BICEPS RUST");             //regel 2 LCD scherm
                 wait(1); 
                 max_value_biceps=0;
                 max_value_triceps=0;
-                for(int x=0; x<200; x++);{ //BICEPS METING
-                    if (envelop_emg0 > max_value_biceps); {
-                    max_value_biceps = envelop_emg0;
-                    }
+                min_value_biceps=0;
+                min_value_triceps=0;
+                int metingstatus=1;
+                
+                if (metingstatus==1) { //BICEPS RUST METING
+                
+                    lcd.cls();
+                    lcd.locate(0,0);         
+                    lcd.printf("BICEPS RUST");   //regel 1 LCD scherm
+                    lcd.locate(0,1);
+                    lcd.printf("ONTSPAN! (3SEC)");             //regel 2 LCD scherm
+                    wait(1); 
+                    tijdtimer.start();
+                    
+                    if (envelop_emg0 > min_value_biceps) {
+                        min_value_biceps = envelop_emg0; 
+                        }
+                    if (tijdtimer == 3 ) {
+                        tijdtimer.stop();
+                        tijdtimer.reset();
+                        metingstatus=2; 
+                        }
                     }
-                lcd.cls();
-                lcd.locate(0,0);         
-                lcd.printf("BICEPS OK");   //regel 1 LCD scherm
-                lcd.locate(0,1);
-                lcd.printf("STAP 2:TRICEPS");             //regel 2 LCD scherm   
-                wait(1);       
-                for(int x=0; x<200; x++); {//TRICEPS METING
-                    if (envelop_emg1 > max_value_triceps); {
-                    max_value_triceps = envelop_emg1;
-                    }
-                    } 
-                lcd.cls();
-                lcd.locate(0,0);         
-                lcd.printf("TRICEPS OK");   //regel 1 LCD scherm
-                lcd.locate(0,1);
-                lcd.printf("De waardes:");             //regel 2 LCD scherm 
-                wait(0.5);    
-                lcd.printf("%f,%f\n",max_value_biceps,max_value_triceps);                        
-                state = RICHTEN;                       
+                if (metingstatus==2) { //TRICEPS RUST METING
+                    lcd.cls();
+                    lcd.locate(0,0);         
+                    lcd.printf("TRICEPS RUST");   //regel 1 LCD scherm
+                    lcd.locate(0,1);
+                    lcd.printf("ONTSPAN! (3SEC)");             //regel 2 LCD scherm
+                    wait(1);                 
+                    tijdtimer.start();
+                    if (envelop_emg1 > min_value_triceps) {
+                        min_value_triceps = envelop_emg1; }
+                    if (tijdtimer == 3 ) {
+                        tijdtimer.stop();
+                        tijdtimer.reset();
+                        metingstatus=3; 
+                        }
+                if (metingstatus==3) { //BICEPS KRACHT METING
+                    lcd.cls();
+                    lcd.locate(0,0);         
+                    lcd.printf("BICEPS MAX");   //regel 1 LCD scherm
+                    lcd.locate(0,1);
+                    lcd.printf("SPAN AAN! (3SEC)");             //regel 2 LCD scherm
+                    wait(1);                 
+                    tijdtimer.start();
+                    if (envelop_emg0 > max_value_biceps) {
+                        max_value_biceps = envelop_emg0; }
+                    if (tijdtimer == 3 ) {
+                        tijdtimer.stop();
+                        tijdtimer.reset();
+                        metingstatus=4; 
+                        }
+                if (metingstatus==4) {//TRICEPS KRACHT METING
+                    lcd.cls();
+                    lcd.locate(0,0);         
+                    lcd.printf("TRICEPS MAX");   //regel 1 LCD scherm
+                    lcd.locate(0,1);
+                    lcd.printf("SPAN AAN! (3SEC)");             //regel 2 LCD scherm                
+                    tijdtimer.start();
+                    if (envelop_emg1 > max_value_triceps) {
+                        max_value_triceps = envelop_emg1; }
+                    if (tijdtimer == 3 ) {
+                        tijdtimer.stop();
+                        tijdtimer.reset();
+                        metingstatus=5; 
+                        }                       
+                if (metingstatus==5) {
+                    state = RICHTEN; }                      
                 break;                          
             }