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:
Wed Jun 27 23:01:53 2018 +0000
Revision:
68:8f549749b8ce
Parent:
67:c86a4b464682
Child:
71:939d179478c4
file transmission partially repaired

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 68:8f549749b8ce 50 - fixing a bug with the data transmission
tnhnrl 68:8f549749b8ce 51 - new mode called continuously transmit data in order to speed up transmission
danstrider 10:085ab7328054 52 */
tnhnrl 65:2ac186553959 53
tzyoung 0:ea293bbf9717 54 #include "mbed.h"
tzyoung 0:ea293bbf9717 55 #include "StaticDefs.hpp"
tnhnrl 65:2ac186553959 56
tnhnrl 65:2ac186553959 57 #ifndef lround
tnhnrl 65:2ac186553959 58 #define lround(var) (long)(var+0.5f)
tnhnrl 65:2ac186553959 59 #endif
tnhnrl 65:2ac186553959 60
tnhnrl 65:2ac186553959 61 ////////////////////////////////////////////////////////////////// NEW TICKER
tnhnrl 65:2ac186553959 62 Ticker systemTicker;
tnhnrl 65:2ac186553959 63 bool setup_complete = false;
tnhnrl 65:2ac186553959 64 volatile unsigned int bTick = 0;
tnhnrl 65:2ac186553959 65 volatile unsigned int timer_counter = 0;
tnhnrl 65:2ac186553959 66
tnhnrl 65:2ac186553959 67 char hex[9];
tnhnrl 65:2ac186553959 68
tnhnrl 65:2ac186553959 69 char * conversion(float input_float) {
tnhnrl 65:2ac186553959 70 int integer_number = lround(100.0 * input_float); //convert floating point input to integer to broadcast over serial (reduce precision)
tnhnrl 65:2ac186553959 71
tnhnrl 65:2ac186553959 72 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 73 sprintf(hex, "%8x", integer_number); //generates spaces 0x20
tnhnrl 65:2ac186553959 74 return hex;
tnhnrl 65:2ac186553959 75 }
tnhnrl 65:2ac186553959 76
tnhnrl 65:2ac186553959 77 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 78 unsigned int val = bTick;
tnhnrl 65:2ac186553959 79 if( val )
tnhnrl 65:2ac186553959 80 bTick = 0;
tnhnrl 65:2ac186553959 81 return( val );
tnhnrl 65:2ac186553959 82 }
tnhnrl 65:2ac186553959 83 ////////////////////////////////////////////////////////////////// NEW TICKER
tnhnrl 20:8987a9ae2bc7 84
tnhnrl 32:f2f8ae34aadc 85 // loop rate used to determine how fast events trigger in the while loop
tnhnrl 65:2ac186553959 86 //Ticker main_loop_rate_ticker;
tnhnrl 65:2ac186553959 87 //Ticker log_loop_rate_ticker;
tnhnrl 32:f2f8ae34aadc 88
tnhnrl 65:2ac186553959 89 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 90 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 91
tnhnrl 65:2ac186553959 92 void loop_trigger() { fsm_loop = true;} // loop trigger (used in while loop)
tnhnrl 34:9b66c5188051 93 void log_loop_trigger() { log_loop = true;} // log loop trigger (used in while loop)
tnhnrl 32:f2f8ae34aadc 94
tnhnrl 65:2ac186553959 95 static int current_state = 0;
tnhnrl 65:2ac186553959 96 static bool file_opened = false;
tnhnrl 65:2ac186553959 97
tnhnrl 65:2ac186553959 98 void FSM() { // FSM loop runs at 100 hz
tnhnrl 65:2ac186553959 99 if(fsm_loop) {
tnhnrl 65:2ac186553959 100 fsm_loop = false; // wait until the loop rate timer fires again
tnhnrl 65:2ac186553959 101 current_state = stateMachine().runStateMachine(); //running State Machine. Returns 0 if sitting idle or keyboard press (SIT_IDLE state).
tnhnrl 65:2ac186553959 102 }
tnhnrl 65:2ac186553959 103 }
tnhnrl 65:2ac186553959 104
tnhnrl 65:2ac186553959 105 void log_function() {
tnhnrl 65:2ac186553959 106 // log loop runs at 1 hz
tnhnrl 65:2ac186553959 107 if (log_loop) {
tnhnrl 65:2ac186553959 108 //when the state machine is not in SIT_IDLE state (or a random keyboard press)
tnhnrl 65:2ac186553959 109
tnhnrl 68:8f549749b8ce 110 //if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) {
tnhnrl 68:8f549749b8ce 111 // ; //pass
tnhnrl 68:8f549749b8ce 112 // }
tnhnrl 65:2ac186553959 113
tnhnrl 68:8f549749b8ce 114 if(current_state != 0) {
tnhnrl 65:2ac186553959 115 if (!file_opened) { //if the log file is not open, open it
tnhnrl 65:2ac186553959 116 mbedLogger().appendLogFile(current_state, 0); //open MBED file once
tnhnrl 65:2ac186553959 117 //sdLogger().appendLogFile(current_state, 0); //open SD file once
tnhnrl 65:2ac186553959 118
tnhnrl 65:2ac186553959 119 file_opened = true; //stops it from continuing to open it
tnhnrl 56:48a8a5a65b82 120
tnhnrl 65:2ac186553959 121 pc().printf(">>>>>>>> Recording. Log file opened. <<<<<<<<\n\r");
tnhnrl 65:2ac186553959 122 }
tnhnrl 65:2ac186553959 123
tnhnrl 65:2ac186553959 124 //record to Mbed file system
tnhnrl 65:2ac186553959 125
tnhnrl 65:2ac186553959 126 mbedLogger().appendLogFile(current_state, 1); //writing data
tnhnrl 65:2ac186553959 127 //sdLogger().appendLogFile(current_state, 1); //writing data
tnhnrl 65:2ac186553959 128 }
tnhnrl 65:2ac186553959 129
tnhnrl 65:2ac186553959 130 //when the current FSM state is zero (SIT_IDLE), close the file
tnhnrl 65:2ac186553959 131 else {
tnhnrl 65:2ac186553959 132 //this can only happen once
tnhnrl 65:2ac186553959 133 if (file_opened) {
tnhnrl 67:c86a4b464682 134 //WRITE ONCE
tnhnrl 67:c86a4b464682 135 mbedLogger().appendLogFile(current_state, 1); //write the idle state, then close
tnhnrl 67:c86a4b464682 136
tnhnrl 65:2ac186553959 137 mbedLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 65:2ac186553959 138 //sdLogger().appendLogFile(current_state, 0); //close log file
tnhnrl 65:2ac186553959 139
tnhnrl 65:2ac186553959 140 file_opened = false;
tnhnrl 65:2ac186553959 141
tnhnrl 65:2ac186553959 142 pc().printf(">>>>>>>> Stopped recording. Log file closed. <<<<<<<<\n\r");
tnhnrl 65:2ac186553959 143 }
tnhnrl 65:2ac186553959 144 }
tnhnrl 65:2ac186553959 145 } //END OF LOG LOOP
tnhnrl 65:2ac186553959 146
tnhnrl 65:2ac186553959 147 log_loop = false; // wait until the loop rate timer fires again
tnhnrl 65:2ac186553959 148 }
tnhnrl 56:48a8a5a65b82 149
tnhnrl 65:2ac186553959 150 static void system_timer(void) {
tnhnrl 65:2ac186553959 151 bTick = 1;
tnhnrl 65:2ac186553959 152
tnhnrl 56:48a8a5a65b82 153 timer_counter++;
tnhnrl 56:48a8a5a65b82 154
tnhnrl 56:48a8a5a65b82 155 //only start these updates when everything is properly setup (through setup function)
tnhnrl 56:48a8a5a65b82 156 if (setup_complete) {
tnhnrl 65:2ac186553959 157 if ( (timer_counter % 1) == 0) { //this runs at 0.001 second intervals (1000 Hz)
tnhnrl 65:2ac186553959 158 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 159 }
tnhnrl 65:2ac186553959 160
tnhnrl 65:2ac186553959 161 if ( (timer_counter % 10) == 0) {
tnhnrl 65:2ac186553959 162 bce().update(); //update() inside LinearActuator class (running at 0.01 second intervals)
tnhnrl 65:2ac186553959 163 batt().update();
tnhnrl 65:2ac186553959 164 }
tnhnrl 65:2ac186553959 165
tnhnrl 65:2ac186553959 166 if ( (timer_counter % 20) == 0 ) { // 0.02 second intervals
tnhnrl 65:2ac186553959 167 rudder().runServo();
tnhnrl 65:2ac186553959 168 }
tnhnrl 65:2ac186553959 169
tnhnrl 65:2ac186553959 170 if ( (timer_counter % 50) == 0 ) { // 0.05 second intervals
tnhnrl 67:c86a4b464682 171 imu().runIMU();
tnhnrl 65:2ac186553959 172 }
tnhnrl 65:2ac186553959 173
tnhnrl 65:2ac186553959 174 if ( (timer_counter % 100) == 0) { // 100,000 microseconds = 0.1 second intervals
tnhnrl 65:2ac186553959 175 depthLoop().runOuterLoop();
tnhnrl 65:2ac186553959 176 pitchLoop().runOuterLoop();
tnhnrl 65:2ac186553959 177 headingLoop().runOuterLoop();
tnhnrl 65:2ac186553959 178 }
tnhnrl 56:48a8a5a65b82 179 }
tnhnrl 56:48a8a5a65b82 180 }
tnhnrl 56:48a8a5a65b82 181
danstrider 10:085ab7328054 182 void setup() {
danstrider 11:3b241ecb75ed 183 pc().baud(57600);
tnhnrl 66:0f20870117b7 184 pc().printf("\n\n\r FSG PCB Bench Test V1.5)\n\n\r");
tnhnrl 65:2ac186553959 185
danstrider 10:085ab7328054 186 // start up the system timer
tnhnrl 65:2ac186553959 187 //systemTimer().start();
tnhnrl 20:8987a9ae2bc7 188
danstrider 10:085ab7328054 189 // set up and start the adc. This runs on a fixed interval and is interrupt driven
tnhnrl 65:2ac186553959 190 adc().initialize();
tnhnrl 67:c86a4b464682 191 //one central interrupt is updating the ADC (not using the start function)
tnhnrl 65:2ac186553959 192
tnhnrl 65:2ac186553959 193 // setup and run the rudder(servo) pwm signal (start the ticker)
tnhnrl 65:2ac186553959 194 //rudder().init();
tnhnrl 65:2ac186553959 195 pc().printf("Rudder servo initialized!\n\r");
danstrider 10:085ab7328054 196
danstrider 10:085ab7328054 197 // set up and start the imu. This polls in the background
danstrider 10:085ab7328054 198 imu().initialize();
tnhnrl 65:2ac186553959 199 //imu().start();
danstrider 10:085ab7328054 200
tnhnrl 48:20e681885161 201 // construct the MBED local file system
danstrider 10:085ab7328054 202 local();
tnhnrl 48:20e681885161 203
tnhnrl 48:20e681885161 204 // construct the SD card file system
tnhnrl 65:2ac186553959 205 //sd_card();
tnhnrl 20:8987a9ae2bc7 206
danstrider 10:085ab7328054 207 // load config data from files
tnhnrl 65:2ac186553959 208 configFileIO().load_BCE_config(); // load the buoyancy engine parameters from the file "bce.txt"
tnhnrl 65:2ac186553959 209 configFileIO().load_BATT_config(); // load the battery mass mover parameters from the file "batt.txt"
tnhnrl 65:2ac186553959 210
tnhnrl 65:2ac186553959 211 configFileIO().load_DEPTH_config(); // load the depth control loop parameters from the file "depth.txt" (contains neutral position)
tnhnrl 65:2ac186553959 212 configFileIO().load_PITCH_config(); // load the depth control loop parameters from the file "pitch.txt" (contains neutral position)
tnhnrl 65:2ac186553959 213
tnhnrl 65:2ac186553959 214 configFileIO().load_RUDDER_config(); // load the rudder servo inner loop parameters from the file "SERVO.txt"
tnhnrl 65:2ac186553959 215 configFileIO().load_HEADING_config(); // load the rudder servo outer loop HEADING control parameters from the file "HEADING.txt" (contains neutral position)
tnhnrl 43:891baf306e0a 216
danstrider 10:085ab7328054 217 // set up the linear actuators. adc has to be running first.
tnhnrl 65:2ac186553959 218 bce().setPIDHighLimit(bce().getTravelLimit()); //travel limit of this linear actuator
danstrider 10:085ab7328054 219 bce().init();
tnhnrl 65:2ac186553959 220 //bce().start(); //removed start, it's handled by the interrupt
tnhnrl 67:c86a4b464682 221 bce().runLinearActuator();
mkelly10 12:a0519d11d2b6 222 bce().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 223
tnhnrl 65:2ac186553959 224 batt().setPIDHighLimit(batt().getTravelLimit()); //travel limit of this linear actuator
danstrider 10:085ab7328054 225 batt().init();
tnhnrl 65:2ac186553959 226 batt().runLinearActuator(); // _init = true;
tnhnrl 65:2ac186553959 227 //batt().start();//removed start, it's handled by the interrupt
mkelly10 12:a0519d11d2b6 228 batt().pause(); // start by not moving
tnhnrl 20:8987a9ae2bc7 229
tnhnrl 65:2ac186553959 230 // set up the depth, pitch, and rudder outer loop controllers
danstrider 10:085ab7328054 231 depthLoop().init();
tnhnrl 65:2ac186553959 232 //removed start, it's handled by the interrupt
tnhnrl 16:3363b9f14913 233 depthLoop().setCommand(stateMachine().getDepthCommand());
tnhnrl 20:8987a9ae2bc7 234
danstrider 10:085ab7328054 235 pitchLoop().init();
tnhnrl 65:2ac186553959 236 //removed start, it's handled by the interrupt
tnhnrl 16:3363b9f14913 237 pitchLoop().setCommand(stateMachine().getPitchCommand());
tnhnrl 55:f4ec445c42fe 238
tnhnrl 55:f4ec445c42fe 239 headingLoop().init();
tnhnrl 65:2ac186553959 240 //removed start, it's handled by the interrupt
tnhnrl 65:2ac186553959 241 //headingLoop().setCommand(stateMachine().getHeadingCommand()); // FIX LATER
tnhnrl 65:2ac186553959 242 //heading flag that adjust the PID error is set in the constructor
tnhnrl 65:2ac186553959 243
tnhnrl 65:2ac186553959 244 //systemTicker.attach_us(&system_timer, 10000); // Interrupt timer running at 0.01 seconds (slower than original ADC time interval)
tnhnrl 65:2ac186553959 245
tnhnrl 65:2ac186553959 246
tnhnrl 20:8987a9ae2bc7 247
tnhnrl 20:8987a9ae2bc7 248 // show that the PID gains are loading from the file
tnhnrl 38:83d06c294807 249 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 250 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 251 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 252
tnhnrl 65:2ac186553959 253 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 254 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 255 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 256
danstrider 10:085ab7328054 257 pc().printf("\n\r");
tnhnrl 21:38c8544db6f4 258
tnhnrl 17:7c16b5671d0e 259 //load sequence from file
tnhnrl 17:7c16b5671d0e 260 sequenceController().loadSequence();
tnhnrl 32:f2f8ae34aadc 261
tnhnrl 47:fb3c7929d3f3 262 //set time of logger (to current or close-to-current time)
tnhnrl 65:2ac186553959 263 mbedLogger().setLogTime();
tnhnrl 65:2ac186553959 264 //sdLogger().setLogTime();
tnhnrl 47:fb3c7929d3f3 265
tnhnrl 47:fb3c7929d3f3 266 //create log files if not present on file system
tnhnrl 47:fb3c7929d3f3 267 mbedLogger().initializeLogFile();
tnhnrl 65:2ac186553959 268 //sdLogger().initializeLogFile();
tnhnrl 65:2ac186553959 269
tnhnrl 68:8f549749b8ce 270 setup_complete = true;
tnhnrl 65:2ac186553959 271 }
tnhnrl 58:94b7fd55185e 272
tnhnrl 68:8f549749b8ce 273 /*************************** v1.8 **************************/
tnhnrl 68:8f549749b8ce 274
danstrider 10:085ab7328054 275 int main() {
danstrider 10:085ab7328054 276 setup();
tnhnrl 56:48a8a5a65b82 277
tnhnrl 68:8f549749b8ce 278 // set up the depth sensor. This is an internal ADC read
tnhnrl 68:8f549749b8ce 279 wait(1.0); //giving this time to work
tnhnrl 68:8f549749b8ce 280 depth().tare(); //this did not work correctly before the ADC starts
tnhnrl 68:8f549749b8ce 281
tnhnrl 65:2ac186553959 282 unsigned int tNow = 0;
tnhnrl 65:2ac186553959 283
tnhnrl 65:2ac186553959 284 pc().baud(57600);
tnhnrl 68:8f549749b8ce 285 pc().printf("\n\n\r FSG PCB v1.7 (XBee) 6/25/2018 \n\n\r");
tnhnrl 56:48a8a5a65b82 286
tnhnrl 56:48a8a5a65b82 287 systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval)
tnhnrl 65:2ac186553959 288
tnhnrl 65:2ac186553959 289 while (1) {
tnhnrl 66:0f20870117b7 290 if( read_ticker() ) // read_ticker runs at the speed of 10 kHz (adc timing)
tnhnrl 65:2ac186553959 291 {
tnhnrl 65:2ac186553959 292 ++tNow;
mkelly10 51:c5c40272ecc3 293
tnhnrl 66:0f20870117b7 294 //run finite state machine fast when transmitting data
tnhnrl 66:0f20870117b7 295 if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) {
tnhnrl 68:8f549749b8ce 296 //if ( (tNow % 10) == 0 ) { // 0.001 second intervals (1000 Hz)
tnhnrl 68:8f549749b8ce 297 if ( (tNow % 100) == 0 ) { // 0.1 second intervals (10 Hz)
tnhnrl 66:0f20870117b7 298 fsm_loop = true;
tnhnrl 66:0f20870117b7 299 FSM();
tnhnrl 66:0f20870117b7 300 }
tnhnrl 45:16b8162188ca 301 }
tnhnrl 34:9b66c5188051 302
tnhnrl 67:c86a4b464682 303 //NOT TRANSMITTING DATA, NORMAL OPERATIONS
tnhnrl 68:8f549749b8ce 304 else {
tnhnrl 68:8f549749b8ce 305 //FSM
tnhnrl 68:8f549749b8ce 306 if ( (tNow % 100) == 0 ) { // 0.1 second intervals
tnhnrl 66:0f20870117b7 307 fsm_loop = true;
tnhnrl 66:0f20870117b7 308 FSM();
tnhnrl 68:8f549749b8ce 309 }
tnhnrl 68:8f549749b8ce 310 //LOGGING
tnhnrl 68:8f549749b8ce 311 if ( (tNow % 1000) == 0 ) { // 1.0 second intervals
tnhnrl 66:0f20870117b7 312 log_loop = true;
tnhnrl 66:0f20870117b7 313 log_function();
tnhnrl 66:0f20870117b7 314 }
tnhnrl 66:0f20870117b7 315 }
tnhnrl 65:2ac186553959 316 }
danstrider 10:085ab7328054 317 }
danstrider 10:085ab7328054 318 }