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
StateMachine/StateMachine.cpp@84:eccd8e837134, 2019-02-19 (annotated)
- Committer:
- joel_ssc
- Date:
- Tue Feb 19 20:11:43 2019 +0000
- Revision:
- 84:eccd8e837134
- Parent:
- 82:0981b9ada820
- Child:
- 85:dd8176285b6e
updated file management of logfiles and diagfile numbers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tnhnrl | 16:3363b9f14913 | 1 | #include "StateMachine.hpp" |
tnhnrl | 16:3363b9f14913 | 2 | #include "StaticDefs.hpp" |
tnhnrl | 20:8987a9ae2bc7 | 3 | |
tnhnrl | 16:3363b9f14913 | 4 | StateMachine::StateMachine() { |
tnhnrl | 52:f207567d3ea4 | 5 | _timeout = 20; // generic timeout for every state, seconds |
joel_ssc | 84:eccd8e837134 | 6 | _yo_time = 400; // timeout for a dive or rise yo, not set for other ops |
joel_ssc | 84:eccd8e837134 | 7 | _state_transition_time = 60; // time to allow motors to come to rest in float_broadcast |
tnhnrl | 28:16c83a2fdefa | 8 | _pitchTolerance = 5.0; // pitch angle tolerance for FLOAT_LEVEL state |
tnhnrl | 20:8987a9ae2bc7 | 9 | |
tnhnrl | 28:16c83a2fdefa | 10 | _bceFloatPosition = bce().getTravelLimit(); // bce position for "float" states (max travel limit for BCE is 320 mm) |
tnhnrl | 28:16c83a2fdefa | 11 | _battFloatPosition = batt().getTravelLimit(); // batt position tail high for "broadcast" state (max travel limit for battery is 75 mm) |
tnhnrl | 20:8987a9ae2bc7 | 12 | |
tnhnrl | 32:f2f8ae34aadc | 13 | _depth_command = 2.0; // user keyboard depth (default) |
tnhnrl | 32:f2f8ae34aadc | 14 | _pitch_command = -20.0; // user keyboard pitch (default) |
tnhnrl | 58:94b7fd55185e | 15 | _heading_command = 0.0; |
tnhnrl | 17:7c16b5671d0e | 16 | |
tnhnrl | 57:ec69651c8c21 | 17 | //new commands |
tnhnrl | 58:94b7fd55185e | 18 | _BCE_dive_offset = 0.0; //starting at the limits |
tnhnrl | 58:94b7fd55185e | 19 | _BMM_dive_offset = 0.0; |
tnhnrl | 57:ec69651c8c21 | 20 | //new commands |
tnhnrl | 57:ec69651c8c21 | 21 | |
tnhnrl | 28:16c83a2fdefa | 22 | _neutral_timer = 0; //timer used in FIND_NEUTRAL sub-FSM |
tnhnrl | 73:f6f378311c8d | 23 | ////////////////////////////// |
tnhnrl | 28:16c83a2fdefa | 24 | _state = SIT_IDLE; // select starting state here |
tnhnrl | 28:16c83a2fdefa | 25 | _isTimeoutRunning = false; // default timer to not running |
tnhnrl | 28:16c83a2fdefa | 26 | _isSubStateTimerRunning = false; // default timer to not running |
tnhnrl | 73:f6f378311c8d | 27 | ///////////////////////////// |
tnhnrl | 24:c7d9b5bf3829 | 28 | _multi_dive_counter = 0; |
joel_ssc | 82:0981b9ada820 | 29 | _multi_leg_counter = 0; |
tnhnrl | 21:38c8544db6f4 | 30 | _depth_KP = depthLoop().getControllerP(); // load current depth value |
tnhnrl | 21:38c8544db6f4 | 31 | _depth_KI = depthLoop().getControllerI(); // load current depth value |
tnhnrl | 21:38c8544db6f4 | 32 | _depth_KD = depthLoop().getControllerD(); // load current depth value |
tnhnrl | 21:38c8544db6f4 | 33 | |
tnhnrl | 21:38c8544db6f4 | 34 | _pitch_KP = pitchLoop().getControllerP(); // load current pitch value |
tnhnrl | 21:38c8544db6f4 | 35 | _pitch_KI = pitchLoop().getControllerI(); // load current pitch value |
tnhnrl | 21:38c8544db6f4 | 36 | _pitch_KD = pitchLoop().getControllerD(); // load current pitch value |
tnhnrl | 21:38c8544db6f4 | 37 | |
tnhnrl | 21:38c8544db6f4 | 38 | _neutral_bce_pos_mm = depthLoop().getOutputOffset(); //load current neutral buoyancy position offset |
tnhnrl | 21:38c8544db6f4 | 39 | _neutral_batt_pos_mm = pitchLoop().getOutputOffset(); //load current neutral buoyancy position offset |
tnhnrl | 23:434f04ef1fad | 40 | |
tnhnrl | 28:16c83a2fdefa | 41 | _state_array_counter = 1; //used to iterate through and record states |
tnhnrl | 28:16c83a2fdefa | 42 | _substate_array_counter = 0; //used to iterate through and record substates |
tnhnrl | 28:16c83a2fdefa | 43 | |
tnhnrl | 28:16c83a2fdefa | 44 | _state_array[0] = SIT_IDLE; //system starts in the SIT_IDLE state, record this |
tnhnrl | 24:c7d9b5bf3829 | 45 | |
tnhnrl | 30:2964617e7676 | 46 | _substate = NEUTRAL_SINKING; //start sub-FSM in NEUTRAL_SINKING |
tnhnrl | 28:16c83a2fdefa | 47 | _previous_substate = -1; //to start sub-FSM |
tnhnrl | 28:16c83a2fdefa | 48 | _previous_state = -1; //for tracking FSM states |
tnhnrl | 28:16c83a2fdefa | 49 | |
tnhnrl | 28:16c83a2fdefa | 50 | _max_recorded_depth_neutral = -99; //float to record max depth |
tnhnrl | 28:16c83a2fdefa | 51 | _max_recorded_depth_dive = -99; //float to record max depth |
tnhnrl | 32:f2f8ae34aadc | 52 | |
tnhnrl | 32:f2f8ae34aadc | 53 | _max_recorded_auto_neutral_depth = -99; |
tnhnrl | 32:f2f8ae34aadc | 54 | |
tnhnrl | 73:f6f378311c8d | 55 | _debug_menu_on = false; //toggle between debug and simple menu screens |
tnhnrl | 57:ec69651c8c21 | 56 | |
tnhnrl | 73:f6f378311c8d | 57 | //new file stuff |
tnhnrl | 73:f6f378311c8d | 58 | _pitch_filter_freq = pitchLoop().getFilterFrequency(); |
tnhnrl | 73:f6f378311c8d | 59 | _pitch_deadband = pitchLoop().getDeadband(); |
tnhnrl | 73:f6f378311c8d | 60 | |
tnhnrl | 73:f6f378311c8d | 61 | _depth_filter_freq = depthLoop().getFilterFrequency(); |
tnhnrl | 73:f6f378311c8d | 62 | _depth_deadband = depthLoop().getDeadband(); |
tnhnrl | 16:3363b9f14913 | 63 | } |
tnhnrl | 20:8987a9ae2bc7 | 64 | |
tnhnrl | 17:7c16b5671d0e | 65 | //Finite State Machine (FSM) |
joel_ssc | 82:0981b9ada820 | 66 | int StateMachine::runStateMachine() { // ends about line 956 |
tnhnrl | 16:3363b9f14913 | 67 | // finite state machine ... each state has at least one exit criteria |
joel_ssc | 82:0981b9ada820 | 68 | static int lpd_oneshots=0; |
joel_ssc | 82:0981b9ada820 | 69 | static int lpr_oneshots=0; |
joel_ssc | 82:0981b9ada820 | 70 | static int finish_leg=0; // allow a rise to complete ( if it takes less than a yo_time, then exit to FB) |
joel_ssc | 82:0981b9ada820 | 71 | static float leg_max_depth = 0; |
joel_ssc | 82:0981b9ada820 | 72 | static float leg_min_depth =0; |
joel_ssc | 82:0981b9ada820 | 73 | static float leg_heading = 90; //go east! |
joel_ssc | 82:0981b9ada820 | 74 | char buf[256]; |
tnhnrl | 17:7c16b5671d0e | 75 | switch (_state) { |
tnhnrl | 16:3363b9f14913 | 76 | case SIT_IDLE : |
joel_ssc | 82:0981b9ada820 | 77 | case FB_EXIT : |
tnhnrl | 73:f6f378311c8d | 78 | case KEYBOARD : |
tnhnrl | 16:3363b9f14913 | 79 | // there actually is no timeout for SIT_IDLE, but this enables some one-shot actions |
tnhnrl | 28:16c83a2fdefa | 80 | if (!_isTimeoutRunning) { |
tnhnrl | 73:f6f378311c8d | 81 | //tare pressure sensor |
tnhnrl | 73:f6f378311c8d | 82 | depth().tare(); // tares to ambient (do on surface) |
tnhnrl | 57:ec69651c8c21 | 83 | |
tnhnrl | 57:ec69651c8c21 | 84 | if (_debug_menu_on) |
tnhnrl | 69:919ac8d7e023 | 85 | printDebugMenu(); |
tnhnrl | 57:ec69651c8c21 | 86 | else |
tnhnrl | 69:919ac8d7e023 | 87 | printSimpleMenu(); |
tnhnrl | 74:d281aaef9766 | 88 | xbee().printf("\r\n\nstate: SIT_IDLE\r\n"); |
tnhnrl | 28:16c83a2fdefa | 89 | _isTimeoutRunning = true; |
tnhnrl | 20:8987a9ae2bc7 | 90 | |
tnhnrl | 16:3363b9f14913 | 91 | // what is active? |
tnhnrl | 16:3363b9f14913 | 92 | bce().pause(); |
tnhnrl | 16:3363b9f14913 | 93 | batt().pause(); |
tnhnrl | 32:f2f8ae34aadc | 94 | |
tnhnrl | 17:7c16b5671d0e | 95 | //reset sub FSM |
tnhnrl | 28:16c83a2fdefa | 96 | _isSubStateTimerRunning = false; |
tnhnrl | 16:3363b9f14913 | 97 | } |
tnhnrl | 20:8987a9ae2bc7 | 98 | |
tnhnrl | 16:3363b9f14913 | 99 | // how exit? |
tnhnrl | 20:8987a9ae2bc7 | 100 | keyboard(); // keyboard function will change the state if needed |
tnhnrl | 16:3363b9f14913 | 101 | break; |
tnhnrl | 49:47ffa4feb6db | 102 | |
tnhnrl | 49:47ffa4feb6db | 103 | case CHECK_TUNING : // state used to check the tuning of the pressure vessel |
tnhnrl | 49:47ffa4feb6db | 104 | // start local state timer and init any other one-shot actions |
tnhnrl | 49:47ffa4feb6db | 105 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 106 | xbee().printf("\r\n\nstate: CHECK_TUNING\r\n"); |
tnhnrl | 73:f6f378311c8d | 107 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 108 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 49:47ffa4feb6db | 109 | _isTimeoutRunning = true; |
tnhnrl | 49:47ffa4feb6db | 110 | |
tnhnrl | 49:47ffa4feb6db | 111 | // what needs to be started? |
tnhnrl | 49:47ffa4feb6db | 112 | bce().unpause(); //this is now active |
tnhnrl | 49:47ffa4feb6db | 113 | batt().unpause(); //this is now active |
tnhnrl | 49:47ffa4feb6db | 114 | |
tnhnrl | 49:47ffa4feb6db | 115 | // what are the commands? (DRIVE THE MOTORS "DIRECTLY") |
tnhnrl | 49:47ffa4feb6db | 116 | bce().setPosition_mm(_neutral_bce_pos_mm); //this variable is loaded from the file at initialization |
tnhnrl | 49:47ffa4feb6db | 117 | batt().setPosition_mm(_neutral_batt_pos_mm); //this variable is loaded from the file at initialization |
tnhnrl | 49:47ffa4feb6db | 118 | |
tnhnrl | 49:47ffa4feb6db | 119 | // getSetPosition_mm is the commanded position in the LinearActuator class |
tnhnrl | 49:47ffa4feb6db | 120 | |
tnhnrl | 74:d281aaef9766 | 121 | xbee().printf("CHECK_TUNING: BCE cmd: %3.1f (BCE current position: %3.1f)\r\n", bce().getSetPosition_mm(), bce().getPosition_mm()); |
tnhnrl | 74:d281aaef9766 | 122 | xbee().printf("CHECK_TUNING: BATT cmd: %3.1f (BATT current position: %3.1f)\r\n", batt().getSetPosition_mm(), bce().getPosition_mm()); |
tnhnrl | 49:47ffa4feb6db | 123 | } |
tnhnrl | 49:47ffa4feb6db | 124 | |
tnhnrl | 49:47ffa4feb6db | 125 | // how exit? |
tnhnrl | 73:f6f378311c8d | 126 | if (_fsm_timer > _timeout) { |
tnhnrl | 74:d281aaef9766 | 127 | xbee().printf("CHECK_TUNING: timed out!\r\n"); |
tnhnrl | 49:47ffa4feb6db | 128 | _state = FLOAT_BROADCAST; |
tnhnrl | 73:f6f378311c8d | 129 | _fsm_timer.reset(); |
tnhnrl | 49:47ffa4feb6db | 130 | _isTimeoutRunning = false; |
tnhnrl | 49:47ffa4feb6db | 131 | } |
tnhnrl | 49:47ffa4feb6db | 132 | |
tnhnrl | 67:c86a4b464682 | 133 | //WHAT IS ACTIVE? |
tnhnrl | 67:c86a4b464682 | 134 | // the inner loop position controls are maintaining the positions of the linear actuators |
tnhnrl | 67:c86a4b464682 | 135 | |
tnhnrl | 49:47ffa4feb6db | 136 | //print status to screen continuously |
tnhnrl | 74:d281aaef9766 | 137 | xbee().printf("CHECK_TUNING: BCE_position: %0.1f, BATT_position: %0.1f (BCE_cmd: %0.1f, BATT_cmd: %0.1f)(depth: %0.1f ft,pitch: %0.1f deg,heading: %0.1f) [%0.1f sec]\r",bce().getPosition_mm(),batt().getPosition_mm(),bce().getSetPosition_mm(),batt().getSetPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 49:47ffa4feb6db | 138 | |
tnhnrl | 49:47ffa4feb6db | 139 | break; |
tnhnrl | 20:8987a9ae2bc7 | 140 | |
tnhnrl | 16:3363b9f14913 | 141 | case EMERGENCY_CLIMB : |
tnhnrl | 16:3363b9f14913 | 142 | // start local state timer and init any other one-shot actions |
tnhnrl | 28:16c83a2fdefa | 143 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 144 | xbee().printf("\r\n\nstate: EMERGENCY_CLIMB\r\n"); |
tnhnrl | 73:f6f378311c8d | 145 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 146 | _fsm_timer.start(); // background timer starts running |
joel_ssc | 84:eccd8e837134 | 147 | _yotimer.reset(); |
joel_ssc | 84:eccd8e837134 | 148 | _yotimer.start(); |
tnhnrl | 28:16c83a2fdefa | 149 | _isTimeoutRunning = true; |
tnhnrl | 16:3363b9f14913 | 150 | |
tnhnrl | 16:3363b9f14913 | 151 | // what needs to be started? |
tnhnrl | 16:3363b9f14913 | 152 | bce().unpause(); |
tnhnrl | 16:3363b9f14913 | 153 | batt().unpause(); |
tnhnrl | 20:8987a9ae2bc7 | 154 | |
tnhnrl | 20:8987a9ae2bc7 | 155 | // what are the commands? |
tnhnrl | 16:3363b9f14913 | 156 | bce().setPosition_mm(bce().getTravelLimit()); |
tnhnrl | 73:f6f378311c8d | 157 | batt().setPosition_mm(10.0); //pull nose up (0.0 was sketchy) |
tnhnrl | 16:3363b9f14913 | 158 | } |
tnhnrl | 20:8987a9ae2bc7 | 159 | |
tnhnrl | 16:3363b9f14913 | 160 | // how exit? |
joel_ssc | 82:0981b9ada820 | 161 | if ((_fsm_timer > _timeout ) || (_yotimer > _yo_time)) { |
tnhnrl | 74:d281aaef9766 | 162 | xbee().printf("EC: timed out\r\n"); |
tnhnrl | 21:38c8544db6f4 | 163 | _state = FLOAT_BROADCAST; |
joel_ssc | 82:0981b9ada820 | 164 | _fsm_timer.reset(); _yotimer.reset(); |
tnhnrl | 28:16c83a2fdefa | 165 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 166 | } |
tnhnrl | 26:7e118fc02eea | 167 | else if (depthLoop().getPosition() < 2.0) { //if the depth is greater than 0.2 feet, go to float broadcast |
tnhnrl | 21:38c8544db6f4 | 168 | _state = FLOAT_BROADCAST; |
joel_ssc | 84:eccd8e837134 | 169 | _fsm_timer.reset(); _yotimer.reset(); |
tnhnrl | 28:16c83a2fdefa | 170 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 171 | } |
tnhnrl | 32:f2f8ae34aadc | 172 | |
tnhnrl | 67:c86a4b464682 | 173 | //WHAT IS ACTIVE? |
tnhnrl | 34:9b66c5188051 | 174 | //print status to screen continuously |
tnhnrl | 74:d281aaef9766 | 175 | xbee().printf("EC: depth: %3.1f, pitch: %0.1f deg [BCE:%0.1f (cmd: %0.1f) BMM:%0.1f (cmd: %0.1f)] [%0.1f sec]\r",depthLoop().getPosition(),pitchLoop().getPosition(),bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),_fsm_timer.read()); |
tnhnrl | 32:f2f8ae34aadc | 176 | |
tnhnrl | 16:3363b9f14913 | 177 | break; |
tnhnrl | 20:8987a9ae2bc7 | 178 | |
tnhnrl | 16:3363b9f14913 | 179 | case FIND_NEUTRAL : |
tnhnrl | 20:8987a9ae2bc7 | 180 | // start local state timer and init any other one-shot actions |
tnhnrl | 28:16c83a2fdefa | 181 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 182 | xbee().printf("\r\n\nstate: FIND_NEUTRAL\r\n"); |
tnhnrl | 73:f6f378311c8d | 183 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 184 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 28:16c83a2fdefa | 185 | _isTimeoutRunning = true; |
tnhnrl | 16:3363b9f14913 | 186 | |
tnhnrl | 16:3363b9f14913 | 187 | // what needs to be started? |
tnhnrl | 16:3363b9f14913 | 188 | bce().unpause(); |
tnhnrl | 16:3363b9f14913 | 189 | batt().unpause(); |
tnhnrl | 74:d281aaef9766 | 190 | |
tnhnrl | 74:d281aaef9766 | 191 | //start with a small offset from MANUAL neutral positions on the BCE only, BMM was pitching too much |
tnhnrl | 74:d281aaef9766 | 192 | float bce_find_neutral_mm = _neutral_bce_pos_mm + 10.0; |
tnhnrl | 74:d281aaef9766 | 193 | //float batt_find_neutral_mm = _neutral_batt_pos_mm + 10.0; |
tnhnrl | 74:d281aaef9766 | 194 | |
tnhnrl | 74:d281aaef9766 | 195 | bce().setPosition_mm(bce_find_neutral_mm); |
tnhnrl | 74:d281aaef9766 | 196 | batt().setPosition_mm(_neutral_batt_pos_mm); //set battery to the same neutral position |
tnhnrl | 17:7c16b5671d0e | 197 | |
tnhnrl | 24:c7d9b5bf3829 | 198 | //first iteration goes into Neutral Finding Sub-FSM |
tnhnrl | 24:c7d9b5bf3829 | 199 | //set the first state of the FSM, and start the sub-FSM |
tnhnrl | 30:2964617e7676 | 200 | _substate = NEUTRAL_SINKING; //first state in neutral sub-FSM is the pressure vessel sinking |
tnhnrl | 28:16c83a2fdefa | 201 | _previous_substate = -1; |
tnhnrl | 28:16c83a2fdefa | 202 | |
tnhnrl | 28:16c83a2fdefa | 203 | //save this state to the array |
tnhnrl | 30:2964617e7676 | 204 | _substate_array[_substate_array_counter] = NEUTRAL_SINKING; //save to state array |
tnhnrl | 28:16c83a2fdefa | 205 | _substate_array_counter++; |
tnhnrl | 28:16c83a2fdefa | 206 | |
tnhnrl | 32:f2f8ae34aadc | 207 | runNeutralStateMachine(); |
tnhnrl | 16:3363b9f14913 | 208 | } |
tnhnrl | 20:8987a9ae2bc7 | 209 | |
tnhnrl | 20:8987a9ae2bc7 | 210 | // how exit? (exit with the timer, if timer still running continue processing sub FSM) |
tnhnrl | 73:f6f378311c8d | 211 | if (_fsm_timer > _timeout) { |
tnhnrl | 74:d281aaef9766 | 212 | xbee().printf("FN: timed out [time: %0.1f sec]\r\n", _fsm_timer.read()); |
tnhnrl | 21:38c8544db6f4 | 213 | _state = EMERGENCY_CLIMB; //new behavior (if this times out it emergency surfaces) |
tnhnrl | 73:f6f378311c8d | 214 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 215 | _isTimeoutRunning = false; |
tnhnrl | 24:c7d9b5bf3829 | 216 | |
tnhnrl | 24:c7d9b5bf3829 | 217 | //record this to the NEUTRAL sub-FSM tracker |
tnhnrl | 28:16c83a2fdefa | 218 | _substate_array[_substate_array_counter] = EMERGENCY_CLIMB; //save to state array |
tnhnrl | 28:16c83a2fdefa | 219 | _substate_array_counter++; |
tnhnrl | 16:3363b9f14913 | 220 | } |
tnhnrl | 21:38c8544db6f4 | 221 | |
tnhnrl | 24:c7d9b5bf3829 | 222 | //what is active? (neutral finding sub-function runs until completion) |
tnhnrl | 24:c7d9b5bf3829 | 223 | //check if substate returned exit state, if so stop running the sub-FSM |
tnhnrl | 26:7e118fc02eea | 224 | else if (runNeutralStateMachine() == NEUTRAL_EXIT) { |
tnhnrl | 21:38c8544db6f4 | 225 | //if successful, FIND_NEUTRAL then goes to RISE |
tnhnrl | 74:d281aaef9766 | 226 | xbee().printf("*************************************** FIND_NEUTRAL sequence complete. Rising.\r\n\n"); |
tnhnrl | 21:38c8544db6f4 | 227 | _state = RISE; |
tnhnrl | 30:2964617e7676 | 228 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 229 | } |
tnhnrl | 32:f2f8ae34aadc | 230 | |
tnhnrl | 17:7c16b5671d0e | 231 | break; |
tnhnrl | 17:7c16b5671d0e | 232 | |
tnhnrl | 16:3363b9f14913 | 233 | case DIVE : |
tnhnrl | 16:3363b9f14913 | 234 | // start local state timer and init any other one-shot actions |
tnhnrl | 32:f2f8ae34aadc | 235 | |
tnhnrl | 28:16c83a2fdefa | 236 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 237 | xbee().printf("\r\n\nstate: DIVE\r\n"); |
tnhnrl | 73:f6f378311c8d | 238 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 239 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 28:16c83a2fdefa | 240 | _isTimeoutRunning = true; |
tnhnrl | 16:3363b9f14913 | 241 | |
tnhnrl | 16:3363b9f14913 | 242 | // what needs to be started? |
tnhnrl | 16:3363b9f14913 | 243 | bce().unpause(); |
tnhnrl | 16:3363b9f14913 | 244 | batt().unpause(); |
tnhnrl | 20:8987a9ae2bc7 | 245 | |
tnhnrl | 16:3363b9f14913 | 246 | // what are the commands? |
tnhnrl | 32:f2f8ae34aadc | 247 | depthLoop().setCommand(_depth_command); |
tnhnrl | 32:f2f8ae34aadc | 248 | pitchLoop().setCommand(_pitch_command); |
tnhnrl | 32:f2f8ae34aadc | 249 | |
tnhnrl | 74:d281aaef9766 | 250 | headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
tnhnrl | 74:d281aaef9766 | 251 | |
tnhnrl | 74:d281aaef9766 | 252 | xbee().printf("DIVE: depth cmd: %3.1f\r\n",depthLoop().getCommand()); |
tnhnrl | 74:d281aaef9766 | 253 | xbee().printf("DIVE: pitch cmd: %3.1f\r\n",pitchLoop().getCommand()); |
tnhnrl | 74:d281aaef9766 | 254 | xbee().printf("DIVE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
tnhnrl | 28:16c83a2fdefa | 255 | |
tnhnrl | 28:16c83a2fdefa | 256 | //reset max dive depth |
tnhnrl | 28:16c83a2fdefa | 257 | _max_recorded_depth_dive = -99; //float to record max depth |
tnhnrl | 16:3363b9f14913 | 258 | } |
tnhnrl | 20:8987a9ae2bc7 | 259 | |
tnhnrl | 16:3363b9f14913 | 260 | // how exit? |
tnhnrl | 73:f6f378311c8d | 261 | if (_fsm_timer.read() > _timeout) { |
tnhnrl | 74:d281aaef9766 | 262 | xbee().printf("DIVE: timed out\r\n\n"); |
tnhnrl | 21:38c8544db6f4 | 263 | _state = RISE; //new behavior 11/17/2017 |
tnhnrl | 73:f6f378311c8d | 264 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 265 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 266 | } |
tnhnrl | 32:f2f8ae34aadc | 267 | else if (depthLoop().getPosition() > depthLoop().getCommand() - 0.5) { // including offset for low momentum approaches |
tnhnrl | 74:d281aaef9766 | 268 | xbee().printf("DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
tnhnrl | 21:38c8544db6f4 | 269 | _state = RISE; |
tnhnrl | 73:f6f378311c8d | 270 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 271 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 272 | } |
tnhnrl | 20:8987a9ae2bc7 | 273 | |
tnhnrl | 67:c86a4b464682 | 274 | // WHAT IS ACTIVE? |
tnhnrl | 74:d281aaef9766 | 275 | xbee().printf("DIVE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 32:f2f8ae34aadc | 276 | bce().setPosition_mm(depthLoop().getOutput()); //constantly checking the Outer Loop output to move the motors |
tnhnrl | 16:3363b9f14913 | 277 | batt().setPosition_mm(pitchLoop().getOutput()); |
tnhnrl | 28:16c83a2fdefa | 278 | |
tnhnrl | 74:d281aaef9766 | 279 | // ACTIVE RUDDER CONTROL |
tnhnrl | 74:d281aaef9766 | 280 | rudder().setPosition_deg(headingLoop().getOutput()); |
tnhnrl | 74:d281aaef9766 | 281 | |
tnhnrl | 28:16c83a2fdefa | 282 | if (depthLoop().getPosition() > _max_recorded_depth_dive) { //debug |
tnhnrl | 28:16c83a2fdefa | 283 | _max_recorded_depth_dive = depthLoop().getPosition(); //new max depth recorded |
tnhnrl | 28:16c83a2fdefa | 284 | } |
tnhnrl | 32:f2f8ae34aadc | 285 | |
tnhnrl | 16:3363b9f14913 | 286 | break; |
tnhnrl | 16:3363b9f14913 | 287 | |
tnhnrl | 16:3363b9f14913 | 288 | case RISE : |
tnhnrl | 16:3363b9f14913 | 289 | // start local state timer and init any other one-shot actions |
tnhnrl | 32:f2f8ae34aadc | 290 | |
tnhnrl | 28:16c83a2fdefa | 291 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 292 | xbee().printf("\r\n\nstate: RISE\r\n"); |
tnhnrl | 73:f6f378311c8d | 293 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 294 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 28:16c83a2fdefa | 295 | _isTimeoutRunning = true; |
tnhnrl | 16:3363b9f14913 | 296 | |
tnhnrl | 16:3363b9f14913 | 297 | // what needs to be started? |
tnhnrl | 16:3363b9f14913 | 298 | bce().unpause(); |
tnhnrl | 16:3363b9f14913 | 299 | batt().unpause(); |
tnhnrl | 16:3363b9f14913 | 300 | |
tnhnrl | 16:3363b9f14913 | 301 | // what are the commands? |
tnhnrl | 28:16c83a2fdefa | 302 | depthLoop().setCommand(-1.0); //make sure to get towards the surface (saw issues at LASR pool) |
tnhnrl | 32:f2f8ae34aadc | 303 | pitchLoop().setCommand(-_pitch_command); |
tnhnrl | 74:d281aaef9766 | 304 | |
tnhnrl | 74:d281aaef9766 | 305 | headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
tnhnrl | 74:d281aaef9766 | 306 | |
tnhnrl | 74:d281aaef9766 | 307 | xbee().printf("RISE: depth cmd: %3.1f\r\n",depthLoop().getCommand()); |
tnhnrl | 74:d281aaef9766 | 308 | xbee().printf("RISE: pitch cmd: %3.1f\r\n",pitchLoop().getCommand()); |
tnhnrl | 74:d281aaef9766 | 309 | xbee().printf("RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
tnhnrl | 16:3363b9f14913 | 310 | } |
tnhnrl | 20:8987a9ae2bc7 | 311 | |
tnhnrl | 16:3363b9f14913 | 312 | // how exit? |
tnhnrl | 73:f6f378311c8d | 313 | if (_fsm_timer.read() > _timeout) { |
tnhnrl | 74:d281aaef9766 | 314 | xbee().printf("RISE: timed out\r\n"); |
tnhnrl | 21:38c8544db6f4 | 315 | _state = EMERGENCY_CLIMB; |
tnhnrl | 73:f6f378311c8d | 316 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 317 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 318 | } |
tnhnrl | 32:f2f8ae34aadc | 319 | |
tnhnrl | 32:f2f8ae34aadc | 320 | //modified from (depthLoop().getPosition() < depthLoop().getCommand() + 0.5) |
tnhnrl | 32:f2f8ae34aadc | 321 | //did not work correctly in bench test (stuck in rise state) |
tnhnrl | 32:f2f8ae34aadc | 322 | else if (depthLoop().getPosition() < 0.5) { |
tnhnrl | 74:d281aaef9766 | 323 | xbee().printf("RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
tnhnrl | 28:16c83a2fdefa | 324 | _state = FLOAT_BROADCAST; |
tnhnrl | 73:f6f378311c8d | 325 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 326 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 327 | } |
tnhnrl | 20:8987a9ae2bc7 | 328 | |
tnhnrl | 67:c86a4b464682 | 329 | // WHAT IS ACTIVE? |
tnhnrl | 74:d281aaef9766 | 330 | xbee().printf("RISE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 17:7c16b5671d0e | 331 | bce().setPosition_mm(depthLoop().getOutput()); //constantly checking the Outer Loop output to move the motors |
tnhnrl | 32:f2f8ae34aadc | 332 | batt().setPosition_mm(pitchLoop().getOutput()); |
tnhnrl | 74:d281aaef9766 | 333 | |
tnhnrl | 74:d281aaef9766 | 334 | // ACTIVE RUDDER CONTROL |
tnhnrl | 74:d281aaef9766 | 335 | rudder().setPosition_deg(headingLoop().getOutput()); |
tnhnrl | 32:f2f8ae34aadc | 336 | |
tnhnrl | 58:94b7fd55185e | 337 | break; |
tnhnrl | 58:94b7fd55185e | 338 | |
tnhnrl | 58:94b7fd55185e | 339 | // NEW DIVE AND RISE SEQUENCES |
tnhnrl | 58:94b7fd55185e | 340 | case POSITION_DIVE : |
tnhnrl | 58:94b7fd55185e | 341 | // start local state timer and init any other one-shot actions |
tnhnrl | 58:94b7fd55185e | 342 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 343 | xbee().printf("\r\n\nstate: POSITION DIVE\r\n"); |
tnhnrl | 73:f6f378311c8d | 344 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 345 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 58:94b7fd55185e | 346 | _isTimeoutRunning = true; |
tnhnrl | 58:94b7fd55185e | 347 | |
tnhnrl | 58:94b7fd55185e | 348 | // what needs to be started? |
tnhnrl | 58:94b7fd55185e | 349 | bce().unpause(); |
tnhnrl | 58:94b7fd55185e | 350 | batt().unpause(); |
tnhnrl | 58:94b7fd55185e | 351 | rudder().unpause(); |
tnhnrl | 58:94b7fd55185e | 352 | |
tnhnrl | 58:94b7fd55185e | 353 | // what are the commands? (using inner loops except for heading outer loop) |
tnhnrl | 58:94b7fd55185e | 354 | // These actions happen ONCE in the POSITION_DIVE sequence |
tnhnrl | 74:d281aaef9766 | 355 | batt().setPosition_mm(_neutral_batt_pos_mm + _BMM_dive_offset); |
tnhnrl | 74:d281aaef9766 | 356 | bce().setPosition_mm(_neutral_bce_pos_mm - _BCE_dive_offset); |
tnhnrl | 58:94b7fd55185e | 357 | |
tnhnrl | 74:d281aaef9766 | 358 | //DEPTH COMMAND |
tnhnrl | 74:d281aaef9766 | 359 | depthLoop().setCommand(_depth_command); |
tnhnrl | 74:d281aaef9766 | 360 | |
tnhnrl | 58:94b7fd55185e | 361 | headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
tnhnrl | 58:94b7fd55185e | 362 | |
tnhnrl | 74:d281aaef9766 | 363 | xbee().printf("POS DIVE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position |
tnhnrl | 74:d281aaef9766 | 364 | xbee().printf("POS DIVE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position |
tnhnrl | 74:d281aaef9766 | 365 | xbee().printf("POS DIVE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
tnhnrl | 58:94b7fd55185e | 366 | |
tnhnrl | 58:94b7fd55185e | 367 | //reset max dive depth |
tnhnrl | 58:94b7fd55185e | 368 | _max_recorded_depth_dive = -99; //float to record max depth |
tnhnrl | 58:94b7fd55185e | 369 | } |
tnhnrl | 58:94b7fd55185e | 370 | |
tnhnrl | 58:94b7fd55185e | 371 | // how exit? |
tnhnrl | 58:94b7fd55185e | 372 | // timer runs out goes to POSITION_RISE |
tnhnrl | 73:f6f378311c8d | 373 | if (_fsm_timer.read() > _timeout) { |
tnhnrl | 74:d281aaef9766 | 374 | xbee().printf("POS DIVE timed out\r\n\n"); |
tnhnrl | 58:94b7fd55185e | 375 | _state = POSITION_RISE; //new behavior 11/17/2017 |
tnhnrl | 73:f6f378311c8d | 376 | _fsm_timer.reset(); |
tnhnrl | 58:94b7fd55185e | 377 | _isTimeoutRunning = false; |
tnhnrl | 58:94b7fd55185e | 378 | } |
tnhnrl | 58:94b7fd55185e | 379 | |
tnhnrl | 58:94b7fd55185e | 380 | // when you reach the dive threshold, surface |
tnhnrl | 58:94b7fd55185e | 381 | else if (depthLoop().getPosition() > depthLoop().getCommand() - 0.5) { // including offset for low momentum approaches |
tnhnrl | 74:d281aaef9766 | 382 | xbee().printf("POS DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
tnhnrl | 58:94b7fd55185e | 383 | _state = POSITION_RISE; |
tnhnrl | 73:f6f378311c8d | 384 | _fsm_timer.reset(); |
tnhnrl | 58:94b7fd55185e | 385 | _isTimeoutRunning = false; |
tnhnrl | 58:94b7fd55185e | 386 | } |
tnhnrl | 58:94b7fd55185e | 387 | |
tnhnrl | 58:94b7fd55185e | 388 | // what is active? |
tnhnrl | 74:d281aaef9766 | 389 | xbee().printf("POS DIVE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 58:94b7fd55185e | 390 | |
tnhnrl | 58:94b7fd55185e | 391 | if (depthLoop().getPosition() > _max_recorded_depth_dive) { |
tnhnrl | 58:94b7fd55185e | 392 | _max_recorded_depth_dive = depthLoop().getPosition(); //new max depth recorded when it is larger than previous values |
tnhnrl | 58:94b7fd55185e | 393 | } |
tnhnrl | 58:94b7fd55185e | 394 | |
tnhnrl | 58:94b7fd55185e | 395 | // ACTIVE RUDDER CONTROL |
tnhnrl | 58:94b7fd55185e | 396 | rudder().setPosition_deg(headingLoop().getOutput()); |
tnhnrl | 58:94b7fd55185e | 397 | |
tnhnrl | 58:94b7fd55185e | 398 | break; |
joel_ssc | 82:0981b9ada820 | 399 | |
joel_ssc | 82:0981b9ada820 | 400 | case LEG_POSITION_DIVE : |
joel_ssc | 82:0981b9ada820 | 401 | // start local state timer and init any other one-shot actions |
joel_ssc | 82:0981b9ada820 | 402 | if (!_isTimeoutRunning) { |
joel_ssc | 82:0981b9ada820 | 403 | xbee().printf("\r\n\nstate: LEG POSITION DIVE first time - start timer\r\n"); |
joel_ssc | 82:0981b9ada820 | 404 | sprintf(buf, "LEG POSITION DIVE start first dive start timer\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 405 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 82:0981b9ada820 | 406 | _fsm_timer.reset(); // timer goes back to zero I am not sure about this reset jcw |
joel_ssc | 82:0981b9ada820 | 407 | _fsm_timer.start(); // background timer starts running |
joel_ssc | 82:0981b9ada820 | 408 | _isTimeoutRunning = true; |
joel_ssc | 82:0981b9ada820 | 409 | _yotimer.reset(); |
joel_ssc | 82:0981b9ada820 | 410 | _yotimer.start(); //sets the yo_timer running on the dive |
joel_ssc | 82:0981b9ada820 | 411 | |
joel_ssc | 82:0981b9ada820 | 412 | // what needs to be started? |
joel_ssc | 82:0981b9ada820 | 413 | bce().unpause(); |
joel_ssc | 82:0981b9ada820 | 414 | batt().unpause(); |
joel_ssc | 82:0981b9ada820 | 415 | rudder().unpause(); |
joel_ssc | 82:0981b9ada820 | 416 | |
joel_ssc | 82:0981b9ada820 | 417 | // what are the commands? (using inner loops except for heading outer loop) |
joel_ssc | 82:0981b9ada820 | 418 | // These actions happen ONCE in the POSITION_DIVE sequence |
joel_ssc | 82:0981b9ada820 | 419 | batt().setPosition_mm(_neutral_batt_pos_mm + _BMM_dive_offset); |
joel_ssc | 82:0981b9ada820 | 420 | bce().setPosition_mm(_neutral_bce_pos_mm - _BCE_dive_offset); |
joel_ssc | 82:0981b9ada820 | 421 | //retrieve commands from structs (loaded from legfile.txt file) |
joel_ssc | 82:0981b9ada820 | 422 | stateMachine().getLegParams(); |
joel_ssc | 82:0981b9ada820 | 423 | |
joel_ssc | 82:0981b9ada820 | 424 | leg_max_depth = currentLegStateStruct.max_depth; |
joel_ssc | 82:0981b9ada820 | 425 | leg_heading = currentLegStateStruct.heading; |
joel_ssc | 82:0981b9ada820 | 426 | |
joel_ssc | 82:0981b9ada820 | 427 | |
joel_ssc | 82:0981b9ada820 | 428 | //DEPTH COMMAND |
joel_ssc | 82:0981b9ada820 | 429 | //depthLoop().setCommand(_depth_command); // I want this to be the max_depth in the legStruct |
joel_ssc | 82:0981b9ada820 | 430 | depthLoop().setCommand(leg_max_depth); // I want this to be the max_depth in the legStruct |
joel_ssc | 82:0981b9ada820 | 431 | |
joel_ssc | 82:0981b9ada820 | 432 | //headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
joel_ssc | 82:0981b9ada820 | 433 | headingLoop().setCommand(leg_heading); //ACTIVE HEADING (mimic of dive and rise code) |
joel_ssc | 82:0981b9ada820 | 434 | |
joel_ssc | 82:0981b9ada820 | 435 | xbee().printf("LEG POS DIVE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 436 | xbee().printf("LEG POS DIVE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 437 | xbee().printf("LEG POS DIVE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 438 | |
joel_ssc | 82:0981b9ada820 | 439 | //reset max dive depth |
joel_ssc | 82:0981b9ada820 | 440 | _max_recorded_depth_dive = -99; //float to record max depth |
joel_ssc | 82:0981b9ada820 | 441 | lpd_oneshots = 1; |
joel_ssc | 82:0981b9ada820 | 442 | } |
joel_ssc | 82:0981b9ada820 | 443 | |
joel_ssc | 82:0981b9ada820 | 444 | if (!lpd_oneshots) { |
joel_ssc | 82:0981b9ada820 | 445 | xbee().printf("\r\n\nstate: LEG POSITION DIVE oneshots\r\n"); |
joel_ssc | 82:0981b9ada820 | 446 | // _fsm_timer.reset(); // timer goes back to zero I am not sure about this reset jcw |
joel_ssc | 82:0981b9ada820 | 447 | // sm_timer.start(); // background timer starts running |
joel_ssc | 82:0981b9ada820 | 448 | _yotimer.reset(); //sets the yo_timer running on the NEW dive |
joel_ssc | 82:0981b9ada820 | 449 | _yotimer.start(); |
joel_ssc | 82:0981b9ada820 | 450 | //_isTimeoutRunning = true; |
joel_ssc | 82:0981b9ada820 | 451 | |
joel_ssc | 82:0981b9ada820 | 452 | // what needs to be started? |
joel_ssc | 82:0981b9ada820 | 453 | bce().unpause(); |
joel_ssc | 82:0981b9ada820 | 454 | batt().unpause(); |
joel_ssc | 82:0981b9ada820 | 455 | rudder().unpause(); |
joel_ssc | 82:0981b9ada820 | 456 | |
joel_ssc | 82:0981b9ada820 | 457 | // what are the commands? (using inner loops except for heading outer loop) |
joel_ssc | 82:0981b9ada820 | 458 | // These actions happen ONCE in the POSITION_DIVE sequence |
joel_ssc | 82:0981b9ada820 | 459 | batt().setPosition_mm(_neutral_batt_pos_mm + _BMM_dive_offset); |
joel_ssc | 82:0981b9ada820 | 460 | bce().setPosition_mm(_neutral_bce_pos_mm - _BCE_dive_offset); |
joel_ssc | 82:0981b9ada820 | 461 | //retrieve commands from structs (loaded from missionleg.cfg file) |
joel_ssc | 82:0981b9ada820 | 462 | leg_max_depth = currentLegStateStruct.max_depth; |
joel_ssc | 82:0981b9ada820 | 463 | leg_heading = currentLegStateStruct.heading; |
joel_ssc | 84:eccd8e837134 | 464 | sprintf(buf, "LEG POSITION DIVE entered via Leg_pos_rise - lpd_oneshots, only restart _yotimer\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 465 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 82:0981b9ada820 | 466 | |
joel_ssc | 82:0981b9ada820 | 467 | //DEPTH COMMAND |
joel_ssc | 82:0981b9ada820 | 468 | //depthLoop().setCommand(_depth_command); // I want this to be the max_depth in the legStruct |
joel_ssc | 82:0981b9ada820 | 469 | depthLoop().setCommand(leg_max_depth); // I want this to be the max_depth in the legStruct |
joel_ssc | 82:0981b9ada820 | 470 | |
joel_ssc | 82:0981b9ada820 | 471 | //headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
joel_ssc | 82:0981b9ada820 | 472 | headingLoop().setCommand(leg_heading); //ACTIVE HEADING (mimic of dive and rise code) |
joel_ssc | 82:0981b9ada820 | 473 | |
joel_ssc | 82:0981b9ada820 | 474 | xbee().printf("LEG POS DIVE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 475 | xbee().printf("LEG POS DIVE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 476 | xbee().printf("LEG POS DIVE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 477 | |
joel_ssc | 82:0981b9ada820 | 478 | lpd_oneshots = 1; |
joel_ssc | 82:0981b9ada820 | 479 | //reset max dive depth |
joel_ssc | 82:0981b9ada820 | 480 | //_max_recorded_depth_dive = -99; //float to record max depth |
joel_ssc | 82:0981b9ada820 | 481 | } // lpd_oneshots if timer is already running |
joel_ssc | 82:0981b9ada820 | 482 | |
joel_ssc | 82:0981b9ada820 | 483 | // how exit? |
joel_ssc | 82:0981b9ada820 | 484 | // timer runs out goes to LEG_POSITION_RISE but finish_leg flag is turned on. |
joel_ssc | 82:0981b9ada820 | 485 | if (_fsm_timer.read() > _timeout) { |
joel_ssc | 82:0981b9ada820 | 486 | xbee().printf("LEG POSITION DIVE timed out for overall leg time\r\n\n"); |
joel_ssc | 82:0981b9ada820 | 487 | _state = LEG_POSITION_RISE; // now start a timer on yo_timer for rise |
joel_ssc | 82:0981b9ada820 | 488 | finish_leg =1; |
joel_ssc | 82:0981b9ada820 | 489 | lpr_oneshots=0; |
joel_ssc | 84:eccd8e837134 | 490 | sprintf(buf, "go to LEG POSITION DIVE on overall leg timeout, set finish_leg=1\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 491 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 82:0981b9ada820 | 492 | // _fsm_timer.reset(); |
joel_ssc | 82:0981b9ada820 | 493 | // _isTimeoutRunning = false; |
joel_ssc | 82:0981b9ada820 | 494 | } |
joel_ssc | 82:0981b9ada820 | 495 | |
joel_ssc | 82:0981b9ada820 | 496 | // when you reach the dive threshold, surface |
joel_ssc | 82:0981b9ada820 | 497 | else if (depthLoop().getPosition() > depthLoop().getCommand() - 0.5) { // including offset for low momentum approaches |
joel_ssc | 82:0981b9ada820 | 498 | xbee().printf("LEG POS DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 499 | _state = LEG_POSITION_RISE; |
joel_ssc | 82:0981b9ada820 | 500 | lpr_oneshots = 0; |
joel_ssc | 84:eccd8e837134 | 501 | |
joel_ssc | 82:0981b9ada820 | 502 | // _fsm_timer.reset(); // reset time if still inside legg long timeout? |
joel_ssc | 82:0981b9ada820 | 503 | // _isTimeoutRunning = false; |
joel_ssc | 82:0981b9ada820 | 504 | } else if(_yotimer.read() > _yo_time ) { |
joel_ssc | 82:0981b9ada820 | 505 | xbee().printf("LEG POS DIVE: yo_time timed out - go to LEG_POSITION_RISE actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 506 | sprintf(buf, "LEG POS DIVE: yo_time timed out - go to LEG_POSITION_RISE\n\n\r"); |
joel_ssc | 82:0981b9ada820 | 507 | mbedLogger().appendDiagFile(buf,3); |
joel_ssc | 82:0981b9ada820 | 508 | _state = LEG_POSITION_RISE; |
joel_ssc | 84:eccd8e837134 | 509 | finish_leg =1; |
joel_ssc | 82:0981b9ada820 | 510 | //_yotimer.reset(); |
joel_ssc | 82:0981b9ada820 | 511 | //_yotimer.start(); // restart the yo timer for next yo in rise mode -- test if depth is small fraction of max_depth and exit to EC if small enough?? |
joel_ssc | 82:0981b9ada820 | 512 | lpr_oneshots=0; |
joel_ssc | 82:0981b9ada820 | 513 | if (depthLoop().getPosition() < 0.7* depthLoop().getCommand()) { //too slow - exit |
joel_ssc | 84:eccd8e837134 | 514 | _state = EMERGENCY_CLIMB; // overridden here for testing |
joel_ssc | 82:0981b9ada820 | 515 | finish_leg = 1; |
joel_ssc | 82:0981b9ada820 | 516 | xbee().printf("LEG POS DIVE:descent too slow (<0.7*maxdepth) - go to EMERGENCY_CLIMB actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
joel_ssc | 84:eccd8e837134 | 517 | sprintf(buf, "LEG POS DIVE: descent too slow yo_time timed out - go to emergency climb but not really for testing\n\n\r"); |
joel_ssc | 82:0981b9ada820 | 518 | mbedLogger().appendDiagFile(buf,3); |
joel_ssc | 84:eccd8e837134 | 519 | _state = LEG_POSITION_RISE; |
joel_ssc | 84:eccd8e837134 | 520 | // _fsm_timer.reset(); |
joel_ssc | 84:eccd8e837134 | 521 | // _isTimeoutRunning = false; |
joel_ssc | 82:0981b9ada820 | 522 | } |
joel_ssc | 82:0981b9ada820 | 523 | } |
joel_ssc | 82:0981b9ada820 | 524 | |
joel_ssc | 82:0981b9ada820 | 525 | // what is active? |
joel_ssc | 82:0981b9ada820 | 526 | xbee().printf("LEG POS DIVE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", |
joel_ssc | 82:0981b9ada820 | 527 | bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(), |
joel_ssc | 82:0981b9ada820 | 528 | depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); |
joel_ssc | 82:0981b9ada820 | 529 | |
joel_ssc | 82:0981b9ada820 | 530 | if (depthLoop().getPosition() > _max_recorded_depth_dive) { |
joel_ssc | 82:0981b9ada820 | 531 | _max_recorded_depth_dive = depthLoop().getPosition(); //new max depth recorded when it is larger than previous values |
joel_ssc | 82:0981b9ada820 | 532 | } |
joel_ssc | 82:0981b9ada820 | 533 | |
joel_ssc | 82:0981b9ada820 | 534 | // ACTIVE RUDDER CONTROL |
joel_ssc | 82:0981b9ada820 | 535 | rudder().setPosition_deg(headingLoop().getOutput()); |
joel_ssc | 82:0981b9ada820 | 536 | |
joel_ssc | 82:0981b9ada820 | 537 | break; // end LEG POSITION DIVE |
tnhnrl | 58:94b7fd55185e | 538 | |
tnhnrl | 58:94b7fd55185e | 539 | case POSITION_RISE : |
tnhnrl | 58:94b7fd55185e | 540 | // start local state timer and init any other one-shot actions |
tnhnrl | 58:94b7fd55185e | 541 | |
tnhnrl | 58:94b7fd55185e | 542 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 543 | xbee().printf("\r\n\nstate: POSITION RISE\r\n"); |
tnhnrl | 73:f6f378311c8d | 544 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 545 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 58:94b7fd55185e | 546 | _isTimeoutRunning = true; |
tnhnrl | 58:94b7fd55185e | 547 | |
tnhnrl | 58:94b7fd55185e | 548 | // what needs to be started? |
tnhnrl | 58:94b7fd55185e | 549 | bce().unpause(); |
tnhnrl | 58:94b7fd55185e | 550 | batt().unpause(); |
tnhnrl | 58:94b7fd55185e | 551 | |
tnhnrl | 74:d281aaef9766 | 552 | // what are the commands? (using inner loops except for heading outer loop) |
tnhnrl | 74:d281aaef9766 | 553 | batt().setPosition_mm(_neutral_batt_pos_mm - _BMM_dive_offset); //reversing the BCE and BATT positions |
tnhnrl | 58:94b7fd55185e | 554 | bce().setPosition_mm(_neutral_bce_pos_mm + _BCE_dive_offset); //reversing the BCE and BATT positions |
tnhnrl | 58:94b7fd55185e | 555 | |
tnhnrl | 58:94b7fd55185e | 556 | headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
tnhnrl | 58:94b7fd55185e | 557 | |
tnhnrl | 74:d281aaef9766 | 558 | xbee().printf("POS RISE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position |
tnhnrl | 74:d281aaef9766 | 559 | xbee().printf("POS RISE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position |
tnhnrl | 74:d281aaef9766 | 560 | xbee().printf("POS RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
tnhnrl | 58:94b7fd55185e | 561 | } |
tnhnrl | 58:94b7fd55185e | 562 | |
tnhnrl | 58:94b7fd55185e | 563 | // how exit? |
tnhnrl | 73:f6f378311c8d | 564 | if (_fsm_timer.read() > _timeout) { |
tnhnrl | 74:d281aaef9766 | 565 | xbee().printf("POS RISE: timed out\r\n"); |
tnhnrl | 58:94b7fd55185e | 566 | _state = EMERGENCY_CLIMB; |
tnhnrl | 73:f6f378311c8d | 567 | _fsm_timer.reset(); |
tnhnrl | 58:94b7fd55185e | 568 | _isTimeoutRunning = false; |
tnhnrl | 58:94b7fd55185e | 569 | } |
tnhnrl | 58:94b7fd55185e | 570 | else if (depthLoop().getPosition() < 0.5) { |
tnhnrl | 74:d281aaef9766 | 571 | xbee().printf("POS RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
tnhnrl | 58:94b7fd55185e | 572 | _state = FLOAT_BROADCAST; |
tnhnrl | 73:f6f378311c8d | 573 | _fsm_timer.reset(); |
tnhnrl | 58:94b7fd55185e | 574 | _isTimeoutRunning = false; |
tnhnrl | 58:94b7fd55185e | 575 | } |
tnhnrl | 58:94b7fd55185e | 576 | |
tnhnrl | 58:94b7fd55185e | 577 | // what is active? |
joel_ssc | 82:0981b9ada820 | 578 | xbee().printf("POS RISE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", |
joel_ssc | 82:0981b9ada820 | 579 | bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(), |
joel_ssc | 82:0981b9ada820 | 580 | rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 58:94b7fd55185e | 581 | |
tnhnrl | 58:94b7fd55185e | 582 | // ACTIVE RUDDER CONTROL |
tnhnrl | 58:94b7fd55185e | 583 | rudder().setPosition_deg(headingLoop().getOutput()); |
tnhnrl | 58:94b7fd55185e | 584 | |
joel_ssc | 82:0981b9ada820 | 585 | break; //end of POS RISE |
joel_ssc | 82:0981b9ada820 | 586 | |
joel_ssc | 82:0981b9ada820 | 587 | case LEG_POSITION_RISE : |
joel_ssc | 82:0981b9ada820 | 588 | // start local state timer and init any other one-shot actions |
joel_ssc | 82:0981b9ada820 | 589 | leg_min_depth = currentLegStateStruct.min_depth; |
joel_ssc | 82:0981b9ada820 | 590 | leg_heading = currentLegStateStruct.heading; |
joel_ssc | 82:0981b9ada820 | 591 | |
joel_ssc | 82:0981b9ada820 | 592 | if (!_isTimeoutRunning) { // this should never occur. the only entry into this case is from LEG_POSITION_DIVE exit |
joel_ssc | 82:0981b9ada820 | 593 | xbee().printf("\r\n\nstate: LEG POSITION RISE\r\n"); |
joel_ssc | 82:0981b9ada820 | 594 | sprintf(buf, "state: LEG POSITION RISE entered with timeout NOT running should not happen\n\n\r"); |
joel_ssc | 82:0981b9ada820 | 595 | mbedLogger().appendDiagFile(buf,3); |
joel_ssc | 82:0981b9ada820 | 596 | //_fsm_timer.reset(); // timer goes back to zero --no |
joel_ssc | 82:0981b9ada820 | 597 | _fsm_timer.start(); // background timer starts running |
joel_ssc | 82:0981b9ada820 | 598 | _isTimeoutRunning = true; |
joel_ssc | 82:0981b9ada820 | 599 | _yotimer.reset(); //reset yo_timer; |
joel_ssc | 82:0981b9ada820 | 600 | _yotimer.start(); //and start it |
joel_ssc | 82:0981b9ada820 | 601 | |
joel_ssc | 82:0981b9ada820 | 602 | // what needs to be started? |
joel_ssc | 82:0981b9ada820 | 603 | bce().unpause(); |
joel_ssc | 82:0981b9ada820 | 604 | batt().unpause(); |
joel_ssc | 82:0981b9ada820 | 605 | stateMachine().getLegParams(); |
joel_ssc | 82:0981b9ada820 | 606 | |
joel_ssc | 82:0981b9ada820 | 607 | // what are the commands? (using inner loops except for heading outer loop) |
joel_ssc | 82:0981b9ada820 | 608 | batt().setPosition_mm(_neutral_batt_pos_mm - _BMM_dive_offset); //reversing the BCE and BATT positions |
joel_ssc | 82:0981b9ada820 | 609 | bce().setPosition_mm(_neutral_bce_pos_mm + _BCE_dive_offset); //reversing the BCE and BATT positions |
joel_ssc | 82:0981b9ada820 | 610 | //retrieve commands from structs (loaded from missionleg.cfg file) |
joel_ssc | 82:0981b9ada820 | 611 | |
joel_ssc | 82:0981b9ada820 | 612 | headingLoop().setCommand(leg_heading); //ACTIVE HEADING (mimic of dive and rise code) |
joel_ssc | 82:0981b9ada820 | 613 | |
joel_ssc | 82:0981b9ada820 | 614 | xbee().printf("LEG POS RISE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 615 | xbee().printf("LEG POS RISE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 616 | xbee().printf("LEG POS RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 617 | lpr_oneshots = 1; |
joel_ssc | 82:0981b9ada820 | 618 | } |
joel_ssc | 82:0981b9ada820 | 619 | if (!lpr_oneshots) { |
joel_ssc | 82:0981b9ada820 | 620 | xbee().printf("\r\n\nstate: LEG POSITION RISE entered via LEG_POSiTION_DIVE finish\r\n"); |
joel_ssc | 84:eccd8e837134 | 621 | sprintf(buf, "state: LEG POSITION RISE entered via LEG_POSITION_DIVE\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 622 | mbedLogger().appendDiagFile(buf,3); |
joel_ssc | 82:0981b9ada820 | 623 | //_fsm_timer.reset(); // timer goes back to zero --no |
joel_ssc | 82:0981b9ada820 | 624 | _yotimer.reset(); //reset yo_timer; |
joel_ssc | 82:0981b9ada820 | 625 | _yotimer.start(); //and start it |
joel_ssc | 82:0981b9ada820 | 626 | //_fsm_timer.start(); timer is already running // background timer starts running |
joel_ssc | 82:0981b9ada820 | 627 | // _isTimeoutRunning = true; |
joel_ssc | 82:0981b9ada820 | 628 | |
joel_ssc | 82:0981b9ada820 | 629 | // what needs to be started? |
joel_ssc | 82:0981b9ada820 | 630 | bce().unpause(); |
joel_ssc | 82:0981b9ada820 | 631 | batt().unpause(); |
joel_ssc | 82:0981b9ada820 | 632 | |
joel_ssc | 82:0981b9ada820 | 633 | // what are the commands? (using inner loops except for heading outer loop) |
joel_ssc | 82:0981b9ada820 | 634 | batt().setPosition_mm(_neutral_batt_pos_mm - _BMM_dive_offset); //reversing the BCE and BATT positions |
joel_ssc | 82:0981b9ada820 | 635 | bce().setPosition_mm(_neutral_bce_pos_mm + _BCE_dive_offset); //reversing the BCE and BATT positions |
joel_ssc | 82:0981b9ada820 | 636 | //retrieve commands from structs (loaded from missionleg.cfg file) |
joel_ssc | 82:0981b9ada820 | 637 | |
joel_ssc | 82:0981b9ada820 | 638 | headingLoop().setCommand(leg_heading); //ACTIVE HEADING (mimic of dive and rise code) |
joel_ssc | 82:0981b9ada820 | 639 | |
joel_ssc | 82:0981b9ada820 | 640 | xbee().printf("LEG POS RISE: BATT cmd: %3.1f\r\n",batt().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 641 | xbee().printf("LEG POS RISE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position |
joel_ssc | 82:0981b9ada820 | 642 | xbee().printf("LEG POS RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 643 | lpr_oneshots = 1; |
joel_ssc | 84:eccd8e837134 | 644 | } // end if(!lpr_oneshots) |
joel_ssc | 82:0981b9ada820 | 645 | |
joel_ssc | 82:0981b9ada820 | 646 | // how exit? |
joel_ssc | 82:0981b9ada820 | 647 | if (_fsm_timer.read() > _timeout) { |
joel_ssc | 82:0981b9ada820 | 648 | xbee().printf("LEG POS RISE: timed out on overall timeout\r\n"); |
joel_ssc | 84:eccd8e837134 | 649 | // _state = EMERGENCY_CLIMB; |
joel_ssc | 84:eccd8e837134 | 650 | finish_leg = 1; // not going immediately to Emergency_climb and not resetting timers means it will take 1 yo-time of rising first |
joel_ssc | 84:eccd8e837134 | 651 | // _fsm_timer.reset(); |
joel_ssc | 84:eccd8e837134 | 652 | sprintf(buf, "LEG POSITION DIVE Ended via overall timeout\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 653 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 84:eccd8e837134 | 654 | // _isTimeoutRunning = false; |
joel_ssc | 82:0981b9ada820 | 655 | } |
joel_ssc | 84:eccd8e837134 | 656 | else if (depthLoop().getPosition() < leg_min_depth - 0.5 ) { // add in check for finish_leg. Don't flip flop between states in that case |
joel_ssc | 82:0981b9ada820 | 657 | xbee().printf("LEG POS RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
joel_ssc | 82:0981b9ada820 | 658 | _state = LEG_POSITION_DIVE; |
joel_ssc | 84:eccd8e837134 | 659 | sprintf(buf, "LEG POSITION RISE flip-flops to LEG_POSITION_DIVE on near surface pressure \n\n\r"); |
joel_ssc | 84:eccd8e837134 | 660 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 82:0981b9ada820 | 661 | //_fsm_timer.reset(); |
joel_ssc | 82:0981b9ada820 | 662 | //_isTimeoutRunning = false; |
joel_ssc | 82:0981b9ada820 | 663 | lpd_oneshots=0; |
joel_ssc | 84:eccd8e837134 | 664 | if(finish_leg ==1) { |
joel_ssc | 84:eccd8e837134 | 665 | _state = EMERGENCY_CLIMB; |
joel_ssc | 84:eccd8e837134 | 666 | _fsm_timer.reset(); _yotimer.reset(); |
joel_ssc | 84:eccd8e837134 | 667 | _isTimeoutRunning = false; |
joel_ssc | 84:eccd8e837134 | 668 | sprintf(buf, "LEG POSITION RISE ... ENDS, and since finish_leg=1, go to Emergency climb\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 669 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 84:eccd8e837134 | 670 | } |
joel_ssc | 82:0981b9ada820 | 671 | } |
joel_ssc | 82:0981b9ada820 | 672 | else if(_yotimer.read() > _yo_time ) { |
joel_ssc | 82:0981b9ada820 | 673 | xbee().printf("LEG POS RISE: yo_time timed out - go to Emergency_CLIMB. Actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
joel_ssc | 84:eccd8e837134 | 674 | _state = EMERGENCY_CLIMB; // add diagnostics message |
joel_ssc | 82:0981b9ada820 | 675 | finish_leg = 1; |
joel_ssc | 84:eccd8e837134 | 676 | _fsm_timer.reset(); _yotimer.reset(); |
joel_ssc | 82:0981b9ada820 | 677 | _isTimeoutRunning = false; |
joel_ssc | 84:eccd8e837134 | 678 | sprintf(buf, "LEG POSITION DIVE ... ENDS on yo_time too long, exit to emergnecy climb + finish_leg=1\n\n\r"); |
joel_ssc | 84:eccd8e837134 | 679 | mbedLogger().appendDiagFile(buf,0); |
joel_ssc | 82:0981b9ada820 | 680 | } |
joel_ssc | 82:0981b9ada820 | 681 | |
joel_ssc | 82:0981b9ada820 | 682 | // what is active? |
joel_ssc | 82:0981b9ada820 | 683 | xbee().printf("LEG POS RISE: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", |
joel_ssc | 82:0981b9ada820 | 684 | bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(), |
joel_ssc | 82:0981b9ada820 | 685 | rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); |
joel_ssc | 82:0981b9ada820 | 686 | |
joel_ssc | 82:0981b9ada820 | 687 | // ACTIVE RUDDER CONTROL |
joel_ssc | 82:0981b9ada820 | 688 | rudder().setPosition_deg(headingLoop().getOutput()); |
joel_ssc | 82:0981b9ada820 | 689 | |
joel_ssc | 82:0981b9ada820 | 690 | break; // end LEG POS RISE |
tnhnrl | 58:94b7fd55185e | 691 | // NEW DIVE AND RISE SEQUENCES |
tnhnrl | 16:3363b9f14913 | 692 | |
tnhnrl | 16:3363b9f14913 | 693 | case FLOAT_LEVEL : |
tnhnrl | 16:3363b9f14913 | 694 | // start local state timer and init any other one-shot actions |
tnhnrl | 28:16c83a2fdefa | 695 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 696 | xbee().printf("\r\n\nstate: FLOAT_LEVEL\r\n"); |
tnhnrl | 73:f6f378311c8d | 697 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 698 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 28:16c83a2fdefa | 699 | _isTimeoutRunning = true; |
tnhnrl | 16:3363b9f14913 | 700 | |
tnhnrl | 16:3363b9f14913 | 701 | // what needs to be started? |
tnhnrl | 16:3363b9f14913 | 702 | bce().unpause(); |
tnhnrl | 16:3363b9f14913 | 703 | batt().unpause(); |
tnhnrl | 16:3363b9f14913 | 704 | |
tnhnrl | 20:8987a9ae2bc7 | 705 | // what are the commands? |
tnhnrl | 28:16c83a2fdefa | 706 | bce().setPosition_mm(_bceFloatPosition); |
tnhnrl | 16:3363b9f14913 | 707 | pitchLoop().setCommand(0.0); |
tnhnrl | 16:3363b9f14913 | 708 | } |
tnhnrl | 20:8987a9ae2bc7 | 709 | |
tnhnrl | 16:3363b9f14913 | 710 | // how exit? |
tnhnrl | 73:f6f378311c8d | 711 | if (_fsm_timer > _timeout) { |
tnhnrl | 74:d281aaef9766 | 712 | xbee().printf("FL: timed out\r\n"); |
tnhnrl | 21:38c8544db6f4 | 713 | _state = FLOAT_BROADCAST; |
tnhnrl | 73:f6f378311c8d | 714 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 715 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 716 | } |
tnhnrl | 28:16c83a2fdefa | 717 | else if (fabs(imu().getPitch() - pitchLoop().getCommand()) < fabs(_pitchTolerance)) { //current tolerance is 5 degrees |
tnhnrl | 74:d281aaef9766 | 718 | xbee().printf("FL: pitch: %3.1f mm, set pos: %3.1f mm, deadband: %3.1f mm\r\n",imu().getPitch(), pitchLoop().getCommand(), _pitchTolerance); |
tnhnrl | 21:38c8544db6f4 | 719 | _state = FLOAT_BROADCAST; |
tnhnrl | 73:f6f378311c8d | 720 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 721 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 722 | } |
tnhnrl | 20:8987a9ae2bc7 | 723 | |
tnhnrl | 16:3363b9f14913 | 724 | // what is active? |
tnhnrl | 74:d281aaef9766 | 725 | xbee().printf("FL: pitchLoop output: %3.1f, batt pos: %3.1f, piston pos: %3.1f [%0.1f sec]\r", pitchLoop().getOutput(), batt().getPosition_mm(), bce().getPosition_mm(), _fsm_timer.read()); |
tnhnrl | 16:3363b9f14913 | 726 | batt().setPosition_mm(pitchLoop().getOutput()); |
tnhnrl | 32:f2f8ae34aadc | 727 | |
tnhnrl | 16:3363b9f14913 | 728 | break; |
tnhnrl | 16:3363b9f14913 | 729 | |
tnhnrl | 16:3363b9f14913 | 730 | case FLOAT_BROADCAST : |
tnhnrl | 16:3363b9f14913 | 731 | // start local state timer and init any other one-shot actions |
tnhnrl | 28:16c83a2fdefa | 732 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 733 | xbee().printf("\r\n\nstate: FLOAT_BROADCAST\r\n"); |
tnhnrl | 73:f6f378311c8d | 734 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 735 | _fsm_timer.start(); // background timer starts running |
joel_ssc | 84:eccd8e837134 | 736 | _yotimer.reset(); |
joel_ssc | 84:eccd8e837134 | 737 | _yotimer.start(); |
tnhnrl | 28:16c83a2fdefa | 738 | _isTimeoutRunning = true; |
tnhnrl | 16:3363b9f14913 | 739 | |
tnhnrl | 16:3363b9f14913 | 740 | // what needs to be started? |
tnhnrl | 16:3363b9f14913 | 741 | bce().unpause(); |
tnhnrl | 16:3363b9f14913 | 742 | batt().unpause(); |
tnhnrl | 20:8987a9ae2bc7 | 743 | |
tnhnrl | 16:3363b9f14913 | 744 | // what are the commands? |
tnhnrl | 55:f4ec445c42fe | 745 | bce().setPosition_mm(_bceFloatPosition); // 320.0 |
tnhnrl | 55:f4ec445c42fe | 746 | batt().setPosition_mm(_battFloatPosition); // 73.0 |
tnhnrl | 74:d281aaef9766 | 747 | |
tnhnrl | 74:d281aaef9766 | 748 | //set rudder to center |
tnhnrl | 74:d281aaef9766 | 749 | rudder().setPosition_deg(0.0); //set rudder to center, zero degrees |
tnhnrl | 16:3363b9f14913 | 750 | } |
tnhnrl | 20:8987a9ae2bc7 | 751 | |
tnhnrl | 16:3363b9f14913 | 752 | // how exit? |
joel_ssc | 82:0981b9ada820 | 753 | |
joel_ssc | 84:eccd8e837134 | 754 | if (_fsm_timer > _timeout || ( _yotimer > _state_transition_time)) { |
tnhnrl | 74:d281aaef9766 | 755 | xbee().printf("FB: timed out\r\n"); |
tnhnrl | 21:38c8544db6f4 | 756 | _state = SIT_IDLE; |
tnhnrl | 73:f6f378311c8d | 757 | _fsm_timer.reset(); |
tnhnrl | 32:f2f8ae34aadc | 758 | |
tnhnrl | 32:f2f8ae34aadc | 759 | //stop recording data |
tnhnrl | 35:2f66ea4863d5 | 760 | //mbedLogger().closeFile(); |
tnhnrl | 32:f2f8ae34aadc | 761 | |
tnhnrl | 28:16c83a2fdefa | 762 | _isTimeoutRunning = false; |
joel_ssc | 82:0981b9ada820 | 763 | if(finish_leg == 1) { _state = FB_EXIT; } // allows exit if finish_leg set by leg_POS_dive, or LEG_POS_RISE timeout or too slow yo |
tnhnrl | 16:3363b9f14913 | 764 | } |
tnhnrl | 74:d281aaef9766 | 765 | |
tnhnrl | 74:d281aaef9766 | 766 | //fix on float_broadcast to account for BCE stopping early in current hardware |
tnhnrl | 74:d281aaef9766 | 767 | else if ( (fabs(bce().getPosition_mm() - bce().getSetPosition_mm()) < 4.0 ) and |
tnhnrl | 20:8987a9ae2bc7 | 768 | (fabs(batt().getPosition_mm() - batt().getSetPosition_mm()) < batt().getDeadband()) ) { |
tnhnrl | 74:d281aaef9766 | 769 | xbee().printf("FB: position: %3.1f mm, set pos: %3.1f mm, deadband: %3.1f mm\r\n",bce().getPosition_mm(), bce().getSetPosition_mm(), bce().getDeadband()); |
tnhnrl | 21:38c8544db6f4 | 770 | _state = SIT_IDLE; |
tnhnrl | 73:f6f378311c8d | 771 | _fsm_timer.reset(); |
tnhnrl | 32:f2f8ae34aadc | 772 | |
tnhnrl | 32:f2f8ae34aadc | 773 | //stop recording data |
tnhnrl | 35:2f66ea4863d5 | 774 | //mbedLogger().closeFile(); |
joel_ssc | 84:eccd8e837134 | 775 | if(finish_leg == 1) { _state = FB_EXIT; } // allows exit if finish_leg set by leg_POS_dive, or LEG_POS_RISE timeout or too slow yo |
tnhnrl | 28:16c83a2fdefa | 776 | _isTimeoutRunning = false; |
tnhnrl | 16:3363b9f14913 | 777 | } |
tnhnrl | 20:8987a9ae2bc7 | 778 | |
tnhnrl | 20:8987a9ae2bc7 | 779 | // what is active? |
joel_ssc | 82:0981b9ada820 | 780 | xbee().printf("FB: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg, heading_imu:%6.1f deg>>[%0.2f sec] \r", |
joel_ssc | 82:0981b9ada820 | 781 | bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(), |
joel_ssc | 82:0981b9ada820 | 782 | depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 32:f2f8ae34aadc | 783 | |
joel_ssc | 82:0981b9ada820 | 784 | if (finish_leg == 1) { _state = FB_EXIT;} |
tnhnrl | 16:3363b9f14913 | 785 | break; |
tnhnrl | 17:7c16b5671d0e | 786 | |
tnhnrl | 17:7c16b5671d0e | 787 | case MULTI_DIVE : |
tnhnrl | 17:7c16b5671d0e | 788 | // start local state timer and init any other one-shot actions |
tnhnrl | 28:16c83a2fdefa | 789 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 790 | xbee().printf("\r\n\nstate: MULTI-DIVE\r\n"); |
tnhnrl | 73:f6f378311c8d | 791 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 792 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 28:16c83a2fdefa | 793 | _isTimeoutRunning = true; |
tnhnrl | 17:7c16b5671d0e | 794 | |
tnhnrl | 17:7c16b5671d0e | 795 | // what needs to be started? |
tnhnrl | 17:7c16b5671d0e | 796 | bce().unpause(); |
tnhnrl | 17:7c16b5671d0e | 797 | batt().unpause(); |
tnhnrl | 17:7c16b5671d0e | 798 | |
tnhnrl | 21:38c8544db6f4 | 799 | //retrieve commands from structs (loaded from sequence.cfg file) |
tnhnrl | 32:f2f8ae34aadc | 800 | float sequence_depth_command = currentStateStruct.depth; |
tnhnrl | 32:f2f8ae34aadc | 801 | float sequence_pitch_command = currentStateStruct.pitch; |
tnhnrl | 17:7c16b5671d0e | 802 | |
tnhnrl | 17:7c16b5671d0e | 803 | // what are the commands? |
tnhnrl | 32:f2f8ae34aadc | 804 | depthLoop().setCommand(sequence_depth_command); |
tnhnrl | 32:f2f8ae34aadc | 805 | pitchLoop().setCommand(sequence_pitch_command); |
tnhnrl | 74:d281aaef9766 | 806 | |
tnhnrl | 74:d281aaef9766 | 807 | |
tnhnrl | 74:d281aaef9766 | 808 | headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
tnhnrl | 74:d281aaef9766 | 809 | xbee().printf("MULTI-DIVE: depth cmd: %3.1f ft, pitch cmd: %3.1f deg\r\n",depthLoop().getCommand(), pitchLoop().getCommand()); |
tnhnrl | 32:f2f8ae34aadc | 810 | |
tnhnrl | 32:f2f8ae34aadc | 811 | //no max depth recording right now |
tnhnrl | 17:7c16b5671d0e | 812 | } |
tnhnrl | 20:8987a9ae2bc7 | 813 | |
tnhnrl | 17:7c16b5671d0e | 814 | // how exit? |
tnhnrl | 73:f6f378311c8d | 815 | if (_fsm_timer > _timeout) { |
tnhnrl | 74:d281aaef9766 | 816 | xbee().printf("\r\n\nMULTI-DIVE: timed out [time: %0.1f]\r\n\n", _fsm_timer.read()); |
tnhnrl | 21:38c8544db6f4 | 817 | _state = MULTI_RISE; //new behavior 11/17/2017 |
tnhnrl | 73:f6f378311c8d | 818 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 819 | _isTimeoutRunning = false; |
tnhnrl | 17:7c16b5671d0e | 820 | } |
tnhnrl | 17:7c16b5671d0e | 821 | else if (depthLoop().getPosition() > depthLoop().getCommand()) { |
tnhnrl | 74:d281aaef9766 | 822 | xbee().printf("MULTI-DIVE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
tnhnrl | 21:38c8544db6f4 | 823 | _state = MULTI_RISE; |
tnhnrl | 73:f6f378311c8d | 824 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 825 | _isTimeoutRunning = false; |
tnhnrl | 17:7c16b5671d0e | 826 | } |
tnhnrl | 20:8987a9ae2bc7 | 827 | |
tnhnrl | 67:c86a4b464682 | 828 | // WHAT IS ACTIVE? |
tnhnrl | 74:d281aaef9766 | 829 | xbee().printf("MD: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 17:7c16b5671d0e | 830 | bce().setPosition_mm(depthLoop().getOutput()); |
tnhnrl | 17:7c16b5671d0e | 831 | batt().setPosition_mm(pitchLoop().getOutput()); |
tnhnrl | 32:f2f8ae34aadc | 832 | |
tnhnrl | 74:d281aaef9766 | 833 | // ACTIVE RUDDER CONTROL |
tnhnrl | 74:d281aaef9766 | 834 | rudder().setPosition_deg(headingLoop().getOutput()); |
tnhnrl | 32:f2f8ae34aadc | 835 | |
tnhnrl | 17:7c16b5671d0e | 836 | break; |
tnhnrl | 17:7c16b5671d0e | 837 | |
tnhnrl | 17:7c16b5671d0e | 838 | case MULTI_RISE : |
tnhnrl | 17:7c16b5671d0e | 839 | // start local state timer and init any other one-shot actions |
tnhnrl | 28:16c83a2fdefa | 840 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 841 | xbee().printf("\r\n\nstate: MULTI-RISE\r\n"); |
tnhnrl | 73:f6f378311c8d | 842 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 843 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 28:16c83a2fdefa | 844 | _isTimeoutRunning = true; |
tnhnrl | 17:7c16b5671d0e | 845 | |
tnhnrl | 17:7c16b5671d0e | 846 | // what needs to be started? |
tnhnrl | 17:7c16b5671d0e | 847 | bce().unpause(); |
tnhnrl | 17:7c16b5671d0e | 848 | batt().unpause(); |
tnhnrl | 17:7c16b5671d0e | 849 | |
tnhnrl | 17:7c16b5671d0e | 850 | //NEW: retrieve depth and pitch commands from config file struct |
tnhnrl | 17:7c16b5671d0e | 851 | // concept is to load this each time the multi-dive restarts |
tnhnrl | 17:7c16b5671d0e | 852 | stateMachine().getDiveSequence(); |
tnhnrl | 17:7c16b5671d0e | 853 | |
tnhnrl | 17:7c16b5671d0e | 854 | //retrieve just pitch command from struct |
tnhnrl | 32:f2f8ae34aadc | 855 | float sequence_pitch_command = currentStateStruct.pitch; |
tnhnrl | 17:7c16b5671d0e | 856 | |
tnhnrl | 17:7c16b5671d0e | 857 | // what are the commands? (send back to 0.5 feet, not surface) // 11/21/2017 |
tnhnrl | 17:7c16b5671d0e | 858 | depthLoop().setCommand(0.5); |
tnhnrl | 32:f2f8ae34aadc | 859 | pitchLoop().setCommand(-sequence_pitch_command); |
tnhnrl | 74:d281aaef9766 | 860 | |
tnhnrl | 74:d281aaef9766 | 861 | headingLoop().setCommand(_heading_command); //ACTIVE HEADING (mimic of dive and rise code) |
tnhnrl | 74:d281aaef9766 | 862 | xbee().printf("MULTI-RISE: depth cmd: 0.0 ft, pitch cmd: %3.1f deg\r\n",depthLoop().getCommand(), pitchLoop().getCommand()); |
tnhnrl | 17:7c16b5671d0e | 863 | } |
tnhnrl | 20:8987a9ae2bc7 | 864 | |
tnhnrl | 17:7c16b5671d0e | 865 | // how exit? |
tnhnrl | 73:f6f378311c8d | 866 | if (_fsm_timer > _timeout) { |
tnhnrl | 74:d281aaef9766 | 867 | xbee().printf("MULTI-RISE: timed out [time: %0.1f]\r\n\n", _fsm_timer.read()); |
tnhnrl | 21:38c8544db6f4 | 868 | _state = EMERGENCY_CLIMB; |
tnhnrl | 73:f6f378311c8d | 869 | _fsm_timer.reset(); |
tnhnrl | 28:16c83a2fdefa | 870 | _isTimeoutRunning = false; |
tnhnrl | 17:7c16b5671d0e | 871 | |
tnhnrl | 17:7c16b5671d0e | 872 | //reset multi-dive sequence to start |
tnhnrl | 24:c7d9b5bf3829 | 873 | _multi_dive_counter = 0; |
tnhnrl | 63:6cb0405fc6e6 | 874 | |
tnhnrl | 68:8f549749b8ce | 875 | // //Reload the dive sequence on exit |
tnhnrl | 68:8f549749b8ce | 876 | // sequenceController().loadSequence(); |
tnhnrl | 17:7c16b5671d0e | 877 | } |
tnhnrl | 20:8987a9ae2bc7 | 878 | else if (depthLoop().getPosition() < 0.5) { // depth is less than 0.5 (zero is surface level) |
tnhnrl | 74:d281aaef9766 | 879 | xbee().printf("MULTI-RISE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); |
tnhnrl | 17:7c16b5671d0e | 880 | |
tnhnrl | 17:7c16b5671d0e | 881 | //going to next state |
tnhnrl | 28:16c83a2fdefa | 882 | _isTimeoutRunning = false; |
tnhnrl | 17:7c16b5671d0e | 883 | |
tnhnrl | 17:7c16b5671d0e | 884 | //successful dive-rise sequence CONTINUES the multi-dive sequence |
tnhnrl | 24:c7d9b5bf3829 | 885 | _multi_dive_counter++; |
tnhnrl | 17:7c16b5671d0e | 886 | |
tnhnrl | 17:7c16b5671d0e | 887 | //UPDATE THE SEQUENCE DATA HERE |
tnhnrl | 17:7c16b5671d0e | 888 | stateMachine().getDiveSequence(); |
tnhnrl | 17:7c16b5671d0e | 889 | |
tnhnrl | 17:7c16b5671d0e | 890 | //check if this is the end of the dive sequence |
tnhnrl | 30:2964617e7676 | 891 | //CHECK BEFORE ANYTHING ELSE that you have reached the "exit" state (FLOAT_BROADCAST) |
tnhnrl | 30:2964617e7676 | 892 | if (currentStateStruct.state == FLOAT_BROADCAST) { |
tnhnrl | 68:8f549749b8ce | 893 | // //Reload the dive sequence on exit |
tnhnrl | 68:8f549749b8ce | 894 | // sequenceController().loadSequence(); |
tnhnrl | 63:6cb0405fc6e6 | 895 | |
tnhnrl | 28:16c83a2fdefa | 896 | _state = FLOAT_BROADCAST; |
tnhnrl | 17:7c16b5671d0e | 897 | } |
tnhnrl | 17:7c16b5671d0e | 898 | |
tnhnrl | 17:7c16b5671d0e | 899 | else |
tnhnrl | 63:6cb0405fc6e6 | 900 | _state = MULTI_DIVE; //Note: need to test if this else statement is necessary |
tnhnrl | 17:7c16b5671d0e | 901 | |
tnhnrl | 24:c7d9b5bf3829 | 902 | //have to stop this with the _multi_dive_counter variable! |
tnhnrl | 17:7c16b5671d0e | 903 | } |
tnhnrl | 20:8987a9ae2bc7 | 904 | |
tnhnrl | 67:c86a4b464682 | 905 | // WHAT IS ACTIVE? |
tnhnrl | 74:d281aaef9766 | 906 | xbee().printf("MR: BcePos (cmd):%6.1f mm(%0.1f), BattPos:%6.1f mm(%0.1f), RUD_deg_cmd: %5.1f <<current depth:%6.1f ft [cmd:%6.1f]), pitch:%6.1f deg [cmd:%6.1f], heading_imu:%6.1f deg>>[%0.2f sec] \r", bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),depthLoop().getCommand(),pitchLoop().getPosition(),pitchLoop().getCommand(),imu().getHeading(),_fsm_timer.read()); |
tnhnrl | 17:7c16b5671d0e | 907 | bce().setPosition_mm(depthLoop().getOutput()); //constantly checking the Outer Loop output to move the motors |
tnhnrl | 17:7c16b5671d0e | 908 | batt().setPosition_mm(pitchLoop().getOutput()); |
tnhnrl | 32:f2f8ae34aadc | 909 | |
tnhnrl | 74:d281aaef9766 | 910 | // ACTIVE RUDDER CONTROL |
tnhnrl | 74:d281aaef9766 | 911 | rudder().setPosition_deg(headingLoop().getOutput()); |
tnhnrl | 32:f2f8ae34aadc | 912 | |
tnhnrl | 17:7c16b5671d0e | 913 | break; |
tnhnrl | 32:f2f8ae34aadc | 914 | |
tnhnrl | 71:939d179478c4 | 915 | case TX_MBED_LOG: |
tnhnrl | 63:6cb0405fc6e6 | 916 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 917 | xbee().printf("\r\n\nstate: TX_MBED_LOG\r\n"); |
tnhnrl | 73:f6f378311c8d | 918 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 919 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 32:f2f8ae34aadc | 920 | _isTimeoutRunning = true; |
tnhnrl | 32:f2f8ae34aadc | 921 | |
tnhnrl | 68:8f549749b8ce | 922 | //mbedLogger().openFileForTransmit(); //starts _fp file pointer at the beginning of the file |
tnhnrl | 68:8f549749b8ce | 923 | |
tnhnrl | 74:d281aaef9766 | 924 | xbee().printf("TX_MBED_LOG set to zero\n\r"); |
tnhnrl | 45:16b8162188ca | 925 | |
tnhnrl | 69:919ac8d7e023 | 926 | //function to read the file and get number of lines (packets to transmit) |
tnhnrl | 69:919ac8d7e023 | 927 | _timeout = mbedLogger().getNumberOfPacketsInCurrentLog(); |
tnhnrl | 68:8f549749b8ce | 928 | |
tnhnrl | 68:8f549749b8ce | 929 | mbedLogger().setTransmitPacketNumber(0); //reset to zero |
tnhnrl | 45:16b8162188ca | 930 | } |
tnhnrl | 45:16b8162188ca | 931 | |
tnhnrl | 69:919ac8d7e023 | 932 | //TIMED OUT |
tnhnrl | 73:f6f378311c8d | 933 | if (_fsm_timer.read() > _timeout) { |
tnhnrl | 74:d281aaef9766 | 934 | xbee().printf("\r\nTX_MBED_LOG: timed out!\r\n"); |
tnhnrl | 63:6cb0405fc6e6 | 935 | |
tnhnrl | 63:6cb0405fc6e6 | 936 | //STATE |
tnhnrl | 45:16b8162188ca | 937 | _state = SIT_IDLE; |
tnhnrl | 63:6cb0405fc6e6 | 938 | |
tnhnrl | 73:f6f378311c8d | 939 | _fsm_timer.reset(); |
tnhnrl | 63:6cb0405fc6e6 | 940 | _isTimeoutRunning = false; |
tnhnrl | 63:6cb0405fc6e6 | 941 | |
tnhnrl | 73:f6f378311c8d | 942 | //mbedLogger().closeLogFile(); |
tnhnrl | 74:d281aaef9766 | 943 | xbee().printf("\r\n\nstate: TX_MBED_LOG (log filed closed)\r\n"); |
tnhnrl | 63:6cb0405fc6e6 | 944 | } |
tnhnrl | 63:6cb0405fc6e6 | 945 | |
tnhnrl | 73:f6f378311c8d | 946 | //received end transmission packet (if this is true) |
tnhnrl | 73:f6f378311c8d | 947 | if (mbedLogger().endTransmitPacket()) { |
tnhnrl | 73:f6f378311c8d | 948 | //STATE |
tnhnrl | 73:f6f378311c8d | 949 | led3() = !led3(); |
tnhnrl | 73:f6f378311c8d | 950 | |
tnhnrl | 73:f6f378311c8d | 951 | _state = SIT_IDLE; |
tnhnrl | 73:f6f378311c8d | 952 | |
tnhnrl | 73:f6f378311c8d | 953 | //reset timer |
tnhnrl | 73:f6f378311c8d | 954 | _fsm_timer.reset(); |
tnhnrl | 73:f6f378311c8d | 955 | |
tnhnrl | 73:f6f378311c8d | 956 | //mbedLogger().closeLogFile(); |
tnhnrl | 73:f6f378311c8d | 957 | |
tnhnrl | 74:d281aaef9766 | 958 | xbee().printf("\r\n\nTX_MBED_LOG: Received end transmission packet.)\r\n"); |
tnhnrl | 73:f6f378311c8d | 959 | } |
tnhnrl | 73:f6f378311c8d | 960 | |
tnhnrl | 68:8f549749b8ce | 961 | //What is active? |
tnhnrl | 73:f6f378311c8d | 962 | //mbedLogger().fsmTransmitData(); |
tnhnrl | 69:919ac8d7e023 | 963 | mbedLogger().checkForPythonTransmitRequest(); |
tnhnrl | 73:f6f378311c8d | 964 | led1() = !led1(); |
tnhnrl | 68:8f549749b8ce | 965 | |
tnhnrl | 45:16b8162188ca | 966 | break; |
tnhnrl | 45:16b8162188ca | 967 | |
tnhnrl | 74:d281aaef9766 | 968 | case RX_SEQUENCE : |
tnhnrl | 74:d281aaef9766 | 969 | xbee().printf("state: RX_SEQUENCE\r\n"); |
tnhnrl | 45:16b8162188ca | 970 | |
tnhnrl | 45:16b8162188ca | 971 | if (!_isTimeoutRunning) { |
tnhnrl | 74:d281aaef9766 | 972 | xbee().printf("RX_SEQUENCE _isTimeoutRunning\r\n"); |
tnhnrl | 73:f6f378311c8d | 973 | _fsm_timer.reset(); // timer goes back to zero |
tnhnrl | 73:f6f378311c8d | 974 | _fsm_timer.start(); // background timer starts running |
tnhnrl | 45:16b8162188ca | 975 | _isTimeoutRunning = true; |
tnhnrl | 45:16b8162188ca | 976 | } |
tnhnrl | 45:16b8162188ca | 977 | |
tnhnrl | 73:f6f378311c8d | 978 | if (_fsm_timer.read() > _timeout) { |
tnhnrl | 74:d281aaef9766 | 979 | xbee().printf("RX_SEQUENCE: timed out!\r\n"); |
tnhnrl | 34:9b66c5188051 | 980 | _state = SIT_IDLE; |
tnhnrl | 73:f6f378311c8d | 981 | _fsm_timer.reset(); |
tnhnrl | 32:f2f8ae34aadc | 982 | _isTimeoutRunning = false; |
tnhnrl | 32:f2f8ae34aadc | 983 | } |
tnhnrl | 32:f2f8ae34aadc | 984 | |
tnhnrl | 45:16b8162188ca | 985 | // what is active? |
tnhnrl | 74:d281aaef9766 | 986 | xbee().printf("Receive sequence active?\r\n"); |
tnhnrl | 32:f2f8ae34aadc | 987 | |
tnhnrl | 32:f2f8ae34aadc | 988 | break; |
tnhnrl | 16:3363b9f14913 | 989 | |
tnhnrl | 16:3363b9f14913 | 990 | default : |
tnhnrl | 74:d281aaef9766 | 991 | xbee().printf("DEBUG: SIT_IDLE\r\n"); |
tnhnrl | 21:38c8544db6f4 | 992 | _state = SIT_IDLE; |
tnhnrl | 28:16c83a2fdefa | 993 | } |
tnhnrl | 28:16c83a2fdefa | 994 | |
tnhnrl | 28:16c83a2fdefa | 995 | //save the state to print to user |
tnhnrl | 28:16c83a2fdefa | 996 | if (_previous_state != _state) { |
tnhnrl | 28:16c83a2fdefa | 997 | _state_array[_state_array_counter] = _state; //save to state array |
tnhnrl | 28:16c83a2fdefa | 998 | _state_array_counter++; |
tnhnrl | 28:16c83a2fdefa | 999 | |
tnhnrl | 28:16c83a2fdefa | 1000 | _previous_state = _state; |
tnhnrl | 28:16c83a2fdefa | 1001 | } |
tnhnrl | 34:9b66c5188051 | 1002 | |
tnhnrl | 34:9b66c5188051 | 1003 | return _state; |
tnhnrl | 73:f6f378311c8d | 1004 | } /* end of runStateMachine */ |
tnhnrl | 20:8987a9ae2bc7 | 1005 | |
tnhnrl | 16:3363b9f14913 | 1006 | // output the keyboard menu for user's reference |
tnhnrl | 69:919ac8d7e023 | 1007 | void StateMachine::printSimpleMenu() { |
tnhnrl | 74:d281aaef9766 | 1008 | xbee().printf("\r\r\n\nSIMPLE KEYBOARD MENU (08/13/2018):\r\r\n"); //make sure depth sensor tares itself on startup |
tnhnrl | 74:d281aaef9766 | 1009 | xbee().printf(" Neutral Positions BCE: %0.1f BMM: %0.1f (LIMIT: BCE: %0.1f BATT: %0.1f)\r\n\n", _neutral_bce_pos_mm, _neutral_batt_pos_mm, bce().getTravelLimit(),batt().getTravelLimit()); |
tnhnrl | 58:94b7fd55185e | 1010 | |
tnhnrl | 74:d281aaef9766 | 1011 | xbee().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1012 | xbee().printf(" J to float level\r\n"); |
tnhnrl | 74:d281aaef9766 | 1013 | xbee().printf(" B to float at broadcast pitch\r\n"); |
tnhnrl | 74:d281aaef9766 | 1014 | xbee().printf(" E to initiate emergency climb\r\n"); |
tnhnrl | 74:d281aaef9766 | 1015 | xbee().printf(" P to print the current log file.\r\n"); |
tnhnrl | 74:d281aaef9766 | 1016 | xbee().printf(" G to transmit MBED log file\r\n"); |
tnhnrl | 74:d281aaef9766 | 1017 | xbee().printf(" I to receive multi-dive sequence file\r\n"); |
tnhnrl | 74:d281aaef9766 | 1018 | xbee().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); |
tnhnrl | 66:0f20870117b7 | 1019 | |
tnhnrl | 74:d281aaef9766 | 1020 | xbee().printf("Q to TYPE in the BMM offset: %0.1f (BMM Dive POS: %0.1f, Rise POS: %0.1f) (positive input offset = pitch down)\r\n",_BMM_dive_offset, _neutral_batt_pos_mm + _BMM_dive_offset, _neutral_batt_pos_mm - _BMM_dive_offset); |
tnhnrl | 74:d281aaef9766 | 1021 | xbee().printf("A to TYPE in the BCE offset: %0.1f (BCE Dive POS: %0.1f, Rise POS: %0.1f) (positive input offset = dive)\r\n",_BCE_dive_offset, _neutral_bce_pos_mm - _BCE_dive_offset, _neutral_bce_pos_mm + _BCE_dive_offset); |
tnhnrl | 74:d281aaef9766 | 1022 | xbee().printf("W to TYPE in the heading command: %0.1f deg (imu heading: %0.1f)\r\n",_heading_command,imu().getHeading()); |
tnhnrl | 74:d281aaef9766 | 1023 | xbee().printf("S to TYPE in depth setpoint: %0.1f (Current depth: %0.1f ft)\r\n",_depth_command, depthLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1024 | xbee().printf("T to TYPE in the timeout (default is 60 seconds): %d s\r\n",_timeout); |
tnhnrl | 58:94b7fd55185e | 1025 | |
tnhnrl | 74:d281aaef9766 | 1026 | xbee().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1027 | xbee().printf(" 8 STREAM SENSOR STATUS (and channel readings)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1028 | xbee().printf(" ? to reset mbed\r\n"); |
tnhnrl | 74:d281aaef9766 | 1029 | xbee().printf(" * (asterisk) to go to DEBUG keyboard menu\r\n"); |
tnhnrl | 57:ec69651c8c21 | 1030 | } |
tnhnrl | 57:ec69651c8c21 | 1031 | |
tnhnrl | 69:919ac8d7e023 | 1032 | void StateMachine::printDebugMenu() { |
tnhnrl | 74:d281aaef9766 | 1033 | xbee().printf("\r\r\n\nDEBUG KEYBOARD MENU (08/08/2018):\r\r\n"); |
tnhnrl | 74:d281aaef9766 | 1034 | xbee().printf(" Y to go into CHECK NEUTRAL TUNING (This is on a timer! Uses NEUTRAL positions!)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1035 | xbee().printf(" N to find neutral\r\n"); |
tnhnrl | 74:d281aaef9766 | 1036 | xbee().printf(" M to initiate multi-dive cycle\r\n"); |
tnhnrl | 74:d281aaef9766 | 1037 | xbee().printf(" D to initiate dive cycle\r\n"); |
tnhnrl | 74:d281aaef9766 | 1038 | xbee().printf(" R to initiate rise\r\n"); |
tnhnrl | 74:d281aaef9766 | 1039 | xbee().printf(" J to float level\r\n"); |
tnhnrl | 74:d281aaef9766 | 1040 | xbee().printf(" B to float at broadcast pitch\r\n"); |
tnhnrl | 74:d281aaef9766 | 1041 | xbee().printf(" E to initiate emergency climb\r\n"); |
tnhnrl | 74:d281aaef9766 | 1042 | xbee().printf(" '}' to HOME the BCE (5 second delay)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1043 | xbee().printf(" '|' to HOME the BMM (5 second delay)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1044 | xbee().printf(" Z to show FSM and sub-FSM states.\r\n"); |
tnhnrl | 74:d281aaef9766 | 1045 | xbee().printf(" P to print the current log file.\r\n"); |
tnhnrl | 74:d281aaef9766 | 1046 | xbee().printf(" X to print the list of log files.\r\n"); |
tnhnrl | 74:d281aaef9766 | 1047 | xbee().printf(" I to receive data.\r\n"); |
tnhnrl | 74:d281aaef9766 | 1048 | xbee().printf(" G to transmit MBED log file (60 second timeout)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1049 | xbee().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1050 | xbee().printf("; or : to TYPE in the BCE neutral position: %0.1f\r\n", _neutral_bce_pos_mm); |
tnhnrl | 74:d281aaef9766 | 1051 | xbee().printf("[ or { to TYPE in the BMM neutral position: %0.1f\r\n", _neutral_batt_pos_mm); |
tnhnrl | 74:d281aaef9766 | 1052 | xbee().printf("Q to TYPE in pitch setpoint: %0.1f (Current IMU pitch: %0.1f deg)\r\n",_pitch_command,imu().getPitch()); |
tnhnrl | 74:d281aaef9766 | 1053 | xbee().printf("A to TYPE in depth setpoint: %0.1f (Current depth: %0.1f ft)\r\n",_depth_command, depthLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1054 | xbee().printf("W to TYPE in the heading command: %0.1f deg (imu heading: %0.1f)\r\n",_heading_command,imu().getHeading()); |
tnhnrl | 74:d281aaef9766 | 1055 | xbee().printf("T to enter in the timeout (default is 60 seconds): %d s\r\n",_timeout); |
tnhnrl | 58:94b7fd55185e | 1056 | |
tnhnrl | 74:d281aaef9766 | 1057 | xbee().printf(" 1 BCE PID sub-menu (type in inputs)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1058 | xbee().printf(" 2 BATT PID sub-menu (type in inputs)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1059 | xbee().printf(" 3 Depth PID sub-menu (type in inputs)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1060 | xbee().printf(" 4 Pitch PID sub-menu (type in inputs)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1061 | xbee().printf(" 5 Rudder (servo) sub-menu\r\n"); |
tnhnrl | 74:d281aaef9766 | 1062 | xbee().printf(" 6 HEADING PID sub-menu (type in inputs)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1063 | xbee().printf(" 7 MANUAL_TUNING sub-menu (does not have a timer!) *** MOTORS ARE ACTIVE *** (bce 200, bmm 40, rudder 1640)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1064 | xbee().printf(" 8 STREAM SENSOR STATUS (and channel readings)\r\n"); |
tnhnrl | 53:c0586fe62b01 | 1065 | |
tnhnrl | 74:d281aaef9766 | 1066 | xbee().printf(" C See sensor readings (and max recorded depth of dive & neutral sequences)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1067 | xbee().printf(" ? to reset mbed\r\n"); |
tnhnrl | 74:d281aaef9766 | 1068 | xbee().printf(" * (asterisk) to go to SIMPLE keyboard menu\r\n"); |
tnhnrl | 16:3363b9f14913 | 1069 | } |
tnhnrl | 20:8987a9ae2bc7 | 1070 | |
tnhnrl | 74:d281aaef9766 | 1071 | //FIND_NEUTRAL sub-Finite State Machine (sub-FSM) |
tnhnrl | 67:c86a4b464682 | 1072 | // Note: the sub-FSM only moves the pistons once at the start of each timer loop |
tnhnrl | 67:c86a4b464682 | 1073 | // (timer completes, moves piston, timer completes, moves piston, etc) |
tnhnrl | 28:16c83a2fdefa | 1074 | int StateMachine::runNeutralStateMachine() { |
tnhnrl | 24:c7d9b5bf3829 | 1075 | switch (_substate) { |
tnhnrl | 20:8987a9ae2bc7 | 1076 | case NEUTRAL_SINKING : |
tnhnrl | 17:7c16b5671d0e | 1077 | //start the 10 second timer |
tnhnrl | 28:16c83a2fdefa | 1078 | if (!_isSubStateTimerRunning) { |
tnhnrl | 73:f6f378311c8d | 1079 | _neutral_timer = _fsm_timer.read() + 5; //record the time when this block is first entered and add 5 seconds |
tnhnrl | 17:7c16b5671d0e | 1080 | |
tnhnrl | 74:d281aaef9766 | 1081 | xbee().printf("\r\n\nNEUTRAL_SINKING: Next retraction at %0.1f sec [current time: %0.1f] (pitch: %0.1f) (BCE getSetPosition: %0.1f)\r\n", _neutral_timer, _fsm_timer.read(), pitchLoop().getPosition(), bce().getSetPosition_mm()); |
tnhnrl | 20:8987a9ae2bc7 | 1082 | |
tnhnrl | 74:d281aaef9766 | 1083 | // what are the commands? (BCE linear actuator active, no BMM or pitch movement) |
tnhnrl | 74:d281aaef9766 | 1084 | bce().setPosition_mm(bce().getSetPosition_mm() - 2.5); |
tnhnrl | 23:434f04ef1fad | 1085 | |
tnhnrl | 74:d281aaef9766 | 1086 | xbee().printf("NEUTRAL_SINKING: Retracting piston 2.5 mm [BCE CMD : %0.1f] (pitch: %0.1f)\r\n", bce().getSetPosition_mm(), pitchLoop().getPosition()); |
tnhnrl | 17:7c16b5671d0e | 1087 | |
tnhnrl | 28:16c83a2fdefa | 1088 | _isSubStateTimerRunning = true; //disable this block after one iteration |
tnhnrl | 17:7c16b5671d0e | 1089 | } |
tnhnrl | 20:8987a9ae2bc7 | 1090 | |
tnhnrl | 20:8987a9ae2bc7 | 1091 | // how exit? |
tnhnrl | 20:8987a9ae2bc7 | 1092 | //once reached the travel limit, no need to keep trying, so exit |
tnhnrl | 25:249e4d56b27c | 1093 | if (bce().getPosition_mm() <= 0) { |
tnhnrl | 74:d281aaef9766 | 1094 | xbee().printf("\r\nDEBUG: BCE current position is %0.1f mm (NEXT SUBSTATE NEUTRAL EXIT)\r\n", bce().getPosition_mm()); |
tnhnrl | 25:249e4d56b27c | 1095 | _substate = NEUTRAL_EXIT; |
tnhnrl | 28:16c83a2fdefa | 1096 | _isSubStateTimerRunning = false; // reset the sub state timer |
tnhnrl | 74:d281aaef9766 | 1097 | } |
tnhnrl | 74:d281aaef9766 | 1098 | //Troy: Pressure vessel went beyond set depth limit, goes to next state |
tnhnrl | 20:8987a9ae2bc7 | 1099 | //once deeper than the commanded setpoint... |
tnhnrl | 32:f2f8ae34aadc | 1100 | else if (depthLoop().getPosition() > _depth_command) { |
tnhnrl | 24:c7d9b5bf3829 | 1101 | _substate = NEUTRAL_SLOWLY_RISE; // next state |
tnhnrl | 28:16c83a2fdefa | 1102 | _isSubStateTimerRunning = false; //reset the sub state timer |
tnhnrl | 20:8987a9ae2bc7 | 1103 | } |
tnhnrl | 20:8987a9ae2bc7 | 1104 | |
tnhnrl | 20:8987a9ae2bc7 | 1105 | // what is active? |
tnhnrl | 20:8987a9ae2bc7 | 1106 | //once the 10 second timer is complete, reset the timeout so the state one-shot entry will move the setpoint |
tnhnrl | 73:f6f378311c8d | 1107 | if (_fsm_timer.read() >= _neutral_timer) { |
tnhnrl | 74:d281aaef9766 | 1108 | xbee().printf("\r\n\n NEUTRAL_SINKING TIMER COMPLETE! [current time: %0.1f]\r\n", _fsm_timer.read()); |
tnhnrl | 17:7c16b5671d0e | 1109 | |
tnhnrl | 28:16c83a2fdefa | 1110 | _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again |
tnhnrl | 17:7c16b5671d0e | 1111 | } |
tnhnrl | 39:58375ca6b6ff | 1112 | |
tnhnrl | 39:58375ca6b6ff | 1113 | // what is active? (only the buoyancy engine moved every 5 seconds at start) |
tnhnrl | 74:d281aaef9766 | 1114 | xbee().printf("BCE current pos: %0.1f mm (BCE setpoint: %0.1f mm) (current depth: %0.1f ft)\r", bce().getPosition_mm(),bce().getSetPosition_mm(),depthLoop().getPosition()); //debug |
tnhnrl | 67:c86a4b464682 | 1115 | |
tnhnrl | 74:d281aaef9766 | 1116 | //the BCE moves every 5 seconds. No BMM or rudder movement. |
tnhnrl | 74:d281aaef9766 | 1117 | |
tnhnrl | 17:7c16b5671d0e | 1118 | break; |
tnhnrl | 17:7c16b5671d0e | 1119 | |
tnhnrl | 17:7c16b5671d0e | 1120 | case NEUTRAL_SLOWLY_RISE: |
tnhnrl | 28:16c83a2fdefa | 1121 | if (!_isSubStateTimerRunning) { |
tnhnrl | 73:f6f378311c8d | 1122 | _neutral_timer = _fsm_timer.read()+ 5; //record the time when this block is first entered and add 5 seconds |
tnhnrl | 17:7c16b5671d0e | 1123 | |
tnhnrl | 74:d281aaef9766 | 1124 | xbee().printf("\r\n\nNEUTRAL_SLOWLY_RISE: Next extension at %0.1f sec) [current time: %0.1f]\r\n",_neutral_timer,_fsm_timer.read()); |
tnhnrl | 17:7c16b5671d0e | 1125 | |
tnhnrl | 20:8987a9ae2bc7 | 1126 | // what are the commands? |
tnhnrl | 32:f2f8ae34aadc | 1127 | //move piston at start of sequence (default: extend 2.0 mm) |
tnhnrl | 74:d281aaef9766 | 1128 | //Pressure vessel should slowly rise |
tnhnrl | 74:d281aaef9766 | 1129 | bce().setPosition_mm(bce().getSetPosition_mm() + 2.0); //no depth command, only motor position |
tnhnrl | 23:434f04ef1fad | 1130 | |
tnhnrl | 74:d281aaef9766 | 1131 | //Troy: I commented out this command, we're finding pitch in the next state. |
tnhnrl | 23:434f04ef1fad | 1132 | // it's okay to run the pitch outer loop now since we've already found pitch level in the previous state |
tnhnrl | 74:d281aaef9766 | 1133 | //pitchLoop().setCommand(0.0); |
tnhnrl | 24:c7d9b5bf3829 | 1134 | |
tnhnrl | 74:d281aaef9766 | 1135 | xbee().printf("NEUTRAL_SLOWLY_RISE: Extending BCE piston 2.0 mm [BCE CMD : %0.1f] (pitch: %0.1f)\r\n", bce().getSetPosition_mm(), pitchLoop().getPosition()); |
tnhnrl | 24:c7d9b5bf3829 | 1136 | |
tnhnrl | 28:16c83a2fdefa | 1137 | _isSubStateTimerRunning = true; //disable this block after one iteration |
tnhnrl | 17:7c16b5671d0e | 1138 | } |
tnhnrl | 17:7c16b5671d0e | 1139 | |
tnhnrl | 20:8987a9ae2bc7 | 1140 | // how exit? |
tnhnrl | 24:c7d9b5bf3829 | 1141 | //once at full travel limit (setPosition) and haven't yet risen, time to give up and exit |
tnhnrl | 24:c7d9b5bf3829 | 1142 | if (bce().getSetPosition_mm() >= bce().getTravelLimit()) { |
tnhnrl | 24:c7d9b5bf3829 | 1143 | _substate = NEUTRAL_EXIT; |
tnhnrl | 28:16c83a2fdefa | 1144 | _isSubStateTimerRunning = false; // reset the sub state timer |
tnhnrl | 17:7c16b5671d0e | 1145 | } |
tnhnrl | 74:d281aaef9766 | 1146 | //Troy: Depth rate will go negative as the pressure vessel starts rising |
tnhnrl | 17:7c16b5671d0e | 1147 | //depth rate or sink rate < 0 ft/s, go to the next substate the next iteration |
tnhnrl | 20:8987a9ae2bc7 | 1148 | else if (depthLoop().getVelocity() < 0) { //less than zero ft/s |
tnhnrl | 74:d281aaef9766 | 1149 | xbee().printf("\r\n\nNEUTRAL_SLOWLY_RISE: Sink Rate < 0 ft/s [time: %0.1f]\r\n", _fsm_timer.read()); |
tnhnrl | 24:c7d9b5bf3829 | 1150 | _substate = NEUTRAL_CHECK_PITCH; |
tnhnrl | 28:16c83a2fdefa | 1151 | _isSubStateTimerRunning = false; // reset the sub state timer |
tnhnrl | 17:7c16b5671d0e | 1152 | } |
tnhnrl | 17:7c16b5671d0e | 1153 | |
tnhnrl | 20:8987a9ae2bc7 | 1154 | // what is active? |
tnhnrl | 20:8987a9ae2bc7 | 1155 | //once 5 second timer complete, reset the timeout so the state one-shot entry will move the setpoint |
tnhnrl | 73:f6f378311c8d | 1156 | if (_fsm_timer.read() >= _neutral_timer) { |
tnhnrl | 74:d281aaef9766 | 1157 | xbee().printf("\r\n\n NEUTRAL_SLOWLY_RISE TIMER COMPLETE! [timer: %0.1f]\r\n", _fsm_timer.read()); |
tnhnrl | 20:8987a9ae2bc7 | 1158 | |
tnhnrl | 28:16c83a2fdefa | 1159 | _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again |
tnhnrl | 17:7c16b5671d0e | 1160 | } |
tnhnrl | 23:434f04ef1fad | 1161 | |
tnhnrl | 32:f2f8ae34aadc | 1162 | // what is active? (only the buoyancy engine moved every 5 seconds) |
tnhnrl | 74:d281aaef9766 | 1163 | xbee().printf("depthLoop getOutput: %0.1f\r", depthLoop().getOutput()); //debug |
tnhnrl | 67:c86a4b464682 | 1164 | |
tnhnrl | 17:7c16b5671d0e | 1165 | break; |
tnhnrl | 17:7c16b5671d0e | 1166 | |
danstrider | 22:a10ee088403b | 1167 | case NEUTRAL_CHECK_PITCH : // fall thru to next state is desired |
danstrider | 22:a10ee088403b | 1168 | // start local state timer and init any other one-shot actions |
tnhnrl | 23:434f04ef1fad | 1169 | |
tnhnrl | 28:16c83a2fdefa | 1170 | if (!_isSubStateTimerRunning) { |
tnhnrl | 73:f6f378311c8d | 1171 | _neutral_timer = _fsm_timer.read() + 10; // record time when this block is entered and add several seconds |
tnhnrl | 74:d281aaef9766 | 1172 | xbee().printf("\r\nNEUTRAL_CHECK_PITCH: Next move in %0.1f sec \r\n",_neutral_timer - _fsm_timer.read()); |
danstrider | 22:a10ee088403b | 1173 | |
tnhnrl | 32:f2f8ae34aadc | 1174 | // what are the commands? (default: retract or extend 0.5 mm) |
tnhnrl | 74:d281aaef9766 | 1175 | if (pitchLoop().getPosition() > 2) { // nose is high (extend batteries) |
tnhnrl | 39:58375ca6b6ff | 1176 | batt().setPosition_mm(batt().getSetPosition_mm() + 0.5); // move battery forward (using setpoint from linear actuator) |
tnhnrl | 74:d281aaef9766 | 1177 | xbee().printf("\r\nNeutral Check Pitch: moving battery FWD in 0.5 mm increments\r\n\n"); |
danstrider | 22:a10ee088403b | 1178 | } |
tnhnrl | 74:d281aaef9766 | 1179 | else if (pitchLoop().getPosition() < -2) { // nose is low (retract batteries) |
tnhnrl | 39:58375ca6b6ff | 1180 | batt().setPosition_mm(batt().getSetPosition_mm() - 0.5); // move battery aft (using setpoint from linear actuator) |
tnhnrl | 74:d281aaef9766 | 1181 | xbee().printf("\r\nNeutral Check Pitch: moving battery AFT in 0.5 mm increments\r\n\n"); |
danstrider | 22:a10ee088403b | 1182 | } |
tnhnrl | 24:c7d9b5bf3829 | 1183 | |
tnhnrl | 28:16c83a2fdefa | 1184 | _isSubStateTimerRunning = true; //disable this block after one iteration |
danstrider | 22:a10ee088403b | 1185 | } |
tnhnrl | 20:8987a9ae2bc7 | 1186 | |
tnhnrl | 28:16c83a2fdefa | 1187 | // how exit? |
tnhnrl | 20:8987a9ae2bc7 | 1188 | //pitch angle and pitch rate within small tolerance |
tnhnrl | 20:8987a9ae2bc7 | 1189 | //benchtop tests confirm angle needs to be around 2 degrees |
tnhnrl | 23:434f04ef1fad | 1190 | if ((fabs(pitchLoop().getPosition()) < 2.0) and (fabs(pitchLoop().getVelocity()) < 5.0)) { |
tnhnrl | 74:d281aaef9766 | 1191 | xbee().printf("Debug: Found Level (NEUTRAL_CHECK_PITCH or NEUTRAL_FIRST_PITCH)\r\n"); //debug |
danstrider | 22:a10ee088403b | 1192 | // found level, but don't need to save anything this time |
tnhnrl | 23:434f04ef1fad | 1193 | |
tnhnrl | 28:16c83a2fdefa | 1194 | if (depthLoop().getPosition() > _max_recorded_depth_neutral) { //debug |
tnhnrl | 28:16c83a2fdefa | 1195 | _max_recorded_depth_neutral = depthLoop().getPosition(); //new max depth recorded |
tnhnrl | 28:16c83a2fdefa | 1196 | } |
tnhnrl | 28:16c83a2fdefa | 1197 | |
tnhnrl | 23:434f04ef1fad | 1198 | // found level and at depth too, so save it all now |
tnhnrl | 32:f2f8ae34aadc | 1199 | if (_substate == NEUTRAL_CHECK_PITCH) { |
danstrider | 22:a10ee088403b | 1200 | //save positions locally |
danstrider | 22:a10ee088403b | 1201 | _neutral_batt_pos_mm = batt().getPosition_mm(); |
danstrider | 22:a10ee088403b | 1202 | _neutral_bce_pos_mm = bce().getPosition_mm(); |
danstrider | 22:a10ee088403b | 1203 | |
danstrider | 22:a10ee088403b | 1204 | //set the neutral positions in each outer loop |
danstrider | 22:a10ee088403b | 1205 | depthLoop().setOutputOffset(_neutral_bce_pos_mm); |
danstrider | 22:a10ee088403b | 1206 | pitchLoop().setOutputOffset(_neutral_batt_pos_mm); |
danstrider | 22:a10ee088403b | 1207 | |
danstrider | 22:a10ee088403b | 1208 | // save into the depth.txt and pitch.txt files |
tnhnrl | 73:f6f378311c8d | 1209 | |
tnhnrl | 73:f6f378311c8d | 1210 | configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm, _pitch_filter_freq, _pitch_deadband); //P,I,D,batt zeroOffset |
tnhnrl | 73:f6f378311c8d | 1211 | configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm, _depth_filter_freq, _depth_deadband); //P,I,D, bce zeroOffset |
tnhnrl | 73:f6f378311c8d | 1212 | |
tnhnrl | 74:d281aaef9766 | 1213 | xbee().printf("\r\n\n>>> Saving Positions: BCE: %0.1f mm, BATT: %0.1f <<<\r\n\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm); |
danstrider | 22:a10ee088403b | 1214 | |
tnhnrl | 24:c7d9b5bf3829 | 1215 | _substate = NEUTRAL_EXIT; |
tnhnrl | 28:16c83a2fdefa | 1216 | _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again |
tnhnrl | 24:c7d9b5bf3829 | 1217 | } |
tnhnrl | 24:c7d9b5bf3829 | 1218 | |
tnhnrl | 24:c7d9b5bf3829 | 1219 | else { |
tnhnrl | 74:d281aaef9766 | 1220 | xbee().printf("\r\nDid not find NEUTRAL_CHECK_PITCH or NEUTRAL_FIRST_PITCH, how did I get here?!\r\n"); |
tnhnrl | 24:c7d9b5bf3829 | 1221 | _substate = NEUTRAL_EXIT; |
danstrider | 22:a10ee088403b | 1222 | } |
tnhnrl | 17:7c16b5671d0e | 1223 | } |
danstrider | 22:a10ee088403b | 1224 | |
danstrider | 22:a10ee088403b | 1225 | // what is active? |
danstrider | 22:a10ee088403b | 1226 | //once timer complete, reset the timeout so the state one-shot entry will move the setpoint |
tnhnrl | 73:f6f378311c8d | 1227 | if (_fsm_timer.read() >= _neutral_timer) { |
tnhnrl | 74:d281aaef9766 | 1228 | xbee().printf("\r\n\nlevel timer COMPLETE!"); |
tnhnrl | 74:d281aaef9766 | 1229 | xbee().printf("\r\n\n (BATT POS: %0.1f) moving 1 mm [timer: %0.1f]\r\n", batt().getPosition_mm(), _fsm_timer.read()); |
tnhnrl | 28:16c83a2fdefa | 1230 | _isSubStateTimerRunning = false; // reset the sub state timer to do one-shot actions again |
danstrider | 22:a10ee088403b | 1231 | } |
tnhnrl | 74:d281aaef9766 | 1232 | |
tnhnrl | 17:7c16b5671d0e | 1233 | break; |
danstrider | 22:a10ee088403b | 1234 | |
danstrider | 22:a10ee088403b | 1235 | //this state could be removed, it is only used as a transition but is needed to stop entering this function |
danstrider | 22:a10ee088403b | 1236 | case NEUTRAL_EXIT : |
tnhnrl | 74:d281aaef9766 | 1237 | xbee().printf("substate: NEUTRAL_EXIT\r\n"); |
tnhnrl | 20:8987a9ae2bc7 | 1238 | break; |
tnhnrl | 21:38c8544db6f4 | 1239 | |
danstrider | 22:a10ee088403b | 1240 | default : |
tnhnrl | 74:d281aaef9766 | 1241 | xbee().printf("how did we get to substate: default?\r\n"); //debug |
tnhnrl | 23:434f04ef1fad | 1242 | //a default within the sub-state machine |
tnhnrl | 24:c7d9b5bf3829 | 1243 | _substate = NEUTRAL_EXIT; |
danstrider | 22:a10ee088403b | 1244 | break; |
tnhnrl | 17:7c16b5671d0e | 1245 | } |
tnhnrl | 20:8987a9ae2bc7 | 1246 | |
tnhnrl | 30:2964617e7676 | 1247 | // reset the sub-FSM if needed (useful if you need to redo the neutral-finding sequence) |
tnhnrl | 24:c7d9b5bf3829 | 1248 | if (_substate == NEUTRAL_EXIT) { |
tnhnrl | 74:d281aaef9766 | 1249 | xbee().printf("******************************** EXITING sub-FSM! *******************************\r\n\n"); |
tnhnrl | 24:c7d9b5bf3829 | 1250 | |
tnhnrl | 30:2964617e7676 | 1251 | //reset internal sub-state back to first entry conditions (first state is immediately sinking) |
tnhnrl | 30:2964617e7676 | 1252 | _substate = NEUTRAL_SINKING; |
tnhnrl | 28:16c83a2fdefa | 1253 | _isSubStateTimerRunning = false; // reset the sub state timer |
tnhnrl | 21:38c8544db6f4 | 1254 | |
tnhnrl | 24:c7d9b5bf3829 | 1255 | //record sub-states to view after sequence |
tnhnrl | 30:2964617e7676 | 1256 | _substate_array[_substate_array_counter] = NEUTRAL_EXIT; //save exit to state array |
tnhnrl | 28:16c83a2fdefa | 1257 | _substate_array_counter++; |
tnhnrl | 23:434f04ef1fad | 1258 | |
tnhnrl | 24:c7d9b5bf3829 | 1259 | //reset _previous_substate on exit (has to be done in FIND_NEUTRAL if emergency exit) |
tnhnrl | 24:c7d9b5bf3829 | 1260 | _previous_substate = -1; |
tnhnrl | 24:c7d9b5bf3829 | 1261 | |
tnhnrl | 24:c7d9b5bf3829 | 1262 | //NEUTRAL_EXIT state is used to tell the greater FSM that this sub-FSM has completed |
tnhnrl | 24:c7d9b5bf3829 | 1263 | return NEUTRAL_EXIT; // message to calling function we just exited |
tnhnrl | 21:38c8544db6f4 | 1264 | } |
tnhnrl | 23:434f04ef1fad | 1265 | else { |
tnhnrl | 24:c7d9b5bf3829 | 1266 | //record sub-states to view after sequence (when changed) |
tnhnrl | 24:c7d9b5bf3829 | 1267 | if (_previous_substate != _substate) { |
tnhnrl | 28:16c83a2fdefa | 1268 | _substate_array[_substate_array_counter] = _substate; //save current state to state array |
tnhnrl | 28:16c83a2fdefa | 1269 | _substate_array_counter++; |
tnhnrl | 24:c7d9b5bf3829 | 1270 | |
tnhnrl | 24:c7d9b5bf3829 | 1271 | //record the current substate for comparison |
tnhnrl | 24:c7d9b5bf3829 | 1272 | _previous_substate = _substate; |
tnhnrl | 24:c7d9b5bf3829 | 1273 | } |
tnhnrl | 24:c7d9b5bf3829 | 1274 | |
tnhnrl | 24:c7d9b5bf3829 | 1275 | return _substate; // message to calling function of what sub-state it's in |
tnhnrl | 23:434f04ef1fad | 1276 | } |
tnhnrl | 17:7c16b5671d0e | 1277 | } |
tnhnrl | 20:8987a9ae2bc7 | 1278 | |
tnhnrl | 57:ec69651c8c21 | 1279 | /* keyboard runs independently of the state machine, handling one key at a time |
tnhnrl | 57:ec69651c8c21 | 1280 | keyboard updates the desired _keyboard_state that is used in the state machine |
tnhnrl | 57:ec69651c8c21 | 1281 | and only allows input when the state is "idle" */ |
tnhnrl | 57:ec69651c8c21 | 1282 | |
tnhnrl | 17:7c16b5671d0e | 1283 | void StateMachine::keyboard() { |
tnhnrl | 57:ec69651c8c21 | 1284 | char user_input; |
tnhnrl | 20:8987a9ae2bc7 | 1285 | |
tnhnrl | 16:3363b9f14913 | 1286 | // check keyboard and make settings changes as requested |
tnhnrl | 17:7c16b5671d0e | 1287 | // states can be changed only at the start of a sequence (when the system is in SIT_IDLE) |
tnhnrl | 21:38c8544db6f4 | 1288 | |
tnhnrl | 37:357e98a929cc | 1289 | //TEST |
tnhnrl | 37:357e98a929cc | 1290 | int _keyboard_state = 0; //made this a local variable because it was retaining the last keyboard state |
tnhnrl | 21:38c8544db6f4 | 1291 | |
tnhnrl | 74:d281aaef9766 | 1292 | if (xbee().readable() && (_state == SIT_IDLE || _state == KEYBOARD)) { |
tnhnrl | 16:3363b9f14913 | 1293 | // get the key |
tnhnrl | 74:d281aaef9766 | 1294 | user_input = xbee().getc(); |
tnhnrl | 17:7c16b5671d0e | 1295 | |
tnhnrl | 28:16c83a2fdefa | 1296 | //record that the keyboard was used |
tnhnrl | 28:16c83a2fdefa | 1297 | _state_array[_state_array_counter] = KEYBOARD; |
tnhnrl | 28:16c83a2fdefa | 1298 | _state_array_counter++; |
tnhnrl | 28:16c83a2fdefa | 1299 | |
tnhnrl | 21:38c8544db6f4 | 1300 | // keyboard has to reset timer each time it's used |
tnhnrl | 28:16c83a2fdefa | 1301 | _isTimeoutRunning = false; |
tnhnrl | 17:7c16b5671d0e | 1302 | |
tnhnrl | 16:3363b9f14913 | 1303 | // check command against desired control buttons |
tnhnrl | 72:250b2665755c | 1304 | |
tnhnrl | 72:250b2665755c | 1305 | /***************************** COMMON COMMANDS *****************************/ |
tnhnrl | 72:250b2665755c | 1306 | if (user_input == 'W') { |
tnhnrl | 74:d281aaef9766 | 1307 | xbee().printf(">> Please enter the heading (deg).\r\n"); |
tnhnrl | 72:250b2665755c | 1308 | _heading_command = getFloatUserInput(); |
tnhnrl | 72:250b2665755c | 1309 | } |
tnhnrl | 73:f6f378311c8d | 1310 | |
tnhnrl | 73:f6f378311c8d | 1311 | //////////////////// TEST |
tnhnrl | 73:f6f378311c8d | 1312 | // else if (user_input == 'l') { |
tnhnrl | 74:d281aaef9766 | 1313 | // xbee().printf("CUT OFF RUDDER SERVO????\n\r"); |
tnhnrl | 73:f6f378311c8d | 1314 | // rudder().pwm_pulse_off(); |
tnhnrl | 73:f6f378311c8d | 1315 | // } |
tnhnrl | 73:f6f378311c8d | 1316 | //////////////////// TEST |
tnhnrl | 73:f6f378311c8d | 1317 | |
tnhnrl | 74:d281aaef9766 | 1318 | else if (user_input == 'K') { |
tnhnrl | 74:d281aaef9766 | 1319 | xbee().printf("(K) BLAST DATA AND EXIT! \n\r"); |
tnhnrl | 74:d281aaef9766 | 1320 | mbedLogger().blastData(); |
tnhnrl | 74:d281aaef9766 | 1321 | } |
tnhnrl | 74:d281aaef9766 | 1322 | |
tnhnrl | 73:f6f378311c8d | 1323 | else if (user_input == 'U') { |
tnhnrl | 74:d281aaef9766 | 1324 | xbee().printf("(U) TRANSMIT MULTIPLE PACKETS \n\r"); |
tnhnrl | 73:f6f378311c8d | 1325 | |
tnhnrl | 73:f6f378311c8d | 1326 | mbedLogger().transmitMultiplePackets(); |
tnhnrl | 73:f6f378311c8d | 1327 | } |
tnhnrl | 73:f6f378311c8d | 1328 | |
tnhnrl | 73:f6f378311c8d | 1329 | else if (user_input == 'H') { |
tnhnrl | 74:d281aaef9766 | 1330 | xbee().printf("(H) BLAST DATA AND MULTIPLE PACKETS! \n\r"); |
tnhnrl | 73:f6f378311c8d | 1331 | wait(1); |
tnhnrl | 73:f6f378311c8d | 1332 | mbedLogger().blastData(); |
tnhnrl | 73:f6f378311c8d | 1333 | |
tnhnrl | 73:f6f378311c8d | 1334 | mbedLogger().transmitMultiplePackets(); |
tnhnrl | 73:f6f378311c8d | 1335 | } |
tnhnrl | 73:f6f378311c8d | 1336 | |
tnhnrl | 73:f6f378311c8d | 1337 | else if (user_input == 'G') { |
tnhnrl | 74:d281aaef9766 | 1338 | xbee().printf("(G) BLAST DATA TEST and use FSM! \n\r"); |
tnhnrl | 73:f6f378311c8d | 1339 | wait(1); |
tnhnrl | 73:f6f378311c8d | 1340 | mbedLogger().blastData(); |
tnhnrl | 73:f6f378311c8d | 1341 | |
tnhnrl | 73:f6f378311c8d | 1342 | _keyboard_state = TX_MBED_LOG; |
tnhnrl | 73:f6f378311c8d | 1343 | } |
tnhnrl | 73:f6f378311c8d | 1344 | |
tnhnrl | 74:d281aaef9766 | 1345 | else if (user_input == 'I') { |
tnhnrl | 74:d281aaef9766 | 1346 | xbee().printf("(I) Receive Multi-Dive Sequence! \n\r"); |
tnhnrl | 74:d281aaef9766 | 1347 | mbedLogger().receiveSequenceFile(); //receive sequence.txt files |
tnhnrl | 74:d281aaef9766 | 1348 | } |
tnhnrl | 74:d281aaef9766 | 1349 | |
tnhnrl | 72:250b2665755c | 1350 | else if (user_input == '8') { |
tnhnrl | 72:250b2665755c | 1351 | keyboard_menu_STREAM_STATUS(); |
tnhnrl | 72:250b2665755c | 1352 | } |
tnhnrl | 74:d281aaef9766 | 1353 | |
tnhnrl | 72:250b2665755c | 1354 | else if (user_input == '?') { |
tnhnrl | 74:d281aaef9766 | 1355 | xbee().printf("\n\n\n>>> Resetting MBED <<<\n\n\n"); |
tnhnrl | 72:250b2665755c | 1356 | wait(0.5); |
tnhnrl | 72:250b2665755c | 1357 | mbed_reset(); |
tnhnrl | 72:250b2665755c | 1358 | } |
tnhnrl | 72:250b2665755c | 1359 | |
tnhnrl | 72:250b2665755c | 1360 | else if (user_input == 'T') { |
tnhnrl | 74:d281aaef9766 | 1361 | xbee().printf("Please enter the timeout (timer) value below: \n\r"); |
tnhnrl | 72:250b2665755c | 1362 | _timeout = fabs(getFloatUserInput()); |
tnhnrl | 72:250b2665755c | 1363 | } |
tnhnrl | 72:250b2665755c | 1364 | |
tnhnrl | 80:4e5d306d695b | 1365 | else if (user_input == '~') { |
tnhnrl | 80:4e5d306d695b | 1366 | xbee().printf("MBED LOG FILE MENU!\r\n"); |
tnhnrl | 80:4e5d306d695b | 1367 | stateMachine().logFileMenu(); |
tnhnrl | 80:4e5d306d695b | 1368 | |
tnhnrl | 80:4e5d306d695b | 1369 | //xbee().printf("ERASING MBED LOG FILE\r\n"); //legacy method |
tnhnrl | 80:4e5d306d695b | 1370 | //mbedLogger().eraseFile(); |
tnhnrl | 80:4e5d306d695b | 1371 | } |
tnhnrl | 80:4e5d306d695b | 1372 | |
tnhnrl | 73:f6f378311c8d | 1373 | else if (user_input == 'C' or user_input == 'c') { |
tnhnrl | 73:f6f378311c8d | 1374 | |
tnhnrl | 74:d281aaef9766 | 1375 | xbee().printf("\r\n\nCURRENT STATUS AND PARAMETERS:\r\n"); |
tnhnrl | 73:f6f378311c8d | 1376 | |
tnhnrl | 74:d281aaef9766 | 1377 | xbee().printf("raw BCE pos: %d \r\n",adc().readCh0()); |
tnhnrl | 74:d281aaef9766 | 1378 | xbee().printf("raw BMM pos: %d \r\n",adc().readCh1()); |
tnhnrl | 74:d281aaef9766 | 1379 | xbee().printf("raw BCE current sense: %d \r\n",adc().readCh2()); |
tnhnrl | 74:d281aaef9766 | 1380 | xbee().printf("raw BMM current sense: %d \r\n",adc().readCh3()); |
tnhnrl | 74:d281aaef9766 | 1381 | xbee().printf("raw depth pressure: %d \r\n",adc().readCh4()); |
tnhnrl | 74:d281aaef9766 | 1382 | xbee().printf("raw vessel pressure %d (internal psi: %0.1f)\r\n", adc().readCh5(),sensors().getInternalPressurePSI()); |
tnhnrl | 74:d281aaef9766 | 1383 | //xbee().printf("raw vessel pressure: %d \r\n",adc().readCh5()); |
tnhnrl | 74:d281aaef9766 | 1384 | xbee().printf("raw board voltage: %d (%0.1f volts)\r\n",adc().readCh6(),sensors().getVoltageInput()); |
tnhnrl | 74:d281aaef9766 | 1385 | xbee().printf("raw board current: %d (%0.3f amps)\r\n",adc().readCh7(), sensors().getCurrentInput()); |
tnhnrl | 74:d281aaef9766 | 1386 | xbee().printf("raw BCE limit switch: %d \r\n",bce().getSwitch()); |
tnhnrl | 74:d281aaef9766 | 1387 | xbee().printf("raw BMM limit switch: %d \r\n",batt().getSwitch()); |
tnhnrl | 74:d281aaef9766 | 1388 | xbee().printf("calc vessel pressure: %f (counts: %d) \r\n",sensors().getInternalPressurePSI(),adc().readCh5()); |
tnhnrl | 73:f6f378311c8d | 1389 | // End of ADC Test |
tnhnrl | 73:f6f378311c8d | 1390 | |
tnhnrl | 74:d281aaef9766 | 1391 | xbee().printf("depth: %3.1f ft\r\n",depthLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1392 | xbee().printf("pitch: %3.1f deg\r\n",imu().getPitch()); |
tnhnrl | 74:d281aaef9766 | 1393 | xbee().printf("bce().getPosition_mm(): %3.1f\r\n",bce().getPosition_mm()); |
tnhnrl | 74:d281aaef9766 | 1394 | xbee().printf("bce().getSetPosition_mm(): %3.1f\r\n",bce().getSetPosition_mm()); |
tnhnrl | 74:d281aaef9766 | 1395 | xbee().printf("batt().getPosition_mm(): %3.1f\r\n",batt().getPosition_mm()); |
tnhnrl | 74:d281aaef9766 | 1396 | xbee().printf("batt().getSetPosition_mm(): %3.1f\r\n",batt().getSetPosition_mm()); |
tnhnrl | 74:d281aaef9766 | 1397 | xbee().printf("depthLoop().getCommand(): %3.1f\r\n",depthLoop().getCommand()); |
tnhnrl | 74:d281aaef9766 | 1398 | xbee().printf("pitchLoop().getCommand(): %3.1f\r\n",pitchLoop().getCommand()); |
tnhnrl | 73:f6f378311c8d | 1399 | |
tnhnrl | 74:d281aaef9766 | 1400 | xbee().printf("\r\nNeutral Buoyancy Positions: bce: %0.1f, batt: %0.1f\r\n",_neutral_bce_pos_mm,_neutral_batt_pos_mm); |
tnhnrl | 74:d281aaef9766 | 1401 | xbee().printf("depthLoop().getOutputOffset(): %0.1f\r\n",depthLoop().getOutputOffset()); |
tnhnrl | 74:d281aaef9766 | 1402 | xbee().printf("pitchLoop().getOutputOffset(): %0.1f\r\n",pitchLoop().getOutputOffset()); |
tnhnrl | 74:d281aaef9766 | 1403 | xbee().printf("Max recorded depth: neutral: %0.1f, dive: %0.1f, auto_neutral_depth: %0.1f\r\n\n",_max_recorded_depth_neutral, _max_recorded_depth_dive, _max_recorded_auto_neutral_depth); |
tnhnrl | 73:f6f378311c8d | 1404 | |
tnhnrl | 74:d281aaef9766 | 1405 | xbee().printf("\r\n"); |
tnhnrl | 76:c802e1da4179 | 1406 | xbee().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, filter_freq: %0.1f, deadband: %0.1f\r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope(), bce().getFilterFrequency(), bce().getDeadband()); |
tnhnrl | 76:c802e1da4179 | 1407 | xbee().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, filter_freq: %0.1f, deadband: %0.1f\r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope(), batt().getFilterFrequency(), batt().getDeadband()); |
tnhnrl | 74:d281aaef9766 | 1408 | xbee().printf("rudder min_pwm:%6.1f, center_pwm:%6.1f, max_pwm:%6.1f (min_deg:%6.1f max_deg:%6.1f)\r\n",rudder().getMinPWM(),rudder().getCenterPWM(),rudder().getMaxPWM(),rudder().getMinDeg(),rudder().getMaxDeg()); |
tnhnrl | 74:d281aaef9766 | 1409 | xbee().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, output offset: %6.1f mm, filter_freq: %0.1f, deadband: %0.1f \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); |
tnhnrl | 74:d281aaef9766 | 1410 | xbee().printf("pitch P:%6.2f, I:%6.2f, D:%6.2f, output offset: %6.1f mm, filter_freq: %0.1f, deadband: %0.1f \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); |
tnhnrl | 74:d281aaef9766 | 1411 | xbee().printf("heading P:%6.2f, I:%6.2f, D:%6.2f, output offset: %6.1f mm, filter_freq: %0.1f, deadband: %0.1f \r\n", headingLoop().getControllerP(), headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset(),headingLoop().getFilterFrequency(),headingLoop().getDeadband()); |
tnhnrl | 73:f6f378311c8d | 1412 | } |
tnhnrl | 73:f6f378311c8d | 1413 | |
tnhnrl | 72:250b2665755c | 1414 | /***************************** COMMON COMMANDS *****************************/ |
tnhnrl | 57:ec69651c8c21 | 1415 | |
tnhnrl | 57:ec69651c8c21 | 1416 | /***************************** DEBUG MENU *****************************/ |
tnhnrl | 72:250b2665755c | 1417 | if (_debug_menu_on) { |
tnhnrl | 57:ec69651c8c21 | 1418 | if (user_input == 'D') { |
tnhnrl | 57:ec69651c8c21 | 1419 | _keyboard_state = DIVE; |
tnhnrl | 57:ec69651c8c21 | 1420 | } |
tnhnrl | 74:d281aaef9766 | 1421 | |
tnhnrl | 74:d281aaef9766 | 1422 | else if (user_input == '}') { |
tnhnrl | 74:d281aaef9766 | 1423 | xbee().printf("HOMING the BCE (5 second delay)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1424 | wait(5); |
tnhnrl | 74:d281aaef9766 | 1425 | bce().homePiston(); |
tnhnrl | 74:d281aaef9766 | 1426 | } |
tnhnrl | 74:d281aaef9766 | 1427 | |
tnhnrl | 74:d281aaef9766 | 1428 | else if (user_input == '|') { |
tnhnrl | 74:d281aaef9766 | 1429 | xbee().printf("HOMING the BMM (5 second delay)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1430 | wait(5); |
tnhnrl | 74:d281aaef9766 | 1431 | batt().homePiston(); |
tnhnrl | 74:d281aaef9766 | 1432 | } |
tnhnrl | 74:d281aaef9766 | 1433 | |
tnhnrl | 57:ec69651c8c21 | 1434 | else if (user_input == 'N') { |
tnhnrl | 57:ec69651c8c21 | 1435 | _keyboard_state = FIND_NEUTRAL; |
tnhnrl | 57:ec69651c8c21 | 1436 | } |
tnhnrl | 57:ec69651c8c21 | 1437 | else if (user_input == 'M') { |
tnhnrl | 57:ec69651c8c21 | 1438 | //currently does not run if there is no file. |
tnhnrl | 57:ec69651c8c21 | 1439 | |
tnhnrl | 57:ec69651c8c21 | 1440 | //need to add method to Sequence Controller that returns -1 |
tnhnrl | 57:ec69651c8c21 | 1441 | // or some check that insures you cannot run the dive sequence without a file |
tnhnrl | 57:ec69651c8c21 | 1442 | |
tnhnrl | 68:8f549749b8ce | 1443 | //load sequence from file |
tnhnrl | 68:8f549749b8ce | 1444 | _multi_dive_counter = 0; |
tnhnrl | 68:8f549749b8ce | 1445 | sequenceController().loadSequence(); |
tnhnrl | 68:8f549749b8ce | 1446 | wait(1); //test if this resets the sequence |
tnhnrl | 68:8f549749b8ce | 1447 | |
tnhnrl | 57:ec69651c8c21 | 1448 | stateMachine().getDiveSequence(); //get first sequence on keyboard press |
tnhnrl | 57:ec69651c8c21 | 1449 | _keyboard_state = currentStateStruct.state; |
tnhnrl | 57:ec69651c8c21 | 1450 | |
tnhnrl | 74:d281aaef9766 | 1451 | xbee().printf("Starting Dive Sequence Controller! (state: %d)\r\n", _keyboard_state); //neutral sequence and dive cycles |
tnhnrl | 57:ec69651c8c21 | 1452 | } |
tnhnrl | 57:ec69651c8c21 | 1453 | else if (user_input == 'R') { |
tnhnrl | 57:ec69651c8c21 | 1454 | _keyboard_state = RISE; |
tnhnrl | 57:ec69651c8c21 | 1455 | } |
tnhnrl | 57:ec69651c8c21 | 1456 | else if (user_input == 'J') { |
tnhnrl | 57:ec69651c8c21 | 1457 | _keyboard_state = FLOAT_LEVEL; |
tnhnrl | 57:ec69651c8c21 | 1458 | } |
tnhnrl | 57:ec69651c8c21 | 1459 | else if (user_input == 'B') { |
tnhnrl | 57:ec69651c8c21 | 1460 | _keyboard_state = FLOAT_BROADCAST; |
tnhnrl | 57:ec69651c8c21 | 1461 | } |
tnhnrl | 57:ec69651c8c21 | 1462 | else if (user_input == 'E') { |
tnhnrl | 57:ec69651c8c21 | 1463 | _keyboard_state = EMERGENCY_CLIMB; |
tnhnrl | 57:ec69651c8c21 | 1464 | } |
tnhnrl | 17:7c16b5671d0e | 1465 | |
tnhnrl | 65:2ac186553959 | 1466 | else if (user_input == 'Y') { |
tnhnrl | 57:ec69651c8c21 | 1467 | _keyboard_state = CHECK_TUNING; |
tnhnrl | 57:ec69651c8c21 | 1468 | } |
tnhnrl | 17:7c16b5671d0e | 1469 | |
tnhnrl | 57:ec69651c8c21 | 1470 | // some debug tools below |
tnhnrl | 57:ec69651c8c21 | 1471 | else if (user_input == 'P') { |
tnhnrl | 57:ec69651c8c21 | 1472 | //Print current SD card log file |
tnhnrl | 57:ec69651c8c21 | 1473 | //printCurrentSdLog(); |
tnhnrl | 57:ec69651c8c21 | 1474 | mbedLogger().printCurrentLogFile(); //print the current log file to the screen |
tnhnrl | 57:ec69651c8c21 | 1475 | } |
tnhnrl | 57:ec69651c8c21 | 1476 | else if (user_input == 'X') { |
tnhnrl | 57:ec69651c8c21 | 1477 | mbedLogger().printMbedDirectory(); //print all log files to the screen |
tnhnrl | 57:ec69651c8c21 | 1478 | } |
tnhnrl | 57:ec69651c8c21 | 1479 | else if (user_input == 'Z') { |
tnhnrl | 74:d281aaef9766 | 1480 | xbee().printf("FSG FSM States: \r\n"); |
tnhnrl | 57:ec69651c8c21 | 1481 | string string_state; |
tnhnrl | 57:ec69651c8c21 | 1482 | |
tnhnrl | 57:ec69651c8c21 | 1483 | for (int i = 0; i < _state_array_counter; i++) { |
tnhnrl | 57:ec69651c8c21 | 1484 | if (_state_array[i] == SIT_IDLE) |
tnhnrl | 57:ec69651c8c21 | 1485 | string_state = "SIT_IDLE <END>"; |
tnhnrl | 57:ec69651c8c21 | 1486 | else if (_state_array[i] == FIND_NEUTRAL) |
tnhnrl | 57:ec69651c8c21 | 1487 | string_state = "FIND_NEUTRAL"; |
tnhnrl | 57:ec69651c8c21 | 1488 | else if (_state_array[i] == DIVE) |
tnhnrl | 57:ec69651c8c21 | 1489 | string_state = "DIVE"; |
tnhnrl | 57:ec69651c8c21 | 1490 | else if (_state_array[i] == RISE) |
tnhnrl | 57:ec69651c8c21 | 1491 | string_state = "RISE"; |
tnhnrl | 57:ec69651c8c21 | 1492 | else if (_state_array[i] == FLOAT_LEVEL) |
tnhnrl | 57:ec69651c8c21 | 1493 | string_state = "FLOAT_LEVEL"; |
tnhnrl | 57:ec69651c8c21 | 1494 | else if (_state_array[i] == FLOAT_BROADCAST) |
tnhnrl | 57:ec69651c8c21 | 1495 | string_state = "FLOAT_BROADCAST"; |
tnhnrl | 57:ec69651c8c21 | 1496 | else if (_state_array[i] == EMERGENCY_CLIMB) |
tnhnrl | 57:ec69651c8c21 | 1497 | string_state = "EMERGENCY_CLIMB"; |
tnhnrl | 57:ec69651c8c21 | 1498 | else if (_state_array[i] == MULTI_DIVE) |
tnhnrl | 57:ec69651c8c21 | 1499 | string_state = "MULTI_DIVE"; |
tnhnrl | 57:ec69651c8c21 | 1500 | else if (_state_array[i] == MULTI_RISE) |
tnhnrl | 57:ec69651c8c21 | 1501 | string_state = "MULTI_RISE"; |
tnhnrl | 57:ec69651c8c21 | 1502 | else if (_state_array[i] == KEYBOARD) |
tnhnrl | 57:ec69651c8c21 | 1503 | string_state = "KEYBOARD"; |
tnhnrl | 74:d281aaef9766 | 1504 | xbee().printf("State #%d: %d (%s)\r\n", i, _state_array[i], string_state.c_str()); |
tnhnrl | 57:ec69651c8c21 | 1505 | } |
tnhnrl | 57:ec69651c8c21 | 1506 | |
tnhnrl | 74:d281aaef9766 | 1507 | xbee().printf("\r\nNeutral sub-FSM States: \r\n"); |
tnhnrl | 57:ec69651c8c21 | 1508 | string string_substate; |
tnhnrl | 57:ec69651c8c21 | 1509 | |
tnhnrl | 57:ec69651c8c21 | 1510 | for (int i = 0; i < _substate_array_counter; i++) { |
tnhnrl | 57:ec69651c8c21 | 1511 | if (_substate_array[i] == NEUTRAL_SINKING) |
tnhnrl | 57:ec69651c8c21 | 1512 | string_substate = "NEUTRAL_SINKING"; |
tnhnrl | 57:ec69651c8c21 | 1513 | else if (_substate_array[i] == NEUTRAL_SLOWLY_RISE) |
tnhnrl | 57:ec69651c8c21 | 1514 | string_substate = "NEUTRAL_SLOWLY_RISE"; |
tnhnrl | 57:ec69651c8c21 | 1515 | else if (_substate_array[i] == NEUTRAL_CHECK_PITCH) |
tnhnrl | 57:ec69651c8c21 | 1516 | string_substate = "NEUTRAL_CHECK_PITCH"; |
tnhnrl | 57:ec69651c8c21 | 1517 | else if (_substate_array[i] == NEUTRAL_EXIT) |
tnhnrl | 57:ec69651c8c21 | 1518 | string_substate = "NEUTRAL_EXIT <-- "; |
tnhnrl | 57:ec69651c8c21 | 1519 | else if (_substate_array[i] == EMERGENCY_CLIMB) |
tnhnrl | 57:ec69651c8c21 | 1520 | string_substate = " -- > EMERGENCY_CLIMB <-- "; |
tnhnrl | 74:d281aaef9766 | 1521 | xbee().printf("Neutral Substate #%d: %d (%s)\r\n", i, _state_array[i], string_substate.c_str()); |
tnhnrl | 57:ec69651c8c21 | 1522 | } |
tnhnrl | 74:d281aaef9766 | 1523 | xbee().printf("\r\n"); //make space between printouts |
tnhnrl | 72:250b2665755c | 1524 | } |
tnhnrl | 72:250b2665755c | 1525 | //BATTERY/PITCH |
tnhnrl | 57:ec69651c8c21 | 1526 | else if (user_input == '[' or user_input == '{') { |
tnhnrl | 74:d281aaef9766 | 1527 | xbee().printf("Please TYPE in the new BATT neutral position.\n\r"); |
tnhnrl | 72:250b2665755c | 1528 | _neutral_batt_pos_mm = getFloatUserInput(); |
tnhnrl | 57:ec69651c8c21 | 1529 | pitchLoop().setOutputOffset(_neutral_batt_pos_mm); // decrease the batt neutral setpoint |
tnhnrl | 74:d281aaef9766 | 1530 | xbee().printf("Adjusting batt neutral position. new offset: %0.1f\r\n",pitchLoop().getOutputOffset()); |
tnhnrl | 57:ec69651c8c21 | 1531 | // save neutral pitch value to config file |
tnhnrl | 73:f6f378311c8d | 1532 | configFileIO().savePitchData(_pitch_KP, _pitch_KI, _pitch_KD, _neutral_batt_pos_mm, _pitch_filter_freq, _pitch_deadband); //P,I,D,batt zeroOffset |
tnhnrl | 57:ec69651c8c21 | 1533 | } |
tnhnrl | 28:16c83a2fdefa | 1534 | |
tnhnrl | 72:250b2665755c | 1535 | //BCE/DEPTH |
tnhnrl | 72:250b2665755c | 1536 | else if (user_input == ';' or user_input == ':') { |
tnhnrl | 74:d281aaef9766 | 1537 | xbee().printf("Please TYPE in the new BCE neutral position.\n\r"); |
tnhnrl | 72:250b2665755c | 1538 | _neutral_bce_pos_mm = getFloatUserInput(); |
tnhnrl | 72:250b2665755c | 1539 | depthLoop().setOutputOffset(_neutral_bce_pos_mm); // decrease the bce neutral setpoint |
tnhnrl | 74:d281aaef9766 | 1540 | xbee().printf("Adjusting bce neutral position. new offset: %0.1f\r\n",depthLoop().getOutputOffset()); |
tnhnrl | 72:250b2665755c | 1541 | // save neutral depth value to config file |
tnhnrl | 73:f6f378311c8d | 1542 | configFileIO().saveDepthData(_depth_KP, _depth_KI, _depth_KD, _neutral_bce_pos_mm, _depth_filter_freq, _depth_deadband); |
tnhnrl | 57:ec69651c8c21 | 1543 | } |
tnhnrl | 57:ec69651c8c21 | 1544 | |
tnhnrl | 72:250b2665755c | 1545 | // change settings |
tnhnrl | 72:250b2665755c | 1546 | //heading is in the common controls |
tnhnrl | 72:250b2665755c | 1547 | else if (user_input == 'Q') { |
tnhnrl | 74:d281aaef9766 | 1548 | xbee().printf(">> Please enter the desired PITCH (deg).\r\n"); |
tnhnrl | 72:250b2665755c | 1549 | _pitch_command = getFloatUserInput(); |
tnhnrl | 57:ec69651c8c21 | 1550 | } |
tnhnrl | 72:250b2665755c | 1551 | else if (user_input == 'A') { |
tnhnrl | 74:d281aaef9766 | 1552 | xbee().printf(">> Please enter the desired DEPTH (ft).\r\n"); |
tnhnrl | 72:250b2665755c | 1553 | _depth_command = getFloatUserInput(); |
tnhnrl | 57:ec69651c8c21 | 1554 | } |
tnhnrl | 72:250b2665755c | 1555 | |
tnhnrl | 57:ec69651c8c21 | 1556 | else if (user_input == '5') { |
tnhnrl | 58:94b7fd55185e | 1557 | keyboard_menu_RUDDER_SERVO_settings(); |
tnhnrl | 57:ec69651c8c21 | 1558 | } |
tnhnrl | 57:ec69651c8c21 | 1559 | |
tnhnrl | 57:ec69651c8c21 | 1560 | else if (user_input == '6') { |
tnhnrl | 58:94b7fd55185e | 1561 | keyboard_menu_HEADING_PID_settings(); |
tnhnrl | 58:94b7fd55185e | 1562 | } |
tnhnrl | 57:ec69651c8c21 | 1563 | |
tnhnrl | 58:94b7fd55185e | 1564 | // go to tuning sub-menu |
tnhnrl | 57:ec69651c8c21 | 1565 | else if (user_input == '7') { |
tnhnrl | 58:94b7fd55185e | 1566 | keyboard_menu_MANUAL_TUNING(); |
tnhnrl | 57:ec69651c8c21 | 1567 | } |
tnhnrl | 57:ec69651c8c21 | 1568 | |
tnhnrl | 73:f6f378311c8d | 1569 | // else if (user_input == 'U') { |
tnhnrl | 73:f6f378311c8d | 1570 | // keyboard_menu_POSITION_READINGS(); |
tnhnrl | 73:f6f378311c8d | 1571 | // } |
tnhnrl | 57:ec69651c8c21 | 1572 | |
tnhnrl | 57:ec69651c8c21 | 1573 | // go to sub-menus for the PID gains (this is blocking) |
tnhnrl | 57:ec69651c8c21 | 1574 | else if (user_input == '1') { |
tnhnrl | 57:ec69651c8c21 | 1575 | keyboard_menu_BCE_PID_settings(); |
tnhnrl | 57:ec69651c8c21 | 1576 | } |
tnhnrl | 57:ec69651c8c21 | 1577 | else if (user_input == '2') { |
tnhnrl | 57:ec69651c8c21 | 1578 | keyboard_menu_BATT_PID_settings(); |
tnhnrl | 57:ec69651c8c21 | 1579 | } |
tnhnrl | 57:ec69651c8c21 | 1580 | else if (user_input == '3') { |
tnhnrl | 57:ec69651c8c21 | 1581 | keyboard_menu_DEPTH_PID_settings(); |
tnhnrl | 57:ec69651c8c21 | 1582 | } |
tnhnrl | 57:ec69651c8c21 | 1583 | else if (user_input == '4') { |
tnhnrl | 57:ec69651c8c21 | 1584 | keyboard_menu_PITCH_PID_settings(); |
tnhnrl | 28:16c83a2fdefa | 1585 | } |
tnhnrl | 73:f6f378311c8d | 1586 | |
tnhnrl | 57:ec69651c8c21 | 1587 | else if (user_input == '*') { |
tnhnrl | 74:d281aaef9766 | 1588 | xbee().printf("SWITCHING TO SIMPLE MENU!\r\n"); |
tnhnrl | 74:d281aaef9766 | 1589 | wait(1); |
tnhnrl | 57:ec69651c8c21 | 1590 | _debug_menu_on = false; |
tnhnrl | 57:ec69651c8c21 | 1591 | } |
tnhnrl | 57:ec69651c8c21 | 1592 | } //end of debug menu |
tnhnrl | 57:ec69651c8c21 | 1593 | /***************************** DEBUG MENU *****************************/ |
tnhnrl | 57:ec69651c8c21 | 1594 | |
tnhnrl | 57:ec69651c8c21 | 1595 | /***************************** SIMPLE MENU *****************************/ |
tnhnrl | 72:250b2665755c | 1596 | else { |
tnhnrl | 58:94b7fd55185e | 1597 | if (user_input == 'V') { |
tnhnrl | 58:94b7fd55185e | 1598 | _keyboard_state = POSITION_DIVE; |
tnhnrl | 57:ec69651c8c21 | 1599 | } |
tnhnrl | 57:ec69651c8c21 | 1600 | else if (user_input == 'N') { |
tnhnrl | 57:ec69651c8c21 | 1601 | _keyboard_state = FIND_NEUTRAL; |
tnhnrl | 57:ec69651c8c21 | 1602 | } |
tnhnrl | 57:ec69651c8c21 | 1603 | else if (user_input == 'J') { |
tnhnrl | 57:ec69651c8c21 | 1604 | _keyboard_state = FLOAT_LEVEL; |
tnhnrl | 57:ec69651c8c21 | 1605 | } |
tnhnrl | 57:ec69651c8c21 | 1606 | else if (user_input == 'B') { |
tnhnrl | 57:ec69651c8c21 | 1607 | _keyboard_state = FLOAT_BROADCAST; |
tnhnrl | 57:ec69651c8c21 | 1608 | } |
tnhnrl | 57:ec69651c8c21 | 1609 | else if (user_input == 'E') { |
tnhnrl | 57:ec69651c8c21 | 1610 | _keyboard_state = EMERGENCY_CLIMB; |
tnhnrl | 57:ec69651c8c21 | 1611 | } |
tnhnrl | 57:ec69651c8c21 | 1612 | |
tnhnrl | 57:ec69651c8c21 | 1613 | // some debug tools below |
tnhnrl | 57:ec69651c8c21 | 1614 | else if (user_input == 'P') { |
tnhnrl | 57:ec69651c8c21 | 1615 | //Print current SD card log file |
tnhnrl | 57:ec69651c8c21 | 1616 | //printCurrentSdLog(); |
tnhnrl | 57:ec69651c8c21 | 1617 | mbedLogger().printCurrentLogFile(); //print the current log file to the screen |
tnhnrl | 72:250b2665755c | 1618 | } |
tnhnrl | 57:ec69651c8c21 | 1619 | |
tnhnrl | 57:ec69651c8c21 | 1620 | //POSITION DIVE COMMANDS |
tnhnrl | 72:250b2665755c | 1621 | else if (user_input == 'Q') { |
tnhnrl | 74:d281aaef9766 | 1622 | xbee().printf(">> Please enter the desired BMM offset (mm).\r\n"); |
tnhnrl | 72:250b2665755c | 1623 | _BMM_dive_offset = getFloatUserInput(); |
tnhnrl | 57:ec69651c8c21 | 1624 | } |
tnhnrl | 72:250b2665755c | 1625 | else if (user_input == 'A') { |
tnhnrl | 74:d281aaef9766 | 1626 | xbee().printf(">> Please enter the desired BCE offset (mm).\r\n"); |
tnhnrl | 72:250b2665755c | 1627 | _BCE_dive_offset = getFloatUserInput(); |
tnhnrl | 57:ec69651c8c21 | 1628 | } |
tnhnrl | 73:f6f378311c8d | 1629 | |
tnhnrl | 73:f6f378311c8d | 1630 | else if (user_input == 'S') { |
tnhnrl | 74:d281aaef9766 | 1631 | xbee().printf(">> Please enter the desired DEPTH (ft).\r\n"); |
tnhnrl | 73:f6f378311c8d | 1632 | _depth_command = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 1633 | } |
tnhnrl | 57:ec69651c8c21 | 1634 | //POSITION DIVE COMMANDS |
tnhnrl | 57:ec69651c8c21 | 1635 | |
tnhnrl | 57:ec69651c8c21 | 1636 | else if (user_input == '*') { |
tnhnrl | 74:d281aaef9766 | 1637 | xbee().printf("SWITCHING TO DEBUG MENU!\r\n"); |
tnhnrl | 57:ec69651c8c21 | 1638 | _debug_menu_on = true; |
tnhnrl | 74:d281aaef9766 | 1639 | wait(1); |
tnhnrl | 57:ec69651c8c21 | 1640 | } |
tnhnrl | 16:3363b9f14913 | 1641 | } |
tnhnrl | 57:ec69651c8c21 | 1642 | /***************************** SIMPLE MENU *****************************/ |
tnhnrl | 17:7c16b5671d0e | 1643 | |
tnhnrl | 17:7c16b5671d0e | 1644 | //when you read the keyboard successfully, change the state |
tnhnrl | 28:16c83a2fdefa | 1645 | _state = _keyboard_state; //set state at the end of this function |
tnhnrl | 74:d281aaef9766 | 1646 | //xbee().printf("\r\n\n ********* KEYBOARD STATE: %d *********\r\n\n", _state); |
tnhnrl | 16:3363b9f14913 | 1647 | } |
tnhnrl | 16:3363b9f14913 | 1648 | } |
tnhnrl | 52:f207567d3ea4 | 1649 | |
tnhnrl | 52:f207567d3ea4 | 1650 | void StateMachine::keyboard_menu_STREAM_STATUS() { |
tnhnrl | 52:f207567d3ea4 | 1651 | char STATUS_key; |
tnhnrl | 52:f207567d3ea4 | 1652 | |
tnhnrl | 52:f207567d3ea4 | 1653 | // show the menu |
tnhnrl | 74:d281aaef9766 | 1654 | xbee().printf("\r\n8: STATUS DEBUG MENU (EXIT WITH 'X' !)\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1655 | |
tnhnrl | 52:f207567d3ea4 | 1656 | while (1) { |
tnhnrl | 74:d281aaef9766 | 1657 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 1658 | STATUS_key = xbee().getc(); //get each keystroke |
tnhnrl | 52:f207567d3ea4 | 1659 | } |
tnhnrl | 52:f207567d3ea4 | 1660 | |
tnhnrl | 52:f207567d3ea4 | 1661 | else { |
tnhnrl | 52:f207567d3ea4 | 1662 | |
tnhnrl | 52:f207567d3ea4 | 1663 | wait(1); |
tnhnrl | 54:d4990fb68404 | 1664 | |
tnhnrl | 58:94b7fd55185e | 1665 | |
tnhnrl | 74:d281aaef9766 | 1666 | // xbee().printf("BCE POS (CMD): %0.1f (%0.1f) BATT POS: %0.1f (%0.1f) PRESS_psi: %0.2f [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rudder_servo_pwm: %0.1f \n[FILT/RAW 0(%d,%d),1(%d),2(%d),6(%d),4(%d),5(%d),6(%d),7(%d)] Switch: BCE(%d) BMM(%d)\r",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getSetPosition_pwm(),adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),adc().readCh5(),adc().readCh6(),adc().readCh7(), bce().getHardwareSwitchStatus(),batt().getHardwareSwitchStatus()); |
tnhnrl | 74:d281aaef9766 | 1667 | xbee().printf("BCE POS: %0.1f (cmd %0.1f) BATT POS: %0.1f (cmd %0.1f) PRESS_psi: %0.2f [depth_ft: %0.2f], PITCH: %0.2f, HEADING: %0.2f, rdr_pwm: %0.1f [FILT/RAW 0(%d,%d),1(%d,%d),2(%d,%d),3(%d,%d),4(%d,%d),5(%d,%d),6(%d,%d),7(%d,%d)] Switch: BCE(%d) BMM(%d)\r",bce().getPosition_mm(), bce().getSetPosition_mm(),batt().getPosition_mm(), batt().getSetPosition_mm(),depth().getPsi(),depthLoop().getPosition(),imu().getPitch(),imu().getHeading(),rudder().getSetPosition_pwm(),adc().readCh0(),adc().readRawCh0(),adc().readCh1(),adc().readRawCh1(),adc().readCh2(),adc().readRawCh2(),adc().readCh3(),adc().readRawCh3(),adc().readCh4(),adc().readRawCh4(),adc().readCh5(),adc().readRawCh5(),adc().readCh6(),adc().readRawCh6(),adc().readCh7(),adc().readRawCh7(),bce().getHardwareSwitchStatus(),batt().getHardwareSwitchStatus()); |
tnhnrl | 52:f207567d3ea4 | 1668 | |
tnhnrl | 52:f207567d3ea4 | 1669 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 52:f207567d3ea4 | 1670 | } |
tnhnrl | 52:f207567d3ea4 | 1671 | |
tnhnrl | 52:f207567d3ea4 | 1672 | // process the keys |
tnhnrl | 58:94b7fd55185e | 1673 | if (STATUS_key == 'X') { |
tnhnrl | 74:d281aaef9766 | 1674 | xbee().printf("\r\nX: EXITING STATUS DEBUG MENU\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1675 | break; //exit the while loop |
tnhnrl | 52:f207567d3ea4 | 1676 | } |
tnhnrl | 52:f207567d3ea4 | 1677 | |
tnhnrl | 52:f207567d3ea4 | 1678 | else { |
tnhnrl | 74:d281aaef9766 | 1679 | xbee().printf("\r\nThis key (%c) does nothing here. ", STATUS_key); |
tnhnrl | 52:f207567d3ea4 | 1680 | } |
tnhnrl | 52:f207567d3ea4 | 1681 | } |
tnhnrl | 52:f207567d3ea4 | 1682 | } |
tnhnrl | 52:f207567d3ea4 | 1683 | |
tnhnrl | 52:f207567d3ea4 | 1684 | void StateMachine::keyboard_menu_RUDDER_SERVO_settings() { |
tnhnrl | 52:f207567d3ea4 | 1685 | //load current parameters from the rudder |
tnhnrl | 52:f207567d3ea4 | 1686 | float rudder_min_pwm = rudder().getMinPWM(); |
tnhnrl | 52:f207567d3ea4 | 1687 | float rudder_max_pwm = rudder().getMaxPWM(); |
tnhnrl | 52:f207567d3ea4 | 1688 | float rudder_ctr_pwm = rudder().getCenterPWM(); |
tnhnrl | 52:f207567d3ea4 | 1689 | float rudder_min_deg = rudder().getMinDeg(); |
tnhnrl | 52:f207567d3ea4 | 1690 | float rudder_max_deg = rudder().getMaxDeg(); |
tnhnrl | 52:f207567d3ea4 | 1691 | |
tnhnrl | 52:f207567d3ea4 | 1692 | char RUDDER_PID_key; |
tnhnrl | 52:f207567d3ea4 | 1693 | |
tnhnrl | 52:f207567d3ea4 | 1694 | // print the menu |
tnhnrl | 74:d281aaef9766 | 1695 | xbee().printf("\r\nRUDDER (servo driver) settings (MENU)"); |
tnhnrl | 74:d281aaef9766 | 1696 | xbee().printf("\r\nAdjust min_pwm/max_pwm/center_pwm/min_deg/max_deg settings with the following keys: N, M, C, K, L"); |
tnhnrl | 74:d281aaef9766 | 1697 | xbee().printf("\r\nHit shift + X to exit w/o saving. Hit shift + S to save.\r\n"); |
tnhnrl | 74:d281aaef9766 | 1698 | xbee().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); |
tnhnrl | 52:f207567d3ea4 | 1699 | |
tnhnrl | 52:f207567d3ea4 | 1700 | // handle the key presses |
tnhnrl | 52:f207567d3ea4 | 1701 | while(1) { |
tnhnrl | 52:f207567d3ea4 | 1702 | // get the user's keystroke from either of the two inputs |
tnhnrl | 74:d281aaef9766 | 1703 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 1704 | RUDDER_PID_key = xbee().getc(); |
tnhnrl | 52:f207567d3ea4 | 1705 | } |
tnhnrl | 52:f207567d3ea4 | 1706 | else { |
tnhnrl | 52:f207567d3ea4 | 1707 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 52:f207567d3ea4 | 1708 | } |
tnhnrl | 52:f207567d3ea4 | 1709 | |
tnhnrl | 52:f207567d3ea4 | 1710 | // handle the user's key input |
tnhnrl | 52:f207567d3ea4 | 1711 | if (RUDDER_PID_key == 'S') { // user wants to save the modified values |
tnhnrl | 52:f207567d3ea4 | 1712 | // set global values |
tnhnrl | 52:f207567d3ea4 | 1713 | rudder().setMinPWM(rudder_min_pwm); |
tnhnrl | 52:f207567d3ea4 | 1714 | rudder().setMaxPWM(rudder_max_pwm); |
tnhnrl | 52:f207567d3ea4 | 1715 | rudder().setCenterPWM(rudder_ctr_pwm); |
tnhnrl | 52:f207567d3ea4 | 1716 | rudder().setMinDeg(rudder_min_deg); |
tnhnrl | 52:f207567d3ea4 | 1717 | rudder().setMaxDeg(rudder_max_deg); |
tnhnrl | 52:f207567d3ea4 | 1718 | |
tnhnrl | 52:f207567d3ea4 | 1719 | // save rudder servo driver values for inner loop |
tnhnrl | 52:f207567d3ea4 | 1720 | configFileIO().saveRudderData(rudder_min_deg, rudder_max_deg, rudder_ctr_pwm, rudder_min_pwm, rudder_max_pwm); |
tnhnrl | 74:d281aaef9766 | 1721 | xbee().printf("RUDDER min pwm: %f, max pwm: %f, center pwm: %f, min deg: %f, max deg: %f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg()); |
tnhnrl | 74:d281aaef9766 | 1722 | xbee().printf("Adjust min_pwm/max_pwm/center_pwm/min_deg/max_deg settings with the following keys: N, M, C, K, L\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1723 | } |
tnhnrl | 52:f207567d3ea4 | 1724 | else if (RUDDER_PID_key == 'X') { |
tnhnrl | 52:f207567d3ea4 | 1725 | break; //exit the while loop |
tnhnrl | 52:f207567d3ea4 | 1726 | } |
tnhnrl | 52:f207567d3ea4 | 1727 | // MIN PWM |
tnhnrl | 52:f207567d3ea4 | 1728 | else if (RUDDER_PID_key == 'N') { |
tnhnrl | 74:d281aaef9766 | 1729 | xbee().printf(">> Type in rudder_min_pwm with keyboard.\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1730 | rudder_min_pwm = getFloatUserInput(); |
tnhnrl | 52:f207567d3ea4 | 1731 | } |
tnhnrl | 52:f207567d3ea4 | 1732 | // MAX PWM |
tnhnrl | 52:f207567d3ea4 | 1733 | else if (RUDDER_PID_key == 'M') { |
tnhnrl | 74:d281aaef9766 | 1734 | xbee().printf(">> Type in rudder_max_pwm with keyboard.\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1735 | rudder_max_pwm = getFloatUserInput(); |
tnhnrl | 52:f207567d3ea4 | 1736 | } |
tnhnrl | 52:f207567d3ea4 | 1737 | // CENTER PWM |
tnhnrl | 52:f207567d3ea4 | 1738 | else if (RUDDER_PID_key == 'C') { |
tnhnrl | 74:d281aaef9766 | 1739 | xbee().printf(">> Type in rudder_ctr_pwm with keyboard.\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1740 | rudder_ctr_pwm = getFloatUserInput(); |
tnhnrl | 52:f207567d3ea4 | 1741 | } |
tnhnrl | 52:f207567d3ea4 | 1742 | // MIN DEG |
tnhnrl | 52:f207567d3ea4 | 1743 | else if (RUDDER_PID_key == 'K') { |
tnhnrl | 74:d281aaef9766 | 1744 | xbee().printf(">> Type in rudder_min_deg with keyboard.\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1745 | rudder_min_deg = getFloatUserInput(); |
tnhnrl | 52:f207567d3ea4 | 1746 | } |
tnhnrl | 52:f207567d3ea4 | 1747 | // MAX DEG |
tnhnrl | 52:f207567d3ea4 | 1748 | else if (RUDDER_PID_key == 'L') { |
tnhnrl | 74:d281aaef9766 | 1749 | xbee().printf(">> Type in rudder_max_deg with keyboard.\r\n"); |
tnhnrl | 52:f207567d3ea4 | 1750 | rudder_max_deg = getFloatUserInput(); |
tnhnrl | 74:d281aaef9766 | 1751 | } |
tnhnrl | 52:f207567d3ea4 | 1752 | else { |
tnhnrl | 74:d281aaef9766 | 1753 | xbee().printf("RUDDER SETUP: [%c] This key does nothing here. \r", RUDDER_PID_key); |
tnhnrl | 52:f207567d3ea4 | 1754 | } |
tnhnrl | 52:f207567d3ea4 | 1755 | } |
tnhnrl | 52:f207567d3ea4 | 1756 | } |
tnhnrl | 54:d4990fb68404 | 1757 | |
tnhnrl | 54:d4990fb68404 | 1758 | void StateMachine::keyboard_menu_COUNTS_STATUS() { |
tnhnrl | 73:f6f378311c8d | 1759 | // DELETE REMOVE |
tnhnrl | 54:d4990fb68404 | 1760 | } |
tnhnrl | 56:48a8a5a65b82 | 1761 | |
tnhnrl | 49:47ffa4feb6db | 1762 | void StateMachine::keyboard_menu_MANUAL_TUNING() { |
tnhnrl | 49:47ffa4feb6db | 1763 | char TUNING_key; |
tnhnrl | 49:47ffa4feb6db | 1764 | |
tnhnrl | 56:48a8a5a65b82 | 1765 | //made these into internal parameters |
tnhnrl | 74:d281aaef9766 | 1766 | float _tuning_bce_pos_mm = 200.0; //safe starting position |
tnhnrl | 74:d281aaef9766 | 1767 | float _tuning_batt_pos_mm = 40.0; //safe starting position |
tnhnrl | 56:48a8a5a65b82 | 1768 | float _tuning_rudder_pos_deg = 0.0; //safe starting position |
tnhnrl | 74:d281aaef9766 | 1769 | float _tuning_rudder_pwm = 1640.0; |
tnhnrl | 56:48a8a5a65b82 | 1770 | |
tnhnrl | 56:48a8a5a65b82 | 1771 | //immediately start at those positions |
tnhnrl | 56:48a8a5a65b82 | 1772 | bce().setPosition_mm(_tuning_bce_pos_mm); |
tnhnrl | 56:48a8a5a65b82 | 1773 | batt().setPosition_mm(_tuning_batt_pos_mm); |
tnhnrl | 56:48a8a5a65b82 | 1774 | rudder().setPosition_deg(_tuning_rudder_pos_deg); |
tnhnrl | 49:47ffa4feb6db | 1775 | |
tnhnrl | 74:d281aaef9766 | 1776 | // show the menu |
tnhnrl | 74:d281aaef9766 | 1777 | xbee().printf("\r\n7: MANUAL TUNING MENU (EXIT WITH 'X' !) (Pause and Unpause rudder ticker with P and U\n"); |
tnhnrl | 74:d281aaef9766 | 1778 | xbee().printf("\r\n(Adjust BCE and BATT positions in real-time. Timeout NOT running! (decrease/increase BCE with A/S, BATT with Q/W, RUDDER with E/R)\r\n"); |
tnhnrl | 74:d281aaef9766 | 1779 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 74:d281aaef9766 | 1780 | |
tnhnrl | 49:47ffa4feb6db | 1781 | // what needs to be started? |
tnhnrl | 49:47ffa4feb6db | 1782 | bce().unpause(); //this is now active |
tnhnrl | 49:47ffa4feb6db | 1783 | batt().unpause(); //this is now active |
tnhnrl | 56:48a8a5a65b82 | 1784 | rudder().unpause(); |
tnhnrl | 49:47ffa4feb6db | 1785 | |
tnhnrl | 69:919ac8d7e023 | 1786 | while (1) { |
tnhnrl | 69:919ac8d7e023 | 1787 | wait(0.1); |
tnhnrl | 69:919ac8d7e023 | 1788 | |
tnhnrl | 74:d281aaef9766 | 1789 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 1790 | TUNING_key = xbee().getc(); //get each keystroke |
tnhnrl | 49:47ffa4feb6db | 1791 | } |
tnhnrl | 49:47ffa4feb6db | 1792 | |
tnhnrl | 58:94b7fd55185e | 1793 | else { |
tnhnrl | 74:d281aaef9766 | 1794 | //xbee().printf("MT: POS (CMD) BCE %3.1f mm (%3.1f mm), BATT %3.1f mm (%3.1f mm) SERVO: %0.1f deg, (%0.1f pwm) PITCH: %0.1f,HEADING: %0.1f \r", bce().getPosition_mm(), bce().getSetPosition_mm(), batt().getPosition_mm(), batt().getSetPosition_mm(), rudder().getSetPosition_deg(), rudder().getSetPosition_pwm(),imu().getPitch(),imu().getHeading()); |
tnhnrl | 49:47ffa4feb6db | 1795 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 49:47ffa4feb6db | 1796 | } |
tnhnrl | 49:47ffa4feb6db | 1797 | |
tnhnrl | 49:47ffa4feb6db | 1798 | // process the keys |
tnhnrl | 49:47ffa4feb6db | 1799 | if (TUNING_key == 'X') { |
tnhnrl | 49:47ffa4feb6db | 1800 | // STOP THE MOTORS BEFORE LEAVING! (Just in case.) |
tnhnrl | 49:47ffa4feb6db | 1801 | bce().pause(); |
tnhnrl | 49:47ffa4feb6db | 1802 | batt().pause(); |
tnhnrl | 56:48a8a5a65b82 | 1803 | rudder().pause(); |
tnhnrl | 56:48a8a5a65b82 | 1804 | |
tnhnrl | 56:48a8a5a65b82 | 1805 | //right now the rudder is always active................................................hmm |
tnhnrl | 56:48a8a5a65b82 | 1806 | //deactivate the pin? new/delete? |
tnhnrl | 49:47ffa4feb6db | 1807 | |
tnhnrl | 49:47ffa4feb6db | 1808 | break; //exit the while loop |
tnhnrl | 49:47ffa4feb6db | 1809 | } |
tnhnrl | 56:48a8a5a65b82 | 1810 | |
tnhnrl | 56:48a8a5a65b82 | 1811 | //Buoyancy Engine |
tnhnrl | 74:d281aaef9766 | 1812 | else if (TUNING_key == 'A' or TUNING_key == 'a') { |
tnhnrl | 56:48a8a5a65b82 | 1813 | _tuning_bce_pos_mm = _tuning_bce_pos_mm - 1.0; |
tnhnrl | 56:48a8a5a65b82 | 1814 | bce().setPosition_mm(_tuning_bce_pos_mm); //this variable is loaded from the file at initialization |
tnhnrl | 74:d281aaef9766 | 1815 | xbee().printf("\r\nMANUAL_TUNING: (BCE CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",bce().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1816 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 52:f207567d3ea4 | 1817 | } |
tnhnrl | 52:f207567d3ea4 | 1818 | |
tnhnrl | 74:d281aaef9766 | 1819 | else if (TUNING_key == 'S' or TUNING_key == 's') { |
tnhnrl | 56:48a8a5a65b82 | 1820 | _tuning_bce_pos_mm = _tuning_bce_pos_mm + 1.0; |
tnhnrl | 56:48a8a5a65b82 | 1821 | bce().setPosition_mm(_tuning_bce_pos_mm); //this variable is loaded from the file at initialization |
tnhnrl | 74:d281aaef9766 | 1822 | xbee().printf("\r\nMANUAL_TUNING: (BCE CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",bce().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1823 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 49:47ffa4feb6db | 1824 | } |
tnhnrl | 49:47ffa4feb6db | 1825 | |
tnhnrl | 56:48a8a5a65b82 | 1826 | //BATTERY |
tnhnrl | 74:d281aaef9766 | 1827 | else if (TUNING_key == 'Q' or TUNING_key == 'q') { |
tnhnrl | 56:48a8a5a65b82 | 1828 | _tuning_batt_pos_mm = _tuning_batt_pos_mm - 1.0; |
tnhnrl | 56:48a8a5a65b82 | 1829 | batt().setPosition_mm(_tuning_batt_pos_mm); //this variable is loaded from the file at initialization |
tnhnrl | 74:d281aaef9766 | 1830 | xbee().printf("\r\nMANUAL_TUNING: (BATT CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",batt().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1831 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 49:47ffa4feb6db | 1832 | } |
tnhnrl | 49:47ffa4feb6db | 1833 | |
tnhnrl | 74:d281aaef9766 | 1834 | else if (TUNING_key == 'W' or TUNING_key == 'w') { |
tnhnrl | 56:48a8a5a65b82 | 1835 | _tuning_batt_pos_mm = _tuning_batt_pos_mm + 1.0; |
tnhnrl | 56:48a8a5a65b82 | 1836 | batt().setPosition_mm(_tuning_batt_pos_mm); //this variable is loaded from the file at initialization |
tnhnrl | 74:d281aaef9766 | 1837 | xbee().printf("\r\nMANUAL_TUNING: (BATT CHANGE: %0.1f)\r\n BCE_position: %0.1f, BATT_position: %0.1f (depth: %0.1f ft, pitch: %0.1f deg)\r",batt().getSetPosition_mm(),bce().getPosition_mm(),batt().getPosition_mm(),depthLoop().getPosition(),pitchLoop().getPosition()); |
tnhnrl | 74:d281aaef9766 | 1838 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 56:48a8a5a65b82 | 1839 | } |
tnhnrl | 56:48a8a5a65b82 | 1840 | |
tnhnrl | 56:48a8a5a65b82 | 1841 | else if (TUNING_key == 'c' or TUNING_key == 'C') { |
tnhnrl | 74:d281aaef9766 | 1842 | xbee().printf("\r\nMT: (CURRENT POSITIONS) BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 56:48a8a5a65b82 | 1843 | } |
tnhnrl | 56:48a8a5a65b82 | 1844 | |
tnhnrl | 56:48a8a5a65b82 | 1845 | //RUDER |
tnhnrl | 74:d281aaef9766 | 1846 | else if (TUNING_key == 'R' or TUNING_key == 'r') { |
tnhnrl | 56:48a8a5a65b82 | 1847 | _tuning_rudder_pos_deg = _tuning_rudder_pos_deg - 0.5; |
tnhnrl | 56:48a8a5a65b82 | 1848 | rudder().setPosition_deg(_tuning_rudder_pos_deg); |
tnhnrl | 74:d281aaef9766 | 1849 | xbee().printf("MT: RUDDER CHANGE %0.1f deg [servo pwm: %f, %0.1f deg] (headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg)\r\n", _tuning_rudder_pos_deg, rudder().getSetPosition_pwm(), rudder().getSetPosition_deg(), headingLoop().getPosition(), imu().getHeading()); |
tnhnrl | 74:d281aaef9766 | 1850 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 56:48a8a5a65b82 | 1851 | } |
tnhnrl | 56:48a8a5a65b82 | 1852 | |
tnhnrl | 74:d281aaef9766 | 1853 | else if (TUNING_key == 'E' or TUNING_key == 'e') { |
tnhnrl | 56:48a8a5a65b82 | 1854 | _tuning_rudder_pos_deg = _tuning_rudder_pos_deg + 0.5; |
tnhnrl | 56:48a8a5a65b82 | 1855 | rudder().setPosition_deg(_tuning_rudder_pos_deg); |
tnhnrl | 74:d281aaef9766 | 1856 | xbee().printf("MT: RUDDER CHANGE %0.1f deg [servo pwm: %f, %0.1f deg] (headingLoop heading: % 0.1f deg, IMU heading: %0.1f deg)\r\n", _tuning_rudder_pos_deg, rudder().getSetPosition_pwm(), rudder().getSetPosition_deg(), headingLoop().getPosition(), imu().getHeading()); |
tnhnrl | 74:d281aaef9766 | 1857 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 56:48a8a5a65b82 | 1858 | } |
tnhnrl | 56:48a8a5a65b82 | 1859 | |
tnhnrl | 74:d281aaef9766 | 1860 | else if (TUNING_key == '-' or TUNING_key == '_') { |
tnhnrl | 74:d281aaef9766 | 1861 | _tuning_rudder_pwm -= 10.0; |
tnhnrl | 74:d281aaef9766 | 1862 | rudder().setPWM(_tuning_rudder_pwm); |
tnhnrl | 74:d281aaef9766 | 1863 | xbee().printf("MT: (-) RUDDER CHANGE %0.1f pwm\n\r", rudder().getSetPosition_pwm()); |
tnhnrl | 74:d281aaef9766 | 1864 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 56:48a8a5a65b82 | 1865 | } |
tnhnrl | 74:d281aaef9766 | 1866 | |
tnhnrl | 74:d281aaef9766 | 1867 | else if (TUNING_key == '=' or TUNING_key == '+') { |
tnhnrl | 74:d281aaef9766 | 1868 | _tuning_rudder_pwm += 10.0; |
tnhnrl | 74:d281aaef9766 | 1869 | rudder().setPWM(_tuning_rudder_pwm); |
tnhnrl | 74:d281aaef9766 | 1870 | xbee().printf("MT: (+) RUDDER CHANGE %0.1f pwm\n\r", rudder().getSetPosition_pwm()); |
tnhnrl | 74:d281aaef9766 | 1871 | xbee().printf("\r\nMT: BCE pos:%5.1f (cmd:%5.1f), BMM:%5.1f (cmd:%5.1f), RUDDER:%6.1f (%6.1f deg) (depth: %0.1f ft, pitch: %0.1f deg, headingLoop heading: %0.1f deg, IMU heading: %0.1f deg) \n\n\r",bce().getPosition_mm(),bce().getSetPosition_mm(),batt().getPosition_mm(),batt().getSetPosition_mm(),rudder().getSetPosition_pwm(),rudder().getSetPosition_deg(),depthLoop().getPosition(),pitchLoop().getPosition(), headingLoop().getPosition(),imu().getHeading()); |
tnhnrl | 49:47ffa4feb6db | 1872 | } |
tnhnrl | 49:47ffa4feb6db | 1873 | |
tnhnrl | 49:47ffa4feb6db | 1874 | else { |
tnhnrl | 74:d281aaef9766 | 1875 | xbee().printf("\r\nMANUAL_TUNING: [%c] This key does nothing here. \r", TUNING_key); |
tnhnrl | 56:48a8a5a65b82 | 1876 | } |
tnhnrl | 49:47ffa4feb6db | 1877 | } |
tnhnrl | 49:47ffa4feb6db | 1878 | } |
tnhnrl | 52:f207567d3ea4 | 1879 | |
tnhnrl | 52:f207567d3ea4 | 1880 | void StateMachine::keyboard_menu_CHANNEL_READINGS() { |
tnhnrl | 52:f207567d3ea4 | 1881 | char TUNING_key; |
tnhnrl | 52:f207567d3ea4 | 1882 | |
tnhnrl | 52:f207567d3ea4 | 1883 | // show the menu |
tnhnrl | 74:d281aaef9766 | 1884 | xbee().printf("\r\n8: CHANNEL READINGS (EXIT WITH 'X' !)"); |
tnhnrl | 55:f4ec445c42fe | 1885 | |
tnhnrl | 55:f4ec445c42fe | 1886 | while (1) { |
tnhnrl | 74:d281aaef9766 | 1887 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 1888 | TUNING_key = xbee().getc(); //get each keystroke |
tnhnrl | 55:f4ec445c42fe | 1889 | } |
tnhnrl | 55:f4ec445c42fe | 1890 | |
tnhnrl | 55:f4ec445c42fe | 1891 | // process the keys |
tnhnrl | 55:f4ec445c42fe | 1892 | if (TUNING_key == 'X') { |
tnhnrl | 55:f4ec445c42fe | 1893 | // STOP THE MOTORS BEFORE LEAVING! (Just in case.) |
tnhnrl | 55:f4ec445c42fe | 1894 | bce().pause(); |
tnhnrl | 55:f4ec445c42fe | 1895 | batt().pause(); |
tnhnrl | 55:f4ec445c42fe | 1896 | |
tnhnrl | 55:f4ec445c42fe | 1897 | break; //exit the while loop |
tnhnrl | 55:f4ec445c42fe | 1898 | } |
tnhnrl | 55:f4ec445c42fe | 1899 | |
tnhnrl | 55:f4ec445c42fe | 1900 | else { |
tnhnrl | 55:f4ec445c42fe | 1901 | wait(0.5); |
tnhnrl | 74:d281aaef9766 | 1902 | xbee().printf("0(%d),1(%d),2(%d),6(%d),4(%d),5(%d),6(%d),7(%d)\r\n",adc().readCh0(),adc().readCh1(),adc().readCh2(),adc().readCh3(),adc().readCh4(),adc().readCh5(),adc().readCh6(),adc().readCh7()); |
tnhnrl | 55:f4ec445c42fe | 1903 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 55:f4ec445c42fe | 1904 | } |
tnhnrl | 55:f4ec445c42fe | 1905 | } |
tnhnrl | 55:f4ec445c42fe | 1906 | } |
tnhnrl | 49:47ffa4feb6db | 1907 | |
tnhnrl | 16:3363b9f14913 | 1908 | void StateMachine::keyboard_menu_BCE_PID_settings() { |
tnhnrl | 73:f6f378311c8d | 1909 | char BCE_PID_key; |
tnhnrl | 63:6cb0405fc6e6 | 1910 | |
tnhnrl | 76:c802e1da4179 | 1911 | // load current values from files |
tnhnrl | 76:c802e1da4179 | 1912 | float bce_KP = bce().getControllerP(); |
tnhnrl | 76:c802e1da4179 | 1913 | float bce_KI = bce().getControllerI(); |
tnhnrl | 76:c802e1da4179 | 1914 | float bce_KD = bce().getControllerD(); |
tnhnrl | 76:c802e1da4179 | 1915 | |
tnhnrl | 76:c802e1da4179 | 1916 | float bce_deadband = bce().getDeadband(); |
tnhnrl | 76:c802e1da4179 | 1917 | float bce_frequency = bce().getFilterFrequency(); |
tnhnrl | 76:c802e1da4179 | 1918 | int bce_zero_offset = bce().getZeroCounts(); |
tnhnrl | 76:c802e1da4179 | 1919 | //BCE frequency and deadband are hardcoded! |
tnhnrl | 16:3363b9f14913 | 1920 | |
tnhnrl | 16:3363b9f14913 | 1921 | // show the menu |
tnhnrl | 76:c802e1da4179 | 1922 | xbee().printf("\n\rBuoyancy Engine PID gain settings (MENU). ADJUST WITH CARE!"); |
tnhnrl | 76:c802e1da4179 | 1923 | xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B, zero offset = Z\n\r"); |
tnhnrl | 74:d281aaef9766 | 1924 | xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); |
tnhnrl | 76:c802e1da4179 | 1925 | xbee().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, filter_freq: %0.1f, deadband: %0.1f\r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope(), bce().getFilterFrequency(), bce().getDeadband()); |
tnhnrl | 63:6cb0405fc6e6 | 1926 | |
tnhnrl | 63:6cb0405fc6e6 | 1927 | // handle the key presses |
tnhnrl | 63:6cb0405fc6e6 | 1928 | while(1) { |
tnhnrl | 63:6cb0405fc6e6 | 1929 | // get the user's keystroke from either of the two inputs |
tnhnrl | 74:d281aaef9766 | 1930 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 1931 | BCE_PID_key = xbee().getc(); |
tnhnrl | 63:6cb0405fc6e6 | 1932 | } |
tnhnrl | 63:6cb0405fc6e6 | 1933 | else { |
tnhnrl | 63:6cb0405fc6e6 | 1934 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 63:6cb0405fc6e6 | 1935 | } |
tnhnrl | 63:6cb0405fc6e6 | 1936 | |
tnhnrl | 63:6cb0405fc6e6 | 1937 | // handle the user's key input |
tnhnrl | 73:f6f378311c8d | 1938 | if (BCE_PID_key == 'S') { // user wants to save these modified values |
tnhnrl | 63:6cb0405fc6e6 | 1939 | // set values |
tnhnrl | 63:6cb0405fc6e6 | 1940 | bce().setControllerP(bce_KP); |
tnhnrl | 63:6cb0405fc6e6 | 1941 | bce().setControllerI(bce_KI); |
tnhnrl | 76:c802e1da4179 | 1942 | bce().setControllerD(bce_KD); |
tnhnrl | 76:c802e1da4179 | 1943 | |
tnhnrl | 76:c802e1da4179 | 1944 | bce().setDeadband(bce_deadband); |
tnhnrl | 76:c802e1da4179 | 1945 | bce().setFilterFrequency(bce_frequency); |
tnhnrl | 76:c802e1da4179 | 1946 | bce().setZeroCounts(bce_zero_offset); //integer value |
tnhnrl | 63:6cb0405fc6e6 | 1947 | |
tnhnrl | 73:f6f378311c8d | 1948 | // save to "BCE.TXT" file |
tnhnrl | 76:c802e1da4179 | 1949 | //saveBattData(float batt_p_gain, float batt_i_gain, float batt_d_gain, int batt_zeroOffset, float batt_filter_freq, float batt_deadband) |
tnhnrl | 76:c802e1da4179 | 1950 | configFileIO().saveBCEData(bce_KP, bce_KI, bce_KD, bce_zero_offset, bce_frequency, bce_deadband); |
tnhnrl | 76:c802e1da4179 | 1951 | xbee().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, filter_freq: %0.1f, deadband: %0.1f\r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope(), bce().getFilterFrequency(), bce().getDeadband()); |
tnhnrl | 63:6cb0405fc6e6 | 1952 | } |
tnhnrl | 73:f6f378311c8d | 1953 | else if (BCE_PID_key == 'X') { |
tnhnrl | 63:6cb0405fc6e6 | 1954 | break; //exit the while loop |
tnhnrl | 63:6cb0405fc6e6 | 1955 | } |
tnhnrl | 73:f6f378311c8d | 1956 | else if (BCE_PID_key == 'P') { |
tnhnrl | 74:d281aaef9766 | 1957 | xbee().printf(">> Type in proportional gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 1958 | bce_KP = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 1959 | } |
tnhnrl | 73:f6f378311c8d | 1960 | else if (BCE_PID_key == 'I') { |
tnhnrl | 74:d281aaef9766 | 1961 | xbee().printf(">> Type in integral gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 1962 | bce_KI = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 1963 | } |
tnhnrl | 73:f6f378311c8d | 1964 | else if (BCE_PID_key == 'D') { |
tnhnrl | 74:d281aaef9766 | 1965 | xbee().printf(">> Type in derivative gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 1966 | bce_KD = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 1967 | } |
tnhnrl | 73:f6f378311c8d | 1968 | else if (BCE_PID_key == 'F') { |
tnhnrl | 74:d281aaef9766 | 1969 | xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); |
tnhnrl | 76:c802e1da4179 | 1970 | bce_frequency = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 1971 | } |
tnhnrl | 73:f6f378311c8d | 1972 | else if (BCE_PID_key == 'B') { |
tnhnrl | 74:d281aaef9766 | 1973 | xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); |
tnhnrl | 76:c802e1da4179 | 1974 | bce_deadband = getFloatUserInput(); |
tnhnrl | 76:c802e1da4179 | 1975 | } |
tnhnrl | 76:c802e1da4179 | 1976 | else if (BCE_PID_key == 'Z') { |
tnhnrl | 76:c802e1da4179 | 1977 | xbee().printf(">> Type in zero count offset with keyboard.\n\r"); |
tnhnrl | 76:c802e1da4179 | 1978 | bce_zero_offset = (int)getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 1979 | } |
tnhnrl | 63:6cb0405fc6e6 | 1980 | else { |
tnhnrl | 74:d281aaef9766 | 1981 | xbee().printf("\n\rBCE: [%c] This key does nothing here. \r", BCE_PID_key); |
tnhnrl | 63:6cb0405fc6e6 | 1982 | } |
tnhnrl | 63:6cb0405fc6e6 | 1983 | } |
tnhnrl | 63:6cb0405fc6e6 | 1984 | } |
tnhnrl | 63:6cb0405fc6e6 | 1985 | |
tnhnrl | 63:6cb0405fc6e6 | 1986 | void StateMachine::keyboard_menu_BATT_PID_settings() { |
tnhnrl | 73:f6f378311c8d | 1987 | char BMM_PID_key; |
tnhnrl | 76:c802e1da4179 | 1988 | |
tnhnrl | 76:c802e1da4179 | 1989 | // load current values from files |
tnhnrl | 76:c802e1da4179 | 1990 | float batt_KP = batt().getControllerP(); |
tnhnrl | 76:c802e1da4179 | 1991 | float batt_KI = batt().getControllerI(); |
tnhnrl | 76:c802e1da4179 | 1992 | float batt_KD = batt().getControllerD(); |
tnhnrl | 63:6cb0405fc6e6 | 1993 | |
tnhnrl | 76:c802e1da4179 | 1994 | float batt_deadband = batt().getDeadband(); |
tnhnrl | 76:c802e1da4179 | 1995 | float batt_frequency = batt().getFilterFrequency(); |
tnhnrl | 76:c802e1da4179 | 1996 | int batt_zero_offset = batt().getZeroCounts(); |
tnhnrl | 76:c802e1da4179 | 1997 | //BATT frequency and deadband are hardcoded! |
tnhnrl | 63:6cb0405fc6e6 | 1998 | |
tnhnrl | 63:6cb0405fc6e6 | 1999 | // print the menu |
tnhnrl | 74:d281aaef9766 | 2000 | xbee().printf("\n\rBattery Motor PID gain settings (MENU)"); |
tnhnrl | 74:d281aaef9766 | 2001 | xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); |
tnhnrl | 74:d281aaef9766 | 2002 | xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); |
tnhnrl | 76:c802e1da4179 | 2003 | xbee().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, filter_freq: %0.1f, deadband: %0.1f\r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope(), batt().getFilterFrequency(), batt().getDeadband()); |
tnhnrl | 76:c802e1da4179 | 2004 | |
tnhnrl | 16:3363b9f14913 | 2005 | // handle the key presses |
tnhnrl | 16:3363b9f14913 | 2006 | while(1) { |
tnhnrl | 16:3363b9f14913 | 2007 | // get the user's keystroke from either of the two inputs |
tnhnrl | 74:d281aaef9766 | 2008 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 2009 | BMM_PID_key = xbee().getc(); |
tnhnrl | 16:3363b9f14913 | 2010 | } |
tnhnrl | 16:3363b9f14913 | 2011 | else { |
tnhnrl | 16:3363b9f14913 | 2012 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 16:3363b9f14913 | 2013 | } |
tnhnrl | 16:3363b9f14913 | 2014 | |
tnhnrl | 16:3363b9f14913 | 2015 | // handle the user's key input |
tnhnrl | 73:f6f378311c8d | 2016 | if (BMM_PID_key == 'S') { // user wants to save these modified values |
tnhnrl | 16:3363b9f14913 | 2017 | // set values |
tnhnrl | 63:6cb0405fc6e6 | 2018 | batt().setControllerP(batt_KP); |
tnhnrl | 63:6cb0405fc6e6 | 2019 | batt().setControllerI(batt_KI); |
tnhnrl | 76:c802e1da4179 | 2020 | batt().setControllerD(batt_KD); |
tnhnrl | 76:c802e1da4179 | 2021 | |
tnhnrl | 76:c802e1da4179 | 2022 | batt().setDeadband(batt_deadband); |
tnhnrl | 76:c802e1da4179 | 2023 | batt().setFilterFrequency(batt_frequency); |
tnhnrl | 76:c802e1da4179 | 2024 | batt().setZeroCounts(batt_zero_offset); //integer value |
tnhnrl | 16:3363b9f14913 | 2025 | |
tnhnrl | 38:83d06c294807 | 2026 | // save to "BATT.TXT" file |
tnhnrl | 76:c802e1da4179 | 2027 | //saveBCEData(float bce_p_gain, float bce_i_gain, float bce_d_gain, int bce_zeroOffset, float bce_filter_freq, float bce_deadband) |
tnhnrl | 76:c802e1da4179 | 2028 | configFileIO().saveBattData(batt_KP, batt_KI, batt_KD, batt_zero_offset, batt_frequency, batt_deadband); |
tnhnrl | 76:c802e1da4179 | 2029 | xbee().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero offset: %3i, limit %6.1f mm, slope %0.5f, filter_freq: %0.1f, deadband: %0.1f\r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope(), batt().getFilterFrequency(), batt().getDeadband()); |
tnhnrl | 16:3363b9f14913 | 2030 | } |
tnhnrl | 73:f6f378311c8d | 2031 | else if (BMM_PID_key == 'X') { |
tnhnrl | 16:3363b9f14913 | 2032 | break; //exit the while loop |
tnhnrl | 16:3363b9f14913 | 2033 | } |
tnhnrl | 73:f6f378311c8d | 2034 | else if (BMM_PID_key == 'P') { |
tnhnrl | 74:d281aaef9766 | 2035 | xbee().printf(">> Type in proportional gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2036 | batt_KP = getFloatUserInput(); |
tnhnrl | 16:3363b9f14913 | 2037 | } |
tnhnrl | 73:f6f378311c8d | 2038 | else if (BMM_PID_key == 'I') { |
tnhnrl | 74:d281aaef9766 | 2039 | xbee().printf(">> Type in integral gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2040 | batt_KI = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2041 | } |
tnhnrl | 73:f6f378311c8d | 2042 | else if (BMM_PID_key == 'D') { |
tnhnrl | 74:d281aaef9766 | 2043 | xbee().printf(">> Type in derivative gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2044 | batt_KD = getFloatUserInput(); |
tnhnrl | 16:3363b9f14913 | 2045 | } |
tnhnrl | 73:f6f378311c8d | 2046 | else if (BMM_PID_key == 'F') { |
tnhnrl | 74:d281aaef9766 | 2047 | xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); |
tnhnrl | 76:c802e1da4179 | 2048 | batt_frequency = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2049 | } |
tnhnrl | 73:f6f378311c8d | 2050 | else if (BMM_PID_key == 'B') { |
tnhnrl | 74:d281aaef9766 | 2051 | xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); |
tnhnrl | 76:c802e1da4179 | 2052 | batt_deadband = getFloatUserInput(); |
tnhnrl | 76:c802e1da4179 | 2053 | } |
tnhnrl | 76:c802e1da4179 | 2054 | else if (BMM_PID_key == 'Z') { |
tnhnrl | 76:c802e1da4179 | 2055 | xbee().printf(">> Type in zero count offset with keyboard.\n\r"); |
tnhnrl | 76:c802e1da4179 | 2056 | batt_zero_offset = (int)getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2057 | } |
tnhnrl | 16:3363b9f14913 | 2058 | else { |
tnhnrl | 74:d281aaef9766 | 2059 | xbee().printf("\n\rBATT: [%c] This key does nothing here. \r", BMM_PID_key); |
tnhnrl | 16:3363b9f14913 | 2060 | } |
tnhnrl | 16:3363b9f14913 | 2061 | } |
tnhnrl | 16:3363b9f14913 | 2062 | } |
tnhnrl | 20:8987a9ae2bc7 | 2063 | |
tnhnrl | 16:3363b9f14913 | 2064 | void StateMachine::keyboard_menu_DEPTH_PID_settings() { |
tnhnrl | 73:f6f378311c8d | 2065 | char DEPTH_PID_key; |
tnhnrl | 63:6cb0405fc6e6 | 2066 | |
tnhnrl | 63:6cb0405fc6e6 | 2067 | float depth_KP = depthLoop().getControllerP(); // load current depth value |
tnhnrl | 63:6cb0405fc6e6 | 2068 | float depth_KI = depthLoop().getControllerI(); // load current depth value |
tnhnrl | 63:6cb0405fc6e6 | 2069 | float depth_KD = depthLoop().getControllerD(); // load current depth value |
tnhnrl | 76:c802e1da4179 | 2070 | |
tnhnrl | 73:f6f378311c8d | 2071 | float depth_freq = depthLoop().getFilterFrequency(); |
tnhnrl | 73:f6f378311c8d | 2072 | float depth_deadband = depthLoop().getDeadband(); |
tnhnrl | 16:3363b9f14913 | 2073 | |
tnhnrl | 63:6cb0405fc6e6 | 2074 | // print the menu |
tnhnrl | 74:d281aaef9766 | 2075 | xbee().printf("\n\rDEPTH (Buoyancy Engine O.L.) PID gain settings (MENU)"); |
tnhnrl | 74:d281aaef9766 | 2076 | xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); |
tnhnrl | 74:d281aaef9766 | 2077 | xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); |
tnhnrl | 74:d281aaef9766 | 2078 | xbee().printf("DEPTH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(),depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); |
tnhnrl | 16:3363b9f14913 | 2079 | |
tnhnrl | 16:3363b9f14913 | 2080 | // handle the key presses |
tnhnrl | 16:3363b9f14913 | 2081 | while(1) { |
tnhnrl | 16:3363b9f14913 | 2082 | // get the user's keystroke from either of the two inputs |
tnhnrl | 74:d281aaef9766 | 2083 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 2084 | DEPTH_PID_key = xbee().getc(); |
tnhnrl | 16:3363b9f14913 | 2085 | } |
tnhnrl | 16:3363b9f14913 | 2086 | else { |
tnhnrl | 16:3363b9f14913 | 2087 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 16:3363b9f14913 | 2088 | } |
tnhnrl | 16:3363b9f14913 | 2089 | |
tnhnrl | 16:3363b9f14913 | 2090 | // handle the user's key input |
tnhnrl | 73:f6f378311c8d | 2091 | if (DEPTH_PID_key == 'S') { // user wants to save these modified values |
tnhnrl | 63:6cb0405fc6e6 | 2092 | // set values |
tnhnrl | 63:6cb0405fc6e6 | 2093 | depthLoop().setControllerP(depth_KP); |
tnhnrl | 63:6cb0405fc6e6 | 2094 | depthLoop().setControllerI(depth_KI); |
tnhnrl | 73:f6f378311c8d | 2095 | depthLoop().setControllerD(depth_KD); |
tnhnrl | 76:c802e1da4179 | 2096 | |
tnhnrl | 73:f6f378311c8d | 2097 | depthLoop().setFilterFrequency(depth_freq); |
tnhnrl | 73:f6f378311c8d | 2098 | depthLoop().setDeadband(depth_deadband); |
tnhnrl | 63:6cb0405fc6e6 | 2099 | |
tnhnrl | 63:6cb0405fc6e6 | 2100 | // save to "DEPTH.TXT" file |
tnhnrl | 73:f6f378311c8d | 2101 | configFileIO().saveDepthData(depth_KP, depth_KI, depth_KD, _neutral_bce_pos_mm, depth_freq, depth_deadband); //P,I,D, bce zeroOffset |
tnhnrl | 73:f6f378311c8d | 2102 | |
tnhnrl | 74:d281aaef9766 | 2103 | xbee().printf("DEPTH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(),depthLoop().getOutputOffset(),depthLoop().getFilterFrequency(),depthLoop().getDeadband()); |
tnhnrl | 16:3363b9f14913 | 2104 | |
tnhnrl | 63:6cb0405fc6e6 | 2105 | //set class variables that will be used in find neutral sequence |
tnhnrl | 63:6cb0405fc6e6 | 2106 | _depth_KP = depthLoop().getControllerP(); // load current depth value |
tnhnrl | 63:6cb0405fc6e6 | 2107 | _depth_KI = depthLoop().getControllerI(); // load current depth value |
tnhnrl | 63:6cb0405fc6e6 | 2108 | _depth_KD = depthLoop().getControllerD(); // load current depth value |
tnhnrl | 16:3363b9f14913 | 2109 | } |
tnhnrl | 73:f6f378311c8d | 2110 | else if (DEPTH_PID_key == 'X') { |
tnhnrl | 16:3363b9f14913 | 2111 | break; //exit the while loop |
tnhnrl | 16:3363b9f14913 | 2112 | } |
tnhnrl | 73:f6f378311c8d | 2113 | else if (DEPTH_PID_key == 'P') { |
tnhnrl | 74:d281aaef9766 | 2114 | xbee().printf(">> Type in proportional gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2115 | depth_KP = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2116 | } |
tnhnrl | 73:f6f378311c8d | 2117 | else if (DEPTH_PID_key == 'I') { |
tnhnrl | 74:d281aaef9766 | 2118 | xbee().printf(">> Type in integral gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2119 | depth_KI = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2120 | } |
tnhnrl | 73:f6f378311c8d | 2121 | else if (DEPTH_PID_key == 'D') { |
tnhnrl | 74:d281aaef9766 | 2122 | xbee().printf(">> Type in derivative gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2123 | depth_KD = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2124 | } |
tnhnrl | 73:f6f378311c8d | 2125 | else if (DEPTH_PID_key == 'F') { |
tnhnrl | 74:d281aaef9766 | 2126 | xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); |
tnhnrl | 73:f6f378311c8d | 2127 | depth_freq = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2128 | } |
tnhnrl | 73:f6f378311c8d | 2129 | else if (DEPTH_PID_key == 'B') { |
tnhnrl | 74:d281aaef9766 | 2130 | xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); |
tnhnrl | 73:f6f378311c8d | 2131 | depth_deadband = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2132 | } |
tnhnrl | 16:3363b9f14913 | 2133 | else { |
tnhnrl | 74:d281aaef9766 | 2134 | xbee().printf("\n\rDEPTH: [%c] This key does nothing here. \r", DEPTH_PID_key); |
tnhnrl | 16:3363b9f14913 | 2135 | } |
tnhnrl | 16:3363b9f14913 | 2136 | } |
tnhnrl | 16:3363b9f14913 | 2137 | } |
tnhnrl | 16:3363b9f14913 | 2138 | |
tnhnrl | 16:3363b9f14913 | 2139 | void StateMachine::keyboard_menu_PITCH_PID_settings() { |
tnhnrl | 73:f6f378311c8d | 2140 | char PITCH_PID_key; |
tnhnrl | 63:6cb0405fc6e6 | 2141 | |
tnhnrl | 63:6cb0405fc6e6 | 2142 | float pitch_KP = pitchLoop().getControllerP(); // load current pitch value |
tnhnrl | 63:6cb0405fc6e6 | 2143 | float pitch_KI = pitchLoop().getControllerI(); // load current pitch value |
tnhnrl | 63:6cb0405fc6e6 | 2144 | float pitch_KD = pitchLoop().getControllerD(); // load current pitch value |
tnhnrl | 76:c802e1da4179 | 2145 | |
tnhnrl | 73:f6f378311c8d | 2146 | float pitch_freq = pitchLoop().getFilterFrequency(); |
tnhnrl | 73:f6f378311c8d | 2147 | float pitch_deadband = pitchLoop().getDeadband(); |
tnhnrl | 16:3363b9f14913 | 2148 | |
tnhnrl | 16:3363b9f14913 | 2149 | // print the menu |
tnhnrl | 74:d281aaef9766 | 2150 | xbee().printf("\n\rPITCH (Battery Motor O.L.) PID gain settings (MENU)"); |
tnhnrl | 74:d281aaef9766 | 2151 | xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); |
tnhnrl | 74:d281aaef9766 | 2152 | xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.)\n\n\n\r"); |
tnhnrl | 74:d281aaef9766 | 2153 | xbee().printf("PITCH P: %3.3f, I: %3.3f, D %3.3f, offset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); |
tnhnrl | 63:6cb0405fc6e6 | 2154 | |
tnhnrl | 16:3363b9f14913 | 2155 | // handle the key presses |
tnhnrl | 16:3363b9f14913 | 2156 | while(1) { |
tnhnrl | 16:3363b9f14913 | 2157 | // get the user's keystroke from either of the two inputs |
tnhnrl | 74:d281aaef9766 | 2158 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 2159 | PITCH_PID_key = xbee().getc(); |
tnhnrl | 16:3363b9f14913 | 2160 | } |
tnhnrl | 16:3363b9f14913 | 2161 | else { |
tnhnrl | 16:3363b9f14913 | 2162 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 16:3363b9f14913 | 2163 | } |
tnhnrl | 63:6cb0405fc6e6 | 2164 | |
tnhnrl | 16:3363b9f14913 | 2165 | // handle the user's key input |
tnhnrl | 73:f6f378311c8d | 2166 | if (PITCH_PID_key == 'S') { // user wants to save these modified values |
tnhnrl | 63:6cb0405fc6e6 | 2167 | // set values |
tnhnrl | 63:6cb0405fc6e6 | 2168 | pitchLoop().setControllerP(pitch_KP); |
tnhnrl | 63:6cb0405fc6e6 | 2169 | pitchLoop().setControllerI(pitch_KI); |
tnhnrl | 73:f6f378311c8d | 2170 | pitchLoop().setControllerD(pitch_KD); |
tnhnrl | 76:c802e1da4179 | 2171 | |
tnhnrl | 73:f6f378311c8d | 2172 | pitchLoop().setFilterFrequency(pitch_freq); |
tnhnrl | 73:f6f378311c8d | 2173 | pitchLoop().setDeadband(pitch_deadband); |
tnhnrl | 63:6cb0405fc6e6 | 2174 | |
tnhnrl | 73:f6f378311c8d | 2175 | // save to "PITCH.TXT" file (doesn't modify neutral position) |
tnhnrl | 73:f6f378311c8d | 2176 | configFileIO().savePitchData(pitch_KP, pitch_KI, pitch_KD, _neutral_batt_pos_mm, pitch_freq, pitch_deadband); |
tnhnrl | 73:f6f378311c8d | 2177 | |
tnhnrl | 74:d281aaef9766 | 2178 | xbee().printf("PITCH P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset(),pitchLoop().getFilterFrequency(),pitchLoop().getDeadband()); |
tnhnrl | 73:f6f378311c8d | 2179 | |
tnhnrl | 63:6cb0405fc6e6 | 2180 | _pitch_KP = pitchLoop().getControllerP(); // load current pitch value |
tnhnrl | 63:6cb0405fc6e6 | 2181 | _pitch_KI = pitchLoop().getControllerI(); // load current pitch value |
tnhnrl | 63:6cb0405fc6e6 | 2182 | _pitch_KD = pitchLoop().getControllerD(); // load current pitch value |
tnhnrl | 16:3363b9f14913 | 2183 | } |
tnhnrl | 73:f6f378311c8d | 2184 | else if (PITCH_PID_key == 'X') { |
tnhnrl | 16:3363b9f14913 | 2185 | break; //exit the while loop |
tnhnrl | 16:3363b9f14913 | 2186 | } |
tnhnrl | 73:f6f378311c8d | 2187 | else if (PITCH_PID_key == 'P') { |
tnhnrl | 74:d281aaef9766 | 2188 | xbee().printf(">> Type in proportional gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2189 | pitch_KP = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2190 | } |
tnhnrl | 73:f6f378311c8d | 2191 | else if (PITCH_PID_key == 'I') { |
tnhnrl | 74:d281aaef9766 | 2192 | xbee().printf(">> Type in integral gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2193 | pitch_KI = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2194 | } |
tnhnrl | 73:f6f378311c8d | 2195 | else if (PITCH_PID_key == 'D') { |
tnhnrl | 74:d281aaef9766 | 2196 | xbee().printf(">> Type in derivative gain with keyboard.\n\r"); |
tnhnrl | 63:6cb0405fc6e6 | 2197 | pitch_KD = getFloatUserInput(); |
tnhnrl | 63:6cb0405fc6e6 | 2198 | } |
tnhnrl | 73:f6f378311c8d | 2199 | else if (PITCH_PID_key == 'F') { |
tnhnrl | 74:d281aaef9766 | 2200 | xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); |
tnhnrl | 73:f6f378311c8d | 2201 | pitch_freq = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2202 | } |
tnhnrl | 73:f6f378311c8d | 2203 | else if (PITCH_PID_key == 'B') { |
tnhnrl | 74:d281aaef9766 | 2204 | xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); |
tnhnrl | 73:f6f378311c8d | 2205 | pitch_deadband = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2206 | } |
tnhnrl | 16:3363b9f14913 | 2207 | else { |
tnhnrl | 74:d281aaef9766 | 2208 | xbee().printf("\n\rPITCH: [%c] This key does nothing here. \r", PITCH_PID_key); |
tnhnrl | 73:f6f378311c8d | 2209 | } |
tnhnrl | 73:f6f378311c8d | 2210 | } |
tnhnrl | 73:f6f378311c8d | 2211 | } |
tnhnrl | 73:f6f378311c8d | 2212 | |
tnhnrl | 73:f6f378311c8d | 2213 | void StateMachine::keyboard_menu_HEADING_PID_settings() { |
tnhnrl | 73:f6f378311c8d | 2214 | char HEADING_PID_key; |
tnhnrl | 73:f6f378311c8d | 2215 | |
tnhnrl | 73:f6f378311c8d | 2216 | float heading_KP = headingLoop().getControllerP(); |
tnhnrl | 73:f6f378311c8d | 2217 | float heading_KI = headingLoop().getControllerI(); |
tnhnrl | 76:c802e1da4179 | 2218 | float heading_KD = headingLoop().getControllerD(); |
tnhnrl | 76:c802e1da4179 | 2219 | |
tnhnrl | 73:f6f378311c8d | 2220 | float heading_offset_deg = headingLoop().getOutputOffset(); |
tnhnrl | 73:f6f378311c8d | 2221 | float heading_freq = headingLoop().getFilterFrequency(); |
tnhnrl | 73:f6f378311c8d | 2222 | float heading_deadband = headingLoop().getDeadband(); |
tnhnrl | 73:f6f378311c8d | 2223 | |
tnhnrl | 73:f6f378311c8d | 2224 | // print the menu |
tnhnrl | 74:d281aaef9766 | 2225 | xbee().printf("\n\rHEADING (rudder outer loop) PID gain settings (MENU)"); |
tnhnrl | 74:d281aaef9766 | 2226 | xbee().printf("\n\rAdjust PID settings with the following keys: P I D. Filter = F, deadband = B.\n\r"); |
tnhnrl | 74:d281aaef9766 | 2227 | xbee().printf("\n\r Adjust zero offset with O (oh)."); |
tnhnrl | 74:d281aaef9766 | 2228 | xbee().printf("\n\r(Hit shift + X to exit w/o saving. Hit shift + S to save.\n\r"); |
tnhnrl | 74:d281aaef9766 | 2229 | xbee().printf("HEADING P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n\r\n", headingLoop().getControllerP(),headingLoop().getControllerI(),headingLoop().getControllerD(),headingLoop().getOutputOffset(),headingLoop().getFilterFrequency(),headingLoop().getDeadband()); |
tnhnrl | 73:f6f378311c8d | 2230 | |
tnhnrl | 73:f6f378311c8d | 2231 | // handle the key presses |
tnhnrl | 73:f6f378311c8d | 2232 | while(1) { |
tnhnrl | 73:f6f378311c8d | 2233 | // get the user's keystroke from either of the two inputs |
tnhnrl | 74:d281aaef9766 | 2234 | if (xbee().readable()) { |
tnhnrl | 74:d281aaef9766 | 2235 | HEADING_PID_key = xbee().getc(); |
tnhnrl | 73:f6f378311c8d | 2236 | } |
tnhnrl | 73:f6f378311c8d | 2237 | else { |
tnhnrl | 73:f6f378311c8d | 2238 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 73:f6f378311c8d | 2239 | } |
tnhnrl | 73:f6f378311c8d | 2240 | |
tnhnrl | 73:f6f378311c8d | 2241 | // handle the user's key input |
tnhnrl | 73:f6f378311c8d | 2242 | if (HEADING_PID_key == 'S') { // user wants to save the modified values |
tnhnrl | 73:f6f378311c8d | 2243 | // set global values |
tnhnrl | 73:f6f378311c8d | 2244 | headingLoop().setControllerP(heading_KP); |
tnhnrl | 73:f6f378311c8d | 2245 | headingLoop().setControllerI(heading_KI); |
tnhnrl | 73:f6f378311c8d | 2246 | headingLoop().setControllerD(heading_KD); |
tnhnrl | 73:f6f378311c8d | 2247 | headingLoop().setOutputOffset(heading_offset_deg); |
tnhnrl | 74:d281aaef9766 | 2248 | headingLoop().setFilterFrequency(heading_freq); |
tnhnrl | 74:d281aaef9766 | 2249 | headingLoop().setDeadband(heading_deadband); |
tnhnrl | 74:d281aaef9766 | 2250 | |
tnhnrl | 73:f6f378311c8d | 2251 | // save pitch PID values for outer loop (must save neutral position also) |
tnhnrl | 74:d281aaef9766 | 2252 | configFileIO().saveHeadingData(heading_KP, heading_KI, heading_KD, heading_offset_deg, heading_freq, heading_deadband); //_neutral_heading_pos_deg); |
tnhnrl | 74:d281aaef9766 | 2253 | xbee().printf("HEADING P: %3.3f, I: %3.3f, D %3.3f, zeroOffset: %3.1f mm (filter: %0.2f, deadband: %0.2f)\r\n\r\n", headingLoop().getControllerP(),headingLoop().getControllerI(),headingLoop().getControllerD(),headingLoop().getOutputOffset(),headingLoop().getFilterFrequency(),headingLoop().getDeadband()); |
tnhnrl | 73:f6f378311c8d | 2254 | } |
tnhnrl | 73:f6f378311c8d | 2255 | else if (HEADING_PID_key == 'X') { |
tnhnrl | 73:f6f378311c8d | 2256 | break; //exit the while loop |
tnhnrl | 73:f6f378311c8d | 2257 | } |
tnhnrl | 73:f6f378311c8d | 2258 | |
tnhnrl | 73:f6f378311c8d | 2259 | else if (HEADING_PID_key == 'P') { |
tnhnrl | 73:f6f378311c8d | 2260 | heading_KP = getFloatUserInput();; |
tnhnrl | 73:f6f378311c8d | 2261 | } |
tnhnrl | 73:f6f378311c8d | 2262 | else if (HEADING_PID_key == 'I') { |
tnhnrl | 73:f6f378311c8d | 2263 | heading_KI = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2264 | } |
tnhnrl | 73:f6f378311c8d | 2265 | else if (HEADING_PID_key == 'D') { |
tnhnrl | 73:f6f378311c8d | 2266 | heading_KD = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2267 | } |
tnhnrl | 73:f6f378311c8d | 2268 | else if (HEADING_PID_key == 'F') { |
tnhnrl | 74:d281aaef9766 | 2269 | xbee().printf(">> Type in FILTER FREQUENCY with keyboard.\n\r"); |
tnhnrl | 73:f6f378311c8d | 2270 | heading_freq = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2271 | } |
tnhnrl | 73:f6f378311c8d | 2272 | else if (HEADING_PID_key == 'B') { |
tnhnrl | 74:d281aaef9766 | 2273 | xbee().printf(">> Type in DEADBAND with keyboard.\n\r"); |
tnhnrl | 73:f6f378311c8d | 2274 | heading_deadband = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2275 | } |
tnhnrl | 73:f6f378311c8d | 2276 | else if (HEADING_PID_key == 'O') { |
tnhnrl | 73:f6f378311c8d | 2277 | heading_offset_deg = getFloatUserInput(); |
tnhnrl | 73:f6f378311c8d | 2278 | } |
tnhnrl | 73:f6f378311c8d | 2279 | else { |
tnhnrl | 74:d281aaef9766 | 2280 | xbee().printf("HEADING SETUP: [%c] This key does nothing here. \r", HEADING_PID_key); |
tnhnrl | 16:3363b9f14913 | 2281 | } |
tnhnrl | 16:3363b9f14913 | 2282 | } |
tnhnrl | 16:3363b9f14913 | 2283 | } |
tnhnrl | 20:8987a9ae2bc7 | 2284 | |
tnhnrl | 16:3363b9f14913 | 2285 | float StateMachine::getDepthCommand() { |
tnhnrl | 32:f2f8ae34aadc | 2286 | return _depth_command; |
tnhnrl | 16:3363b9f14913 | 2287 | } |
tnhnrl | 20:8987a9ae2bc7 | 2288 | |
tnhnrl | 16:3363b9f14913 | 2289 | float StateMachine::getPitchCommand() { |
tnhnrl | 32:f2f8ae34aadc | 2290 | return _pitch_command; |
tnhnrl | 32:f2f8ae34aadc | 2291 | } |
tnhnrl | 32:f2f8ae34aadc | 2292 | |
tnhnrl | 32:f2f8ae34aadc | 2293 | float StateMachine::getDepthReading() { |
tnhnrl | 32:f2f8ae34aadc | 2294 | return _depth_reading; |
tnhnrl | 32:f2f8ae34aadc | 2295 | } |
tnhnrl | 32:f2f8ae34aadc | 2296 | |
tnhnrl | 32:f2f8ae34aadc | 2297 | float StateMachine::getPitchReading() { |
tnhnrl | 32:f2f8ae34aadc | 2298 | return _pitch_reading; |
tnhnrl | 32:f2f8ae34aadc | 2299 | } |
tnhnrl | 32:f2f8ae34aadc | 2300 | |
tnhnrl | 32:f2f8ae34aadc | 2301 | float StateMachine::getTimerReading() { |
tnhnrl | 32:f2f8ae34aadc | 2302 | return _timer_reading; |
tnhnrl | 17:7c16b5671d0e | 2303 | } |
tnhnrl | 28:16c83a2fdefa | 2304 | |
tnhnrl | 17:7c16b5671d0e | 2305 | void StateMachine::setState(int input_state) { |
tnhnrl | 21:38c8544db6f4 | 2306 | _state = input_state; |
tnhnrl | 73:f6f378311c8d | 2307 | |
tnhnrl | 73:f6f378311c8d | 2308 | _isTimeoutRunning = false; //to start each state you have to reset this |
tnhnrl | 17:7c16b5671d0e | 2309 | } |
tnhnrl | 20:8987a9ae2bc7 | 2310 | |
tnhnrl | 17:7c16b5671d0e | 2311 | int StateMachine::getState() { |
tnhnrl | 17:7c16b5671d0e | 2312 | return _state; //return the current state of the system |
tnhnrl | 17:7c16b5671d0e | 2313 | } |
tnhnrl | 20:8987a9ae2bc7 | 2314 | |
tnhnrl | 17:7c16b5671d0e | 2315 | void StateMachine::setTimeout(float input_timeout) { |
tnhnrl | 17:7c16b5671d0e | 2316 | _timeout = input_timeout; |
tnhnrl | 17:7c16b5671d0e | 2317 | } |
tnhnrl | 20:8987a9ae2bc7 | 2318 | |
tnhnrl | 17:7c16b5671d0e | 2319 | void StateMachine::setDepthCommand(float input_depth_command) { |
tnhnrl | 32:f2f8ae34aadc | 2320 | _depth_command = input_depth_command; |
tnhnrl | 17:7c16b5671d0e | 2321 | } |
tnhnrl | 20:8987a9ae2bc7 | 2322 | |
tnhnrl | 17:7c16b5671d0e | 2323 | void StateMachine::setPitchCommand(float input_pitch_command) { |
tnhnrl | 32:f2f8ae34aadc | 2324 | _pitch_command = input_pitch_command; |
tnhnrl | 17:7c16b5671d0e | 2325 | } |
tnhnrl | 20:8987a9ae2bc7 | 2326 | |
tnhnrl | 17:7c16b5671d0e | 2327 | void StateMachine::setNeutralPositions(float batt_pos_mm, float bce_pos_mm) { |
tnhnrl | 21:38c8544db6f4 | 2328 | _neutral_batt_pos_mm = batt_pos_mm; |
tnhnrl | 21:38c8544db6f4 | 2329 | _neutral_bce_pos_mm = bce_pos_mm; |
tnhnrl | 17:7c16b5671d0e | 2330 | |
tnhnrl | 74:d281aaef9766 | 2331 | xbee().printf("Neutral Buoyancy Positions: batt: %0.1f, bce: %0.1f\r\n",_neutral_batt_pos_mm,_neutral_bce_pos_mm); |
tnhnrl | 17:7c16b5671d0e | 2332 | } |
tnhnrl | 20:8987a9ae2bc7 | 2333 | |
tnhnrl | 17:7c16b5671d0e | 2334 | //process one state at a time |
tnhnrl | 17:7c16b5671d0e | 2335 | void StateMachine::getDiveSequence() { |
tnhnrl | 17:7c16b5671d0e | 2336 | //iterate through this sequence using the FSM |
tnhnrl | 24:c7d9b5bf3829 | 2337 | currentStateStruct.state = sequenceController().sequenceStructLoaded[_multi_dive_counter].state; |
tnhnrl | 24:c7d9b5bf3829 | 2338 | currentStateStruct.timeout = sequenceController().sequenceStructLoaded[_multi_dive_counter].timeout; |
tnhnrl | 24:c7d9b5bf3829 | 2339 | currentStateStruct.depth = sequenceController().sequenceStructLoaded[_multi_dive_counter].depth; |
tnhnrl | 24:c7d9b5bf3829 | 2340 | currentStateStruct.pitch = sequenceController().sequenceStructLoaded[_multi_dive_counter].pitch; |
tnhnrl | 17:7c16b5671d0e | 2341 | |
tnhnrl | 17:7c16b5671d0e | 2342 | _timeout = currentStateStruct.timeout; //set timeout before exiting this function |
tnhnrl | 32:f2f8ae34aadc | 2343 | } |
joel_ssc | 82:0981b9ada820 | 2344 | //process one state at a time |
joel_ssc | 82:0981b9ada820 | 2345 | void StateMachine::getLegParams() { |
joel_ssc | 82:0981b9ada820 | 2346 | //iterate through this sequence using the FSM |
joel_ssc | 82:0981b9ada820 | 2347 | currentLegStateStruct.state = legController().legStructLoaded[_multi_leg_counter].state; |
joel_ssc | 82:0981b9ada820 | 2348 | currentLegStateStruct.timeout = legController().legStructLoaded[_multi_leg_counter].timeout; |
joel_ssc | 82:0981b9ada820 | 2349 | currentLegStateStruct.yo_time = legController().legStructLoaded[_multi_leg_counter].yo_time; //timer for each up/down segment |
joel_ssc | 82:0981b9ada820 | 2350 | currentLegStateStruct.min_depth = legController().legStructLoaded[_multi_leg_counter].min_depth; |
joel_ssc | 82:0981b9ada820 | 2351 | currentLegStateStruct.max_depth = legController().legStructLoaded[_multi_leg_counter].max_depth; |
joel_ssc | 82:0981b9ada820 | 2352 | currentLegStateStruct.heading = legController().legStructLoaded[_multi_leg_counter].heading; |
joel_ssc | 82:0981b9ada820 | 2353 | |
joel_ssc | 82:0981b9ada820 | 2354 | _timeout = currentLegStateStruct.timeout; //set timeout before exiting this function |
joel_ssc | 82:0981b9ada820 | 2355 | _yo_time = currentLegStateStruct.yo_time; |
joel_ssc | 82:0981b9ada820 | 2356 | _state = currentLegStateStruct.state; |
joel_ssc | 82:0981b9ada820 | 2357 | } |
tnhnrl | 32:f2f8ae34aadc | 2358 | |
tnhnrl | 32:f2f8ae34aadc | 2359 | void StateMachine::printCurrentSdLog() { |
tnhnrl | 74:d281aaef9766 | 2360 | xbee().printf("SD card log work in progress\r\n"); |
tnhnrl | 32:f2f8ae34aadc | 2361 | //might be worth saving the last few logs to the MBED... |
tnhnrl | 32:f2f8ae34aadc | 2362 | } |
tnhnrl | 32:f2f8ae34aadc | 2363 | |
tnhnrl | 52:f207567d3ea4 | 2364 | // 06/06/2018 |
tnhnrl | 52:f207567d3ea4 | 2365 | float StateMachine::getFloatUserInput() { |
tnhnrl | 52:f207567d3ea4 | 2366 | float float_conversion = 0.0; |
tnhnrl | 52:f207567d3ea4 | 2367 | |
tnhnrl | 52:f207567d3ea4 | 2368 | while(1) { |
tnhnrl | 52:f207567d3ea4 | 2369 | bool valid_input = false; //flag for valid or invalid input |
tnhnrl | 52:f207567d3ea4 | 2370 | |
tnhnrl | 74:d281aaef9766 | 2371 | xbee().printf("\n\rPlease enter your number below and press ENTER:\r\n"); |
tnhnrl | 52:f207567d3ea4 | 2372 | char user_string [80]; //variable to store input as a character array |
tnhnrl | 52:f207567d3ea4 | 2373 | |
tnhnrl | 74:d281aaef9766 | 2374 | xbee().scanf("%s", user_string); //read formatted data from stdin |
tnhnrl | 74:d281aaef9766 | 2375 | xbee().printf("\n\n\ruser_string was <%s>\r\n", user_string); |
tnhnrl | 52:f207567d3ea4 | 2376 | |
tnhnrl | 52:f207567d3ea4 | 2377 | //check through the string for invalid characters (decimal values 43 through 57) |
tnhnrl | 52:f207567d3ea4 | 2378 | for (int c = 0; c < strlen(user_string); c++) { |
tnhnrl | 74:d281aaef9766 | 2379 | //xbee().printf("character is [%c]\r\n", user_string[c]); //debug |
tnhnrl | 52:f207567d3ea4 | 2380 | if (user_string[c] >= 43 and user_string[c] <= 57) { |
tnhnrl | 74:d281aaef9766 | 2381 | //xbee().printf("VALID CHARACTER!\r\n"); //debug |
tnhnrl | 52:f207567d3ea4 | 2382 | ; |
tnhnrl | 52:f207567d3ea4 | 2383 | } |
tnhnrl | 52:f207567d3ea4 | 2384 | else { |
tnhnrl | 74:d281aaef9766 | 2385 | xbee().printf("INVALID INPUT!\r\n"); |
tnhnrl | 52:f207567d3ea4 | 2386 | break; |
tnhnrl | 52:f207567d3ea4 | 2387 | } |
tnhnrl | 52:f207567d3ea4 | 2388 | |
tnhnrl | 52:f207567d3ea4 | 2389 | if (c == (strlen(user_string) - 1)) { |
tnhnrl | 52:f207567d3ea4 | 2390 | valid_input = true; |
tnhnrl | 52:f207567d3ea4 | 2391 | } |
tnhnrl | 52:f207567d3ea4 | 2392 | } |
tnhnrl | 52:f207567d3ea4 | 2393 | |
tnhnrl | 52:f207567d3ea4 | 2394 | if (valid_input) { |
tnhnrl | 52:f207567d3ea4 | 2395 | float_conversion = atof(user_string); |
tnhnrl | 74:d281aaef9766 | 2396 | xbee().printf("VALID INPUT! Your input was: %3.3f (PRESS \"S\" (shift + S) to save!)\r\n", float_conversion); |
tnhnrl | 52:f207567d3ea4 | 2397 | break; |
tnhnrl | 52:f207567d3ea4 | 2398 | } |
tnhnrl | 52:f207567d3ea4 | 2399 | } |
tnhnrl | 52:f207567d3ea4 | 2400 | |
tnhnrl | 52:f207567d3ea4 | 2401 | return float_conversion; |
tnhnrl | 67:c86a4b464682 | 2402 | } |
tnhnrl | 67:c86a4b464682 | 2403 | |
tnhnrl | 73:f6f378311c8d | 2404 | float StateMachine::getTimerValue() { |
tnhnrl | 73:f6f378311c8d | 2405 | return _fsm_timer; |
tnhnrl | 80:4e5d306d695b | 2406 | } |
tnhnrl | 80:4e5d306d695b | 2407 | |
tnhnrl | 80:4e5d306d695b | 2408 | void StateMachine::logFileMenu() { |
tnhnrl | 80:4e5d306d695b | 2409 | char FILE_MENU_key; |
tnhnrl | 80:4e5d306d695b | 2410 | |
tnhnrl | 80:4e5d306d695b | 2411 | // print the menu |
tnhnrl | 80:4e5d306d695b | 2412 | xbee().printf("\n\r>>> LOG FILE MENU. Y = Yes, erase file (and exit). N = No, keep file (and exit). P = Print file size.<<<\n\r"); |
tnhnrl | 80:4e5d306d695b | 2413 | |
tnhnrl | 80:4e5d306d695b | 2414 | // handle the key presses |
tnhnrl | 80:4e5d306d695b | 2415 | while(1) { |
tnhnrl | 80:4e5d306d695b | 2416 | // get the user's keystroke from either of the two inputs |
tnhnrl | 80:4e5d306d695b | 2417 | if (xbee().readable()) { |
tnhnrl | 80:4e5d306d695b | 2418 | xbee().printf("\n\r>>> LOG FILE MENU. Y = Yes, erase file (and exit). N = No, keep file (and exit). P = Print file size.<<<\n\r"); |
tnhnrl | 80:4e5d306d695b | 2419 | FILE_MENU_key = xbee().getc(); |
tnhnrl | 80:4e5d306d695b | 2420 | } |
tnhnrl | 80:4e5d306d695b | 2421 | else { |
tnhnrl | 80:4e5d306d695b | 2422 | continue; // didn't get a user input, so keep waiting for it |
tnhnrl | 80:4e5d306d695b | 2423 | } |
tnhnrl | 80:4e5d306d695b | 2424 | |
tnhnrl | 80:4e5d306d695b | 2425 | // handle the user's key input |
tnhnrl | 80:4e5d306d695b | 2426 | if (FILE_MENU_key == 'P') { // user wants to save these modified values |
tnhnrl | 80:4e5d306d695b | 2427 | xbee().printf("\n\r>> Printing log file size!\n\r"); |
tnhnrl | 80:4e5d306d695b | 2428 | wait(2); |
tnhnrl | 80:4e5d306d695b | 2429 | mbedLogger().getFileSize("/local/LOG000.csv"); |
tnhnrl | 80:4e5d306d695b | 2430 | } |
tnhnrl | 80:4e5d306d695b | 2431 | else if (FILE_MENU_key == 'Y') { |
tnhnrl | 80:4e5d306d695b | 2432 | xbee().printf("\n\r>> Erasing MBED LOG FILE!\n\r"); |
tnhnrl | 80:4e5d306d695b | 2433 | wait(2); |
tnhnrl | 80:4e5d306d695b | 2434 | mbedLogger().eraseFile(); |
tnhnrl | 80:4e5d306d695b | 2435 | break; |
tnhnrl | 80:4e5d306d695b | 2436 | } |
tnhnrl | 80:4e5d306d695b | 2437 | else if (FILE_MENU_key == 'N') { |
tnhnrl | 80:4e5d306d695b | 2438 | xbee().printf("\n\r>> EXITING MENU. Log file intact.\n\r"); |
tnhnrl | 80:4e5d306d695b | 2439 | wait(2); |
tnhnrl | 80:4e5d306d695b | 2440 | break; |
tnhnrl | 80:4e5d306d695b | 2441 | } |
tnhnrl | 80:4e5d306d695b | 2442 | else { |
tnhnrl | 80:4e5d306d695b | 2443 | xbee().printf("\n\r[%c] This key does nothing here. \r", FILE_MENU_key); |
tnhnrl | 80:4e5d306d695b | 2444 | } |
tnhnrl | 80:4e5d306d695b | 2445 | } |
tnhnrl | 16:3363b9f14913 | 2446 | } |