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
main.cpp@23:434f04ef1fad, 2017-11-28 (annotated)
- Committer:
- tnhnrl
- Date:
- Tue Nov 28 18:00:09 2017 +0000
- Revision:
- 23:434f04ef1fad
- Parent:
- 22:a10ee088403b
- Child:
- 24:c7d9b5bf3829
Changes from 11/28/17 10:30 am pool test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
danstrider | 10:085ab7328054 | 1 | /* |
danstrider | 10:085ab7328054 | 2 | Starting from Trent's Linear Actuator code from 2017-10-19, these modifications |
danstrider | 10:085ab7328054 | 3 | by Dan add an outer loop controller for depth and pitch to command the inner |
danstrider | 10:085ab7328054 | 4 | linear actuator loops. |
danstrider | 10:085ab7328054 | 5 | Modified 2017-10-20 revA by Dan |
danstrider | 10:085ab7328054 | 6 | - added outer loop controller, but it is hanging the mbed. (turns out it was the imu update) |
danstrider | 10:085ab7328054 | 7 | Modified 2017-10-22 revA by Dan |
danstrider | 10:085ab7328054 | 8 | - outer loop now works with a call to outerloop.update() in main loop(), not with an attached ticker |
danstrider | 10:085ab7328054 | 9 | Modified 2017-10-22 revB by Dan |
danstrider | 10:085ab7328054 | 10 | - enabled both depth and pitch outer loop controllers |
danstrider | 10:085ab7328054 | 11 | - added ability to keyboard reset |
danstrider | 10:085ab7328054 | 12 | Modified 2017-10-22 revC by Dan |
danstrider | 10:085ab7328054 | 13 | - major update to the IMU library processing to make a state machine that doesn't hang |
danstrider | 10:085ab7328054 | 14 | - added lat/lon/alt and GNSS fix information to the IMU library |
danstrider | 10:085ab7328054 | 15 | - brought out the pin names into the constructors of IMU, omega, SpiADC |
danstrider | 10:085ab7328054 | 16 | Modified 2017-10-22 revD by Dan |
danstrider | 10:085ab7328054 | 17 | - everything seems to be working, shy of re-checking on the hardware |
danstrider | 10:085ab7328054 | 18 | - Depth sensor call done inside the OuterLoop, but should somehow be set as a callback instead |
danstrider | 10:085ab7328054 | 19 | - IMU sensor call done inside the OuterLoop, but should somehow be set as a callback instead |
danstrider | 10:085ab7328054 | 20 | Modified 2017-10-23 revA by Dan/Matt |
danstrider | 10:085ab7328054 | 21 | - linear actuator hardware works great, limit switches, sensing, etc. |
danstrider | 10:085ab7328054 | 22 | - outer loops run, but move the BCE in the wrong direction. |
danstrider | 10:085ab7328054 | 23 | - new IMU code doesn't read from the sensor correctly, but doesn't hang up either. |
danstrider | 10:085ab7328054 | 24 | - depth sensor worked fine, just needs zero bias adjustment. |
danstrider | 11:3b241ecb75ed | 25 | Modified 2017-10-24 by Troy |
danstrider | 11:3b241ecb75ed | 26 | - added offset to outerloop |
danstrider | 11:3b241ecb75ed | 27 | Modified 2017-10-26 by Dan |
danstrider | 11:3b241ecb75ed | 28 | - brought over a state machine and new keyboard controls ... currently just dumped into main. |
danstrider | 11:3b241ecb75ed | 29 | Modified 2017-10-26 by Matt |
danstrider | 11:3b241ecb75ed | 30 | - new IMU code imported and working well with the hardware. |
danstrider | 11:3b241ecb75ed | 31 | Modified 2017-10-26 revB by Dan |
danstrider | 11:3b241ecb75ed | 32 | - This version has been in the pool. |
danstrider | 11:3b241ecb75ed | 33 | - Get occasional ADC bad string pot batt & piston. On initial sensor reads, see negative positions. |
danstrider | 11:3b241ecb75ed | 34 | But after running FLOAT_BROADCAST, string pot positions are normal. Not sure why. |
danstrider | 11:3b241ecb75ed | 35 | - Repeatedly got stuck in RISE with a +60s timeout. Battery hit end bell and stalled out. |
danstrider | 11:3b241ecb75ed | 36 | - keyboard and state machine are in main, probably shouldn't be, but easier to debug. |
danstrider | 11:3b241ecb75ed | 37 | - Really happy with the logic and flow of the state machine. Timeouts work. |
danstrider | 11:3b241ecb75ed | 38 | - Need to add a means to drive the linear actuators manually ... toggle out stop() in SIT_IDLE. |
danstrider | 11:3b241ecb75ed | 39 | - Need to add keyboard commands to modify the zeroOffset positions. |
danstrider | 14:85b64a4d08e8 | 40 | Modified 2017-10-30 by Dan, Trent, Matt, Troy |
danstrider | 14:85b64a4d08e8 | 41 | - changed .stop() to .pause() and many .start() to .unpause() ... fixed the negative ADC and lets |
danstrider | 14:85b64a4d08e8 | 42 | the PVF's keep running even though the motor isn't moving. |
danstrider | 14:85b64a4d08e8 | 43 | - changed exit conditions to use filtered depth from the outer loop. less noisy. |
danstrider | 14:85b64a4d08e8 | 44 | Modified 2017-10-31 by Dan, Matt |
danstrider | 14:85b64a4d08e8 | 45 | - added oversampling and a tare function to the depth sensor. |
danstrider | 14:85b64a4d08e8 | 46 | - updated main and keyboard to include tare in setup() and a keyboard tare option. |
danstrider | 14:85b64a4d08e8 | 47 | - looks like the piston isn't zeroing correctly, unclear why, should be unrelated to depth sensor. |
danstrider | 15:2a8cfd3f1cf5 | 48 | Modified 2017-10-31 (again) by Dan, Matt, and Troy |
danstrider | 15:2a8cfd3f1cf5 | 49 | - POOL TESTED! |
danstrider | 15:2a8cfd3f1cf5 | 50 | - Tuned the PID gains with magic. Works to hold mostly level during BCE runs. Dive is awesome. |
danstrider | 15:2a8cfd3f1cf5 | 51 | - Neutral won't do what we want ... without large depth P, it won't get to depth. |
danstrider | 15:2a8cfd3f1cf5 | 52 | - Dive with just P doesn't overshoot depth at 0.0 deg, but does with -20 deg. Timeout should probably be RISE. |
danstrider | 15:2a8cfd3f1cf5 | 53 | - Files depth/pitch updated with tuned defaults. |
tnhnrl | 16:3363b9f14913 | 54 | Modified 2017-11-06 by Troy |
tnhnrl | 16:3363b9f14913 | 55 | - Added acronyms to print statements (when running this with XBee you don't know what mode the |
tnhnrl | 16:3363b9f14913 | 56 | hardware is in because of signal dropping out) |
tnhnrl | 16:3363b9f14913 | 57 | - Fixed print error with setpoints by printing out the setpoint variable, not the outerloop getCommand |
tnhnrl | 16:3363b9f14913 | 58 | (command is sent every time hardware dives, finds neutral, etc.) |
tnhnrl | 16:3363b9f14913 | 59 | - Set the pitchCommand input to 0 on the "find neutral" command, it was sending a non-zero pitch command |
tnhnrl | 16:3363b9f14913 | 60 | - Created a class for the StateMachine |
tnhnrl | 17:7c16b5671d0e | 61 | Modified 2017-11-14 by Troy |
tnhnrl | 17:7c16b5671d0e | 62 | - Changed tare to void function (functions does not return anything when called) |
tnhnrl | 17:7c16b5671d0e | 63 | - Added a "subclass" in the cases for the Neutral Finding Sequence (Sinking, Slowly Rise, Check Pitch (and save positions)) |
tnhnrl | 17:7c16b5671d0e | 64 | Modified 2017-11-20 by Troy |
tnhnrl | 17:7c16b5671d0e | 65 | - Modified StateMachine class to separate keyboard inputs from FSM |
tnhnrl | 17:7c16b5671d0e | 66 | - Added Neutral Finding sub-statemachine |
tnhnrl | 17:7c16b5671d0e | 67 | - Verified both state machines are working with hardware on desktop |
tnhnrl | 17:7c16b5671d0e | 68 | - Added class to save neutral battery and buoyancy engine positions to neutral.cfg file |
tnhnrl | 17:7c16b5671d0e | 69 | Modified 2017-11-21 by Troy |
tnhnrl | 17:7c16b5671d0e | 70 | - Need to check remove ConfigFileIO and place saving functions into config_functions.cpp (rename ConfigFunctions.cpp) |
tnhnrl | 17:7c16b5671d0e | 71 | - Added multi-dive (and multi-rise) states to FSM (may incorporate single dive states into states) |
tnhnrl | 17:7c16b5671d0e | 72 | - Need to double-check behavior of sub-FSM but bench-top testing showed correct behavior for transition from sinking, to slowly rise, to check pitch |
tnhnrl | 17:7c16b5671d0e | 73 | - Need to add a check for the multi-dive sequence file (sequence.cfg) being loaded on the MBED |
tnhnrl | 20:8987a9ae2bc7 | 74 | Modified 2017-11-21 by Dan |
tnhnrl | 20:8987a9ae2bc7 | 75 | - removed blocker and set up a loop rate timer that runs the state machine and keyboard at 10 Hz. |
tnhnrl | 20:8987a9ae2bc7 | 76 | - work inside StateMachine and particularly in the findNeutralSubState. |
tnhnrl | 21:38c8544db6f4 | 77 | Modified 2017-11-22 by Troy |
tnhnrl | 21:38c8544db6f4 | 78 | - Placed config_functions into ConfigFileIO and added the ability to write the neutral positions to the depth & pitch files |
tnhnrl | 21:38c8544db6f4 | 79 | - Streamlined sub-FSM and Find_Neutral state |
tnhnrl | 21:38c8544db6f4 | 80 | - PID depth and pitch gains have been made into class variables so that they can be resaved to the depth/pitch files |
tnhnrl | 21:38c8544db6f4 | 81 | - Added the ability to save depth & pitch gains and neutral offsets (configfile writes entire file at once) |
tnhnrl | 21:38c8544db6f4 | 82 | - Minor formatting fixes |
tnhnrl | 21:38c8544db6f4 | 83 | - Fixed issue with keyboard function, the keyboard function was continuously active instead of checking pc readable in sit idle |
tnhnrl | 21:38c8544db6f4 | 84 | - Bench tested neutral finding sequence and multi-dive sequence, so far so good |
tnhnrl | 21:38c8544db6f4 | 85 | - Question: Why do we want the keyboard and FSM to run together, specifically allowing the FSM call the keyboard? |
danstrider | 22:a10ee088403b | 86 | Modified 2017-11-22 by Dan |
danstrider | 22:a10ee088403b | 87 | - added ability for substate NEUTRAL_CHECK_PITCH to move the battery toward level, then saves offsets. |
danstrider | 22:a10ee088403b | 88 | - added new entry state NEUTRAL_FIRST_PITCH that also moves the battery toward level, but doesn't save. |
tnhnrl | 23:434f04ef1fad | 89 | Modified 2017-11-27 by Troy |
tnhnrl | 23:434f04ef1fad | 90 | - Fixed exit condition (restart at NEUTRAL_FIRST_PITCH) |
tnhnrl | 23:434f04ef1fad | 91 | - Pool tested, needed to run timer for longer than 5 minutes (neutral finding sequence timed out) |
tnhnrl | 23:434f04ef1fad | 92 | - IMU fell off tape |
tnhnrl | 23:434f04ef1fad | 93 | Modified 2017-11-28 Rev A by Dan/Troy |
tnhnrl | 23:434f04ef1fad | 94 | - Modified NEUTRAL_FIRST_PITCH to save the battery offset into the Pitch Outer Loop before beginning neutral finding sequence before sinking |
tnhnrl | 23:434f04ef1fad | 95 | - Pitch Outer Loop now runs NEUTRAL_SINKING and NEUTRAL_SLOWLY_RISE states (instead of batt fixed position control) |
tnhnrl | 23:434f04ef1fad | 96 | - NEUTRAL_SINKING has been changed to a 5-second timer (vice 10 seconds) |
tnhnrl | 23:434f04ef1fad | 97 | - NEUTRAL_SLOWLY_RISE has been changed to move the piston 2 mm each interval (vice 1 mm) |
tnhnrl | 23:434f04ef1fad | 98 | Modified 2017-11-28 Rev B by Dan/Troy |
tnhnrl | 23:434f04ef1fad | 99 | - Changed pitch rate margin from absolute value < 0.5 deg/sec to 5.0 deg/s |
tnhnrl | 23:434f04ef1fad | 100 | - Changed sink timer to move piston 5 mm at a time instead of 10 mm |
tnhnrl | 23:434f04ef1fad | 101 | - Find level motion will now run every 10 seconds instead of 5 seconds |
tnhnrl | 23:434f04ef1fad | 102 | - Created an integer array to do a quick check of what states Find Neutral sub-FSM ran through (press "c" to see states) |
danstrider | 10:085ab7328054 | 103 | */ |
tnhnrl | 20:8987a9ae2bc7 | 104 | |
tzyoung | 0:ea293bbf9717 | 105 | #include "mbed.h" |
tzyoung | 0:ea293bbf9717 | 106 | #include "StaticDefs.hpp" |
tnhnrl | 20:8987a9ae2bc7 | 107 | |
tnhnrl | 20:8987a9ae2bc7 | 108 | // loop rate timer for slowing down how fast while(1) runs in main() |
tnhnrl | 20:8987a9ae2bc7 | 109 | Ticker loop_rate_ticker; |
tnhnrl | 20:8987a9ae2bc7 | 110 | volatile bool loop = false; |
tnhnrl | 20:8987a9ae2bc7 | 111 | void loop_trigger() { loop = true; }; // loop trigger |
tnhnrl | 20:8987a9ae2bc7 | 112 | |
danstrider | 10:085ab7328054 | 113 | void setup() { |
danstrider | 11:3b241ecb75ed | 114 | pc().baud(57600); |
tnhnrl | 23:434f04ef1fad | 115 | pc().printf("\n\n\rFSG 2017-11-27\n\n\r"); |
tnhnrl | 20:8987a9ae2bc7 | 116 | |
danstrider | 10:085ab7328054 | 117 | // start up the system timer |
tzyoung | 0:ea293bbf9717 | 118 | systemTime().start(); |
tnhnrl | 20:8987a9ae2bc7 | 119 | |
danstrider | 10:085ab7328054 | 120 | // set up and start the adc. This runs on a fixed interval and is interrupt driven |
tzyoung | 0:ea293bbf9717 | 121 | adc().initialize(); |
tzyoung | 0:ea293bbf9717 | 122 | adc().start(); |
danstrider | 10:085ab7328054 | 123 | |
danstrider | 10:085ab7328054 | 124 | // set up and start the imu. This polls in the background |
danstrider | 10:085ab7328054 | 125 | imu().initialize(); |
danstrider | 10:085ab7328054 | 126 | imu().start(); |
danstrider | 10:085ab7328054 | 127 | |
danstrider | 10:085ab7328054 | 128 | // set up the depth sensor. This is an internal ADC read, but eventually will be on the ltc1298 |
danstrider | 14:85b64a4d08e8 | 129 | depth().init(); |
danstrider | 14:85b64a4d08e8 | 130 | depth().tare(); |
danstrider | 10:085ab7328054 | 131 | |
danstrider | 10:085ab7328054 | 132 | // construct a local file system |
danstrider | 10:085ab7328054 | 133 | local(); |
tnhnrl | 20:8987a9ae2bc7 | 134 | |
danstrider | 10:085ab7328054 | 135 | // load config data from files |
tnhnrl | 21:38c8544db6f4 | 136 | configFileIO().load_BCE_config(); // load the buoyancy engine parameters from the file "bce.txt" |
tnhnrl | 21:38c8544db6f4 | 137 | configFileIO().load_BATT_config(); // load the battery mass mover parameters from the file "batt.txt" |
tnhnrl | 21:38c8544db6f4 | 138 | configFileIO().load_DEPTH_config(); // load the depth control loop parameters from the file "depth.txt" (contains neutral position) |
tnhnrl | 21:38c8544db6f4 | 139 | configFileIO().load_PITCH_config(); // load the depth control loop parameters from the file "pitch.txt" (contains neutral position) |
tnhnrl | 20:8987a9ae2bc7 | 140 | |
danstrider | 10:085ab7328054 | 141 | // set up the linear actuators. adc has to be running first. |
danstrider | 10:085ab7328054 | 142 | bce().init(); |
danstrider | 10:085ab7328054 | 143 | bce().start(); |
mkelly10 | 12:a0519d11d2b6 | 144 | bce().pause(); // start by not moving |
tnhnrl | 20:8987a9ae2bc7 | 145 | |
danstrider | 10:085ab7328054 | 146 | batt().init(); |
tzyoung | 2:892b58e56712 | 147 | batt().start(); |
mkelly10 | 12:a0519d11d2b6 | 148 | batt().pause(); // start by not moving |
tnhnrl | 20:8987a9ae2bc7 | 149 | |
danstrider | 10:085ab7328054 | 150 | // set up the depth and pitch outer loop controllers |
danstrider | 10:085ab7328054 | 151 | depthLoop().init(); |
tnhnrl | 13:84fcbe1dcd62 | 152 | depthLoop().start(); |
tnhnrl | 16:3363b9f14913 | 153 | depthLoop().setCommand(stateMachine().getDepthCommand()); |
tnhnrl | 20:8987a9ae2bc7 | 154 | |
danstrider | 10:085ab7328054 | 155 | pitchLoop().init(); |
tnhnrl | 13:84fcbe1dcd62 | 156 | pitchLoop().start(); |
tnhnrl | 16:3363b9f14913 | 157 | pitchLoop().setCommand(stateMachine().getPitchCommand()); |
tnhnrl | 20:8987a9ae2bc7 | 158 | |
tnhnrl | 20:8987a9ae2bc7 | 159 | // show that the PID gains are loading from the file |
tnhnrl | 21:38c8544db6f4 | 160 | 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 | 161 | 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 | 162 | 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 | 163 | 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 | 164 | pc().printf("\n\r"); |
tnhnrl | 21:38c8544db6f4 | 165 | |
tnhnrl | 17:7c16b5671d0e | 166 | //load sequence from file |
tnhnrl | 17:7c16b5671d0e | 167 | sequenceController().loadSequence(); |
tnhnrl | 20:8987a9ae2bc7 | 168 | |
tnhnrl | 20:8987a9ae2bc7 | 169 | // establish the main loop rate |
tnhnrl | 20:8987a9ae2bc7 | 170 | loop_rate_ticker.attach(&loop_trigger, 0.1); // fires the ticker at 10 Hz rate |
tnhnrl | 21:38c8544db6f4 | 171 | } |
tnhnrl | 20:8987a9ae2bc7 | 172 | |
danstrider | 10:085ab7328054 | 173 | int main() { |
danstrider | 10:085ab7328054 | 174 | setup(); |
tnhnrl | 16:3363b9f14913 | 175 | |
danstrider | 10:085ab7328054 | 176 | while(1) { |
tnhnrl | 20:8987a9ae2bc7 | 177 | // does this stuff at the loop rate |
tnhnrl | 20:8987a9ae2bc7 | 178 | if(loop) { |
tnhnrl | 20:8987a9ae2bc7 | 179 | led1() = !led1(); // blink |
tnhnrl | 20:8987a9ae2bc7 | 180 | stateMachine().runStateMachine(); |
tnhnrl | 20:8987a9ae2bc7 | 181 | loop = false; // wait until the loop rate timer fires again |
tnhnrl | 17:7c16b5671d0e | 182 | } |
danstrider | 10:085ab7328054 | 183 | } |
danstrider | 10:085ab7328054 | 184 | } |