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:
Fri Feb 15 16:00:17 2019 +0000
Revision:
82:0981b9ada820
Parent:
81:7ff2c6467892
Child:
84:eccd8e837134
intermediate stage of file leg system

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
tnhnrl 68:8f549749b8ce 238 /*************************** v1.8 **************************/
tnhnrl 68:8f549749b8ce 239
tnhnrl 73:f6f378311c8d 240 int main() {
tnhnrl 73:f6f378311c8d 241 setup(); //setup electronics/hardware
joel_ssc 82:0981b9ada820 242 // on landing, check orientation, if upside down, fix that first
tnhnrl 72:250b2665755c 243 systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
tnhnrl 68:8f549749b8ce 244
tnhnrl 65:2ac186553959 245 unsigned int tNow = 0;
joel_ssc 82:0981b9ada820 246 int vernum=0;
joel_ssc 82:0981b9ada820 247 int diagnum=0;
joel_ssc 82:0981b9ada820 248 char buf[256];
tnhnrl 75:92e79d23d29a 249 xbee().printf("\n\n\r 2018-08-14 FSG PCB XBee (setup complete) \n\n\r");
joel_ssc 82:0981b9ada820 250 sprintf(buf, "\n\n\r 2018-08-14 FSG PCB XBee line234main (setup complete) \n\n\r");
joel_ssc 82:0981b9ada820 251 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 252 sprintf(buf, "finished setting up and will exit\n\n\r");
joel_ssc 82:0981b9ada820 253 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 254 tNow=5; sprintf(buf, "log file config values logfile= %s diag file= %s\n", configFileIO().logFilesStruct.logFileName,
joel_ssc 82:0981b9ada820 255 configFileIO().logFilesStruct.diagFileName); tNow=0;
joel_ssc 82:0981b9ada820 256 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 257 vernum = configFileIO().logFilesStruct.logversion;
joel_ssc 82:0981b9ada820 258 diagnum = configFileIO().logFilesStruct.diagversion;
joel_ssc 82:0981b9ada820 259 sprintf(buf, "translated values LOG FILE VERSION number (vernum)=%d diag file version number(diagnum) = %d\n", vernum, diagnum);
joel_ssc 82:0981b9ada820 260 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 261 sprintf(buf, "logfiles_struct values - direct LOG FILE VERSION ().logversion=%d diag file version().diagversion = %d\n",
joel_ssc 82:0981b9ada820 262 configFileIO().logFilesStruct.logversion, configFileIO().logFilesStruct.diagversion);
joel_ssc 82:0981b9ada820 263 mbedLogger().appendDiagFile(buf,3);
joel_ssc 82:0981b9ada820 264 sprintf(buf, "try another messgae after closing file up and then will exit\n\n\r");
joel_ssc 82:0981b9ada820 265 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 266 //wait(5);
joel_ssc 82:0981b9ada820 267 //exit(0);
tnhnrl 56:48a8a5a65b82 268 systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
joel_ssc 82:0981b9ada820 269 int keeprunning = 1;
tnhnrl 65:2ac186553959 270
joel_ssc 82:0981b9ada820 271 if(have_legfile) {
joel_ssc 82:0981b9ada820 272 //install the leg variables in a structure, and set the state there.
joel_ssc 82:0981b9ada820 273 stateMachine().getLegParams(); //should set up everything with proper LEG_POSITION_DIVE state
joel_ssc 82:0981b9ada820 274 }
joel_ssc 82:0981b9ada820 275 while (keeprunning) {
tnhnrl 66:0f20870117b7 276 if( read_ticker() ) // read_ticker runs at the speed of 10 kHz (adc timing)
tnhnrl 65:2ac186553959 277 {
tnhnrl 65:2ac186553959 278 ++tNow;
mkelly10 51:c5c40272ecc3 279
tnhnrl 81:7ff2c6467892 280 //Note to self: Retest data transmission code.
tnhnrl 81:7ff2c6467892 281 //This is currently running at 0.1 second intervals (10 hz) and was working well for data transmission
tnhnrl 74:d281aaef9766 282 if (current_state == TX_MBED_LOG or current_state == RX_SEQUENCE) {
tnhnrl 73:f6f378311c8d 283 if ( (tNow % 100) == 0 ) { // 0.01 second intervals (100 Hz)
tnhnrl 66:0f20870117b7 284 fsm_loop = true;
tnhnrl 66:0f20870117b7 285 FSM();
tnhnrl 66:0f20870117b7 286 }
joel_ssc 82:0981b9ada820 287 } // end if(currentstate..)
tnhnrl 34:9b66c5188051 288
tnhnrl 67:c86a4b464682 289 //NOT TRANSMITTING DATA, NORMAL OPERATIONS
tnhnrl 68:8f549749b8ce 290 else {
tnhnrl 68:8f549749b8ce 291 //FSM
tnhnrl 68:8f549749b8ce 292 if ( (tNow % 100) == 0 ) { // 0.1 second intervals
tnhnrl 66:0f20870117b7 293 fsm_loop = true;
tnhnrl 66:0f20870117b7 294 FSM();
tnhnrl 73:f6f378311c8d 295
tnhnrl 73:f6f378311c8d 296 //get commands and update GUI
tnhnrl 73:f6f378311c8d 297 gui().getCommandFSM();
tnhnrl 68:8f549749b8ce 298 }
tnhnrl 68:8f549749b8ce 299 //LOGGING
tnhnrl 68:8f549749b8ce 300 if ( (tNow % 1000) == 0 ) { // 1.0 second intervals
tnhnrl 66:0f20870117b7 301 log_loop = true;
tnhnrl 66:0f20870117b7 302 log_function();
tnhnrl 66:0f20870117b7 303 }
joel_ssc 82:0981b9ada820 304 } // end else {
joel_ssc 82:0981b9ada820 305 if(current_state == FB_EXIT) {
joel_ssc 82:0981b9ada820 306 log_loop=true;
joel_ssc 82:0981b9ada820 307 log_function();
joel_ssc 82:0981b9ada820 308 keeprunning=0; // and this will force exit to the main while() loop.
joel_ssc 82:0981b9ada820 309 }
joel_ssc 82:0981b9ada820 310 } // end if(read_ticker) {
joel_ssc 82:0981b9ada820 311 } // end while(keeprunning)
joel_ssc 82:0981b9ada820 312 mbedLogger().appendLogFile(current_state, 1);
joel_ssc 82:0981b9ada820 313 sprintf(buf, "exiting out of the leg loop via FB_EXIT\n\n\r");
joel_ssc 82:0981b9ada820 314 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 315 wait(25);
joel_ssc 82:0981b9ada820 316
joel_ssc 82:0981b9ada820 317 mbedLogger().appendLogFile(current_state, 1);
joel_ssc 82:0981b9ada820 318 mbedLogger().appendLogFile(current_state, 0);
joel_ssc 82:0981b9ada820 319 sprintf(buf, "wait 25 more seconds? out of the leg loop via FB_EXIT\n\n\r");
joel_ssc 82:0981b9ada820 320 mbedLogger().appendDiagFile(buf,0);
joel_ssc 82:0981b9ada820 321 exit(0);
joel_ssc 82:0981b9ada820 322 } // end main()