most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown
Dependencies: mbed MODSERIAL FATFileSystem
Diff: StateMachine/StateMachine.cpp
- Revision:
- 68:8f549749b8ce
- Parent:
- 67:c86a4b464682
- Child:
- 69:919ac8d7e023
--- a/StateMachine/StateMachine.cpp Mon Jun 25 15:44:00 2018 +0000 +++ b/StateMachine/StateMachine.cpp Wed Jun 27 23:01:53 2018 +0000 @@ -69,7 +69,7 @@ // finite state machine ... each state has at least one exit criteria switch (_state) { case SIT_IDLE : - case KEYBOARD: + case KEYBOARD: // there actually is no timeout for SIT_IDLE, but this enables some one-shot actions if (!_isTimeoutRunning) { @@ -643,8 +643,8 @@ //reset multi-dive sequence to start _multi_dive_counter = 0; - //Reload the dive sequence on exit - sequenceController().loadSequence(); +// //Reload the dive sequence on exit +// sequenceController().loadSequence(); } else if (depthLoop().getPosition() < 0.5) { // depth is less than 0.5 (zero is surface level) pc().printf("MULTI-RISE: depth: %3.1f, cmd: %3.1f\r\n", depthLoop().getPosition(), depthLoop().getCommand()); @@ -661,8 +661,8 @@ //check if this is the end of the dive sequence //CHECK BEFORE ANYTHING ELSE that you have reached the "exit" state (FLOAT_BROADCAST) if (currentStateStruct.state == FLOAT_BROADCAST) { - //Reload the dive sequence on exit - sequenceController().loadSequence(); +// //Reload the dive sequence on exit +// sequenceController().loadSequence(); _state = FLOAT_BROADCAST; } @@ -689,20 +689,19 @@ timer.start(); // background timer starts running _isTimeoutRunning = true; - mbedLogger().getNumberOfPacketsInCurrentLog(); //open the file, read the number of lines in the log file - transmit_packet_number = mbedLogger().getNumberOfPackets(); + //mbedLogger().openFileForTransmit(); //starts _fp file pointer at the beginning of the file + + pc().printf("TRANSMIT_MBED_LOG set to zero\n\r"); - //set the timeout internally (integer value)! - _timeout = mbedLogger().getLogSize(); //works after current log function above - _timeout = _timeout - (_timeout % 10) + 10; //remove the last digit and keep it as multiples of 10 (add a buffer of 10 seconds just in case it's below 10) - - //STATE - //TRANSMIT_MBED_LOG + //get number of packets (lines in the file) + mbedLogger().getNumberOfPacketsInCurrentLog(); + + mbedLogger().setTransmitPacketNumber(0); //reset to zero } if (timer.read() > _timeout) { - mbedLogger().closeLogFile(); //on timeout close the log file that was opened for reading - pc().printf("\r\nTRANSMIT_MBED_LOG: timed out!\r\n"); + //mbedLogger().closeLogFile(); //on timeout close the log file that was opened for reading + //pc().printf("\r\nTRANSMIT_MBED_LOG: timed out!\r\n"); //STATE _state = SIT_IDLE; @@ -712,25 +711,36 @@ //send a command to the Python GUI to stop looking for data //SEND COMMAND WHEN TRANSMISSION ENDS PREMATURELY - pc().printf("%c%c%c%c",0x15,0x15,0x15,0x15); + //pc().printf("%c%c%c%c",0x15,0x15,0x15,0x15); + + mbedLogger().closeLogFile(); //test 6/27 + pc().printf("\r\n\nstate: TRANSMIT_MBED_LOG (log filed closed)\r\n"); } //IF THIS IS ZERO - if (mbedLogger().currentPacketNumber() > transmit_packet_number) { - pc().printf("mbedLogger().currentPacketNumber() > transmit_packet_number"); - - //STATE +// if (mbedLogger().currentPacketNumber() > transmit_packet_number) { +// pc().printf("mbedLogger().currentPacketNumber() > transmit_packet_number"); +// +// //STATE +// _state = SIT_IDLE; +// +// timer.reset(); +// _isTimeoutRunning = false; +// +// mbedLogger().closeLogFile(); //on timeout close the log file that was opened for reading +// } + + //What is active? + + //boolean function that transmits until it's finished + if (mbedLogger().fsmTransmitData()) + ; + else { + mbedLogger().closeLogFile(); + pc().printf("StateMachine: TRANSMIT_MBED_LOG (closeLogFile)\n\r"); _state = SIT_IDLE; - - timer.reset(); - _isTimeoutRunning = false; - - mbedLogger().closeLogFile(); //on timeout close the log file that was opened for reading } - //What is active? - mbedLogger().readTransmitPacketOneChar(); //led2 shows you pc readable - break; case RECEIVE_SEQUENCE : @@ -778,7 +788,7 @@ // output the keyboard menu for user's reference void StateMachine::showSimpleMenu() { - pc().printf("\r\r\n\nSIMPLE KEYBOARD MENU (06/22/2018):\r\r\n"); //make sure depth sensor tares itself on startup + pc().printf("\r\r\n\nSIMPLE KEYBOARD MENU (06/27/2018):\r\r\n"); //make sure depth sensor tares itself on startup pc().printf(" Neutral Positions BCE: %0.1f BMM: %0.1f \r\n", _neutral_bce_pos_mm, _neutral_batt_pos_mm); pc().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); @@ -787,6 +797,7 @@ pc().printf(" E to initiate emergency climb\r\n"); pc().printf(" P to print the current log file.\r\n"); pc().printf(" O to transmit current log file.\r\n"); + pc().printf(" G to MBED_TRANSMIT_LOG\r\n"); pc().printf(" ~ to erase mbed log file. (clear before logging more than a few runs)\r\n"); pc().printf("k/l to decrease/increase BCE offset: %3.1f (Dive POS: %0.1f, Rise POS: %0.1f)\r\n",_BCE_dive_offset, _neutral_bce_pos_mm - _BCE_dive_offset, _neutral_bce_pos_mm + _BCE_dive_offset); @@ -806,7 +817,7 @@ } void StateMachine::showDebugMenu() { - pc().printf("\r\r\n\nDEBUG KEYBOARD MENU (06/22/2018):\r\r\n"); + pc().printf("\r\r\n\nDEBUG KEYBOARD MENU (06/27/2018):\r\r\n"); pc().printf(" Y to go into CHECK NEUTRAL TUNING (This is on a timer! Uses NEUTRAL positions!)\r\n"); pc().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); pc().printf(" N to find neutral\r\n"); @@ -1102,6 +1113,11 @@ //need to add method to Sequence Controller that returns -1 // or some check that insures you cannot run the dive sequence without a file + //load sequence from file + _multi_dive_counter = 0; + sequenceController().loadSequence(); + wait(1); //test if this resets the sequence + stateMachine().getDiveSequence(); //get first sequence on keyboard press _keyboard_state = currentStateStruct.state; @@ -1138,7 +1154,7 @@ mbedLogger().printMbedDirectory(); //print all log files to the screen } else if (user_input == 'O') { - _keyboard_state = TRANSMIT_MBED_LOG; //Transmit data (work in progress) + mbedLogger().continuouslyTransmitDataNoTimer(); //_keyboard_state = TRANSMIT_MBED_LOG; //Transmit data (work in progress) } else if (user_input == 'I') { mbedLogger().receiveMissionDataWithTicker(); //receive sequence.txt files @@ -1401,8 +1417,13 @@ mbedLogger().printCurrentLogFile(); //print the current log file to the screen } else if (user_input == 'O') { - _keyboard_state = TRANSMIT_MBED_LOG; //Transmit data (work in progress) + mbedLogger().continuouslyTransmitDataNoTimer(); } + + else if (user_input == 'G') { + _keyboard_state = TRANSMIT_MBED_LOG; + } + else if (user_input == '~') { pc().printf("ERASING MBED LOG FILE\r\n"); mbedLogger().eraseFile(); @@ -1417,14 +1438,21 @@ float vmeasured = 0; unsigned int raw = adc().readCh5(); vmeasured = ((float)raw)/4095.0*vref; + + //same equations in mbed logger + float press_xducer_PSI = (22.029*(5.0*adc().readCh5()/4095.0) + 10.884) * 0.145038; // Press_Xducer (on-board) + float voltage_input = (adc().readCh6()/4095.0) * 5.0 * 7.8; //tnh + float current_input = adc().readCh7()/4095.0; + pc().printf("raw BCE pos: %d \r\n",adc().readCh0()); pc().printf("raw BMM pos: %d \r\n",adc().readCh1()); pc().printf("raw BCE current sense: %d \r\n",adc().readCh2()); pc().printf("raw BMM current sense: %d \r\n",adc().readCh3()); pc().printf("raw depth pressure: %d \r\n",adc().readCh4()); - pc().printf("raw vessel pressure: %d \r\n",adc().readCh5()); - pc().printf("raw battery voltage: %d \r\n",adc().readCh6()); - pc().printf("raw board current: %d \r\n",adc().readCh7()); + pc().printf("raw vessel pressure %d (internal psi: %0.1f)\r\n", adc().readCh5(),press_xducer_PSI); + //pc().printf("raw vessel pressure: %d \r\n",adc().readCh5()); + pc().printf("raw board voltage: %d (%0.1f volts)\r\n",adc().readCh6(),voltage_input); + pc().printf("raw board current: %d (%0.3f amps)\r\n",adc().readCh7(), current_input); pc().printf("raw BCE limit switch: %d \r\n",bce().getSwitch()); pc().printf("raw BMM limit switch: %d \r\n",batt().getSwitch()); pc().printf("raw vessel pressure: %f %d \r\n",vmeasured,raw);