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 the FsmContext.
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 Details

    • enter

      default void enter(FsmContext<ContextT> context, FsmTransition<StateT> transition)
      Runs once when this state is entered, before any calls to execute(FsmContext, FsmTransition). The default implementation does nothing. May call transition.transitionTo(...) to immediately redirect to a different state (an "entry guard") - if it does, this state's exit(FsmContext, FsmTransition) still runs before the new state's enter() does.
      Parameters:
      context - The context for the current execution cycle.
      transition - Callback to request a transition to a different state.
    • execute

      void execute(FsmContext<ContextT> context, FsmTransition<StateT> transition)
      Runs every time the owning FiniteStateMachine is executed while this state is current, mirroring how a WPILib Command is ticked via execute(). May call transition.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

      default void exit(FsmContext<ContextT> context, FsmTransition<StateT> transition)
      Runs once when this state is exited, after the last call to execute(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.