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