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:
21:38c8544db6f4
Parent:
20:8987a9ae2bc7
Child:
22:a10ee088403b
--- a/main.cpp	Wed Nov 22 14:32:06 2017 +0000
+++ b/main.cpp	Wed Nov 22 23:04:11 2017 +0000
@@ -74,11 +74,19 @@
     Modified 2017-11-21 by Dan
         - removed blocker and set up a loop rate timer that runs the state machine and keyboard at 10 Hz.
         - work inside StateMachine and particularly in the findNeutralSubState.
+    Modified 2017-11-22 by Troy
+        - Placed config_functions into ConfigFileIO and added the ability to write the neutral positions to the depth & pitch files
+        - Streamlined sub-FSM and Find_Neutral state
+        - PID depth and pitch gains have been made into class variables so that they can be resaved to the depth/pitch files
+        - Added the ability to save depth & pitch gains and neutral offsets (configfile writes entire file at once)
+        - Minor formatting fixes
+        - Fixed issue with keyboard function, the keyboard function was continuously active instead of checking pc readable in sit idle
+        - Bench tested neutral finding sequence and multi-dive sequence, so far so good
+        - Question: Why do we want the keyboard and FSM to run together, specifically allowing the FSM call the keyboard?
 */
  
 #include "mbed.h"
 #include "StaticDefs.hpp"
-#include "config_functions.h"
  
 // loop rate timer for slowing down how fast while(1) runs in main()
 Ticker loop_rate_ticker;
@@ -86,8 +94,8 @@
 void loop_trigger() { loop = true; }; // loop trigger
  
 void setup() {
-    pc().printf("\n\n\r\rFSG 2017-11-21\n\r");
     pc().baud(57600);
+    pc().printf("\n\n\rFSG 2017-11-22\n\n\r");
  
     // start up the system timer
     systemTime().start();
@@ -108,10 +116,10 @@
     local();
  
     // load config data from files
-    load_BCE_config();      // load the buoyancy engine parameters from the file "bce.txt"
-    load_BATT_config();     // load the battery mass mover parameters from the file "batt.txt"
-    load_DEPTH_config();    // load the depth control loop parameters from the file "depth.txt"
-    load_PITCH_config();    // load the depth control loop parameters from the file "pitch.txt"
+    configFileIO().load_BCE_config();      // load the buoyancy engine parameters from the file "bce.txt"
+    configFileIO().load_BATT_config();     // load the battery mass mover parameters from the file "batt.txt"
+    configFileIO().load_DEPTH_config();    // load the depth control loop parameters from the file "depth.txt" (contains neutral position)
+    configFileIO().load_PITCH_config();    // load the depth control loop parameters from the file "pitch.txt" (contains neutral position)
  
     // set up the linear actuators.  adc has to be running first.
     bce().init();
@@ -132,29 +140,18 @@
     pitchLoop().setCommand(stateMachine().getPitchCommand());
  
     // show that the PID gains are loading from the file
-    pc().printf("bce    P: %3.2f, I: %3.2f, D %3.2f, zero %3i, limit %3.0f mm, slope %3.3f  \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope());
-    pc().printf("batt   P: %3.2f, I: %3.2f, D %3.2f, zero %3i, limit %3.0f mm, slope %3.3f  \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope());
-    pc().printf("depth  P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset());
-    pc().printf("pitch  P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset());
+    pc().printf("bce    P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %3.0f mm, slope %3.3f  \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 %3.0f mm, slope %3.3f  \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());
     pc().printf("\n\r");
-    
-    //set the neutral positions in the FSM
-    // load neutral motor positions from the neutral.cfg file
-    configFileIO().loadNeutralPositions();
-        
-    // in discussion said this was actually in pitch.txt and depth.txt
-    // fixing on Wednesday (Troy)
-    pc().printf("\n\rLoading neutral positions from file.\n\r");
-    stateMachine().setNeutralPositions(configFileIO().getBattPos(), configFileIO().getBCEPos());     //batt, bce
-    
+         
     //load sequence from file
     sequenceController().loadSequence();
  
     // establish the main loop rate
     loop_rate_ticker.attach(&loop_trigger, 0.1); // fires the ticker at 10 Hz rate
-}
- 
- 
+} 
  
 int main() {
     setup();