Class StateMachine.State
java.lang.Object
org.wpilib.command3.StateMachine.State
- Enclosing class:
StateMachine
A state in a state machine. Each state has a command that will be run when it is active. States
can transition to other states when some condition is met when that state is active, or
automatically transition to another state when it completes if no transition conditions were
met. A state with no transitions will never transition to another state, and will cause the
state machine to exit when the state completes; likewise, a state with no incoming transitions
will never be active.
-
Method Summary
Modifier and TypeMethodDescriptionStarts building a transition that will exit the state machine when triggered, rather than moving to a different state.voidAdds a function to be called when this state is entered.voidAdds a function to be called when this state is exited.switchTo(Supplier<StateMachine.State> dynamic) Starts build a transition to some dynamic state.Starts building a transition to the specified state.
-
Method Details
-
onEnter
Adds a function to be called when this state is entered. Callbacks are invoked immediately after the state's command is scheduled, and are run in the same order they were added.Note: if a callback schedules any commands, those commands will be scoped to the lifetime of the entire state machine, not this state's lifetime.
- Parameters:
callback- The callback to run. Cannot be null.
-
onExit
Adds a function to be called when this state is exited. Callbacks are invoked immediately before the state's command is canceled, and are run in the order they were added. If the command finishes naturally, the callbacks are run immediately after it completes and before the next state is entered.- Parameters:
callback- The callback to run. Cannot be null.
-
switchTo
Starts building a transition to the specified state.- Parameters:
to- The state to transition to. Cannot be null.- Returns:
- A builder for the transition.
-
switchTo
Starts build a transition to some dynamic state. The supplier will be evaluated at the time the transition's condition is met.- Parameters:
dynamic- The dynamic state supplier. Cannot be null.- Returns:
- A builder for the transition.
-
exitStateMachine
Starts building a transition that will exit the state machine when triggered, rather than moving to a different state.- Returns:
- A builder for the transition.
-