update with altimeter, swimfile.txt endleg.txt, etc see changes_13sep.txt also reset_PI()
Dependencies: mbed MODSERIAL FATFileSystem
Diff: main.cpp
- Revision:
- 20:8987a9ae2bc7
- Parent:
- 17:7c16b5671d0e
- Child:
- 21:38c8544db6f4
--- a/main.cpp Wed Nov 22 00:08:03 2017 +0000 +++ b/main.cpp Wed Nov 22 14:32:06 2017 +0000 @@ -71,29 +71,27 @@ - Added multi-dive (and multi-rise) states to FSM (may incorporate single dive states into states) - Need to double-check behavior of sub-FSM but bench-top testing showed correct behavior for transition from sinking, to slowly rise, to check pitch - Need to add a check for the multi-dive sequence file (sequence.cfg) being loaded on the MBED + Modified 2017-11-21 by Dan + - removed blocker and set up a loop rate timer that runs the state machine and keyboard at 10 Hz. + - work inside StateMachine and particularly in the findNeutralSubState. */ - + #include "mbed.h" #include "StaticDefs.hpp" #include "config_functions.h" - -volatile bool blocker = true; //volatile used to prevent compiler from optimizing this (assuming the state is constant) -volatile bool keyboard_flag = true; - -Ticker blocker_ticker; - -//blocker using a ticker -void reset_blocker() { - blocker = false; -}; - + +// loop rate timer for slowing down how fast while(1) runs in main() +Ticker loop_rate_ticker; +volatile bool loop = false; +void loop_trigger() { loop = true; }; // loop trigger + void setup() { - pc().printf("\n\n\r\rFSG 2017-11-20\n\r"); + pc().printf("\n\n\r\rFSG 2017-11-21\n\r"); pc().baud(57600); - + // start up the system timer systemTime().start(); - + // set up and start the adc. This runs on a fixed interval and is interrupt driven adc().initialize(); adc().start(); @@ -108,32 +106,32 @@ // construct a local file system local(); - + // load config data from files load_BCE_config(); // load the buoyancy engine parameters from the file "bce.txt" load_BATT_config(); // load the battery mass mover parameters from the file "batt.txt" load_DEPTH_config(); // load the depth control loop parameters from the file "depth.txt" load_PITCH_config(); // load the depth control loop parameters from the file "pitch.txt" - + // set up the linear actuators. adc has to be running first. bce().init(); bce().start(); bce().pause(); // start by not moving - + batt().init(); batt().start(); batt().pause(); // start by not moving - + // set up the depth and pitch outer loop controllers depthLoop().init(); depthLoop().start(); depthLoop().setCommand(stateMachine().getDepthCommand()); - + pitchLoop().init(); pitchLoop().start(); pitchLoop().setCommand(stateMachine().getPitchCommand()); - - // do not leave this in. Check that PID gains are loading + + // show that the PID gains are loading from the file pc().printf("bce P: %3.2f, I: %3.2f, D %3.2f, zero %3i, limit %3.0f mm, slope %3.3f \r\n", bce().getControllerP(), bce().getControllerI(), bce().getControllerD(), bce().getZeroCounts(), bce().getTravelLimit(), bce().getPotSlope()); pc().printf("batt P: %3.2f, I: %3.2f, D %3.2f, zero %3i, limit %3.0f mm, slope %3.3f \r\n", batt().getControllerP(), batt().getControllerI(), batt().getControllerD(), batt().getZeroCounts(), batt().getTravelLimit(), batt().getPotSlope()); pc().printf("depth P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f mm \r\n", depthLoop().getControllerP(), depthLoop().getControllerI(), depthLoop().getControllerD(), depthLoop().getOutputOffset()); @@ -151,36 +149,22 @@ //load sequence from file sequenceController().loadSequence(); + + // establish the main loop rate + loop_rate_ticker.attach(&loop_trigger, 0.1); // fires the ticker at 10 Hz rate } - - - + + + int main() { setup(); - blocker_ticker.attach(&reset_blocker, 0.01); // 100 Hz loop rate - uint32_t n = 0; - while(1) { - led1() = !led1(); // blink - - //"blocker" while loop runs at 100 hz because of the ticker - while(blocker) { - if (keyboard_flag) { - stateMachine().keyboard(); //current concept runs keyboard and state machine in a while loop - stateMachine().runStateMachine(); - - keyboard_flag = false; - } + // does this stuff at the loop rate + if(loop) { + led1() = !led1(); // blink + stateMachine().runStateMachine(); + loop = false; // wait until the loop rate timer fires again } - - //this runs at 10 hz - if (n%10 == 0) - { - keyboard_flag = true; //the flag controls the rate at which this operates - } - - //keyboard_flag = true; //set the keyboard flag - blocker = true; //reset the blocker while loop when this is completed } } \ No newline at end of file