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

Committer:
joel_ssc
Date:
Tue Feb 19 20:11:43 2019 +0000
Revision:
84:eccd8e837134
Parent:
82:0981b9ada820
Child:
85:dd8176285b6e
updated file management of logfiles and diagfile numbers

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tzyoung 0:ea293bbf9717 1 #include "mbed.h"
tzyoung 0:ea293bbf9717 2 #include "StaticDefs.hpp"
tnhnrl 65:2ac186553959 3
tnhnrl 65:2ac186553959 4 ////////////////////////////////////////////////////////////////// NEW TICKER
tnhnrl 65:2ac186553959 5 Ticker systemTicker;
tnhnrl 65:2ac186553959 6 bool setup_complete = false;
tnhnrl 65:2ac186553959 7 volatile unsigned int bTick = 0;
tnhnrl 65:2ac186553959 8 volatile unsigned int timer_counter = 0;
tnhnrl 65:2ac186553959 9
tnhnrl 65:2ac186553959 10 static unsigned int read_ticker(void) { //Basically this makes sure you're reading the data at one instance (not while it's changing)
tnhnrl 65:2ac186553959 11 unsigned int val = bTick;
tnhnrl 65:2ac186553959 12 if( val )
tnhnrl 65:2ac186553959 13 bTick = 0;
tnhnrl 65:2ac186553959 14 return( val );
tnhnrl 65:2ac186553959 15 }
tnhnrl 65:2ac186553959 16 ////////////////////////////////////////////////////////////////// NEW TICKER
tnhnrl 32:f2f8ae34aadc 17
tnhnrl 65:2ac186553959 18 volatile bool fsm_loop = false; //used so the compiler does not optimize this variable (load from memory, do not assume state of variable)
tnhnrl 34:9b66c5188051 19 volatile bool log_loop = false; //used so the compiler does not optimize this variable (load from memory, do not assume state of variable)
tnhnrl 32:f2f8ae34aadc 20
tnhnrl 65:2ac186553959 21 void loop_trigger() { fsm_loop = true;} // loop trigger (used in while loop)
tnhnrl 34:9b66c5188051 22 void log_loop_trigger() { log_loop = true;} // log loop trigger (used in while loop)
tnhnrl 32:f2f8ae34aadc 23
joel_ssc 82:0981b9ada820 24 static int current_state = 0;
joel_ssc 82:0981b9ada820 25 static int have_legfile = 0;
tnhnrl 65:2ac186553959 26 static bool file_opened = false;
tnhnrl 65:2ac186553959 27
tnhnrl 73:f6f378311c8d 28 void FSM() { // FSM loop runs at 10 hz
tnhnrl 65:2ac186553959 29 if(fsm_loop) {
tnhnrl 73:f6f378311c8d 30 // led one removed
tnhnrl 65:2ac186553959 31 fsm_loop = false; // wait until the loop rate timer fires again
tnhnrl 65:2ac186553959 32 current_state = stateMachine().runStateMachine(); //running State Machine. Returns 0 if sitting idle or keyboard press (SIT_IDLE state).
tnhnrl 65:2ac186553959 33 }
tnhnrl 65:2ac186553959 34 }
tnhnrl 65:2ac186553959 35
tnhnrl 65:2ac186553959 36 void log_function() {
tnhnrl 65:2ac186553959 37 // log loop runs at 1 hz
joel_ssc 82:0981b9ada820 38 if (log_loop) { //start logloop8
tnhnrl 65:2ac186553959 39 //when the state machine is not in SIT_IDLE state (or a random keyboard press)
tnhnrl 65:2ac186553959 40
joel_ssc 82:0981b9ada820 41 if(current_state != 0) { //first if - not in sit_idle/keyboard state
tnhnrl 65:2ac186553959 42 if (!file_opened) { //if the log file is not open, open it
joel_ssc 82:0981b9ada820 43 mbedLogger().appendLogFile(current_state, 1); //open MBED file once
tnhnrl 80:4e5d306d695b 44 //sdLogger().appendLogFile(current_state, 0); //open SD file once
tnhnrl 65:2ac186553959 45
tnhnrl 65:2ac186553959 46 file_opened = true; //stops it from continuing to open it
tnhnrl 56:48a8a5a65b82 47
joel_ssc 82:0981b9ada820 48 xbee().printf(">>>>>>>> Recording. Log file re opened. <<<<<<<<\n\r");
tnhnrl 65:2ac186553959 49 }
joel_ssc 82:0981b9ada820 50 else {
tnhnrl 65:2ac186553959 51
joel_ssc 82:0981b9ada820 52 //just record to the Mbed file system
tnhnrl 65:2ac186553959 53
joel_ssc 82:0981b9ada820 54 mbedLogger().appendLogFile(current_state, 1); //writing data
joel_ssc 82:0981b9ada820 55 //sdLogger().appendLogFile(current_state, 1); //writing data
joel_ssc 82:0981b9ada820 56 }
joel_ssc 82:0981b9ada820 57 } //end first if
tnhnrl 65:2ac186553959 58
tnhnrl 65:2ac186553959 59 //when the current FSM state is zero (SIT_IDLE), close the file
joel_ssc 82:0981b9ada820 60 else { //start first else for current_state ==0 sit idle/keyboard
tnhnrl 65:2ac186553959 61 //this can only happen once
tnhnrl 65:2ac186553959 62 if (file_opened) {
tnhnrl 67:c86a4b464682 63 //WRITE ONCE
tnhnrl 67:c86a4b464682 64 mbedLogger().appendLogFile(current_state, 1); //write the idle state, then close
tnhnrl 80:4e5d306d695b 65 //sdLogger().appendLogFile(current_state, 1); //write the idle state, then close
tnhnrl 67:c86a4b464682 66
tnhnrl 65:2ac186553959 67 mbedLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 80:4e5d306d695b 68 //sdLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 65:2ac186553959 69
tnhnrl 65:2ac186553959 70 file_opened = false;
tnhnrl 65:2ac186553959 71
tnhnrl 74:d281aaef9766 72 xbee().printf(">>>>>>>> Stopped recording. Log file closed. <<<<<<<<\n\r");
tnhnrl 65:2ac186553959 73 }
joel_ssc 82:0981b9ada820 74 } //end first else
tnhnrl 74:d281aaef9766 75 } //END OF LOG LOOP8
tnhnrl 65:2ac186553959 76
tnhnrl 65:2ac186553959 77 log_loop = false; // wait until the loop rate timer fires again
tnhnrl 65:2ac186553959 78 }
tnhnrl 56:48a8a5a65b82 79
tnhnrl 72:250b2665755c 80 //single system timer to run hardware/electronics timing
tnhnrl 65:2ac186553959 81 static void system_timer(void) {
tnhnrl 65:2ac186553959 82 bTick = 1;
tnhnrl 65:2ac186553959 83
tnhnrl 56:48a8a5a65b82 84 timer_counter++;
tnhnrl 56:48a8a5a65b82 85
tnhnrl 56:48a8a5a65b82 86 //only start these updates when everything is properly setup (through setup function)
tnhnrl 56:48a8a5a65b82 87 if (setup_complete) {
tnhnrl 74:d281aaef9766 88 if ( (timer_counter % 5) == 0) { //this runs at 0.005 second intervals (200 Hz)
tnhnrl 65:2ac186553959 89 adc().update(); //every iteration of this the A/D converter runs //now this runs at 0.01 second intervals 03/12/2018
tnhnrl 65:2ac186553959 90 }
tnhnrl 65:2ac186553959 91
tnhnrl 65:2ac186553959 92 if ( (timer_counter % 10) == 0) {
tnhnrl 65:2ac186553959 93 bce().update(); //update() inside LinearActuator class (running at 0.01 second intervals)
tnhnrl 65:2ac186553959 94 batt().update();
tnhnrl 65:2ac186553959 95 }
tnhnrl 65:2ac186553959 96
tnhnrl 65:2ac186553959 97 if ( (timer_counter % 20) == 0 ) { // 0.02 second intervals
tnhnrl 74:d281aaef9766 98 rudder().runServo();
tnhnrl 65:2ac186553959 99 }
tnhnrl 65:2ac186553959 100
tnhnrl 65:2ac186553959 101 if ( (timer_counter % 50) == 0 ) { // 0.05 second intervals
tnhnrl 67:c86a4b464682 102 imu().runIMU();
tnhnrl 65:2ac186553959 103 }
tnhnrl 73:f6f378311c8d 104
tnhnrl 65:2ac186553959 105 if ( (timer_counter % 100) == 0) { // 100,000 microseconds = 0.1 second intervals
tnhnrl 65:2ac186553959 106 depthLoop().runOuterLoop();
tnhnrl 65:2ac186553959 107 pitchLoop().runOuterLoop();
tnhnrl 65:2ac186553959 108 headingLoop().runOuterLoop();
tnhnrl 65:2ac186553959 109 }
tnhnrl 73:f6f378311c8d 110
tnhnrl 73:f6f378311c8d 111 if ( (timer_counter % 1000) == 0) { // update at 1.0 second intervals
tnhnrl 73:f6f378311c8d 112 //gui().updateGUI();
tnhnrl 73:f6f378311c8d 113 }
tnhnrl 74:d281aaef9766 114
tnhnrl 74:d281aaef9766 115 if ( (timer_counter % 30000) == 0) { // update at 30.0 second intervals
tnhnrl 74:d281aaef9766 116 //pc().printf("XB!\n");
tnhnrl 74:d281aaef9766 117 }
tnhnrl 56:48a8a5a65b82 118 }
tnhnrl 56:48a8a5a65b82 119 }
tnhnrl 56:48a8a5a65b82 120
danstrider 10:085ab7328054 121 void setup() {
joel_ssc 82:0981b9ada820 122 // xbee().baud(115200); // comment out so default is 9600 for USB communications
tnhnrl 81:7ff2c6467892 123 xbee().printf("\n\n\r 2018-11-08 FSG PCB XBee\n\n\r");
tnhnrl 74:d281aaef9766 124
tnhnrl 74:d281aaef9766 125 //pc().baud(57600);
tnhnrl 65:2ac186553959 126
danstrider 10:085ab7328054 127 // start up the system timer
tnhnrl 65:2ac186553959 128 //systemTimer().start();
tnhnrl 20:8987a9ae2bc7 129
danstrider 10:085ab7328054 130 // set up and start the adc. This runs on a fixed interval and is interrupt driven
tnhnrl 65:2ac186553959 131 adc().initialize();
tnhnrl 67:c86a4b464682 132 //one central interrupt is updating the ADC (not using the start function)
tnhnrl 65:2ac186553959 133
tnhnrl 65:2ac186553959 134 // setup and run the rudder(servo) pwm signal (start the ticker)
tnhnrl 65:2ac186553959 135 //rudder().init();
tnhnrl 74:d281aaef9766 136 xbee().printf("Rudder servo initialized!\n\r");
danstrider 10:085ab7328054 137
danstrider 10:085ab7328054 138 // set up and start the imu. This polls in the background
danstrider 10:085ab7328054 139 imu().initialize();
tnhnrl 65:2ac186553959 140 //imu().start();
danstrider 10:085ab7328054 141
tnhnrl 48:20e681885161 142 // construct the MBED local file system
danstrider 10:085ab7328054 143 local();
tnhnrl 48:20e681885161 144
tnhnrl 79:3688c3a0d7f4 145 // construct the SD card file system TEST 10/23/18
tnhnrl 80:4e5d306d695b 146 //sd_card();
joel_ssc 82:0981b9ada820 147 // mbedLogger().initializeDiagFile();
danstrider 10:085ab7328054 148 // load config data from files
joel_ssc 82:0981b9ada820 149 mbedLogger().setLogTime();
joel_ssc 82:0981b9ada820 150 int print_diag = 0; // do not print to diag file before it is named
joel_ssc 82:0981b9ada820 151 configFileIO().load_LogVers_config(print_diag); // version numbers of the log and diag files from "logvers.txt"
joel_ssc 82:0981b9ada820 152 mbedLogger().initializeDiagFile(print_diag);
joel_ssc 82:0981b9ada820 153 print_diag=1;
joel_ssc 82:0981b9ada820 154 configFileIO().load_LogVers_config(print_diag); // Cnow print info to diag file
joel_ssc 82:0981b9ada820 155 mbedLogger().initializeDiagFile(print_diag);
joel_ssc 82:0981b9ada820 156
tnhnrl 65:2ac186553959 157 configFileIO().load_BCE_config(); // load the buoyancy engine parameters from the file "bce.txt"
tnhnrl 65:2ac186553959 158 configFileIO().load_BATT_config(); // load the battery mass mover parameters from the file "batt.txt"
tnhnrl 65:2ac186553959 159
tnhnrl 65:2ac186553959 160 configFileIO().load_DEPTH_config(); // load the depth control loop parameters from the file "depth.txt" (contains neutral position)
tnhnrl 65:2ac186553959 161 configFileIO().load_PITCH_config(); // load the depth control loop parameters from the file "pitch.txt" (contains neutral position)
tnhnrl 65:2ac186553959 162
tnhnrl 65:2ac186553959 163 configFileIO().load_RUDDER_config(); // load the rudder servo inner loop parameters from the file "SERVO.txt"
tnhnrl 65:2ac186553959 164 configFileIO().load_HEADING_config(); // load the rudder servo outer loop HEADING control parameters from the file "HEADING.txt" (contains neutral position)
tnhnrl 43:891baf306e0a 165
danstrider 10:085ab7328054 166 // set up the linear actuators. adc has to be running first.
tnhnrl 65:2ac186553959 167 bce().setPIDHighLimit(bce().getTravelLimit()); //travel limit of this linear actuator
danstrider 10:085ab7328054 168 bce().init();
tnhnrl 65:2ac186553959 169 //bce().start(); //removed start, it's handled by the interrupt
tnhnrl 67:c86a4b464682 170 bce().runLinearActuator();
mkelly10 12:a0519d11d2b6 171 bce().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 172
tnhnrl 65:2ac186553959 173 batt().setPIDHighLimit(batt().getTravelLimit()); //travel limit of this linear actuator
danstrider 10:085ab7328054 174 batt().init();
tnhnrl 65:2ac186553959 175 batt().runLinearActuator(); // _init = true;
tnhnrl 65:2ac186553959 176 //batt().start();//removed start, it's handled by the interrupt
mkelly10 12:a0519d11d2b6 177 batt().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 178
tnhnrl 65:2ac186553959 179 // set up the depth, pitch, and rudder outer loop controllers
danstrider 10:085ab7328054 180 depthLoop().init();
tnhnrl 65:2ac186553959 181 //removed start, it's handled by the interrupt
tnhnrl 16:3363b9f14913 182 depthLoop().setCommand(stateMachine().getDepthCommand());
tnhnrl 20:8987a9ae2bc7 183
danstrider 10:085ab7328054 184 pitchLoop().init();
tnhnrl 65:2ac186553959 185 //removed start, it's handled by the interrupt
tnhnrl 16:3363b9f14913 186 pitchLoop().setCommand(stateMachine().getPitchCommand());
tnhnrl 55:f4ec445c42fe 187
tnhnrl 55:f4ec445c42fe 188 headingLoop().init();
tnhnrl 65:2ac186553959 189 //removed start, it's handled by the interrupt
tnhnrl 65:2ac186553959 190 //headingLoop().setCommand(stateMachine().getHeadingCommand()); // FIX LATER
tnhnrl 65:2ac186553959 191 //heading flag that adjust the PID error is set in the constructor
tnhnrl 65:2ac186553959 192
tnhnrl 65:2ac186553959 193 //systemTicker.attach_us(&system_timer, 10000); // Interrupt timer running at 0.01 seconds (slower than original ADC time interval)
tnhnrl 65:2ac186553959 194
tnhnrl 65:2ac186553959 195
tnhnrl 20:8987a9ae2bc7 196
tnhnrl 20:8987a9ae2bc7 197 // show that the PID gains are loading from the file
joel_ssc 82:0981b9ada820 198 xbee().printf("bce P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", bce().getControllerP(), bce().getControllerI(),
joel_ssc 82:0981b9ada820 199 bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope());
joel_ssc 82:0981b9ada820 200 xbee().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", batt().getControllerP(),
joel_ssc 82:0981b9ada820 201 batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope());
joel_ssc 82:0981b9ada820 202 xbee().printf("rudder min pwm: %6.2f, max pwm: %6.2f, center pwm: %6.2f, min deg: %6.2f, max deg: %6.2f\r\n", rudder().getMinPWM(), rudder().getMaxPWM(),
joel_ssc 82:0981b9ada820 203 rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg());
joel_ssc 82:0981b9ada820 204 xbee().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(),
joel_ssc 82:0981b9ada820 205 depthLoop().getControllerD(), depthLoop().getOutputOffset());
joel_ssc 82:0981b9ada820 206 xbee().printf("pitch P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(),
joel_ssc 82:0981b9ada820 207 pitchLoop().getControllerD(), pitchLoop().getOutputOffset());
joel_ssc 82:0981b9ada820 208 xbee().printf("heading P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f deg (deadband: %0.1f)\r\n", headingLoop().getControllerP(),
joel_ssc 82:0981b9ada820 209 headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset(), headingLoop().getDeadband());
tnhnrl 65:2ac186553959 210
tnhnrl 74:d281aaef9766 211 xbee().printf("\n\r");
tnhnrl 21:38c8544db6f4 212
tnhnrl 17:7c16b5671d0e 213 //load sequence from file
tnhnrl 17:7c16b5671d0e 214 sequenceController().loadSequence();
joel_ssc 82:0981b9ada820 215 char buf[256];
joel_ssc 82:0981b9ada820 216 //xbee().printf("\n\n\r 2018-08-14 FSG PCB XBee (setup complete) \n\n\r");
joel_ssc 82:0981b9ada820 217 sprintf(buf, "\n\n\r in setup(): starting legController().loadleg() \n\n\r");
joel_ssc 82:0981b9ada820 218 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 219 have_legfile = legController().loadLeg();
tnhnrl 32:f2f8ae34aadc 220
joel_ssc 82:0981b9ada820 221 //set time of logger (to current or close-to-current time) now set earlier at line 149
joel_ssc 82:0981b9ada820 222 // mbedLogger().setLogTime();
tnhnrl 65:2ac186553959 223 //sdLogger().setLogTime();
tnhnrl 47:fb3c7929d3f3 224
tnhnrl 47:fb3c7929d3f3 225 //create log files if not present on file system
tnhnrl 47:fb3c7929d3f3 226 mbedLogger().initializeLogFile();
joel_ssc 82:0981b9ada820 227
joel_ssc 82:0981b9ada820 228 mbedLogger().appendLogFile(current_state, 1); //write the idle state, then close
joel_ssc 82:0981b9ada820 229 //sdLogger().appendLogFile(current_state, 1); //write the idle state, then close
joel_ssc 82:0981b9ada820 230
joel_ssc 82:0981b9ada820 231 mbedLogger().appendLogFile(current_state, 0); //close log file added jcw nov 9 2018 for test
joel_ssc 82:0981b9ada820 232 //sdLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 80:4e5d306d695b 233 //sdLogger().initializeLogFile(); // works 10/23/18
tnhnrl 65:2ac186553959 234
tnhnrl 68:8f549749b8ce 235 setup_complete = true;
tnhnrl 65:2ac186553959 236 }
tnhnrl 58:94b7fd55185e 237
joel_ssc 84:eccd8e837134 238 void cycle_logfiles(int logversion, int diagversion) {
joel_ssc 84:eccd8e837134 239 //int logversion;
joel_ssc 84:eccd8e837134 240 //int diagversion;
joel_ssc 84:eccd8e837134 241 char bufx[256];
joel_ssc 84:eccd8e837134 242 sprintf(bufx, "\n\n\r in cycle_logfiles(%d, %d): starting new diag file. Will add 1 to these values \n\n\r", logversion, diagversion);
joel_ssc 84:eccd8e837134 243 mbedLogger().appendDiagFile(bufx,0);
joel_ssc 84:eccd8e837134 244 mbedLogger().appendLogFile(current_state, 0); //both files are now closed
joel_ssc 84:eccd8e837134 245 //use the present values and increment
joel_ssc 84:eccd8e837134 246 //logversion = configFileIO().logFilesStruct.logversion + 1;
joel_ssc 84:eccd8e837134 247 //diagversion = configFileIO().logFilesStruct.diagversion + 1;
joel_ssc 84:eccd8e837134 248 configFileIO().saveLogVersData(logversion+1, diagversion+1); // updates the file logvers.txt
joel_ssc 84:eccd8e837134 249 configFileIO().load_LogVers_config(0); // now read them back into the structure
joel_ssc 84:eccd8e837134 250 mbedLogger().initializeDiagFile(0); //don't print before initializing
joel_ssc 84:eccd8e837134 251
joel_ssc 84:eccd8e837134 252
joel_ssc 84:eccd8e837134 253 mbedLogger().initializeLogFile();
joel_ssc 84:eccd8e837134 254 mbedLogger().initializeDiagFile(1);
joel_ssc 84:eccd8e837134 255
joel_ssc 84:eccd8e837134 256 }
joel_ssc 84:eccd8e837134 257
tnhnrl 68:8f549749b8ce 258 /*************************** v1.8 **************************/
tnhnrl 68:8f549749b8ce 259
tnhnrl 73:f6f378311c8d 260 int main() {
tnhnrl 73:f6f378311c8d 261 setup(); //setup electronics/hardware
joel_ssc 82:0981b9ada820 262 // on landing, check orientation, if upside down, fix that first
tnhnrl 72:250b2665755c 263 systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
tnhnrl 68:8f549749b8ce 264
tnhnrl 65:2ac186553959 265 unsigned int tNow = 0;
joel_ssc 82:0981b9ada820 266 int vernum=0;
joel_ssc 82:0981b9ada820 267 int diagnum=0;
joel_ssc 82:0981b9ada820 268 char buf[256];
tnhnrl 75:92e79d23d29a 269 xbee().printf("\n\n\r 2018-08-14 FSG PCB XBee (setup complete) \n\n\r");
joel_ssc 82:0981b9ada820 270 sprintf(buf, "\n\n\r 2018-08-14 FSG PCB XBee line234main (setup complete) \n\n\r");
joel_ssc 82:0981b9ada820 271 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 272 sprintf(buf, "finished setting up and will exit\n\n\r");
joel_ssc 82:0981b9ada820 273 mbedLogger().appendDiagFile(buf,3);
joel_ssc 84:eccd8e837134 274 //tNow=5; sprintf(buf, "log file config values logfile= %s diag file= %s\n", configFileIO().logFilesStruct.logFileName,
joel_ssc 84:eccd8e837134 275 // configFileIO().logFilesStruct.diagFileName); tNow=0;
joel_ssc 82:0981b9ada820 276 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 277 vernum = configFileIO().logFilesStruct.logversion;
joel_ssc 82:0981b9ada820 278 diagnum = configFileIO().logFilesStruct.diagversion;
joel_ssc 82:0981b9ada820 279 sprintf(buf, "translated values LOG FILE VERSION number (vernum)=%d diag file version number(diagnum) = %d\n", vernum, diagnum);
joel_ssc 82:0981b9ada820 280 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 281 sprintf(buf, "logfiles_struct values - direct LOG FILE VERSION ().logversion=%d diag file version().diagversion = %d\n",
joel_ssc 82:0981b9ada820 282 configFileIO().logFilesStruct.logversion, configFileIO().logFilesStruct.diagversion);
joel_ssc 82:0981b9ada820 283 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 284 sprintf(buf, "try another messgae after closing file up and then will exit\n\n\r");
joel_ssc 82:0981b9ada820 285 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 286
joel_ssc 84:eccd8e837134 287
joel_ssc 84:eccd8e837134 288 // increment the log file names once
joel_ssc 84:eccd8e837134 289 //cycle_logfiles(vernum,diagnum);
joel_ssc 84:eccd8e837134 290 //sprintf(buf, "This message should be in a new diag file\n\n\r");
joel_ssc 84:eccd8e837134 291 //mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 292 // mbedLogger().appendLogFile(current_state, 1);
joel_ssc 82:0981b9ada820 293 //wait(5);
joel_ssc 82:0981b9ada820 294 //exit(0);
tnhnrl 56:48a8a5a65b82 295 systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
joel_ssc 82:0981b9ada820 296 int keeprunning = 1;
tnhnrl 65:2ac186553959 297
joel_ssc 82:0981b9ada820 298 if(have_legfile) {
joel_ssc 82:0981b9ada820 299 //install the leg variables in a structure, and set the state there.
joel_ssc 82:0981b9ada820 300 stateMachine().getLegParams(); //should set up everything with proper LEG_POSITION_DIVE state
joel_ssc 82:0981b9ada820 301 }
joel_ssc 84:eccd8e837134 302 while (keeprunning) {
joel_ssc 84:eccd8e837134 303 if( read_ticker() ) { // read_ticker runs at the speed of 10 kHz (adc timing)
tnhnrl 65:2ac186553959 304 ++tNow;
mkelly10 51:c5c40272ecc3 305
tnhnrl 81:7ff2c6467892 306 //Note to self: Retest data transmission code.
tnhnrl 81:7ff2c6467892 307 //This is currently running at 0.1 second intervals (10 hz) and was working well for data transmission
tnhnrl 74:d281aaef9766 308 if (current_state == TX_MBED_LOG or current_state == RX_SEQUENCE) {
tnhnrl 73:f6f378311c8d 309 if ( (tNow % 100) == 0 ) { // 0.01 second intervals (100 Hz)
tnhnrl 66:0f20870117b7 310 fsm_loop = true;
tnhnrl 66:0f20870117b7 311 FSM();
tnhnrl 66:0f20870117b7 312 }
joel_ssc 82:0981b9ada820 313 } // end if(currentstate..)
joel_ssc 84:eccd8e837134 314
tnhnrl 67:c86a4b464682 315 //NOT TRANSMITTING DATA, NORMAL OPERATIONS
joel_ssc 84:eccd8e837134 316 else { // **88**
joel_ssc 84:eccd8e837134 317 //FSM
tnhnrl 68:8f549749b8ce 318 if ( (tNow % 100) == 0 ) { // 0.1 second intervals
tnhnrl 66:0f20870117b7 319 fsm_loop = true;
tnhnrl 66:0f20870117b7 320 FSM();
joel_ssc 84:eccd8e837134 321
tnhnrl 73:f6f378311c8d 322 //get commands and update GUI
tnhnrl 73:f6f378311c8d 323 gui().getCommandFSM();
joel_ssc 84:eccd8e837134 324 }
joel_ssc 84:eccd8e837134 325 //LOGGING
joel_ssc 84:eccd8e837134 326 if ( (tNow % 1000) == 0 ) { // 1.0 second intervals
joel_ssc 84:eccd8e837134 327 log_loop = true;
joel_ssc 84:eccd8e837134 328 log_function();
joel_ssc 84:eccd8e837134 329 sprintf(buf, "hit 1 second log interval in main loop tNow =%d \n\n\r", tNow);
joel_ssc 84:eccd8e837134 330 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 331 }
joel_ssc 84:eccd8e837134 332 //update the log and diagnostics files
joel_ssc 84:eccd8e837134 333 if ( (tNow % 4600) == 0 ) { // 1.0 hour intervals check for testing via 7 second intervals
joel_ssc 84:eccd8e837134 334 sprintf(buf, "hit 4.6 second replace_logfiles interval in main loop tNow =%d \n\n\r", tNow);
joel_ssc 84:eccd8e837134 335 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 336 vernum = configFileIO().logFilesStruct.logversion;
joel_ssc 84:eccd8e837134 337 diagnum = configFileIO().logFilesStruct.diagversion;
joel_ssc 84:eccd8e837134 338 sprintf(buf, "cycle log file names at 7.6 seconds. This message should be in old diag file\n\n\r");
joel_ssc 84:eccd8e837134 339 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 340 cycle_logfiles(vernum,diagnum);
joel_ssc 84:eccd8e837134 341 sprintf(buf, "cycled log files at 7 seconds, This message should be in a NEW diag file\n\n\r");
joel_ssc 84:eccd8e837134 342 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 343 // close the log and diagnostics files
joel_ssc 84:eccd8e837134 344 // increment the version numbers for each
joel_ssc 84:eccd8e837134 345 // save the new version numbers
joel_ssc 84:eccd8e837134 346 // initialize new log and diagnostics files
tnhnrl 66:0f20870117b7 347 log_loop = true;
tnhnrl 66:0f20870117b7 348 log_function();
tnhnrl 66:0f20870117b7 349 }
joel_ssc 84:eccd8e837134 350 } // end else { at **88**
joel_ssc 84:eccd8e837134 351 if(current_state == FB_EXIT) {
joel_ssc 84:eccd8e837134 352 log_loop=true;
joel_ssc 84:eccd8e837134 353 log_function();
joel_ssc 84:eccd8e837134 354 keeprunning=0; // and this will force exit to the main while() loop.
joel_ssc 84:eccd8e837134 355 sprintf(buf, "INSIDE main loop: BUT now called to exit out of it via FB_EXIT\n\n\r");
joel_ssc 84:eccd8e837134 356 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 357 }
joel_ssc 82:0981b9ada820 358 } // end if(read_ticker) {
joel_ssc 82:0981b9ada820 359 } // end while(keeprunning)
joel_ssc 82:0981b9ada820 360 mbedLogger().appendLogFile(current_state, 1);
joel_ssc 84:eccd8e837134 361 sprintf(buf, "outside of main loop: exiting out of the leg loop via FB_EXIT\n\n\r");
joel_ssc 82:0981b9ada820 362 mbedLogger().appendDiagFile(buf,0);
joel_ssc 84:eccd8e837134 363 wait(25);
joel_ssc 84:eccd8e837134 364
joel_ssc 82:0981b9ada820 365 mbedLogger().appendLogFile(current_state, 1);
joel_ssc 82:0981b9ada820 366 mbedLogger().appendLogFile(current_state, 0);
joel_ssc 82:0981b9ada820 367 sprintf(buf, "wait 25 more seconds? out of the leg loop via FB_EXIT\n\n\r");
joel_ssc 82:0981b9ada820 368 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 369 exit(0);
joel_ssc 82:0981b9ada820 370 } // end main()