Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL FATFileSystem
Revision 88:1813f583cee9, committed 2019-05-09
- Comitter:
- joel_ssc
- Date:
- Thu May 09 14:26:40 2019 +0000
- Parent:
- 87:6d95f853dab3
- Child:
- 89:0b8291dbf340
- Commit message:
- all functionality to splashdown, find neutral, and start mission.; short timeouts for testing still in code.
Changed in this revision
--- a/ConfigFileIO/ConfigFileIO.cpp Wed May 08 13:24:04 2019 +0000
+++ b/ConfigFileIO/ConfigFileIO.cpp Thu May 09 14:26:40 2019 +0000
@@ -548,6 +548,28 @@
xbee().printf("\n\rFile no_float.txt written.\n\r");
}
}
+void ConfigFileIO::save_FinalTime() {
+ ConfigFile timefile_txt;
+ int last_time;
+ char header[128];
+ sprintf(header,"# Timestamp at last moment before closing shop\n");
+
+ char string_end_time[128];
+ last_time = mbedLogger().getSystemTime();
+ sprintf(string_end_time, "%d", last_time);
+ timefile_txt.setValue("TimeStamp", string_end_time);
+
+
+ //SAVE THE DATA!
+ xbee().printf("Saving timestamp value!");
+
+ if (!timefile_txt.write("/local/newtime.txt")) {
+ xbee().printf("\n\rERROR: (SAVE)Failure to write time.txt file.");
+ }
+else {
+ xbee().printf("\n\rFile newtime.txt successfully written.\n\r");
+ }
+}
int ConfigFileIO::load_DEPTH_config() {
ConfigFile cfg;
int count = 0;
--- a/ConfigFileIO/ConfigFileIO.hpp Wed May 08 13:24:04 2019 +0000
+++ b/ConfigFileIO/ConfigFileIO.hpp Thu May 09 14:26:40 2019 +0000
@@ -39,6 +39,7 @@
void saveNeutralStatus(int setval, int bce_neutral_mm, int batt_neutral_mm);
int load_setneutral_status();
void report_no_neutral_found(int bce_last_pos, int batt_last_pos);
+ void save_FinalTime();
void report_still_inverted( float roll_value, int yotime);
void saveLogVersData(int logversion, int diagversion);
int load_BATT_config();
--- a/StateMachine/StateMachine.cpp Wed May 08 13:24:04 2019 +0000
+++ b/StateMachine/StateMachine.cpp Thu May 09 14:26:40 2019 +0000
@@ -2630,6 +2630,11 @@
_state = currentLegStateStruct.state;
// _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.
}
+void StateMachine::setstate_frommain(int set_state_val, int new_timeout) { // used for setting state from main, when find_neutral has not been run
+ _state = set_state_val;
+ _timeout = new_timeout;
+ }
+
void StateMachine::printCurrentSdLog() {
xbee().printf("SD card log work in progress\r\n");
--- a/StateMachine/StateMachine.hpp Wed May 08 13:24:04 2019 +0000
+++ b/StateMachine/StateMachine.hpp Thu May 09 14:26:40 2019 +0000
@@ -92,6 +92,7 @@
int getState();
void setState(int input_state);
+ void setstate_frommain(int set_state_val, int new_timeout);
void setTimeout(float input_timeout);
void setDepthCommand(float input_depth_command);
--- a/main.cpp Wed May 08 13:24:04 2019 +0000
+++ b/main.cpp Thu May 09 14:26:40 2019 +0000
@@ -44,7 +44,7 @@
if (log_loop) { //start logloop8
//when the state machine is not in SIT_IDLE state (or a random keyboard press)
- if(current_state != 0) { //first if - not in sit_idle/keyboard state
+ if((current_state != SIT_IDLE) && (current_state != FLYING_IDLE)) { //first if - not in sit_idle/keyboard state
if (!file_opened) { //if the log file is not open, open it
mbedLogger().appendLogFile(current_state, 1); //open MBED file once
//sdLogger().appendLogFile(current_state, 0); //open SD file once
@@ -243,6 +243,7 @@
have_legfile = legController().loadLeg(); // this should be 1 if the legfile reader has found 1 or more legs
current_state = legController().legStructLoaded[0].state;
+ begin_state = current_state;
sprintf(buf, "in setup(): have_legfile = %d current_state = %d (sit_idle= 0 or 1)\n", have_legfile, current_state);
mbedLogger().appendDiagFile(buf,3);
sprintf(buf, "in setup(): LEG_POSITION_DIVE = %d START_SWIM = %d \n", LEG_POSITION_DIVE, START_SWIM);
@@ -306,7 +307,7 @@
int main() {
setup(); //setup electronics/hardware
// on landing, check orientation, if upside down, fix that first
- systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
+ // systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
led2()=1; led4()=0;
unsigned int tNow = 0;
int vernum=0;
@@ -315,6 +316,8 @@
xbee().printf("\n\n\r 2018-08-14 FSG PCB XBee (setup complete) \n\n\r");
sprintf(buf, "\n\n\r 2019-may-07 FSG PCB XBee line315 in main (setup complete) \n\n\r");
mbedLogger().appendDiagFile(buf,3);
+ int fn_timeout = 240;
+ int save_timeout = 300;
//tNow=5; sprintf(buf, "log file config values logfile= %s diag file= %s\n", configFileIO().logFilesStruct.logFileName,
@@ -378,6 +381,33 @@
//NOT TRANSMITTING DATA, NORMAL OPERATIONS
else { // **88**
//FSM
+ // preamble to running the FSM
+ if (setval == 0 && (begin_state != FLYING_IDLE) && (current_state == START_SWIM || current_state == LEG_POSITION_DIVE) && (fabs(imu().getRoll()) < 30)) {
+ // These tests mean: - second start,plus already upright
+ // from setup() current_state = legController().legStructLoaded[0].state; either start_swim or leg_pos_dive
+ save_state = current_state;
+ neutral_via_leg =1;
+ save_timeout = legController().legStructLoaded[0].timeout;
+ fn_timeout = 240;
+ current_state = FIND_NEUTRAL; // does runStatemachine know about this value?
+ sprintf(buf, "in main(): setval==0, but upright, so pre-empt start_swim or leg_pos_dive\n set state directly to find_neutral\n");
+ mbedLogger().appendDiagFile(buf,3);
+ stateMachine().setstate_frommain(FIND_NEUTRAL, fn_timeout); // this will change state inside runstatemachine, change state val inthe right structure, first
+ }
+ if ( (neutral_via_leg == 1) && (setval == 1) && current_state == RISE) { // usual endstate of FIND_NEUTRAL new state for after successful find neutral
+ current_state = save_state; //setval reset at line 366 when find_neutral succeeds
+ stateMachine().setstate_frommain(current_state, save_timeout); //back to what you were doing
+ sprintf(buf, "in main(): presumably after find_neutral exits to RISE, but successful in setting setval\n");
+ mbedLogger().appendDiagFile(buf,3);
+ neutral_via_leg = 0;
+ }
+ if ( (neutral_via_leg == 1) && (setval == 0) && current_state == RISE) { // failed endstate of FIND_NEUTRAL new state
+
+ sprintf(buf, "in main(): presumably after find_neutral exits to RISE, UNSUCCESSFULLY\n");
+ mbedLogger().appendDiagFile(buf,3);
+ neutral_via_leg = 0;
+ }
+ // end preamble
if ( (tNow % 100) == 0 ) { // 0.1 second intervals
fsm_loop = true;
FSM();
@@ -447,5 +477,6 @@
sprintf(buf, "wait 5 more seconds? out of the leg loop via FB_EXIT\n\n\r");
mbedLogger().appendDiagFile(buf,0);
led1()=0; led2()=0; led3()= 0 ;led4()=0;
+ configFileIO().save_FinalTime(); // saves last time before closing shop
exit(0);
} // end main()
\ No newline at end of file