State Machine
Generic state machine for subsystems.
Manages state transitions with history tracking and validation.
Example:
enum class ElevatorState(val position: Double) {
DEFAULT(0.0),
L1(0.5),
L2(1.0)
}
object Elevator : SubsystemBase() {
private val stateMachine = StateMachine(ElevatorState.DEFAULT)
var state: ElevatorState
get() = stateMachine.currentState
set(value) = stateMachine.transitionTo(value)
override fun periodic() {
// Execute behavior based on current state
setPosition(state.position)
}
}Content copied to clipboard
Parameters
S
State type (typically an enum)
initial State
Starting state