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:
73:f6f378311c8d
Parent:
72:250b2665755c
Child:
74:d281aaef9766
diff -r 250b2665755c -r f6f378311c8d main.cpp
--- a/main.cpp	Mon Jul 02 14:28:22 2018 +0000
+++ b/main.cpp	Mon Jul 30 16:48:48 2018 +0000
@@ -1,57 +1,3 @@
-/*
-    Modified FSG PCB V_1_1
-        - Freezes when doing a dive or any timed sequence (commented out SD card references)
-        - commented out sdLogger().appendLogFile(current_state, 0);     //open SD file once
-        - commented out sdLogger().appendLogFile(current_state, 1);    //writing data
-        - commented out sdLogger().appendLogFile(current_state, 0);    //close log file
-        - reduced timer to 20 seconds for bench testing
-        - modified ConfigFileIO for rudder()
-        - added in getFloatUserInput function from newer code
-        - changed LinearActuator & batt() in StaticDefs to match new pinouts from Bob/Matt/Troy fixes
-        - slowed down battery motor because it's silly fast at 30 volts (bench test)
-            * BCE gain is proportional 0.1 now 0.01
-        - BATT was moving in the wrong direction, gain was P: 0.10, I: 0.0, D: 0.0
-            * change gain to P: -0.10 (gain was flipped, I think the old circuit board had the voltages flipped ? ?)
-        - StateMachine changes for testing
-            * added keyboard_menu_STREAM_STATUS();
-            * added keyboard_menu_RUDDER_SERVO_settings();
-        - modified the zero on the battery position from 610 to 836
-        - BMM (batt) slope may be incorrect, seems low, currently 0.12176
-        - modified the zero on BCE from 253 to 460
-        - Pressure readings are wrong
-            * added readADCCounts() to omegaPX209 class to see channel readings
-            * modified omegaPX209 class to use filtered ADC readings from SpiADC.readCh4()
-        - fixed rudderLoop to headingLoop from newer code
-    Modified FSG PCB V_1_2
-        - added init headingLoop to main
-        - added pitch and heading outputs to STREAM_STATUS
-    NOTE: Flipped motor controller output on connector side with battery mass mover (BMM)
-        - Motor direction was opposite the BCE motor (because of gearing) 
-        - BMM P gain is now positive 0.02 (from -0.10)
-    Modified FSG PCB V_1_3
-        - added timing code for interrupt that drives the rudder (testing with o-scope)
-        - PID controller replaced with newer version from 5/29 code branch
-        - StateMachine hanged style of variables to match convention in code
-    Modified FSG PCB V_1_4
-        - adc tests
-    Modified FSG PCB V_1_5
-        - IMU update
-        - Testing print outs
-    Modified FSG PCB V_1_6
-        - new BMM zero count of 240 (confirmed manually)
-        - new BCE zero count of 400 (confirmed manually)
-        - Modified emergency climb to go to position 10 on the BMM, not zero (almost relying on the limit switch)
-        - fixed keyboard input; including typing in the timeout (can enter exact times)
-    Modified FSG PCB V_1_7
-        - removed data logger references
-        - fixed bug where I was logging data twice in the interrupt code and the main file
-        - fixed bug where Multi-Dive sequence wasn't restarting (the counter used to get the current state was not reset)
-    Modified FSG PCB v_1_8
-        - fixing a bug with the data transmission (output had newline character)
-        - new mode called continuously transmit data in order to speed up transmission
-        - 
-*/
-
 #include "mbed.h"
 #include "StaticDefs.hpp"
 
@@ -86,8 +32,9 @@
 static int current_state = 0;     
 static bool file_opened = false;
 
-void FSM() {                    // FSM loop runs at 100 hz
+void FSM() {                    // FSM loop runs at 10 hz
     if(fsm_loop) {
+        // led one removed
         fsm_loop = false;       // wait until the loop rate timer fires again
         current_state = stateMachine().runStateMachine();       //running State Machine. Returns 0 if sitting idle or keyboard press (SIT_IDLE state).
     }
@@ -156,18 +103,22 @@
         }
         
         if ( (timer_counter % 20) == 0 ) {    // 0.02 second intervals
-            rudder().runServo();
+            //rudder().runServo();
         }
         
         if ( (timer_counter % 50) == 0 ) {    // 0.05 second intervals 
             imu().runIMU();
         }
-        
+                
         if ( (timer_counter % 100) == 0) {     // 100,000 microseconds = 0.1 second intervals
             depthLoop().runOuterLoop();
             pitchLoop().runOuterLoop();
             headingLoop().runOuterLoop();
         }
+        
+        if ( (timer_counter % 1000) == 0) {        // update at 1.0 second intervals
+            //gui().updateGUI();
+        }
     }
 }
 
@@ -264,15 +215,15 @@
 
 /*************************** v1.8 **************************/
 
-int main() {
-    setup();
+int main() {   
+    setup();    //setup electronics/hardware
     
     systemTicker.attach_us(&system_timer, 1000);         // Interrupt timer running at 0.001 seconds       (slower than original ADC time interval)
     
     unsigned int tNow = 0;
     
     //pc().baud(57600);
-    pc().printf("\n\n\r FSG PCB v1.8 (XBee) 07/02/2018 \n\n\r");
+    pc().printf("\n\n\r FSG PCB v1.8 (XBee) 07/12/2018 \n\n\r");
     
     systemTicker.attach_us(&system_timer, 1000);         // Interrupt timer running at 0.001 seconds       (slower than original ADC time interval)
         
@@ -283,7 +234,7 @@
 
             //run finite state machine fast when transmitting data
             if (current_state == TX_MBED_LOG or current_state == RECEIVE_SEQUENCE) {
-                if ( (tNow % 10) == 0 ) {   // 0.01 second intervals  (100 Hz)
+                if ( (tNow % 100) == 0 ) {   // 0.01 second intervals  (100 Hz)
                     fsm_loop = true;
                     FSM();
                 }
@@ -295,6 +246,9 @@
                 if ( (tNow % 100) == 0 ) {   // 0.1 second intervals
                     fsm_loop = true;
                     FSM();
+                    
+                    //get commands and update GUI
+                    gui().getCommandFSM();
                 }        
             //LOGGING     
                 if ( (tNow % 1000) == 0 ) {   // 1.0 second intervals