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
main.cpp@65:2ac186553959, 2018-06-19 (annotated)
- Committer:
- tnhnrl
- Date:
- Tue Jun 19 18:10:50 2018 +0000
- Revision:
- 65:2ac186553959
- Parent:
- 63:6cb0405fc6e6
- Child:
- 66:0f20870117b7
Version with limit switches in output
Who changed what in which revision?
User | Revision | Line number | New 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 | |
tnhnrl | 54:d4990fb68404 | 29 | NOTE: Flipped motor controller output on connector side with battery mass mover (BMM) |
tnhnrl | 54:d4990fb68404 | 30 | - Motor direction was opposite the BCE motor (because of gearing) |
tnhnrl | 54:d4990fb68404 | 31 | - BMM P gain is now positive 0.02 (from -0.10) |
tnhnrl | 54:d4990fb68404 | 32 | |
tnhnrl | 58:94b7fd55185e | 33 | Modified FSG PCB V_1_3 |
tnhnrl | 56:48a8a5a65b82 | 34 | - added timing code for interrupt that drives the rudder (testing with o-scope) |
tnhnrl | 58:94b7fd55185e | 35 | - PID controller replaced with newer version from 5/29 code branch |
tnhnrl | 58:94b7fd55185e | 36 | - StateMachine hanged style of variables to match convention in code |
tnhnrl | 63:6cb0405fc6e6 | 37 | |
tnhnrl | 63:6cb0405fc6e6 | 38 | Modified FSG PCB V_1_4 |
tnhnrl | 63:6cb0405fc6e6 | 39 | - adcLed = 0; in adc |
tnhnrl | 65:2ac186553959 | 40 | |
tnhnrl | 65:2ac186553959 | 41 | Modified FSG PCB V_1_5 |
tnhnrl | 65:2ac186553959 | 42 | - IMU update |
danstrider | 10:085ab7328054 | 43 | */ |
tnhnrl | 65:2ac186553959 | 44 | |
tnhnrl | 65:2ac186553959 | 45 | /* removed unused variables */ |
tzyoung | 0:ea293bbf9717 | 46 | #include "mbed.h" |
tzyoung | 0:ea293bbf9717 | 47 | #include "StaticDefs.hpp" |
tnhnrl | 65:2ac186553959 | 48 | |
tnhnrl | 65:2ac186553959 | 49 | #ifndef lround |
tnhnrl | 65:2ac186553959 | 50 | #define lround(var) (long)(var+0.5f) |
tnhnrl | 65:2ac186553959 | 51 | #endif |
tnhnrl | 65:2ac186553959 | 52 | |
tnhnrl | 65:2ac186553959 | 53 | ////////////////////////////////////////////////////////////////// NEW TICKER |
tnhnrl | 65:2ac186553959 | 54 | Ticker systemTicker; |
tnhnrl | 65:2ac186553959 | 55 | bool setup_complete = false; |
tnhnrl | 65:2ac186553959 | 56 | volatile unsigned int bTick = 0; |
tnhnrl | 65:2ac186553959 | 57 | volatile unsigned int timer_counter = 0; |
tnhnrl | 65:2ac186553959 | 58 | |
tnhnrl | 65:2ac186553959 | 59 | char hex[9]; |
tnhnrl | 65:2ac186553959 | 60 | |
tnhnrl | 65:2ac186553959 | 61 | char * conversion(float input_float) { |
tnhnrl | 65:2ac186553959 | 62 | int integer_number = lround(100.0 * input_float); //convert floating point input to integer to broadcast over serial (reduce precision) |
tnhnrl | 65:2ac186553959 | 63 | |
tnhnrl | 65:2ac186553959 | 64 | 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 | 65 | sprintf(hex, "%8x", integer_number); //generates spaces 0x20 |
tnhnrl | 65:2ac186553959 | 66 | return hex; |
tnhnrl | 65:2ac186553959 | 67 | } |
tnhnrl | 65:2ac186553959 | 68 | |
tnhnrl | 65:2ac186553959 | 69 | 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 | 70 | unsigned int val = bTick; |
tnhnrl | 65:2ac186553959 | 71 | if( val ) |
tnhnrl | 65:2ac186553959 | 72 | bTick = 0; |
tnhnrl | 65:2ac186553959 | 73 | return( val ); |
tnhnrl | 65:2ac186553959 | 74 | } |
tnhnrl | 65:2ac186553959 | 75 | ////////////////////////////////////////////////////////////////// NEW TICKER |
tnhnrl | 20:8987a9ae2bc7 | 76 | |
tnhnrl | 32:f2f8ae34aadc | 77 | // loop rate used to determine how fast events trigger in the while loop |
tnhnrl | 65:2ac186553959 | 78 | //Ticker main_loop_rate_ticker; |
tnhnrl | 65:2ac186553959 | 79 | //Ticker log_loop_rate_ticker; |
tnhnrl | 32:f2f8ae34aadc | 80 | |
tnhnrl | 65:2ac186553959 | 81 | 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 | 82 | 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 | 83 | |
tnhnrl | 65:2ac186553959 | 84 | void loop_trigger() { fsm_loop = true;} // loop trigger (used in while loop) |
tnhnrl | 34:9b66c5188051 | 85 | void log_loop_trigger() { log_loop = true;} // log loop trigger (used in while loop) |
tnhnrl | 32:f2f8ae34aadc | 86 | |
tnhnrl | 65:2ac186553959 | 87 | static int current_state = 0; |
tnhnrl | 65:2ac186553959 | 88 | static bool file_opened = false; |
tnhnrl | 65:2ac186553959 | 89 | |
tnhnrl | 65:2ac186553959 | 90 | void FSM() { // FSM loop runs at 100 hz |
tnhnrl | 65:2ac186553959 | 91 | if(fsm_loop) { |
tnhnrl | 65:2ac186553959 | 92 | fsm_loop = false; // wait until the loop rate timer fires again |
tnhnrl | 65:2ac186553959 | 93 | current_state = stateMachine().runStateMachine(); //running State Machine. Returns 0 if sitting idle or keyboard press (SIT_IDLE state). |
tnhnrl | 65:2ac186553959 | 94 | } |
tnhnrl | 65:2ac186553959 | 95 | } |
tnhnrl | 65:2ac186553959 | 96 | |
tnhnrl | 65:2ac186553959 | 97 | void log_function() { |
tnhnrl | 65:2ac186553959 | 98 | // log loop runs at 1 hz |
tnhnrl | 65:2ac186553959 | 99 | if (log_loop) { |
tnhnrl | 65:2ac186553959 | 100 | //when the state machine is not in SIT_IDLE state (or a random keyboard press) |
tnhnrl | 65:2ac186553959 | 101 | |
tnhnrl | 65:2ac186553959 | 102 | if (current_state == TRANSMIT_MBED_LOG or current_state == RECEIVE_SEQUENCE) { |
tnhnrl | 65:2ac186553959 | 103 | ; //pass |
tnhnrl | 65:2ac186553959 | 104 | } |
tnhnrl | 65:2ac186553959 | 105 | |
tnhnrl | 65:2ac186553959 | 106 | else if(current_state != 0) { |
tnhnrl | 65:2ac186553959 | 107 | if (!file_opened) { //if the log file is not open, open it |
tnhnrl | 65:2ac186553959 | 108 | mbedLogger().appendLogFile(current_state, 0); //open MBED file once |
tnhnrl | 65:2ac186553959 | 109 | //sdLogger().appendLogFile(current_state, 0); //open SD file once |
tnhnrl | 65:2ac186553959 | 110 | |
tnhnrl | 65:2ac186553959 | 111 | file_opened = true; //stops it from continuing to open it |
tnhnrl | 56:48a8a5a65b82 | 112 | |
tnhnrl | 65:2ac186553959 | 113 | pc().printf(">>>>>>>> Recording. Log file opened. <<<<<<<<\n\r"); |
tnhnrl | 65:2ac186553959 | 114 | } |
tnhnrl | 65:2ac186553959 | 115 | |
tnhnrl | 65:2ac186553959 | 116 | //record to Mbed file system |
tnhnrl | 65:2ac186553959 | 117 | led4() = !led4(); |
tnhnrl | 65:2ac186553959 | 118 | |
tnhnrl | 65:2ac186553959 | 119 | mbedLogger().appendLogFile(current_state, 1); //writing data |
tnhnrl | 65:2ac186553959 | 120 | //sdLogger().appendLogFile(current_state, 1); //writing data |
tnhnrl | 65:2ac186553959 | 121 | } |
tnhnrl | 65:2ac186553959 | 122 | |
tnhnrl | 65:2ac186553959 | 123 | //when the current FSM state is zero (SIT_IDLE), close the file |
tnhnrl | 65:2ac186553959 | 124 | else { |
tnhnrl | 65:2ac186553959 | 125 | //this can only happen once |
tnhnrl | 65:2ac186553959 | 126 | if (file_opened) { |
tnhnrl | 65:2ac186553959 | 127 | mbedLogger().appendLogFile(current_state, 0); //close log file |
tnhnrl | 65:2ac186553959 | 128 | //sdLogger().appendLogFile(current_state, 0); //close log file |
tnhnrl | 65:2ac186553959 | 129 | |
tnhnrl | 65:2ac186553959 | 130 | file_opened = false; |
tnhnrl | 65:2ac186553959 | 131 | |
tnhnrl | 65:2ac186553959 | 132 | pc().printf(">>>>>>>> Stopped recording. Log file closed. <<<<<<<<\n\r"); |
tnhnrl | 65:2ac186553959 | 133 | } |
tnhnrl | 65:2ac186553959 | 134 | } |
tnhnrl | 65:2ac186553959 | 135 | } //END OF LOG LOOP |
tnhnrl | 65:2ac186553959 | 136 | |
tnhnrl | 65:2ac186553959 | 137 | log_loop = false; // wait until the loop rate timer fires again |
tnhnrl | 65:2ac186553959 | 138 | } |
tnhnrl | 56:48a8a5a65b82 | 139 | |
tnhnrl | 65:2ac186553959 | 140 | static void system_timer(void) { |
tnhnrl | 65:2ac186553959 | 141 | bTick = 1; |
tnhnrl | 65:2ac186553959 | 142 | |
tnhnrl | 56:48a8a5a65b82 | 143 | timer_counter++; |
tnhnrl | 56:48a8a5a65b82 | 144 | |
tnhnrl | 56:48a8a5a65b82 | 145 | //only start these updates when everything is properly setup (through setup function) |
tnhnrl | 56:48a8a5a65b82 | 146 | if (setup_complete) { |
tnhnrl | 65:2ac186553959 | 147 | if ( (timer_counter % 1) == 0) { //this runs at 0.001 second intervals (1000 Hz) |
tnhnrl | 65:2ac186553959 | 148 | 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 | 149 | } |
tnhnrl | 65:2ac186553959 | 150 | |
tnhnrl | 65:2ac186553959 | 151 | if ( (timer_counter % 10) == 0) { |
tnhnrl | 65:2ac186553959 | 152 | bce().update(); //update() inside LinearActuator class (running at 0.01 second intervals) |
tnhnrl | 65:2ac186553959 | 153 | batt().update(); |
tnhnrl | 65:2ac186553959 | 154 | led2() = !led2(); |
tnhnrl | 65:2ac186553959 | 155 | } |
tnhnrl | 65:2ac186553959 | 156 | |
tnhnrl | 65:2ac186553959 | 157 | if ( (timer_counter % 20) == 0 ) { // 0.02 second intervals |
tnhnrl | 65:2ac186553959 | 158 | rudder().runServo(); |
tnhnrl | 65:2ac186553959 | 159 | } |
tnhnrl | 65:2ac186553959 | 160 | |
tnhnrl | 65:2ac186553959 | 161 | if ( (timer_counter % 50) == 0 ) { // 0.05 second intervals |
tnhnrl | 65:2ac186553959 | 162 | //imu().runIMU(); |
tnhnrl | 65:2ac186553959 | 163 | } |
tnhnrl | 65:2ac186553959 | 164 | |
tnhnrl | 65:2ac186553959 | 165 | if ( (timer_counter % 100) == 0) { // 100,000 microseconds = 0.1 second intervals |
tnhnrl | 65:2ac186553959 | 166 | depthLoop().runOuterLoop(); |
tnhnrl | 65:2ac186553959 | 167 | pitchLoop().runOuterLoop(); |
tnhnrl | 65:2ac186553959 | 168 | headingLoop().runOuterLoop(); |
tnhnrl | 65:2ac186553959 | 169 | } |
tnhnrl | 65:2ac186553959 | 170 | |
tnhnrl | 65:2ac186553959 | 171 | if ( (timer_counter % 500) == 0) { // 500,000 microseconds = 0.5 second intervals |
tnhnrl | 65:2ac186553959 | 172 | //serialComms().getDepthPitchHeading(); |
tnhnrl | 65:2ac186553959 | 173 | log_loop = true; |
tnhnrl | 65:2ac186553959 | 174 | log_function(); |
tnhnrl | 65:2ac186553959 | 175 | } |
tnhnrl | 56:48a8a5a65b82 | 176 | } |
tnhnrl | 56:48a8a5a65b82 | 177 | } |
tnhnrl | 56:48a8a5a65b82 | 178 | |
danstrider | 10:085ab7328054 | 179 | void setup() { |
danstrider | 11:3b241ecb75ed | 180 | pc().baud(57600); |
tnhnrl | 65:2ac186553959 | 181 | pc().printf("\n\n\r 2018_03_28_wireless (FSG bench test)\n\n\r"); |
tnhnrl | 65:2ac186553959 | 182 | |
danstrider | 10:085ab7328054 | 183 | // start up the system timer |
tnhnrl | 65:2ac186553959 | 184 | //systemTimer().start(); |
tnhnrl | 20:8987a9ae2bc7 | 185 | |
danstrider | 10:085ab7328054 | 186 | // set up and start the adc. This runs on a fixed interval and is interrupt driven |
tnhnrl | 65:2ac186553959 | 187 | adc().initialize(); |
tnhnrl | 65:2ac186553959 | 188 | //adc().start(); |
tnhnrl | 65:2ac186553959 | 189 | |
tnhnrl | 65:2ac186553959 | 190 | // setup and run the rudder(servo) pwm signal (start the ticker) |
tnhnrl | 65:2ac186553959 | 191 | //rudder().init(); |
tnhnrl | 65:2ac186553959 | 192 | pc().printf("Rudder servo initialized!\n\r"); |
danstrider | 10:085ab7328054 | 193 | |
danstrider | 10:085ab7328054 | 194 | // set up and start the imu. This polls in the background |
danstrider | 10:085ab7328054 | 195 | imu().initialize(); |
tnhnrl | 65:2ac186553959 | 196 | //imu().start(); |
danstrider | 10:085ab7328054 | 197 | |
danstrider | 10:085ab7328054 | 198 | // set up the depth sensor. This is an internal ADC read, but eventually will be on the ltc1298 |
danstrider | 14:85b64a4d08e8 | 199 | depth().init(); |
danstrider | 14:85b64a4d08e8 | 200 | depth().tare(); |
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 |
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 | 65:2ac186553959 | 270 | setup_complete = true; |
tnhnrl | 65:2ac186553959 | 271 | } |
tnhnrl | 58:94b7fd55185e | 272 | |
danstrider | 10:085ab7328054 | 273 | int main() { |
danstrider | 10:085ab7328054 | 274 | setup(); |
tnhnrl | 56:48a8a5a65b82 | 275 | |
tnhnrl | 65:2ac186553959 | 276 | unsigned int tNow = 0; |
tnhnrl | 65:2ac186553959 | 277 | |
tnhnrl | 65:2ac186553959 | 278 | pc().baud(57600); |
tnhnrl | 65:2ac186553959 | 279 | pc().printf("\n\n\r TICKER TEST 05/25/2018 running at 10 kHz (0.0001 second interval) \n\n\r"); |
tnhnrl | 56:48a8a5a65b82 | 280 | |
tnhnrl | 56:48a8a5a65b82 | 281 | systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval) |
tnhnrl | 65:2ac186553959 | 282 | |
tnhnrl | 65:2ac186553959 | 283 | while (1) { |
tnhnrl | 65:2ac186553959 | 284 | if( read_ticker() ) // read_ticker runs at the speed of 10 kHz |
tnhnrl | 65:2ac186553959 | 285 | { |
tnhnrl | 65:2ac186553959 | 286 | ++tNow; |
mkelly10 | 51:c5c40272ecc3 | 287 | |
tnhnrl | 65:2ac186553959 | 288 | if ( (tNow % 10) == 0 ) { // 0.001 second intervals //if ( (tNow % 100) == 0 ) { // 0.01 second intervals |
tnhnrl | 65:2ac186553959 | 289 | fsm_loop = true; |
tnhnrl | 65:2ac186553959 | 290 | FSM(); |
tnhnrl | 45:16b8162188ca | 291 | } |
tnhnrl | 34:9b66c5188051 | 292 | |
tnhnrl | 65:2ac186553959 | 293 | // if ( (tNow % 1000) == 0 ) { // 1.0 second intervals |
tnhnrl | 65:2ac186553959 | 294 | // log_loop = true; |
tnhnrl | 65:2ac186553959 | 295 | // log_function(); |
tnhnrl | 65:2ac186553959 | 296 | // } |
tnhnrl | 65:2ac186553959 | 297 | } |
danstrider | 10:085ab7328054 | 298 | } |
danstrider | 10:085ab7328054 | 299 | } |