most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Revision:
57:ec69651c8c21
Parent:
56:48a8a5a65b82
Child:
58:94b7fd55185e
--- a/StateMachine/StateMachine.cpp	Tue Jun 12 16:20:03 2018 +0000
+++ b/StateMachine/StateMachine.cpp	Thu Jun 14 16:10:25 2018 +0000
@@ -12,6 +12,11 @@
     _depth_command = 2.0;                        // user keyboard depth (default)
     _pitch_command = -20.0;                      // user keyboard pitch (default)
     
+    //new commands
+    _BCE_position_command = bce().getTravelLimit();     //starting at the limits
+    _BMM_position_command = batt().getTravelLimit();
+    //new commands
+    
     _neutral_timer        = 0;                  //timer used in FIND_NEUTRAL sub-FSM
  
     _state = SIT_IDLE;                          // select starting state here
@@ -52,6 +57,8 @@
     _max_recorded_auto_neutral_depth = -99;
     
     _file_closed = true;
+    
+    _debug_menu_on = false;                     //toggle between debug and simple menu screens
 }
  
 //Finite State Machine (FSM)
@@ -64,7 +71,11 @@
     case KEYBOARD:
         // there actually is no timeout for SIT_IDLE, but this enables some one-shot actions
         if (!_isTimeoutRunning) {
-            showMenu();
+            
+            if (_debug_menu_on)
+                showDebugMenu();
+            else
+                showSimpleMenu();
             pc().printf("\r\n\nstate: SIT_IDLE\r\n");
             _isTimeoutRunning = true; 
  
@@ -694,14 +705,62 @@
 }
  
 // output the keyboard menu for user's reference
-void StateMachine::showMenu() {
-    pc().printf("\r\r\n\nKEYBOARD MENU (06/11/2018):\r\r\n");
+void StateMachine::showSimpleMenu() {
+//                if (user_input == 'D') {
+//                _keyboard_state = DIVE;
+//            }
+//            else if (user_input == 'N') {
+//                _keyboard_state = FIND_NEUTRAL;
+//            }
+//            else if (user_input == 'L') {
+//                _keyboard_state = FLOAT_LEVEL;
+//            }
+//            else if (user_input == 'B') {
+//                _keyboard_state = FLOAT_BROADCAST;
+//            }
+//            else if (user_input == 'E') {
+//                _keyboard_state = EMERGENCY_CLIMB;
+//            }
+//            
+//            // some debug tools below
+//            else if (user_input == 'P') {
+//                //Print current SD card log file
+//                //printCurrentSdLog();
+//                mbedLogger().printCurrentLogFile();        //print the current log file to the screen
+//            }
+//            else if (user_input == 'O') {
+//                _keyboard_state = TRANSMIT_LOG;      //Transmit data (work in progress)
+//            }
+//            else if (user_input == '~') {
+//                pc().printf("ERASING MBED LOG FILE\n\r"); 
+//                mbedLogger().eraseFile();
+        
+    pc().printf("\r\r\n\nSIMPLE KEYBOARD MENU (06/14/2018):\r\r\n");        //make sure depth sensor tares itself on startup
+    pc().printf(" D to initiate dive cycle\r\n");
+    pc().printf(" J to float level\r\n");
+    pc().printf(" B to float at broadcast pitch\r\n");
+    pc().printf(" E to initiate emergency climb\r\n");
+    pc().printf(" P to print the current log file.\r\n");
+    pc().printf(" O to transmit current log file.\r\n");
+    pc().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n");
+    pc().printf("[/] to change bce neutral position: %0.1f\r\n", _neutral_bce_pos_mm);
+    pc().printf("</> to change batt neutral position: %0.1f\r\n", _neutral_batt_pos_mm);
+    pc().printf("Q/W to decrease/increase pitch setpoint: %3.1f\r\n",_pitch_command);
+    pc().printf("A/S to decrease/increase depth setpoint: %3.1f\r\n",_depth_command);
+    pc().printf("+/- to decrease/increase timeout: %d s\r\n",_timeout);        
+    pc().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n");
+    pc().printf(" ? to reset mbed\r\n");
+    pc().printf(" * (asterisk) to go to DEBUG menu\r\n");
+}
+
+void StateMachine::showDebugMenu() {
+    pc().printf("\r\r\n\nDEBUG MENU (06/14/2018):\r\r\n");
     pc().printf(" T to go into CHECK TUNING (This is on a timer! Uses NEUTRAL positions!)\r\n");
     pc().printf(" N to find neutral\r\n");
     pc().printf(" M to initiate multi-dive cycle\r\n");
     pc().printf(" D to initiate dive cycle\r\n");
     pc().printf(" R to initiate rise\r\n");
-    pc().printf(" L to float level\r\n");
+    pc().printf(" J to float level\r\n");
     pc().printf(" B to float at broadcast pitch\r\n");
     pc().printf(" E to initiate emergency climb\r\n");
     pc().printf(" '|' to tare the depth sensor (vertical bar)\r\n");
@@ -729,6 +788,7 @@
     
     pc().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n");
     pc().printf(" ? to reset mbed\r\n");
+    pc().printf(" * (asterisk) go to SIMPLE menu\r\n");
 }
  
 //Find Neutral sub finite state machine
@@ -930,11 +990,12 @@
     }
 }
  
-// keyboard runs independently of the state machine, handling one key at a time
-//keyboard updates the desired _keyboard_state that is used in the state machine
-//and only allows input when the state is "idle"
+/*  keyboard runs independently of the state machine, handling one key at a time
+    keyboard updates the desired _keyboard_state that is used in the state machine
+    and only allows input when the state is "idle" */
+    
 void StateMachine::keyboard() {
-    char userInput;
+    char user_input;
  
     // check keyboard and make settings changes as requested
     // states can be changed only at the start of a sequence (when the system is in SIT_IDLE)
@@ -944,7 +1005,7 @@
     
     if (pc().readable() && (_state == SIT_IDLE || _state == KEYBOARD)) {        
         // get the key
-        userInput = pc().getc();    
+        user_input = pc().getc();    
         
         //record that the keyboard was used
         _state_array[_state_array_counter] = KEYBOARD;
@@ -954,254 +1015,350 @@
         _isTimeoutRunning = false;
         
         // check command against desired control buttons
-        if (userInput == 'D') {
-            _keyboard_state = DIVE;
-        }
-        else if (userInput == 'N') {
-            _keyboard_state = FIND_NEUTRAL;
-        }
-        else if (userInput == 'M') {
-            //currently does not run if there is no file.
+        
+/***************************** DEBUG MENU *****************************/             
+        if (_debug_menu_on) {
             
-            //need to add method to Sequence Controller that returns -1 
-            //   or some check that insures you cannot run the dive sequence without a file
+            if (user_input == 'D') {
+                _keyboard_state = DIVE;
+            }
+            else if (user_input == 'N') {
+                _keyboard_state = FIND_NEUTRAL;
+            }
+            else if (user_input == 'M') {
+                //currently does not run if there is no file.
+                
+                //need to add method to Sequence Controller that returns -1 
+                //   or some check that insures you cannot run the dive sequence without a file
+                
+                stateMachine().getDiveSequence();               //get first sequence on keyboard press
+                _keyboard_state = currentStateStruct.state;
+                
+                pc().printf("Starting Dive Sequence Controller! (state: %d)\n\r", _keyboard_state);  //neutral sequence and dive cycles
+            }
+            else if (user_input == 'R') {
+                _keyboard_state = RISE;
+            }
+            else if (user_input == 'J') {
+                _keyboard_state = FLOAT_LEVEL;
+            }
+            else if (user_input == 'B') {
+                _keyboard_state = FLOAT_BROADCAST;
+            }
+            else if (user_input == 'E') {
+                _keyboard_state = EMERGENCY_CLIMB;
+            }
             
-            stateMachine().getDiveSequence();               //get first sequence on keyboard press
-            _keyboard_state = currentStateStruct.state;
+            else if (user_input == 'T') {
+                _keyboard_state = CHECK_TUNING;
+            }
             
-            pc().printf("Starting Dive Sequence Controller! (state: %d)\n\r", _keyboard_state);  //neutral sequence and dive cycles
-        }
-        else if (userInput == 'R') {
-            _keyboard_state = RISE;
-        }
-        else if (userInput == 'L') {
-            _keyboard_state = FLOAT_LEVEL;
-        }
-        else if (userInput == 'B') {
-            _keyboard_state = FLOAT_BROADCAST;
-        }
-        else if (userInput == 'E') {
-            _keyboard_state = EMERGENCY_CLIMB;
-        }
-        
-        else if (userInput == 'T') {
-            _keyboard_state = CHECK_TUNING;
-        }
-        
-        // some debug tools below
-        else if (userInput == 'P') {
-            //Print current SD card log file
-            //printCurrentSdLog();
-            mbedLogger().printCurrentLogFile();        //print the current log file to the screen
-        }
-        else if (userInput == 'X') {
-            mbedLogger().printMbedDirectory();        //print all log files to the screen
-        }
-        else if (userInput == 'O') {
-            _keyboard_state = TRANSMIT_LOG;      //Transmit data (work in progress)
-        }
-        else if (userInput == 'I') {
-            mbedLogger().receiveMissionDataWithTicker();    //receive sequence.txt files
-        }
-        else if (userInput == '~') {
-            pc().printf("ERASING MBED LOG FILE\n\r"); 
-            mbedLogger().eraseFile();
-        }
-        else if (userInput == 'Z') {
-            pc().printf("FSG FSM States: \n\r");
-            string string_state;
+            // some debug tools below
+            else if (user_input == 'P') {
+                //Print current SD card log file
+                //printCurrentSdLog();
+                mbedLogger().printCurrentLogFile();        //print the current log file to the screen
+            }
+            else if (user_input == 'X') {
+                mbedLogger().printMbedDirectory();        //print all log files to the screen
+            }
+            else if (user_input == 'O') {
+                _keyboard_state = TRANSMIT_LOG;      //Transmit data (work in progress)
+            }
+            else if (user_input == 'I') {
+                mbedLogger().receiveMissionDataWithTicker();    //receive sequence.txt files
+            }
+            else if (user_input == '~') {
+                pc().printf("ERASING MBED LOG FILE\n\r"); 
+                mbedLogger().eraseFile();
+            }
+            else if (user_input == 'Z') {
+                pc().printf("FSG FSM States: \n\r");
+                string string_state;
+                
+                for (int i = 0; i < _state_array_counter; i++) {
+                    if (_state_array[i] == SIT_IDLE)
+                        string_state = "SIT_IDLE              <END>";
+                    else if (_state_array[i] == FIND_NEUTRAL)
+                        string_state = "FIND_NEUTRAL";
+                    else if (_state_array[i] == DIVE)
+                        string_state = "DIVE";
+                    else if (_state_array[i] == RISE)
+                        string_state = "RISE";
+                    else if (_state_array[i] == FLOAT_LEVEL)
+                        string_state = "FLOAT_LEVEL";
+                    else if (_state_array[i] == FLOAT_BROADCAST)
+                        string_state = "FLOAT_BROADCAST";          
+                    else if (_state_array[i] == EMERGENCY_CLIMB)
+                        string_state = "EMERGENCY_CLIMB";
+                    else if (_state_array[i] == MULTI_DIVE)
+                        string_state = "MULTI_DIVE";
+                    else if (_state_array[i] == MULTI_RISE)
+                        string_state = "MULTI_RISE";
+                    else if (_state_array[i] == KEYBOARD)
+                        string_state = "KEYBOARD";                    
+                    pc().printf("State #%d: %d (%s)\n\r", i, _state_array[i], string_state.c_str());
+                }
+                
+                pc().printf("\n\rNeutral sub-FSM States: \n\r");
+                string string_substate;
+                
+                for (int i = 0; i < _substate_array_counter; i++) {
+                    if (_substate_array[i] == NEUTRAL_SINKING)
+                        string_substate = "NEUTRAL_SINKING";
+                    else if (_substate_array[i] == NEUTRAL_SLOWLY_RISE)
+                        string_substate = "NEUTRAL_SLOWLY_RISE";
+                    else if (_substate_array[i] == NEUTRAL_CHECK_PITCH)
+                        string_substate = "NEUTRAL_CHECK_PITCH";
+                    else if (_substate_array[i] == NEUTRAL_EXIT)
+                        string_substate = "NEUTRAL_EXIT                  <--   ";
+                    else if (_substate_array[i] == EMERGENCY_CLIMB)
+                        string_substate = " -- > EMERGENCY_CLIMB  <-- ";                
+                    pc().printf("Neutral Substate #%d: %d (%s)\n\r", i, _state_array[i], string_substate.c_str());
+                }
+                pc().printf("\n\r");  //make space between printouts
+            }
+            else if (user_input == '|') {
+                pc().printf("taring depth sensor\r\n");
+                pc().printf("Pre-tare:  press: %3.3f psi, depth: %3.3f ft\r\n", depth().getPsi(), depth().getDepthFt());
+                wait(0.1);
+                depth().tare(); // tares to ambient (do on surface)
+                pc().printf("Post-tare: press: %3.3f psi, depth: %3.3f ft\r\n", depth().getPsi(), depth().getDepthFt());
+            }
             
-            for (int i = 0; i < _state_array_counter; i++) {
-                if (_state_array[i] == SIT_IDLE)
-                    string_state = "SIT_IDLE              <END>";
-                else if (_state_array[i] == FIND_NEUTRAL)
-                    string_state = "FIND_NEUTRAL";
-                else if (_state_array[i] == DIVE)
-                    string_state = "DIVE";
-                else if (_state_array[i] == RISE)
-                    string_state = "RISE";
-                else if (_state_array[i] == FLOAT_LEVEL)
-                    string_state = "FLOAT_LEVEL";
-                else if (_state_array[i] == FLOAT_BROADCAST)
-                    string_state = "FLOAT_BROADCAST";          
-                else if (_state_array[i] == EMERGENCY_CLIMB)
-                    string_state = "EMERGENCY_CLIMB";
-                else if (_state_array[i] == MULTI_DIVE)
-                    string_state = "MULTI_DIVE";
-                else if (_state_array[i] == MULTI_RISE)
-                    string_state = "MULTI_RISE";
-                else if (_state_array[i] == KEYBOARD)
-                    string_state = "KEYBOARD";                    
-                pc().printf("State #%d: %d (%s)\n\r", i, _state_array[i], string_state.c_str());
+            else if (user_input == '[' or user_input == '{') {
+                _neutral_bce_pos_mm = depthLoop().getOutputOffset() - 1;
+                depthLoop().setOutputOffset(_neutral_bce_pos_mm); // decrease the bce neutral setpoint
+                pc().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset());
+                // save neutral depth value to config file
+                configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm);
+            }
+            else if (user_input == ']' or user_input == '}') {
+                _neutral_bce_pos_mm = depthLoop().getOutputOffset() + 1;
+                depthLoop().setOutputOffset(_neutral_bce_pos_mm); // increase the bce neutral setpoint
+                pc().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset());
+                // save neutral depth value to config file
+                configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm);
+            }
+            else if (user_input == '<' or user_input == ',') {
+                _neutral_batt_pos_mm = pitchLoop().getOutputOffset() - 1;
+                pitchLoop().setOutputOffset(_neutral_batt_pos_mm); // decrease the batt neutral setpoint
+                pc().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset());
+                // save neutral pitch value to config file
+                configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm);
+            }
+            else if (user_input == '>' or user_input == '.') {
+                _neutral_batt_pos_mm = pitchLoop().getOutputOffset() + 1;
+                pitchLoop().setOutputOffset(_neutral_batt_pos_mm); // increase the batt neutral setpoint
+                pc().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset());
+                // save neutral pitch value to config file
+                configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm);
             }
             
-            pc().printf("\n\rNeutral sub-FSM States: \n\r");
-            string string_substate;
+            else if (user_input == '?') {
+                pc().printf("\n\n\n>>> Resetting MBED <<<\n\n\n");
+                wait(0.5);
+                mbed_reset();
+            }
+     
+            // change settings        
+            else if (user_input == 'Q' or user_input == 'q') {
+                _pitch_command -= 0.5;         //decrement the pitch setpoint
+                pitchLoop().setCommand(_pitch_command);
+                pc().printf(">>> new pitch angle setpoint: %0.3f deg (decreased)\r\n", pitchLoop().getCommand());
+            }
+            else if (user_input == 'W' or user_input == 'w') {
+                _pitch_command += 0.5;         //increment the pitch setpoint
+                pitchLoop().setCommand(_pitch_command);
+                pc().printf(">>> new pitch angle setpoint: %0.3f deg (increased)\r\n", pitchLoop().getCommand());
+            }
+            else if (user_input == 'A' or user_input == 'a') {
+                _depth_command -= 0.5;         //decrement the depth setpoint
+                depthLoop().setCommand(_depth_command);
+                pc().printf(">>> new depth (ft) setpoint: %0.3f ft (sink)\r\n", depthLoop().getCommand());
+            }
+            else if (user_input == 'S' or user_input == 's') {
+                _depth_command += 0.5;         //increment the depth setpoint
+                depthLoop().setCommand(_depth_command);
+                pc().printf(">>> new depth setpoint: %0.3f ft (rise)\r\n", depthLoop().getCommand());
+            }
+            else if (user_input == '-') {
+                _timeout -= 10.0;               //decrement the timeout
+                pc().printf(">>> timeout decreased: %d\r\n", _timeout);
+            }
+            else if (user_input == '=' or user_input == '+') {
+                _timeout += 10.0;               //increment the timeout
+                pc().printf(">>> timeout increased: %d\r\n", _timeout);
+            }
             
-            for (int i = 0; i < _substate_array_counter; i++) {
-                if (_substate_array[i] == NEUTRAL_SINKING)
-                    string_substate = "NEUTRAL_SINKING";
-                else if (_substate_array[i] == NEUTRAL_SLOWLY_RISE)
-                    string_substate = "NEUTRAL_SLOWLY_RISE";
-                else if (_substate_array[i] == NEUTRAL_CHECK_PITCH)
-                    string_substate = "NEUTRAL_CHECK_PITCH";
-                else if (_substate_array[i] == NEUTRAL_EXIT)
-                    string_substate = "NEUTRAL_EXIT                  <--   ";
-                else if (_substate_array[i] == EMERGENCY_CLIMB)
-                    string_substate = " -- > EMERGENCY_CLIMB  <-- ";                
-                pc().printf("Neutral Substate #%d: %d (%s)\n\r", i, _state_array[i], string_substate.c_str());
+            // go to tuning sub-menu
+            else if (user_input == '5') {
+                keyboard_menu_MANUAL_TUNING();
+            }
+            
+            else if (user_input == '6') {
+                keyboard_menu_STREAM_STATUS();
+            }
+            
+            else if (user_input == '7') {
+                keyboard_menu_RUDDER_SERVO_settings();
+            }
+            
+            else if (user_input == '8') {
+                keyboard_menu_CHANNEL_READINGS();
+            }
+            else if (user_input == '9') {
+                keyboard_menu_POSITION_READINGS();
+            }
+            
+            // go to sub-menus for the PID gains (this is blocking)
+            else if (user_input == '1') {
+                keyboard_menu_BCE_PID_settings();
+            }
+            else if (user_input == '2') {
+                keyboard_menu_BATT_PID_settings();
+            }
+            else if (user_input == '3') {
+                keyboard_menu_DEPTH_PID_settings();
+            }
+            else if (user_input == '4') {
+                keyboard_menu_PITCH_PID_settings();
             }
-            pc().printf("\n\r");  //make space between printouts
-        }
-        else if (userInput == '|') {
-            pc().printf("taring depth sensor\r\n");
-            pc().printf("Pre-tare:  press: %3.3f psi, depth: %3.3f ft\r\n", depth().getPsi(), depth().getDepthFt());
-            wait(0.1);
-            depth().tare(); // tares to ambient (do on surface)
-            pc().printf("Post-tare: press: %3.3f psi, depth: %3.3f ft\r\n", depth().getPsi(), depth().getDepthFt());
-        }
-        
-        else if (userInput == '[' or userInput == '{') {
-            _neutral_bce_pos_mm = depthLoop().getOutputOffset() - 1;
-            depthLoop().setOutputOffset(_neutral_bce_pos_mm); // decrease the bce neutral setpoint
-            pc().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset());
-            // save neutral depth value to config file
-            configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm);
-        }
-        else if (userInput == ']' or userInput == '}') {
-            _neutral_bce_pos_mm = depthLoop().getOutputOffset() + 1;
-            depthLoop().setOutputOffset(_neutral_bce_pos_mm); // increase the bce neutral setpoint
-            pc().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset());
-            // save neutral depth value to config file
-            configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm);
-        }
-        else if (userInput == '<' or userInput == ',') {
-            _neutral_batt_pos_mm = pitchLoop().getOutputOffset() - 1;
-            pitchLoop().setOutputOffset(_neutral_batt_pos_mm); // decrease the batt neutral setpoint
-            pc().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset());
-            // save neutral pitch value to config file
-            configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm);
-        }
-        else if (userInput == '>' or userInput == '.') {
-            _neutral_batt_pos_mm = pitchLoop().getOutputOffset() + 1;
-            pitchLoop().setOutputOffset(_neutral_batt_pos_mm); // increase the batt neutral setpoint
-            pc().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset());
-            // save neutral pitch value to config file
-            configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm);
-        }
-        
-        else if (userInput == '?') {
-            pc().printf("\n\n\n>>> Resetting MBED <<<\n\n\n");
-            wait(0.5);
-            mbed_reset();
-        }
- 
-        // change settings        
-        else if (userInput == 'Q' or userInput == 'q') {
-            _pitch_command -= 0.5;         //decrement the pitch setpoint
-            pitchLoop().setCommand(_pitch_command);
-            pc().printf(">>> new pitch angle setpoint: %0.3f deg (decreased)\r\n", pitchLoop().getCommand());
-        }
-        else if (userInput == 'W' or userInput == 'w') {
-            _pitch_command += 0.5;         //increment the pitch setpoint
-            pitchLoop().setCommand(_pitch_command);
-            pc().printf(">>> new pitch angle setpoint: %0.3f deg (increased)\r\n", pitchLoop().getCommand());
-        }
-        else if (userInput == 'A' or userInput == 'a') {
-            _depth_command -= 0.5;         //decrement the depth setpoint
-            depthLoop().setCommand(_depth_command);
-            pc().printf(">>> new depth (ft) setpoint: %0.3f ft (sink)\r\n", depthLoop().getCommand());
-        }
-        else if (userInput == 'S' or userInput == 's') {
-            _depth_command += 0.5;         //increment the depth setpoint
-            depthLoop().setCommand(_depth_command);
-            pc().printf(">>> new depth setpoint: %0.3f ft (rise)\r\n", depthLoop().getCommand());
+            
+            else if (user_input == 'C' or user_input == 'c') {
+                
+                pc().printf("\n\n\rCURRENT STATUS AND PARAMETERS:\n\r");
+                
+                // Testing out ADC
+                float vref = 5.6;
+                float vmeasured = 0;
+                unsigned int raw = adc().readCh5();
+                vmeasured = ((float)raw)/4095.0*vref;
+                pc().printf("raw BCE pos: %d \r\n",adc().readCh0());
+                pc().printf("raw BMM pos: %d \r\n",adc().readCh1());
+                pc().printf("raw BCE current sense: %d \r\n",adc().readCh2());
+                pc().printf("raw BMM current sense: %d \r\n",adc().readCh3());
+                pc().printf("raw depth pressure: %d \r\n",adc().readCh4());
+                pc().printf("raw vessel pressure: %d \r\n",adc().readCh5());
+                pc().printf("raw battery voltage: %d \r\n",adc().readCh6());
+                pc().printf("raw board current: %d \r\n",adc().readCh7());
+                pc().printf("raw BCE limit switch: %d \r\n",bce().getSwitch());
+                pc().printf("raw BMM limit switch: %d \r\n",batt().getSwitch());
+                pc().printf("raw vessel pressure: %f %d \r\n",vmeasured,raw);
+                // End of ADC Test
+                
+                pc().printf("depth: %3.1f ft\r\n",depthLoop().getPosition());
+                pc().printf("pitch: %3.1f deg\r\n",imu().getPitch());
+                pc().printf("bce().getPosition_mm(): %3.1f\r\n",bce().getPosition_mm());
+                pc().printf("bce().getSetPosition_mm(): %3.1f\r\n",bce().getSetPosition_mm());
+                pc().printf("batt().getPosition_mm(): %3.1f\r\n",batt().getPosition_mm());
+                pc().printf("batt().getSetPosition_mm(): %3.1f\r\n",batt().getSetPosition_mm());
+                pc().printf("depthLoop().getCommand(): %3.1f\r\n",depthLoop().getCommand());
+                pc().printf("pitchLoop().getCommand(): %3.1f\r\n",pitchLoop().getCommand());
+                
+                pc().printf("\n\rNeutral Buoyancy Positions: bce: %0.1f, batt: %0.1f\r\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm);
+                pc().printf("depthLoop().getOutputOffset(): %0.1f\r\n",depthLoop().getOutputOffset());
+                pc().printf("pitchLoop().getOutputOffset(): %0.1f\r\n",pitchLoop().getOutputOffset());
+                pc().printf("Max recorded depth: neutral: %0.1f, dive: %0.1f, auto_neutral_depth: %0.1f\n\n\r",_max_recorded_depth_neutral, _max_recorded_depth_dive, _max_recorded_auto_neutral_depth);
+                
+                pc().printf("\n\r");
+                pc().printf("bce    P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f  \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope());
+                pc().printf("batt   P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f  \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope());
+                pc().printf("depth  P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset());
+                pc().printf("pitch  P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset());
+            }
+
+//POSITION DIVE COMMANDS
+            else if (user_input == 'k') {
+                _BCE_position_command -= 1.0;
+                pc().printf("Decreased BCE CMD to %0.1f\n\r", _BCE_position_command);
+            }
+            else if (user_input == 'l') {
+                _BCE_position_command += 1.0;
+                pc().printf("Increased BCE CMD to %0.1f\n\r", _BCE_position_command);
+            }
+            else if (user_input == ';') {
+                _BMM_position_command -= 1.0;
+                pc().printf("Decreased BMM CMD to %0.1f\n\r", _BMM_position_command);
+            }
+            else if (user_input == '\'') {
+                _BMM_position_command += 1.0;
+                pc().printf("Increased BMM CMD to %0.1f\n\r", _BMM_position_command);
+            }
+//POSITION DIVE COMMANDS
+            
+            else if (user_input == '*') {
+                pc().printf("SWITCHING TO SIMPLE MENU!\n\r"); 
+                wait(2);
+                _debug_menu_on = false;
+            }
+        }   //end of debug menu
+/***************************** DEBUG MENU *****************************/
+            
+/***************************** SIMPLE MENU *****************************/
+        else {       
+            if (user_input == 'D') {
+                _keyboard_state = DIVE;
+            }
+            else if (user_input == 'N') {
+                _keyboard_state = FIND_NEUTRAL;
+            }
+            else if (user_input == 'J') {
+                _keyboard_state = FLOAT_LEVEL;
+            }
+            else if (user_input == 'B') {
+                _keyboard_state = FLOAT_BROADCAST;
+            }
+            else if (user_input == 'E') {
+                _keyboard_state = EMERGENCY_CLIMB;
+            }
+            
+            // some debug tools below
+            else if (user_input == 'P') {
+                //Print current SD card log file
+                //printCurrentSdLog();
+                mbedLogger().printCurrentLogFile();        //print the current log file to the screen
+            }
+            else if (user_input == 'O') {
+                _keyboard_state = TRANSMIT_LOG;      //Transmit data (work in progress)
+            }
+            else if (user_input == '~') {
+                pc().printf("ERASING MBED LOG FILE\n\r"); 
+                mbedLogger().eraseFile();
+            }
+            
+            else if (user_input == '?') {
+                pc().printf("\n\n\n>>> Resetting MBED <<<\n\n\n");
+                wait(0.5);
+                mbed_reset();
+            }
+            
+//POSITION DIVE COMMANDS
+            else if (user_input == 'k') {
+                _BCE_position_command -= 1.0;
+                pc().printf("Decreased BCE CMD to %0.1f\n\r", _BCE_position_command);
+            }
+            else if (user_input == 'l') {
+                _BCE_position_command += 1.0;
+                pc().printf("Increased BCE CMD to %0.1f\n\r", _BCE_position_command);
+            }
+            else if (user_input == ';') {
+                _BMM_position_command -= 1.0;
+                pc().printf("Decreased BMM CMD to %0.1f\n\r", _BMM_position_command);
+            }
+            else if (user_input == '\'') {
+                _BMM_position_command += 1.0;
+                pc().printf("Increased BMM CMD to %0.1f\n\r", _BMM_position_command);
+            }
+//POSITION DIVE COMMANDS
+            
+            else if (user_input == '*') {
+                pc().printf("SWITCHING TO DEBUG MENU!\n\r"); 
+                _debug_menu_on = true;
+                wait(2);
+            }
         }
-        else if (userInput == '-') {
-            _timeout -= 10.0;               //decrement the timeout
-            pc().printf(">>> timeout decreased: %d\r\n", _timeout);
-        }
-        else if (userInput == '=' or userInput == '+') {
-            _timeout += 10.0;               //increment the timeout
-            pc().printf(">>> timeout increased: %d\r\n", _timeout);
-        }
-        
-        // go to tuning sub-menu
-        else if (userInput == '5') {
-            keyboard_menu_MANUAL_TUNING();
-        }
-        
-        else if (userInput == '6') {
-            keyboard_menu_STREAM_STATUS();
-        }
-        
-        else if (userInput == '7') {
-            keyboard_menu_RUDDER_SERVO_settings();
-        }
-        
-        else if (userInput == '8') {
-            keyboard_menu_CHANNEL_READINGS();
-        }
-        else if (userInput == '9') {
-            keyboard_menu_POSITION_READINGS();
-        }
-        
-        // go to sub-menus for the PID gains (this is blocking)
-        else if (userInput == '1') {
-            keyboard_menu_BCE_PID_settings();
-        }
-        else if (userInput == '2') {
-            keyboard_menu_BATT_PID_settings();
-        }
-        else if (userInput == '3') {
-            keyboard_menu_DEPTH_PID_settings();
-        }
-        else if (userInput == '4') {
-            keyboard_menu_PITCH_PID_settings();
-        }
-        
-        else if (userInput == 'C' or userInput == 'c') {
-            
-            pc().printf("\n\n\rCURRENT STATUS AND PARAMETERS:\n\r");
-            
-            // Testing out ADC
-            float vref = 5.6;
-            float vmeasured = 0;
-            unsigned int raw = adc().readCh5();
-            vmeasured = ((float)raw)/4095.0*vref;
-            pc().printf("raw BCE pos: %d \r\n",adc().readCh0());
-            pc().printf("raw BMM pos: %d \r\n",adc().readCh1());
-            pc().printf("raw BCE current sense: %d \r\n",adc().readCh2());
-            pc().printf("raw BMM current sense: %d \r\n",adc().readCh3());
-            pc().printf("raw depth pressure: %d \r\n",adc().readCh4());
-            pc().printf("raw vessel pressure: %d \r\n",adc().readCh5());
-            pc().printf("raw battery voltage: %d \r\n",adc().readCh6());
-            pc().printf("raw board current: %d \r\n",adc().readCh7());
-            pc().printf("raw BCE limit switch: %d \r\n",bce().getSwitch());
-            pc().printf("raw BMM limit switch: %d \r\n",batt().getSwitch());
-            pc().printf("raw vessel pressure: %f %d \r\n",vmeasured,raw);
-            // End of ADC Test
-            
-            pc().printf("depth: %3.1f ft\r\n",depthLoop().getPosition());
-            pc().printf("pitch: %3.1f deg\r\n",imu().getPitch());
-            pc().printf("bce().getPosition_mm(): %3.1f\r\n",bce().getPosition_mm());
-            pc().printf("bce().getSetPosition_mm(): %3.1f\r\n",bce().getSetPosition_mm());
-            pc().printf("batt().getPosition_mm(): %3.1f\r\n",batt().getPosition_mm());
-            pc().printf("batt().getSetPosition_mm(): %3.1f\r\n",batt().getSetPosition_mm());
-            pc().printf("depthLoop().getCommand(): %3.1f\r\n",depthLoop().getCommand());
-            pc().printf("pitchLoop().getCommand(): %3.1f\r\n",pitchLoop().getCommand());
-            
-            pc().printf("\n\rNeutral Buoyancy Positions: bce: %0.1f, batt: %0.1f\r\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm);
-            pc().printf("depthLoop().getOutputOffset(): %0.1f\r\n",depthLoop().getOutputOffset());
-            pc().printf("pitchLoop().getOutputOffset(): %0.1f\r\n",pitchLoop().getOutputOffset());
-            pc().printf("Max recorded depth: neutral: %0.1f, dive: %0.1f, auto_neutral_depth: %0.1f\n\n\r",_max_recorded_depth_neutral, _max_recorded_depth_dive, _max_recorded_auto_neutral_depth);
-            
-            pc().printf("\n\r");
-            pc().printf("bce    P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f  \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope());
-            pc().printf("batt   P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f  \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope());
-            pc().printf("depth  P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset());
-            pc().printf("pitch  P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset());
-        }
+/***************************** SIMPLE MENU *****************************/
         
         //when you read the keyboard successfully, change the state
         _state = _keyboard_state;   //set state at the end of this function
@@ -1224,7 +1381,7 @@
             
             wait(1);         
             
-            pc().printf("BCE POS (CMD): %0.1f (%0.1f) BATT POS: %0.1f (%0.1f) PRESS_psi: %0.2f (unfiltered: %0.2f), PITCH: %0.2f, HEADING: %0.2f, rudder_servo_pwm: %0.1f\r\n",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depth().getRawPSI(),imu().getPitch(),imu().getHeading(),rudder().getPosition_pwm());
+            pc().printf("BCE POS (CMD): %0.1f (%0.1f) BATT POS: %0.1f (%0.1f) PRESS_psi: %0.2f (unfiltered: %0.2f) [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rudder_servo_pwm: %0.1f\r\n",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depth().getRawPSI(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getPosition_pwm());
             
             //pc().printf("(set) BCE POS: %0.1f (%0.1f) BATT POS: %0.1f (%0.1f) PRESS: %0.2f )(channel reading: %d) (volt: %0.2f) << %0.2f >> (Pressure: %0.2f (raw: %0.2f) PITCH: %0.2f HEADING: %0.2f)\r\n",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(), depthLoop().getPosition(),depth().readADCCounts(),depth().readVoltage(),depth().getPsi(),depth().getRawPSI(),depth().getRawPSI(),imu().getPitch(),imu().getHeading());