Software · Controls

State Machine Lab

Flip switches and step through loops to see how our state machines pick their state.

Step 1 of 7

Why?

Dimmer switch

dashed red = wanted

Inside one loop

Loop 0

1handleStateTransition picks the next state

2updateLogic runs that state

no if

          

Go deeper

The rules we follow
  • Buttons and autos only call setWantedState(...). The wanted state is sticky: it stays until something asks for another.
  • Every condition lives in handleStateTransition. Write it as a table: switch on system_state_, then on wanted. A request with no arm is ignored.
  • updateLogic has no if. It is a switch (system_state_) where each arm commands its mechanisms.
  • If a state would behave differently on a condition, split it into step states and let the table pick.
  • No enter or exit actions: each state commands everything every loop, so nothing needs undoing.
The shooter's Java

    
The robot's super state machine

On our robot, RobotContainer extends MwSuperStateMachine. Every loop it runs its own handleStateTransition and updateLogic first, then every subsystem's, so a subsystem sees the robot's request in the same loop. The 2026 robot's SHOOT is asked for but never entered: the table picks SHOOT_WAIT, SHOOT_FEED, SHOOT_FEED_BRAKED or SHOOT_PASS_INTAKE from whether the shooter is ready and the robot is moving.

Read more

State Machines, Subsystems (a subsystem's transition table) and the State Machines lesson.