Interface FsmState<StateT extends Enum<StateT> & FsmState<StateT,ContextT>, ContextT>
- Type Parameters:
StateT- The enum type implementing this interface.ContextT- The type of the payload carried by theFsmContext.
- All Known Implementing Classes:
HumanVsMachineState
public interface FsmState<StateT extends Enum<StateT> & FsmState<StateT,ContextT>, ContextT>
The behavior contract implemented by every state of a
FiniteStateMachine. Typically implemented by an enum,
with each constant providing its own execute() (and, optionally, enter()/exit()) via a
constant-specific class body - see FiniteStateMachine for a worked example.
States must be stateless. Enum constants are singletons shared by every FiniteStateMachine instance
that uses that enum type. Any mutable data a state needs to read or write belongs on ContextT (the payload
carried by FsmContext), never as a field on the enum itself - otherwise two independent state machines using
the same enum will corrupt each other's state.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidenter(FsmContext<ContextT> context, FsmTransition<StateT> transition) Runs once when this state is entered, before any calls toexecute(FsmContext, FsmTransition).voidexecute(FsmContext<ContextT> context, FsmTransition<StateT> transition) Runs every time the owningFiniteStateMachineis executed while this state is current, mirroring how a WPILibCommandis ticked viaexecute().default voidexit(FsmContext<ContextT> context, FsmTransition<StateT> transition) Runs once when this state is exited, after the last call toexecute(FsmContext, FsmTransition)while it was current.
-
Method Details
-
enter
Runs once when this state is entered, before any calls toexecute(FsmContext, FsmTransition). The default implementation does nothing. May calltransition.transitionTo(...)to immediately redirect to a different state (an "entry guard") - if it does, this state'sexit(FsmContext, FsmTransition)still runs before the new state'senter()does.- Parameters:
context- The context for the current execution cycle.transition- Callback to request a transition to a different state.
-
execute
Runs every time the owningFiniteStateMachineis executed while this state is current, mirroring how a WPILibCommandis ticked viaexecute(). May calltransition.transitionTo(...)to request a transition to a different state.- Parameters:
context- The context for the current execution cycle.transition- Callback to request a transition to a different state.
-
exit
Runs once when this state is exited, after the last call toexecute(FsmContext, FsmTransition)while it was current. The default implementation does nothing.- Parameters:
context- The context for the current execution cycle.transition- Callback to request a transition to a different state.
-