RIT VEXU Core API
Loading...
Searching...
No Matches
MaybeMessage Class Reference

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.

Detailed Description

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
SystemThe 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`
Messagethe message enum that a state or an outside can send and that states respond to
delay_msthe delay to wait between each state processing to allow other threads to work
do_logtrue 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

Constructor & Destructor Documentation

◆ MaybeMessage()

MaybeMessage::MaybeMessage ( Message msg)
inline

Create a maybemessage with a message.

Parameters
msgthe message to hold on to

Member Function Documentation

◆ has_message()

bool MaybeMessage::has_message ( )
inline

check if the message is here

Returns
true if there is a message

◆ message()

Message MaybeMessage::message ( )
inline

Get the message stored. The return value is invalid unless has_message returned true.

Returns
The message if it exists. Undefined otherwise

The documentation for this class was generated from the following file: