groep 16 / Mbed 2 deprecated Project_BioRobotics_12

Dependencies:   mbed QEI HIDScope BiQuad4th_order biquadFilter MODSERIAL FastPWM

Revision:
9:8b2d6ec577e3
Parent:
8:2afb66572fc4
Child:
10:3f93fdb90c29
Child:
17:e5d9a543157b
--- a/main.cpp	Wed Oct 31 09:12:59 2018 +0000
+++ b/main.cpp	Wed Oct 31 10:30:34 2018 +0000
@@ -16,7 +16,9 @@
 DigitalOut led_green(LED_GREEN);
 DigitalOut led_blue(LED_BLUE);
 // Buttons
-DigitalIn button_clbrt(SW2);
+DigitalIn button_clbrt_home(SW2);
+DigitalIn button_Demo(D5);
+DigitalIn button_Emg(D6);
 DigitalIn Fail_button(SW3);
 // Modserial
 MODSERIAL pc(USBTX, USBRX);
@@ -126,13 +128,13 @@
         led_red = 0; led_green = 0; led_blue = 0;   // Colouring the led WHITE
         
         // State transition logic
-        if (button_clbrt == 0) 
+        if (button_clbrt_home == 0) 
         {
             currentState = MOTOR_ANGLE_CLBRT;
             stateChanged = true;
             pc.printf("Starting Calibration\n\r");
         }
-        if (Fail_button == 0)
+        else if (Fail_button == 0)
         {
             currentState = FAILURE_MODE;
             stateChanged = true;
@@ -194,7 +196,6 @@
          // of the maximum measured value, we move to the Homing state.
                     
          wait(5.0f); // time_in_this_state > 5.0f
-         // if moving_average(procd_emg) < 0.1*max_procd_emg_ever
          // INSERT CALIBRATING
          currentState = HOMING;
         if (Fail_button == 0)
@@ -207,7 +208,7 @@
         case HOMING:
         // Description:
         // Robot moves to the home starting configuration
-        pc.printf("HOMING, moving to the home starting configuration. \r\n");
+        pc.printf("HOMING \r\n");
                     
         led_red = 0; led_green = 1; led_red = 0;                  // Colouring the led PURPLE
                 
@@ -216,7 +217,6 @@
         // signal state.
                 
         wait(5.0f); // time_in_this_state > 5.0f
-        // if ((fabs(angle_error1) < 0.01f) && (fabs(angle_error2) < 0.01f)) {
         // INSERT MOVEMENT
         currentState = WAITING4SIGNAL;
         if (Fail_button == 0)
@@ -229,37 +229,37 @@
         case WAITING4SIGNAL:
         // Description:
         // In this state the robot waits for an action to occur.
-        pc.printf("Press d to run the demo, Press e to move with EMG, Press c to re-calibrate. \r\n");            
+        
         led_red = 0; led_green = 0; led_blue = 0;                // Colouring the led WHITE
                 
         // Requirements to move to the next state:
         // If a certain button is pressed we move to the corresponding 
         // state (MOVE_W_DEMO, MOVE_W_EMG or SHUTDOWN)
-                
-        // CANNOT USE KEYBOARD. SO LOOK FOR ALTERNATIVE
-        c = pc.getc();
-        if (c == 'd') 
+                        
+        if (button_clbrt_home == 0) 
         {
-            pc.printf("MOVE_W_DEMO, Running the demo \r\n");
-            currentState = MOVE_W_DEMO;
-            
+            currentState = MOTOR_ANGLE_CLBRT;
+            stateChanged = true;
+            pc.printf("Starting Calibration \n\r");
         }
-        else if (c == 'e') 
+        else if (button_Demo == 1) 
         {
-            pc.printf("MOVE_W_EMG, Moving with use of EMG \r\n");
-            currentState = MOVE_W_EMG;
+            currentState = MOVE_W_DEMO;
+            pc.printf("DEMO \r\n");
+            wait(1.0f);
         }
-        else if (c == 'c') 
+        else if (button_Emg == 1) 
         {
-            pc.printf("Starting Calibration\n\r");
-            currentState = MOTOR_ANGLE_CLBRT;
+            currentState = MOVE_W_EMG;
+            pc.printf("EMG \r\n");
+            wait(1.0f);
         }
-        
-        if (Fail_button == 0)
+        else if (Fail_button == 0)
         {
             currentState = FAILURE_MODE;
             stateChanged = true;
         }
+        
         break;
                 
         case MOVE_W_DEMO:
@@ -274,15 +274,14 @@
         // will the move to the corresponding state.
                 
         // BUILD DEMO MODE
-        // FIND ALTERNATIVE FOR KEYBOARD
-        c = pc.getcNb();
-        if (c == 'h') 
+        
+        if (button_clbrt_home == 0) 
         {
-        currentState = HOMING;
+            currentState = HOMING;
+            stateChanged = true;
+            pc.printf("Moving home\n\r");
         }
-        wait(1.0f);
-        
-        if (Fail_button == 0)
+        else if (Fail_button == 0)
         {
             currentState = FAILURE_MODE;
             stateChanged = true;
@@ -312,16 +311,14 @@
         // Requirements to move to the next state:
         // When the home button or the failure button is pressed, we 
         // will the move to the corresponding state.
-                
-        wait(1);
-        c = pc.getcNb();
-        if (c == 'h') 
+        
+        if (button_clbrt_home == 0) 
         {
-        currentState = HOMING;
-        }
-        wait(1.0f);
-        
-        if (Fail_button == 0)
+            currentState = MOTOR_ANGLE_CLBRT;
+            stateChanged = true;
+            pc.printf("Starting Calibration \n\r");
+        }        
+        else if (Fail_button == 0)
         {
             currentState = FAILURE_MODE;
             stateChanged = true;