|
RIT VEXU Core API
|
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. More...
#include <state_machine.h>
Public Member Functions | |
| MaybeMessage () | |
| Empty message - when theres no message. | |
| MaybeMessage (Message msg) | |
| Create a maybemessage with a message. | |
| bool | has_message () |
| check if the message is here | |
| Message | message () |
| Get the message stored. The return value is invalid unless has_message returned true. | |
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)
| 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 */ template <typename System, typename IDType, typename Message, int32_t delay_ms, bool do_log = false> class StateMachine { static_assert(std::is_enum<Message>::value, "Message should be an enum (it's easier that way)"); static_assert(std::is_enum<IDType>::value, "IDType should be an enum (it's easier that way)"); |
public: /**
MaybeMessage a message of Message type or nothing MaybeMessage m = {}; // empty MaybeMessage m = Message::EnumField1
|
inline |
Create a maybemessage with a message.
| msg | the message to hold on to |
|
inline |
check if the message is here
|
inline |
Get the message stored. The return value is invalid unless has_message returned true.