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