Biorobotics / Robot-Software

Dependencies:   HIDScope MODSERIAL QEI biquadFilter mbed Servo

Revision:
34:7d672cd04486
Parent:
33:eb77ed8d167c
Child:
35:6110d0b5513b
diff -r eb77ed8d167c -r 7d672cd04486 main.cpp
--- a/main.cpp	Tue Oct 30 08:34:45 2018 +0000
+++ b/main.cpp	Tue Oct 30 08:54:33 2018 +0000
@@ -38,6 +38,11 @@
 Timer state_timer;
 Timer emg_timer;
 
+// Timeouts and related variables
+Timeout make_button_active;
+bool button_suppressed = false;
+
+// States
 enum States {failure, waiting, calib_emg, calib_enc, operational, demo, homing}; //All possible robot states
 enum Emg_measures_states {not_in_calib_emg, calib_right_bicep, calib_right_tricep, calib_left_bicep, calib_left_tricep}; // States inside
 
@@ -57,7 +62,7 @@
 
 
 // Variables for calibration
-double calib_q1 = 0.5*3.1415926535f;
+double calib_q1 = 0.5f*3.1415926535f;
 double calib_q2 = 3.1415926535f;
 double off_set_q1 = 0; // This variable is used to determine the off set from our definition from q1 and q2.
 double off_set_q2 = 0;
@@ -82,7 +87,6 @@
 bool state_changed = false;
 const double T = 0.001;
 
-
 // Resolution of the encoder at the output axle
 double resolution = (2.0f*3.1415926535f/double(counts_per_rotation))*(1.0/131.0); // In radians
 
@@ -108,6 +112,10 @@
     if (output_counter == 100) {pc.printf("Something something... %f",u1); output_counter = 0;}  //Print to screen at 10 Hz with MODSERIAL
 }
 
+void unsuppressing_button(){
+    button_suppressed = false;    
+}
+
 void state_machine() {
     switch(current_state) { //States can be: failure, wait, calib_enc, calib_emg, operational, demo,
         case waiting:  //Nothing useful here, maybe a blinking LED for fun and communication to the user
@@ -262,11 +270,14 @@
             else if(process_emg_1 >= 0.02) { des_vy = vymax * 0.33; }
             else { des_vy = 0; }
             
-            if (button.read() == true) {
+            if (button.read() == true && button_suppressed == false ) {
                 current_state = demo; 
                 state_changed = true;
-                } // Isn't this going to cause problems as it will switch on and of very quickly?
-            
+                button_suppressed = true;
+                
+                make_button_active.attach(&unsuppressing_button,0.5);
+
+                } 
             
             break;
             
@@ -276,9 +287,13 @@
                     state_changed = false;
                 }
                 
-            if (button.read() == true) {
+            if (button.read() == true && button_suppressed == false ) {
                 current_state = operational;
                 state_changed = true;
+                
+                button_suppressed = true;
+                
+                make_button_active.attach(&unsuppressing_button,0.5);
             }
             
             break;