State Machine
Template class for the internal state machine. This class does not hold any inherent value except as a superclass for the LED state machine. This file defines the system states and abstracts the underlying state tracking.
- Author
Braidan Duffy
Usage
The StateMachine
object tracks the value of systemState
through a pointer reference. By changing the value of systemState
, the machine will automatically adjust the execution process defined in executeState()
. This is best done through the state method StateMachine::changeSystemState()
as it will automatically update the previous system state as well.
- Version
1.0
- Date
2024-03-05
- Copyright
Copyright (c) 2024
Enums
-
enum State
Values:
-
enumerator IDLE_NO_CONNECTION
Micro-ROS node is awaiting connection to Agent.
-
enumerator IDLE_WITH_CONNECTION
Micro-ROS node is connected to Agent.
-
enumerator PARTIAL_FORWARD
Motor is moving forward, but not at full speed.
-
enumerator PARTIAL_REVERSE
Motor is moving reverse, but not at full speed.
-
enumerator FULL_FORWARD
Motor is moving forward at full speed.
-
enumerator FULL_REVERSE
Motor is moving reverse at full speed.
-
enumerator DEVICE_IDENTIFY
Micro-ROS node is commanded to identify itself using the LED.
-
enumerator MOTOR_DISABLED
Motor is disabled due to motor fault.
-
enumerator SENSOR_FAULT
One or more sensors have encountered an error.
-
enumerator DRIVER_FAULT
The motor driver has encountered an error.
-
enumerator TRANSPORT_FAULT
The Micro-ROS transport layer has encountered an error.
-
enumerator IDLE_NO_CONNECTION
Variables
-
class StateMachine
- #include <state_machine.h>
Superclass object that encapsulates and handles a changing system state variable.
Subclassed by LEDStateMachine
Public Functions
-
inline StateMachine(State ¤tStatePtr)
Construct a new State Machine object.
- Parameters:
currentStatePtr – Pointer to the system state global variable
-
inline virtual void executeState()
Execute functions based on the current system state.
Note
Should be executed in an asynchronous loop
Public Static Functions
-
static inline void changeSystemState(State newState)
Changes the value of the global
systemState
variable. Saves the system state topreviousSystemState
before making the change. If the State Machine object is initialized with thesystemState
variable, this will automatically update its internal state value.- Parameters:
newState – The new desired system state
-
inline StateMachine(State ¤tStatePtr)