template<typename System, typename IDType, typename Message, int32_t delay_ms, bool do_log = false>
class StateMachine< System, IDType, Message, delay_ms, do_log >
State Machine :)))))) A fun fun way of controlling stateful subsystems - used in the 2023-2024 Over Under game for our overly complex intake-cata subsystem (see there for an example) The statemachine runs in a background thread and a user thread can interact with it through current_state and send_message.
Designwise: the System class should hold onto any motors, feedback controllers, etc that are persistent in the system States themselves should hold any data that only that state needs. For example if a state should be exitted after a certain amount of time, it should hold a timer rather than the System holding that timer. (see Junder from 2024 for an example of this design)
- Template Parameters
-
System | The system that this is the base class of class Thing : public StateMachine<Thing> @tparam IDType The ID enum that recognizes states. Hint hint, use an enum class` |
Message | the message enum that a state or an outside can send and that states respond to |
delay_ms | the delay to wait between each state processing to allow other threads to work |
do_log | true if you want print statements describing incoming messages and current states. If true, it is expected that IDType and Message have a function called to_string that takes them as its only parameter and returns a std::string |