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
Diff: StateMachine/StateMachine.hpp
- Revision:
- 20:8987a9ae2bc7
- Parent:
- 17:7c16b5671d0e
- Child:
- 21:38c8544db6f4
--- a/StateMachine/StateMachine.hpp Wed Nov 22 00:08:03 2017 +0000 +++ b/StateMachine/StateMachine.hpp Wed Nov 22 14:32:06 2017 +0000 @@ -1,28 +1,31 @@ #ifndef STATEMACHINE_HPP #define STATEMACHINE_HPP - + #include "mbed.h" - + extern "C" void mbed_reset(); // utilized to reset the mbed - -// state enumerations + +// main finite state enumerations enum { SIT_IDLE, // stops both motors, exits after a keyboard input - KEYBOARD, // handles an individual keypress, exits to state by a keyboard menu FIND_NEUTRAL, // dives to depth at zero pitch, exits when stable DIVE, // dives to depth at negative pitch, exits when crossing a defined depth RISE, // rises to surface at positive pitch, exits when near surface FLOAT_LEVEL, // bce position to float, pitch loop active at zero, exits when stable near zero pitch FLOAT_BROADCAST, // bce position to float, batt position forward to hold tail up, exits when actuators done EMERGENCY_CLIMB, // bce position to full rise, batt position to full aft, exits when at surface + MULTI_DIVE, // NEW: multi-dive sequence + MULTI_RISE // NEW: multi-rise sequence +}; + +// find_neutral finite state machine enumerations +enum { NEUTRAL_SINKING, // NEW: FIND_NEUTRAL immediately goes into "sinking" NEUTRAL_SLOWLY_RISE, // NEW: Once sinking times out, goes into "check pitch" NEUTRAL_CHECK_PITCH, // NEW: Once pitch rate confirmed, saves the data and exits to RISE state - NEUTRAL_EXIT, // NEW: sub-FSM has completed all checks - MULTI_DIVE, // NEW: multi-dive sequence - MULTI_RISE // NEW: multi-rise sequence + NEUTRAL_EXIT // NEW: sub-FSM has completed all checks }; - + //struct for saving the data struct currentSequenceStruct { int state; //for the current StateMachine, states are ID-ed with enumeration @@ -30,7 +33,7 @@ float depth; float pitch; }; - + class StateMachine { public: StateMachine(); @@ -82,11 +85,10 @@ float _neutral_sink_timer; float _neutral_rise_timer; - //volatile bool isTimeoutRunning; bool isTimeoutRunning; float previousPosition_mm; - bool isSubStateTimeoutRunning; + bool isSubStateTimerRunning; float _neutral_buoyancy_bce_pos_mm; float _neutral_buoyancy_batt_pos_mm; @@ -97,5 +99,5 @@ int _state_counter; currentSequenceStruct currentStateStruct; //type_of_struct struct_name }; - + #endif \ No newline at end of file