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:
68:8f549749b8ce
Parent:
67:c86a4b464682
Child:
71:939d179478c4
--- a/main.cpp	Mon Jun 25 15:44:00 2018 +0000
+++ b/main.cpp	Wed Jun 27 23:01:53 2018 +0000
@@ -25,11 +25,9 @@
     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
@@ -46,10 +44,13 @@
         - 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
+        - new mode called continuously transmit data in order to speed up transmission
 */
 
-/* removed unused variables */
 #include "mbed.h"
 #include "StaticDefs.hpp"
 
@@ -106,11 +107,11 @@
     if (log_loop) {
         //when the state machine is not in SIT_IDLE state (or a random keyboard press)
 
-        if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) {                
-            ;   //pass
-        }
+        //if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) {                
+//            ;   //pass
+//        }
         
-        else if(current_state != 0) {
+        if(current_state != 0) {
             if (!file_opened) {                                 //if the log file is not open, open it
                 mbedLogger().appendLogFile(current_state, 0);   //open MBED file once
                 //sdLogger().appendLogFile(current_state, 0);     //open SD file once
@@ -121,7 +122,6 @@
             }
             
             //record to Mbed file system   
-            led4() = !led4();
             
             mbedLogger().appendLogFile(current_state, 1);    //writing data
             //sdLogger().appendLogFile(current_state, 1);    //writing data
@@ -161,7 +161,6 @@
         if ( (timer_counter % 10) == 0) {
             bce().update();      //update() inside LinearActuator class (running at 0.01 second intervals)
             batt().update();
-            led2() = !led2();
         }
         
         if ( (timer_counter % 20) == 0 ) {    // 0.02 second intervals
@@ -177,12 +176,6 @@
             pitchLoop().runOuterLoop();
             headingLoop().runOuterLoop();
         }
-        
-        if ( (timer_counter % 500) == 0) {     // 500,000 microseconds = 0.5 second intervals
-            //serialComms().getDepthPitchHeading();
-            log_loop = true;
-            log_function();
-       }
     }
 }
 
@@ -274,22 +267,22 @@
     mbedLogger().initializeLogFile();
     //sdLogger().initializeLogFile();
     
-    setup_complete = true;
-    
-    // set up the depth sensor. This is an internal ADC read, but eventually will be on the ltc1298
-    wait(0.1);          //giving this time to work
-    depth().init();
-    wait(0.1);          //giving this time to work
-    depth().tare();   //this did not work correctly before the ADC starts
+    setup_complete = true;    
 }
 
+/*************************** v1.8 **************************/
+
 int main() {
     setup();
     
+    // set up the depth sensor. This is an internal ADC read
+    wait(1.0);          //giving this time to work
+    depth().tare();   //this did not work correctly before the ADC starts
+    
     unsigned int tNow = 0;
     
     pc().baud(57600);
-    pc().printf("\n\n\r FSG PCB v1.6 (XBee) 6/22/2018 \n\n\r");
+    pc().printf("\n\n\r FSG PCB v1.7 (XBee) 6/25/2018 \n\n\r");
     
     systemTicker.attach_us(&system_timer, 1000);         // Interrupt timer running at 0.001 seconds       (slower than original ADC time interval)
         
@@ -300,24 +293,24 @@
 
             //run finite state machine fast when transmitting data
             if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) {
-                if ( (tNow % 10) == 0 ) {   // 0.001 second intervals  (1000 Hz)
+                //if ( (tNow % 10) == 0 ) {   // 0.001 second intervals  (1000 Hz)
+                if ( (tNow % 100) == 0 ) {   // 0.1 second intervals  (10 Hz)
                     fsm_loop = true;
                     FSM();
                 }
             }
             
             //NOT TRANSMITTING DATA, NORMAL OPERATIONS
-            else {
-                if ( (tNow % 100) == 0 ) {   // 0.1 second intervals (10 Hz)
+            else {  
+            //FSM
+                if ( (tNow % 100) == 0 ) {   // 0.1 second intervals
                     fsm_loop = true;
                     FSM();
-                }
-                
-                if ( (tNow % 1000) == 0 ) {   // 1.0 second intervals
+                }        
+            //LOGGING     
+                if ( (tNow % 1000) == 0 ) {   // 1.0 second intervals                
                     log_loop = true;
                     log_function();
-                    
-                    led1() = !led1();
                 }
             }
         }