update with altimeter, swimfile.txt endleg.txt, etc see changes_13sep.txt also reset_PI()
Dependencies: mbed MODSERIAL FATFileSystem
Diff: main.cpp
- Revision:
- 17:7c16b5671d0e
- Parent:
- 16:3363b9f14913
- Child:
- 20:8987a9ae2bc7
--- a/main.cpp Mon Nov 06 22:57:56 2017 +0000 +++ b/main.cpp Tue Nov 21 22:03:26 2017 +0000 @@ -58,14 +58,37 @@ (command is sent every time hardware dives, finds neutral, etc.) - Set the pitchCommand input to 0 on the "find neutral" command, it was sending a non-zero pitch command - Created a class for the StateMachine + Modified 2017-11-14 by Troy + - Changed tare to void function (functions does not return anything when called) + - Added a "subclass" in the cases for the Neutral Finding Sequence (Sinking, Slowly Rise, Check Pitch (and save positions)) + Modified 2017-11-20 by Troy + - Modified StateMachine class to separate keyboard inputs from FSM + - Added Neutral Finding sub-statemachine + - Verified both state machines are working with hardware on desktop + - Added class to save neutral battery and buoyancy engine positions to neutral.cfg file + Modified 2017-11-21 by Troy + - Need to check remove ConfigFileIO and place saving functions into config_functions.cpp (rename ConfigFunctions.cpp) + - 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 */ #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; +}; + void setup() { - pc().printf("\n\n\r\rFSG 2017-11-06\n\r"); + pc().printf("\n\n\r\rFSG 2017-11-20\n\r"); pc().baud(57600); // start up the system timer @@ -116,14 +139,48 @@ 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()); pc().printf("pitch P: %3.2f, I: %3.2f, D %3.2f, offset: %3.1f mm \r\n", pitchLoop().getControllerP(), pitchLoop().getControllerI(), pitchLoop().getControllerD(), pitchLoop().getOutputOffset()); pc().printf("\n\r"); + + //set the neutral positions in the FSM + // load neutral motor positions from the neutral.cfg file + configFileIO().loadNeutralPositions(); + + // in discussion said this was actually in pitch.txt and depth.txt + // fixing on Wednesday (Troy) + pc().printf("\n\rLoading neutral positions from file.\n\r"); + stateMachine().setNeutralPositions(configFileIO().getBattPos(), configFileIO().getBCEPos()); //batt, bce + + //load sequence from file + sequenceController().loadSequence(); } + + int main() { setup(); + blocker_ticker.attach(&reset_blocker, 0.01); // 100 Hz loop rate + uint32_t n = 0; + while(1) { led1() = !led1(); // blink - stateMachine().runStateMachine(); + //"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; + } + } + + //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