State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Revision:
44:0056118c01b2
Parent:
42:cafa56da9ed2
Child:
45:f0066593c174
diff -r cafa56da9ed2 -r 0056118c01b2 main.cpp
--- a/main.cpp	Thu Nov 01 16:15:30 2018 +0000
+++ b/main.cpp	Thu Nov 01 17:04:41 2018 +0000
@@ -211,6 +211,9 @@
     static const double max_speed = 0.01;
     static double speed_x;
     static double speed_y;
+    
+    static bool last_state_1;
+    static bool last_state_2;
 
     if(last_state != current_state) {
         last_state = current_state;
@@ -227,13 +230,16 @@
         screen.display_up_down_arrow(control_goes_up);
         screen.display_left_right_arrow(control_goes_right);
 
-        debug_forward_kinematics = true;
+ //       debug_forward_kinematics = true;
+        
+        last_state_1 = false;
+        last_state_2 = false;
     }
     
     bool emg_1_state = emg_1.get_is_envelope_over_threshold();
     bool emg_2_state = emg_2.get_is_envelope_over_threshold();
     
-    if (emg_1_state) {
+    if (emg_1_state && !last_state_1) {
         led_green = 0;
 
         if (control_goes_up) {
@@ -243,9 +249,10 @@
         }
     } else {
         led_green = 1;
+        speed_y = 0;
     }
     
-    if (emg_2_state) {
+    if (emg_2_state && !last_state_2) {
         led_blue = 0;
         if (control_goes_right) {
             speed_x = max_speed;
@@ -254,7 +261,11 @@
         }
     } else {
         led_blue = 1;
+        speed_x = 0;
     }
+    
+    last_state_1 = emg_1_state;
+    last_state_2 = emg_2_state;
 
     /*
     if (debug_forward_kinematics) {