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:
14:85b64a4d08e8
Parent:
13:84fcbe1dcd62
Child:
15:2a8cfd3f1cf5
diff -r 84fcbe1dcd62 -r 85b64a4d08e8 main.cpp
--- a/main.cpp	Mon Oct 30 21:09:19 2017 +0000
+++ b/main.cpp	Tue Oct 31 17:06:52 2017 +0000
@@ -37,6 +37,14 @@
         - Really happy with the logic and flow of the state machine. Timeouts work.
         - Need to add a means to drive the linear actuators manually ... toggle out stop() in SIT_IDLE.
         - Need to add keyboard commands to modify the zeroOffset positions.
+    Modified 2017-10-30 by Dan, Trent, Matt, Troy
+        - changed .stop() to .pause() and many .start() to .unpause() ... fixed the negative ADC and lets
+            the PVF's keep running even though the motor isn't moving.
+        - changed exit conditions to use filtered depth from the outer loop.  less noisy.
+    Modified 2017-10-31 by Dan, Matt
+        - added oversampling and a tare function to the depth sensor.
+        - updated main and keyboard to include tare in setup() and a keyboard tare option.
+        - looks like the piston isn't zeroing correctly, unclear why, should be unrelated to depth sensor.
 */
 
 #include "mbed.h"
@@ -68,7 +76,7 @@
 float bceFloatPosition = 300;   // bce position for "float" states
 float battFloatPosition = 50;   // batt position for "broadcast" state
 float depthCommand = 3.5; // user keyboard depth
-float pitchCommand = -5.0; // user keyboard depth
+float pitchCommand = 0.0; // user keyboard depth
 
 
 void setup() {
@@ -87,7 +95,8 @@
     imu().start();
     
     // set up the depth sensor. This is an internal ADC read, but eventually will be on the ltc1298
-    depth().initialize();
+    depth().init();
+    depth().tare();
     
     // construct a local file system
     local();
@@ -110,11 +119,11 @@
     // set up the depth and pitch outer loop controllers
     depthLoop().init();
     depthLoop().start();
-    depthLoop().setCommand(-2.5);
+    depthLoop().setCommand(depthCommand);
 
     pitchLoop().init();
     pitchLoop().start();
-    pitchLoop().setCommand(0.0);
+    pitchLoop().setCommand(pitchCommand);
 
     // do not leave this in. Check that PID gains are loading
     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());
@@ -404,6 +413,7 @@
     pc().printf(" B to float at broadcast pitch\r\n");
     pc().printf(" E to initiate emergency climb\r\n");
     pc().printf(" H to run homing sequence on both BCE and Batt\r\n");
+    pc().printf(" T to tare the depth sensor\r\n");
     pc().printf("Q/W to decrease/increase pitch setpoint: %3.1f\r\n",pitchLoop().getCommand());
     pc().printf("A/S to decrease/increase depth setpoint: %3.1f\r\n",depthLoop().getCommand());
     pc().printf("+/- to decrease/increase timeout: %d s\r\n",timeout);
@@ -452,6 +462,13 @@
             batt().unpause(); batt().homePiston(); batt().pause();
             return SIT_IDLE;
         }
+        else if (userInput == 'T' or userInput == 't') {
+            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 == '?') {
             pc().printf("\n\n\n>>> Resetting MBED <<<\n\n\n");
             wait(0.5);
@@ -531,7 +548,7 @@
         // there actually is no timeout for SIT_IDLE, but this enables some one-shot actions
         if (!isTimeoutRunning) {
             showMenu();
-            pc().printf("\r\nstate: SIT_IDLE\r\n");
+            pc().printf("\r\n\nstate: SIT_IDLE\r\n");
             isTimeoutRunning = true;
 
             // what is active?
@@ -546,7 +563,7 @@
         break;
         
     case KEYBOARD :
-        pc().printf("\r\nstate: KEYBOARD\r\n");
+        pc().printf("\r\n\nstate: KEYBOARD\r\n");
         if (pc().readable()) {
             state = keyboard(); // get new state command
             if (state == -1) { // error, that wasn't a new state command
@@ -559,7 +576,7 @@
     case EMERGENCY_CLIMB :
         // start local state timer and init any other one-shot actions
         if (!isTimeoutRunning) {
-            pc().printf("\r\nstate: EMERGENCY_CLIMB\r\n");
+            pc().printf("\r\n\nstate: EMERGENCY_CLIMB\r\n");
             timer.reset(); // timer goes back to zero
             timer.start(); // background timer starts running
             isTimeoutRunning = true;
@@ -590,7 +607,7 @@
     case FIND_NEUTRAL :
         // start local state timer and init any other one-shot actions
         if (!isTimeoutRunning) {
-            pc().printf("\r\nstate: FIND_NEUTRAL\r\n");
+            pc().printf("\r\n\nstate: FIND_NEUTRAL\r\n");
             timer.reset(); // timer goes back to zero
             timer.start(); // background timer starts running
             isTimeoutRunning = true;
@@ -625,7 +642,7 @@
     case DIVE :
         // start local state timer and init any other one-shot actions
         if (!isTimeoutRunning) {
-            pc().printf("\r\nstate: DIVE\r\n");
+            pc().printf("\r\n\nstate: DIVE\r\n");
             timer.reset(); // timer goes back to zero
             timer.start(); // background timer starts running
             isTimeoutRunning = true;
@@ -662,7 +679,7 @@
     case RISE :
         // start local state timer and init any other one-shot actions
         if (!isTimeoutRunning) {
-            pc().printf("\r\nstate: RISE\r\n");
+            pc().printf("\r\n\nstate: RISE\r\n");
             timer.reset(); // timer goes back to zero
             timer.start(); // background timer starts running
             isTimeoutRunning = true;
@@ -699,7 +716,7 @@
     case FLOAT_LEVEL :
         // start local state timer and init any other one-shot actions
         if (!isTimeoutRunning) {
-            pc().printf("\r\nstate: FLOAT_LEVEL\r\n");
+            pc().printf("\r\n\nstate: FLOAT_LEVEL\r\n");
             timer.reset(); // timer goes back to zero
             timer.start(); // background timer starts running
             isTimeoutRunning = true;
@@ -733,7 +750,7 @@
     case FLOAT_BROADCAST :
         // start local state timer and init any other one-shot actions
         if (!isTimeoutRunning) {
-            pc().printf("\r\nstate: FLOAT_BROADCAST\r\n");
+            pc().printf("\r\n\nstate: FLOAT_BROADCAST\r\n");
             timer.reset(); // timer goes back to zero
             timer.start(); // background timer starts running
             isTimeoutRunning = true;