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:
39:58375ca6b6ff
Parent:
38:83d06c294807
Child:
43:891baf306e0a
--- a/main.cpp	Thu Dec 21 17:05:35 2017 +0000
+++ b/main.cpp	Thu Dec 21 23:13:44 2017 +0000
@@ -1,67 +1,4 @@
 /*
-    Modified 2017-11-29 revA by Troy
-        - changelog.txt carries previous changes
-        - Incorporated email changes and did quick bench test
-            1) In FIND_NEUTRAL, add bce().setPosition_mm(bceFloatPosition) to the one-shot actions after the unpause().  
-            2) NEUTRAL_FIRST_PITCH, changed batt position by half from 1.0 to 0.5.
-            3) NEUTRAL_SINKING and NEUTRAL_SLOWLY_RISE are using getSetPosition now
-            4) previousPosition_mm deleted (and print statements changed)
-            5) NEUTRAL_SLOWLY_RISE check is using bce().getSetPosition_mm()
-            6) Timers replaced with _neutral_timer variable
-            7) Default timeout is 8 minutes = 480 seconds
-        - Redid the sub-state recording method to only update on state changes
-    Modified 2017-11-29 revB by Troy
-        - minor print fixes
-    Modified 2017-11-29 revC by Troy
-        - removed depthTolerance variable that was not being used.
-    Modified 2017-11-30 revA by Troy/Dan
-        - Modified state RISE to setCommand to -1.0 feet (force out of water) and go to next state (float level) when above 0.5 feet
-        - Modified sub-state NEUTRAL_SINKING to only move 2.5 mm per cycle instead of 5 mm
-        - Commented out home function (accidentally hit home and got stuck while at LASR)
-        - Added max depth neutral and dive variables
-        - Print max recorded depths and current neutral buoyancy positions
-    Modified 2017-11-30 revB by Troy/Dan
-        - Dive and Multi-Dive cycles now exit to FLOAT_BROADCAST state
-        - FLOAT_LEVEL pitchTolerance variable increased from 1.0 degree to 5.0 degrees (PV was difficult to level in LASR pool)
-        - Added the ability to record the states of the FSM and print to user using keyboard "Z"
-    Modified 2017-12-01 revA by Troy
-        - Minor update to 2017-11-30 revB
-        - Now printing current neutral battery and BCE setpoints and max depth in neutral and dive cycle with "C" (and current sensor data)
-        - Pool-tested with successful dives.           
-            1) Dive working correctly.  (And max dive tracker shows that it is reaching the correct commanded depth.)
-            2) Float broadcast working correctly.  (And we are now going directly from dive and rise to float broadcast.)
-            3) Neutral sequence has PV diving with -10 to -20 degrees of pitch, battery command seems to be slow or inactive.
-            3) Float broadcast working correctly.
-            4) FSM tracker and sub-FSM tracker working.
-            5) Antenna working until tail just under water (last depth recorded varies between 1.0 and 1.5 feet)
-    Modified 2017-12-06 revA by Troy
-        - Added "_isTimeoutRunning = false;" to the FIND_NEUTRAL successful exit case ("else if (runNeutralStateMachine() == NEUTRAL_EXIT)"
-            1) This will reset the timeout when the PV has successfully found and saved the neutral BCE and battery positions
-        - Successful dive and multi-dive sequences exit to FLOAT_BROADCAST state (fix was implemented in code that did not respond, reimplemented here)
-            1) Also made the change to the SequenceController (which loads a file that has multiple sequences)
-        - FIND_NEUTRAL starts in NEUTRAL_SINKING with fix on sub-FSM to start with NEUTRAL_SINKING (verified via mbed on bench)
-    Modified 2017-12-07 revA by Troy
-        - Using new neutral finding sequence, dive slowly, rise slowly, then check pitch (pitch is not active at all until final state)
-        - Added additional print information (showing neutral parameters with "C")
-    Modified 2017-12-07 revB by Troy
-        - Momentum offsets reintroduced:
-            1) CASE DIVE uses "else if (depthLoop().getPosition() > depthLoop().getCommand() - 0.5) { // including offset for low momentum approaches"
-            2) CASE RISE uses "else if (depthLoop().getPosition() < depthLoop().getCommand() + 0.5) { // including offset for low momentum approaches"
-        - Momentum on rise command does not exit properly, removed
-    Modified 2017-12-11 revA by Troy
-        - Added a logger function the main while loop
-        - Added vectors (essentially resizable arrays) to hold the data in the State Machine because of memory limitations
-    Modified 2017-12-12 revA by Troy
-        - Logger directly implemented in StateMachine (records every 5 seconds)
-    Modified 2017-12-12 revB by Troy
-        - Logger fixes implemented in StateMachine, was not logging each state, fixed the reset
-        - Made logger into a function call
-    Modified 2017-12-13 revA by Troy
-        - Added function to print log file to screen (tested on bench with multiple dives and timers)
-    Modified 2017-12-18 revA by Troy
-        - Redo of the code to stop opening and closing files each time
-        - This should allow you to write to the open file, then close it once you exit the sequence back to SIT_IDLE
-        - Start record in dive, end when you exit float broadcast...
     Modified 2017-12-19 revA by Troy
         - Fixed OpenLog printing to include states and variable names.  Currently logs to LOG#####.TXT files
             1) Note: The OpenLog only starts a new log when it is power-cycled (with the MBED)
@@ -71,9 +8,10 @@
         - Fixed bug where Dive depth was resetting to rise depth
     Modified 2017-12-21 revA by Troy
         - 2 minute timeout default
-        - add system time to MBED logger
+        - Added system time to MBED logger and OpenLog
         - Fixed bug where it was recording random keyboard presses (other FSM states)
         - Added the ability to save the batt and BCE PID config files
+        - Fixed bug with FIND_NEUTRAL sub-FSM (command was not updating with each timer cycle)
 */
  
 #include "mbed.h"
@@ -91,11 +29,11 @@
 
 void setup() {
     pc().baud(57600);
-    pc().printf("\n\n\rFSG POOL TEST 2017-12-20 revB (DESKTOP SAVE TEST)\n\n\r");
+    pc().printf("\n\n\rFSG POOL TEST 2017-12-21 revA\n\n\r");
     
     //setup data logger baud rate and write the start of the program (every time you reset)
     datalogger().baud(57600);
-    datalogger().printf("DATA, LOGGER, START\n");
+    datalogger().printf("SYSTEM, RESET\n");
  
     // start up the system timer
     systemTime().start();
@@ -167,24 +105,21 @@
         
         static bool file_opened = false;
         
-        // runs at 10 hz
+        // FSM loop runs at 10 hz
         if(loop) {
             led1() = !led1(); // blink led 1
             
-            //running State Machine. Returns 0 if sitting idle (SIT_IDLE state).
+            //running State Machine. Returns 0 if sitting idle or keyboard press (SIT_IDLE state).
             current_state = stateMachine().runStateMachine();
             
             loop = false; // wait until the loop rate timer fires again
         }
         
-        //runs at 1 hz
+        // log loop runs at 1 hz
         if (log_loop) {
             led3() = !led3(); // blink led 3
             
-            //pc().printf("led 3 blinking once a second?\n\r"); //confirmed
-            
             //when the state machine is not in SIT_IDLE state (or a random keyboard press)
-//            if(current_state != 0 or current_state != -1) {
             if(current_state != 0) {
                 //pc().printf("\n\rDEBUG: trying to record data \n\r");    
 
@@ -199,11 +134,11 @@
                 //record to OpenLog hardware
                OpenLog().recordData(current_state);   //start recording   
                 
-                //record to Mbed
+                //record to Mbed file system
                 mbedLogger().saveDataToFile(current_state,stateMachine().dataArray());                
             }
             
-            //when the current state is zero, reset the file
+            //when the current FSM state is zero, reset the file
             else {
                 //this can only happen once
                 if (file_opened) {