Skip to main content

State Machines and Commands

State machines are a powerful way to manage complex robot behaviors by breaking them down into distinct states and defining transitions between those states. In FRC robotics, we often use state machines in conjunction with command-based programming to create modular and reusable code.


Presentation


Exercises

State Machines

  • Write a State Machine in ShooterSubsystem
    • IDLE State: System idle
    • SPIN_UP State: Flywheel spinning up to desired speed
    • SHOOT State: Index balls into flywheel
    • Add an automated transition from SPIN_UP -> SHOOT
    • Add an automated transition from SHOOT -> SPIN_UP
    • Prevent IDLE -> SHOOT transition

Commands

  • Add a ShooterCommands file in the shooter package
    • Create a command to set the wanted state of the shooter to SHOOT
    • Bind the command to a button in OI
  • Create a Instant Command to simulate applied load from launching a ball
    • See available methods for the flywheel mech!
    • Bind the command to a button in OI

Software

  • State Machines: Basics of state machines and how they are used in controls.
  • Subsystems: Overview of subsystem-based programming in FRC robots.
  • Commands: Overview of command-based programming in FRC robots.