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

Committer:
tnhnrl
Date:
Wed Nov 29 15:19:14 2017 +0000
Revision:
24:c7d9b5bf3829
Parent:
23:434f04ef1fad
Child:
27:0a5b90cd65d6
Xbee / Pool version of code with latest code morning of 11/29/17

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danstrider 10:085ab7328054 1 /*
tnhnrl 24:c7d9b5bf3829 2 Modified 2017-11-29 revA by Troy
tnhnrl 24:c7d9b5bf3829 3 - changelog.txt carries previous changes
tnhnrl 24:c7d9b5bf3829 4 - Incorporated email changes and did quick bench test
tnhnrl 24:c7d9b5bf3829 5 - Redid the sub-state recording method to only update on state changes
danstrider 10:085ab7328054 6 */
tnhnrl 20:8987a9ae2bc7 7
tzyoung 0:ea293bbf9717 8 #include "mbed.h"
tzyoung 0:ea293bbf9717 9 #include "StaticDefs.hpp"
tnhnrl 20:8987a9ae2bc7 10
tnhnrl 20:8987a9ae2bc7 11 // loop rate timer for slowing down how fast while(1) runs in main()
tnhnrl 20:8987a9ae2bc7 12 Ticker loop_rate_ticker;
tnhnrl 20:8987a9ae2bc7 13 volatile bool loop = false;
tnhnrl 20:8987a9ae2bc7 14 void loop_trigger() { loop = true; }; // loop trigger
tnhnrl 20:8987a9ae2bc7 15
danstrider 10:085ab7328054 16 void setup() {
danstrider 11:3b241ecb75ed 17 pc().baud(57600);
tnhnrl 24:c7d9b5bf3829 18 pc().printf("\n\n\rFSG POOL TEST 2017-11-29\n\n\r");
tnhnrl 20:8987a9ae2bc7 19
danstrider 10:085ab7328054 20 // start up the system timer
tzyoung 0:ea293bbf9717 21 systemTime().start();
tnhnrl 20:8987a9ae2bc7 22
danstrider 10:085ab7328054 23 // set up and start the adc. This runs on a fixed interval and is interrupt driven
tzyoung 0:ea293bbf9717 24 adc().initialize();
tzyoung 0:ea293bbf9717 25 adc().start();
danstrider 10:085ab7328054 26
danstrider 10:085ab7328054 27 // set up and start the imu. This polls in the background
danstrider 10:085ab7328054 28 imu().initialize();
danstrider 10:085ab7328054 29 imu().start();
danstrider 10:085ab7328054 30
danstrider 10:085ab7328054 31 // set up the depth sensor. This is an internal ADC read, but eventually will be on the ltc1298
danstrider 14:85b64a4d08e8 32 depth().init();
danstrider 14:85b64a4d08e8 33 depth().tare();
danstrider 10:085ab7328054 34
danstrider 10:085ab7328054 35 // construct a local file system
danstrider 10:085ab7328054 36 local();
tnhnrl 20:8987a9ae2bc7 37
danstrider 10:085ab7328054 38 // load config data from files
tnhnrl 21:38c8544db6f4 39 configFileIO().load_BCE_config(); // load the buoyancy engine parameters from the file "bce.txt"
tnhnrl 21:38c8544db6f4 40 configFileIO().load_BATT_config(); // load the battery mass mover parameters from the file "batt.txt"
tnhnrl 21:38c8544db6f4 41 configFileIO().load_DEPTH_config(); // load the depth control loop parameters from the file "depth.txt" (contains neutral position)
tnhnrl 21:38c8544db6f4 42 configFileIO().load_PITCH_config(); // load the depth control loop parameters from the file "pitch.txt" (contains neutral position)
tnhnrl 20:8987a9ae2bc7 43
danstrider 10:085ab7328054 44 // set up the linear actuators. adc has to be running first.
danstrider 10:085ab7328054 45 bce().init();
danstrider 10:085ab7328054 46 bce().start();
mkelly10 12:a0519d11d2b6 47 bce().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 48
danstrider 10:085ab7328054 49 batt().init();
tzyoung 2:892b58e56712 50 batt().start();
mkelly10 12:a0519d11d2b6 51 batt().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 52
danstrider 10:085ab7328054 53 // set up the depth and pitch outer loop controllers
danstrider 10:085ab7328054 54 depthLoop().init();
tnhnrl 13:84fcbe1dcd62 55 depthLoop().start();
tnhnrl 16:3363b9f14913 56 depthLoop().setCommand(stateMachine().getDepthCommand());
tnhnrl 20:8987a9ae2bc7 57
danstrider 10:085ab7328054 58 pitchLoop().init();
tnhnrl 13:84fcbe1dcd62 59 pitchLoop().start();
tnhnrl 16:3363b9f14913 60 pitchLoop().setCommand(stateMachine().getPitchCommand());
tnhnrl 20:8987a9ae2bc7 61
tnhnrl 20:8987a9ae2bc7 62 // show that the PID gains are loading from the file
tnhnrl 21:38c8544db6f4 63 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());
tnhnrl 21:38c8544db6f4 64 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());
tnhnrl 21:38c8544db6f4 65 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());
tnhnrl 21:38c8544db6f4 66 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());
danstrider 10:085ab7328054 67 pc().printf("\n\r");
tnhnrl 21:38c8544db6f4 68
tnhnrl 17:7c16b5671d0e 69 //load sequence from file
tnhnrl 17:7c16b5671d0e 70 sequenceController().loadSequence();
tnhnrl 20:8987a9ae2bc7 71
tnhnrl 20:8987a9ae2bc7 72 // establish the main loop rate
tnhnrl 20:8987a9ae2bc7 73 loop_rate_ticker.attach(&loop_trigger, 0.1); // fires the ticker at 10 Hz rate
tnhnrl 21:38c8544db6f4 74 }
tnhnrl 20:8987a9ae2bc7 75
danstrider 10:085ab7328054 76 int main() {
danstrider 10:085ab7328054 77 setup();
tnhnrl 16:3363b9f14913 78
danstrider 10:085ab7328054 79 while(1) {
tnhnrl 20:8987a9ae2bc7 80 // does this stuff at the loop rate
tnhnrl 20:8987a9ae2bc7 81 if(loop) {
tnhnrl 20:8987a9ae2bc7 82 led1() = !led1(); // blink
tnhnrl 20:8987a9ae2bc7 83 stateMachine().runStateMachine();
tnhnrl 20:8987a9ae2bc7 84 loop = false; // wait until the loop rate timer fires again
tnhnrl 17:7c16b5671d0e 85 }
danstrider 10:085ab7328054 86 }
danstrider 10:085ab7328054 87 }