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:
tnhnrl
Date:
Fri Jun 29 21:52:31 2018 +0000
Revision:
71:939d179478c4
Parent:
68:8f549749b8ce
Child:
72:250b2665755c
recheck

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danstrider 10:085ab7328054 1 /*
tnhnrl 58:94b7fd55185e 2 Modified FSG PCB V_1_1
tnhnrl 52:f207567d3ea4 3 - Freezes when doing a dive or any timed sequence (commented out SD card references)
tnhnrl 52:f207567d3ea4 4 - commented out sdLogger().appendLogFile(current_state, 0); //open SD file once
tnhnrl 52:f207567d3ea4 5 - commented out sdLogger().appendLogFile(current_state, 1); //writing data
tnhnrl 52:f207567d3ea4 6 - commented out sdLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 52:f207567d3ea4 7 - reduced timer to 20 seconds for bench testing
tnhnrl 52:f207567d3ea4 8 - modified ConfigFileIO for rudder()
tnhnrl 52:f207567d3ea4 9 - added in getFloatUserInput function from newer code
tnhnrl 53:c0586fe62b01 10 - changed LinearActuator & batt() in StaticDefs to match new pinouts from Bob/Matt/Troy fixes
tnhnrl 53:c0586fe62b01 11 - slowed down battery motor because it's silly fast at 30 volts (bench test)
tnhnrl 53:c0586fe62b01 12 * BCE gain is proportional 0.1 now 0.01
tnhnrl 53:c0586fe62b01 13 - BATT was moving in the wrong direction, gain was P: 0.10, I: 0.0, D: 0.0
tnhnrl 57:ec69651c8c21 14 * change gain to P: -0.10 (gain was flipped, I think the old circuit board had the voltages flipped ? ?)
tnhnrl 53:c0586fe62b01 15 - StateMachine changes for testing
tnhnrl 53:c0586fe62b01 16 * added keyboard_menu_STREAM_STATUS();
tnhnrl 53:c0586fe62b01 17 * added keyboard_menu_RUDDER_SERVO_settings();
tnhnrl 54:d4990fb68404 18 - modified the zero on the battery position from 610 to 836
tnhnrl 54:d4990fb68404 19 - BMM (batt) slope may be incorrect, seems low, currently 0.12176
tnhnrl 54:d4990fb68404 20 - modified the zero on BCE from 253 to 460
tnhnrl 54:d4990fb68404 21 - Pressure readings are wrong
tnhnrl 54:d4990fb68404 22 * added readADCCounts() to omegaPX209 class to see channel readings
tnhnrl 54:d4990fb68404 23 * modified omegaPX209 class to use filtered ADC readings from SpiADC.readCh4()
tnhnrl 54:d4990fb68404 24 - fixed rudderLoop to headingLoop from newer code
tnhnrl 58:94b7fd55185e 25 Modified FSG PCB V_1_2
tnhnrl 55:f4ec445c42fe 26 - added init headingLoop to main
tnhnrl 55:f4ec445c42fe 27 - added pitch and heading outputs to STREAM_STATUS
tnhnrl 54:d4990fb68404 28 NOTE: Flipped motor controller output on connector side with battery mass mover (BMM)
tnhnrl 54:d4990fb68404 29 - Motor direction was opposite the BCE motor (because of gearing)
tnhnrl 54:d4990fb68404 30 - BMM P gain is now positive 0.02 (from -0.10)
tnhnrl 58:94b7fd55185e 31 Modified FSG PCB V_1_3
tnhnrl 56:48a8a5a65b82 32 - added timing code for interrupt that drives the rudder (testing with o-scope)
tnhnrl 58:94b7fd55185e 33 - PID controller replaced with newer version from 5/29 code branch
tnhnrl 58:94b7fd55185e 34 - StateMachine hanged style of variables to match convention in code
tnhnrl 63:6cb0405fc6e6 35 Modified FSG PCB V_1_4
tnhnrl 67:c86a4b464682 36 - adc tests
tnhnrl 65:2ac186553959 37 Modified FSG PCB V_1_5
tnhnrl 65:2ac186553959 38 - IMU update
tnhnrl 67:c86a4b464682 39 - Testing print outs
tnhnrl 67:c86a4b464682 40 Modified FSG PCB V_1_6
tnhnrl 67:c86a4b464682 41 - new BMM zero count of 240 (confirmed manually)
tnhnrl 67:c86a4b464682 42 - new BCE zero count of 400 (confirmed manually)
tnhnrl 67:c86a4b464682 43 - Modified emergency climb to go to position 10 on the BMM, not zero (almost relying on the limit switch)
tnhnrl 67:c86a4b464682 44 - fixed keyboard input; including typing in the timeout (can enter exact times)
tnhnrl 67:c86a4b464682 45 Modified FSG PCB V_1_7
tnhnrl 67:c86a4b464682 46 - removed data logger references
tnhnrl 68:8f549749b8ce 47 - fixed bug where I was logging data twice in the interrupt code and the main file
tnhnrl 68:8f549749b8ce 48 - fixed bug where Multi-Dive sequence wasn't restarting (the counter used to get the current state was not reset)
tnhnrl 68:8f549749b8ce 49 Modified FSG PCB v_1_8
tnhnrl 71:939d179478c4 50 - fixing a bug with the data transmission (output had newline character)
tnhnrl 68:8f549749b8ce 51 - new mode called continuously transmit data in order to speed up transmission
tnhnrl 71:939d179478c4 52 -
danstrider 10:085ab7328054 53 */
tnhnrl 65:2ac186553959 54
tzyoung 0:ea293bbf9717 55 #include "mbed.h"
tzyoung 0:ea293bbf9717 56 #include "StaticDefs.hpp"
tnhnrl 65:2ac186553959 57
tnhnrl 65:2ac186553959 58 #ifndef lround
tnhnrl 65:2ac186553959 59 #define lround(var) (long)(var+0.5f)
tnhnrl 65:2ac186553959 60 #endif
tnhnrl 65:2ac186553959 61
tnhnrl 65:2ac186553959 62 ////////////////////////////////////////////////////////////////// NEW TICKER
tnhnrl 65:2ac186553959 63 Ticker systemTicker;
tnhnrl 65:2ac186553959 64 bool setup_complete = false;
tnhnrl 65:2ac186553959 65 volatile unsigned int bTick = 0;
tnhnrl 65:2ac186553959 66 volatile unsigned int timer_counter = 0;
tnhnrl 65:2ac186553959 67
tnhnrl 65:2ac186553959 68 char hex[9];
tnhnrl 65:2ac186553959 69
tnhnrl 65:2ac186553959 70 char * conversion(float input_float) {
tnhnrl 65:2ac186553959 71 int integer_number = lround(100.0 * input_float); //convert floating point input to integer to broadcast over serial (reduce precision)
tnhnrl 65:2ac186553959 72
tnhnrl 65:2ac186553959 73 memset(hex, 0, sizeof(hex) ); // void* memset( void* dest, int ch, size_t count ); // CLEAR IT (need null at end of string)
tnhnrl 65:2ac186553959 74 sprintf(hex, "%8x", integer_number); //generates spaces 0x20
tnhnrl 65:2ac186553959 75 return hex;
tnhnrl 65:2ac186553959 76 }
tnhnrl 65:2ac186553959 77
tnhnrl 65:2ac186553959 78 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 79 unsigned int val = bTick;
tnhnrl 65:2ac186553959 80 if( val )
tnhnrl 65:2ac186553959 81 bTick = 0;
tnhnrl 65:2ac186553959 82 return( val );
tnhnrl 65:2ac186553959 83 }
tnhnrl 65:2ac186553959 84 ////////////////////////////////////////////////////////////////// NEW TICKER
tnhnrl 20:8987a9ae2bc7 85
tnhnrl 32:f2f8ae34aadc 86 // loop rate used to determine how fast events trigger in the while loop
tnhnrl 65:2ac186553959 87 //Ticker main_loop_rate_ticker;
tnhnrl 65:2ac186553959 88 //Ticker log_loop_rate_ticker;
tnhnrl 32:f2f8ae34aadc 89
tnhnrl 65:2ac186553959 90 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 91 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 92
tnhnrl 65:2ac186553959 93 void loop_trigger() { fsm_loop = true;} // loop trigger (used in while loop)
tnhnrl 34:9b66c5188051 94 void log_loop_trigger() { log_loop = true;} // log loop trigger (used in while loop)
tnhnrl 32:f2f8ae34aadc 95
tnhnrl 65:2ac186553959 96 static int current_state = 0;
tnhnrl 65:2ac186553959 97 static bool file_opened = false;
tnhnrl 65:2ac186553959 98
tnhnrl 65:2ac186553959 99 void FSM() { // FSM loop runs at 100 hz
tnhnrl 65:2ac186553959 100 if(fsm_loop) {
tnhnrl 65:2ac186553959 101 fsm_loop = false; // wait until the loop rate timer fires again
tnhnrl 65:2ac186553959 102 current_state = stateMachine().runStateMachine(); //running State Machine. Returns 0 if sitting idle or keyboard press (SIT_IDLE state).
tnhnrl 65:2ac186553959 103 }
tnhnrl 65:2ac186553959 104 }
tnhnrl 65:2ac186553959 105
tnhnrl 65:2ac186553959 106 void log_function() {
tnhnrl 65:2ac186553959 107 // log loop runs at 1 hz
tnhnrl 65:2ac186553959 108 if (log_loop) {
tnhnrl 65:2ac186553959 109 //when the state machine is not in SIT_IDLE state (or a random keyboard press)
tnhnrl 65:2ac186553959 110
tnhnrl 68:8f549749b8ce 111 //if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) {
tnhnrl 68:8f549749b8ce 112 // ; //pass
tnhnrl 68:8f549749b8ce 113 // }
tnhnrl 65:2ac186553959 114
tnhnrl 68:8f549749b8ce 115 if(current_state != 0) {
tnhnrl 65:2ac186553959 116 if (!file_opened) { //if the log file is not open, open it
tnhnrl 65:2ac186553959 117 mbedLogger().appendLogFile(current_state, 0); //open MBED file once
tnhnrl 65:2ac186553959 118 //sdLogger().appendLogFile(current_state, 0); //open SD file once
tnhnrl 65:2ac186553959 119
tnhnrl 65:2ac186553959 120 file_opened = true; //stops it from continuing to open it
tnhnrl 56:48a8a5a65b82 121
tnhnrl 65:2ac186553959 122 pc().printf(">>>>>>>> Recording. Log file opened. <<<<<<<<\n\r");
tnhnrl 65:2ac186553959 123 }
tnhnrl 65:2ac186553959 124
tnhnrl 65:2ac186553959 125 //record to Mbed file system
tnhnrl 65:2ac186553959 126
tnhnrl 65:2ac186553959 127 mbedLogger().appendLogFile(current_state, 1); //writing data
tnhnrl 65:2ac186553959 128 //sdLogger().appendLogFile(current_state, 1); //writing data
tnhnrl 65:2ac186553959 129 }
tnhnrl 65:2ac186553959 130
tnhnrl 65:2ac186553959 131 //when the current FSM state is zero (SIT_IDLE), close the file
tnhnrl 65:2ac186553959 132 else {
tnhnrl 65:2ac186553959 133 //this can only happen once
tnhnrl 65:2ac186553959 134 if (file_opened) {
tnhnrl 67:c86a4b464682 135 //WRITE ONCE
tnhnrl 67:c86a4b464682 136 mbedLogger().appendLogFile(current_state, 1); //write the idle state, then close
tnhnrl 67:c86a4b464682 137
tnhnrl 65:2ac186553959 138 mbedLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 65:2ac186553959 139 //sdLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 65:2ac186553959 140
tnhnrl 65:2ac186553959 141 file_opened = false;
tnhnrl 65:2ac186553959 142
tnhnrl 65:2ac186553959 143 pc().printf(">>>>>>>> Stopped recording. Log file closed. <<<<<<<<\n\r");
tnhnrl 65:2ac186553959 144 }
tnhnrl 65:2ac186553959 145 }
tnhnrl 65:2ac186553959 146 } //END OF LOG LOOP
tnhnrl 65:2ac186553959 147
tnhnrl 65:2ac186553959 148 log_loop = false; // wait until the loop rate timer fires again
tnhnrl 65:2ac186553959 149 }
tnhnrl 56:48a8a5a65b82 150
tnhnrl 65:2ac186553959 151 static void system_timer(void) {
tnhnrl 65:2ac186553959 152 bTick = 1;
tnhnrl 65:2ac186553959 153
tnhnrl 56:48a8a5a65b82 154 timer_counter++;
tnhnrl 56:48a8a5a65b82 155
tnhnrl 56:48a8a5a65b82 156 //only start these updates when everything is properly setup (through setup function)
tnhnrl 56:48a8a5a65b82 157 if (setup_complete) {
tnhnrl 65:2ac186553959 158 if ( (timer_counter % 1) == 0) { //this runs at 0.001 second intervals (1000 Hz)
tnhnrl 65:2ac186553959 159 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 160 }
tnhnrl 65:2ac186553959 161
tnhnrl 65:2ac186553959 162 if ( (timer_counter % 10) == 0) {
tnhnrl 65:2ac186553959 163 bce().update(); //update() inside LinearActuator class (running at 0.01 second intervals)
tnhnrl 65:2ac186553959 164 batt().update();
tnhnrl 65:2ac186553959 165 }
tnhnrl 65:2ac186553959 166
tnhnrl 65:2ac186553959 167 if ( (timer_counter % 20) == 0 ) { // 0.02 second intervals
tnhnrl 65:2ac186553959 168 rudder().runServo();
tnhnrl 65:2ac186553959 169 }
tnhnrl 65:2ac186553959 170
tnhnrl 65:2ac186553959 171 if ( (timer_counter % 50) == 0 ) { // 0.05 second intervals
tnhnrl 67:c86a4b464682 172 imu().runIMU();
tnhnrl 65:2ac186553959 173 }
tnhnrl 65:2ac186553959 174
tnhnrl 65:2ac186553959 175 if ( (timer_counter % 100) == 0) { // 100,000 microseconds = 0.1 second intervals
tnhnrl 65:2ac186553959 176 depthLoop().runOuterLoop();
tnhnrl 65:2ac186553959 177 pitchLoop().runOuterLoop();
tnhnrl 65:2ac186553959 178 headingLoop().runOuterLoop();
tnhnrl 65:2ac186553959 179 }
tnhnrl 56:48a8a5a65b82 180 }
tnhnrl 56:48a8a5a65b82 181 }
tnhnrl 56:48a8a5a65b82 182
danstrider 10:085ab7328054 183 void setup() {
danstrider 11:3b241ecb75ed 184 pc().baud(57600);
tnhnrl 66:0f20870117b7 185 pc().printf("\n\n\r FSG PCB Bench Test V1.5)\n\n\r");
tnhnrl 65:2ac186553959 186
danstrider 10:085ab7328054 187 // start up the system timer
tnhnrl 65:2ac186553959 188 //systemTimer().start();
tnhnrl 20:8987a9ae2bc7 189
danstrider 10:085ab7328054 190 // set up and start the adc. This runs on a fixed interval and is interrupt driven
tnhnrl 65:2ac186553959 191 adc().initialize();
tnhnrl 67:c86a4b464682 192 //one central interrupt is updating the ADC (not using the start function)
tnhnrl 65:2ac186553959 193
tnhnrl 65:2ac186553959 194 // setup and run the rudder(servo) pwm signal (start the ticker)
tnhnrl 65:2ac186553959 195 //rudder().init();
tnhnrl 65:2ac186553959 196 pc().printf("Rudder servo initialized!\n\r");
danstrider 10:085ab7328054 197
danstrider 10:085ab7328054 198 // set up and start the imu. This polls in the background
danstrider 10:085ab7328054 199 imu().initialize();
tnhnrl 65:2ac186553959 200 //imu().start();
danstrider 10:085ab7328054 201
tnhnrl 48:20e681885161 202 // construct the MBED local file system
danstrider 10:085ab7328054 203 local();
tnhnrl 48:20e681885161 204
tnhnrl 48:20e681885161 205 // construct the SD card file system
tnhnrl 65:2ac186553959 206 //sd_card();
tnhnrl 20:8987a9ae2bc7 207
danstrider 10:085ab7328054 208 // load config data from files
tnhnrl 65:2ac186553959 209 configFileIO().load_BCE_config(); // load the buoyancy engine parameters from the file "bce.txt"
tnhnrl 65:2ac186553959 210 configFileIO().load_BATT_config(); // load the battery mass mover parameters from the file "batt.txt"
tnhnrl 65:2ac186553959 211
tnhnrl 65:2ac186553959 212 configFileIO().load_DEPTH_config(); // load the depth control loop parameters from the file "depth.txt" (contains neutral position)
tnhnrl 65:2ac186553959 213 configFileIO().load_PITCH_config(); // load the depth control loop parameters from the file "pitch.txt" (contains neutral position)
tnhnrl 65:2ac186553959 214
tnhnrl 65:2ac186553959 215 configFileIO().load_RUDDER_config(); // load the rudder servo inner loop parameters from the file "SERVO.txt"
tnhnrl 65:2ac186553959 216 configFileIO().load_HEADING_config(); // load the rudder servo outer loop HEADING control parameters from the file "HEADING.txt" (contains neutral position)
tnhnrl 43:891baf306e0a 217
danstrider 10:085ab7328054 218 // set up the linear actuators. adc has to be running first.
tnhnrl 65:2ac186553959 219 bce().setPIDHighLimit(bce().getTravelLimit()); //travel limit of this linear actuator
danstrider 10:085ab7328054 220 bce().init();
tnhnrl 65:2ac186553959 221 //bce().start(); //removed start, it's handled by the interrupt
tnhnrl 67:c86a4b464682 222 bce().runLinearActuator();
mkelly10 12:a0519d11d2b6 223 bce().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 224
tnhnrl 65:2ac186553959 225 batt().setPIDHighLimit(batt().getTravelLimit()); //travel limit of this linear actuator
danstrider 10:085ab7328054 226 batt().init();
tnhnrl 65:2ac186553959 227 batt().runLinearActuator(); // _init = true;
tnhnrl 65:2ac186553959 228 //batt().start();//removed start, it's handled by the interrupt
mkelly10 12:a0519d11d2b6 229 batt().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 230
tnhnrl 65:2ac186553959 231 // set up the depth, pitch, and rudder outer loop controllers
danstrider 10:085ab7328054 232 depthLoop().init();
tnhnrl 65:2ac186553959 233 //removed start, it's handled by the interrupt
tnhnrl 16:3363b9f14913 234 depthLoop().setCommand(stateMachine().getDepthCommand());
tnhnrl 20:8987a9ae2bc7 235
danstrider 10:085ab7328054 236 pitchLoop().init();
tnhnrl 65:2ac186553959 237 //removed start, it's handled by the interrupt
tnhnrl 16:3363b9f14913 238 pitchLoop().setCommand(stateMachine().getPitchCommand());
tnhnrl 55:f4ec445c42fe 239
tnhnrl 55:f4ec445c42fe 240 headingLoop().init();
tnhnrl 65:2ac186553959 241 //removed start, it's handled by the interrupt
tnhnrl 65:2ac186553959 242 //headingLoop().setCommand(stateMachine().getHeadingCommand()); // FIX LATER
tnhnrl 65:2ac186553959 243 //heading flag that adjust the PID error is set in the constructor
tnhnrl 65:2ac186553959 244
tnhnrl 65:2ac186553959 245 //systemTicker.attach_us(&system_timer, 10000); // Interrupt timer running at 0.01 seconds (slower than original ADC time interval)
tnhnrl 65:2ac186553959 246
tnhnrl 65:2ac186553959 247
tnhnrl 20:8987a9ae2bc7 248
tnhnrl 20:8987a9ae2bc7 249 // show that the PID gains are loading from the file
tnhnrl 38:83d06c294807 250 pc().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(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope());
tnhnrl 38:83d06c294807 251 pc().printf("batt P:%6.2f, I:%6.2f, D:%6.2f, zero %3i, limit %6.1f mm, slope %0.5f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope());
tnhnrl 65:2ac186553959 252 pc().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(), rudder().getCenterPWM(), rudder().getMinDeg(), rudder().getMaxDeg());
tnhnrl 65:2ac186553959 253
tnhnrl 65:2ac186553959 254 pc().printf("depth P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset());
tnhnrl 65:2ac186553959 255 pc().printf("pitch P:%6.2f, I:%6.2f, D:%6.2f, offset:%6.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset());
tnhnrl 65:2ac186553959 256 pc().printf("heading P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f deg (deadband: %0.1f)\r\n", headingLoop().getControllerP(), headingLoop().getControllerI(), headingLoop().getControllerD(), headingLoop().getOutputOffset(), headingLoop().getDeadband());
tnhnrl 65:2ac186553959 257
danstrider 10:085ab7328054 258 pc().printf("\n\r");
tnhnrl 21:38c8544db6f4 259
tnhnrl 17:7c16b5671d0e 260 //load sequence from file
tnhnrl 17:7c16b5671d0e 261 sequenceController().loadSequence();
tnhnrl 32:f2f8ae34aadc 262
tnhnrl 47:fb3c7929d3f3 263 //set time of logger (to current or close-to-current time)
tnhnrl 65:2ac186553959 264 mbedLogger().setLogTime();
tnhnrl 65:2ac186553959 265 //sdLogger().setLogTime();
tnhnrl 47:fb3c7929d3f3 266
tnhnrl 47:fb3c7929d3f3 267 //create log files if not present on file system
tnhnrl 47:fb3c7929d3f3 268 mbedLogger().initializeLogFile();
tnhnrl 65:2ac186553959 269 //sdLogger().initializeLogFile();
tnhnrl 65:2ac186553959 270
tnhnrl 68:8f549749b8ce 271 setup_complete = true;
tnhnrl 65:2ac186553959 272 }
tnhnrl 58:94b7fd55185e 273
tnhnrl 68:8f549749b8ce 274 /*************************** v1.8 **************************/
tnhnrl 68:8f549749b8ce 275
danstrider 10:085ab7328054 276 int main() {
danstrider 10:085ab7328054 277 setup();
tnhnrl 56:48a8a5a65b82 278
tnhnrl 68:8f549749b8ce 279 // set up the depth sensor. This is an internal ADC read
tnhnrl 68:8f549749b8ce 280 wait(1.0); //giving this time to work
tnhnrl 68:8f549749b8ce 281 depth().tare(); //this did not work correctly before the ADC starts
tnhnrl 68:8f549749b8ce 282
tnhnrl 65:2ac186553959 283 unsigned int tNow = 0;
tnhnrl 65:2ac186553959 284
tnhnrl 65:2ac186553959 285 pc().baud(57600);
tnhnrl 68:8f549749b8ce 286 pc().printf("\n\n\r FSG PCB v1.7 (XBee) 6/25/2018 \n\n\r");
tnhnrl 56:48a8a5a65b82 287
tnhnrl 56:48a8a5a65b82 288 systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
tnhnrl 65:2ac186553959 289
tnhnrl 65:2ac186553959 290 while (1) {
tnhnrl 66:0f20870117b7 291 if( read_ticker() ) // read_ticker runs at the speed of 10 kHz (adc timing)
tnhnrl 65:2ac186553959 292 {
tnhnrl 65:2ac186553959 293 ++tNow;
mkelly10 51:c5c40272ecc3 294
tnhnrl 66:0f20870117b7 295 //run finite state machine fast when transmitting data
tnhnrl 71:939d179478c4 296 if (current_state == TX_MBED_LOG or current_state == RECEIVE_SEQUENCE) {
tnhnrl 68:8f549749b8ce 297 //if ( (tNow % 10) == 0 ) { // 0.001 second intervals (1000 Hz)
tnhnrl 68:8f549749b8ce 298 if ( (tNow % 100) == 0 ) { // 0.1 second intervals (10 Hz)
tnhnrl 66:0f20870117b7 299 fsm_loop = true;
tnhnrl 66:0f20870117b7 300 FSM();
tnhnrl 66:0f20870117b7 301 }
tnhnrl 45:16b8162188ca 302 }
tnhnrl 34:9b66c5188051 303
tnhnrl 67:c86a4b464682 304 //NOT TRANSMITTING DATA, NORMAL OPERATIONS
tnhnrl 68:8f549749b8ce 305 else {
tnhnrl 68:8f549749b8ce 306 //FSM
tnhnrl 68:8f549749b8ce 307 if ( (tNow % 100) == 0 ) { // 0.1 second intervals
tnhnrl 66:0f20870117b7 308 fsm_loop = true;
tnhnrl 66:0f20870117b7 309 FSM();
tnhnrl 68:8f549749b8ce 310 }
tnhnrl 68:8f549749b8ce 311 //LOGGING
tnhnrl 68:8f549749b8ce 312 if ( (tNow % 1000) == 0 ) { // 1.0 second intervals
tnhnrl 66:0f20870117b7 313 log_loop = true;
tnhnrl 66:0f20870117b7 314 log_function();
tnhnrl 66:0f20870117b7 315 }
tnhnrl 66:0f20870117b7 316 }
tnhnrl 65:2ac186553959 317 }
danstrider 10:085ab7328054 318 }
danstrider 10:085ab7328054 319 }