FRC Academy lessons use WPILib’s Command-Based architecture — specificallyDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Holden9607/FRC-Academy/llms.txt
Use this file to discover all available pages before exploring further.
CommandXboxController for button-to-command binding and RunCommand/InstantCommand for inline motor control. This page covers the three command classes you’ll encounter in every FRC Academy lesson.
edu.wpi.first.wpilibj2.command.*
Thecommand package in wpilibj2 is the heart of the Command-Based programming model. Instead of polling button states in a periodic() loop, you bind commands directly to controller triggers — WPILib schedules them automatically.
CommandXboxController
Full class:edu.wpi.first.wpilibj2.command.CommandXboxController
CommandXboxController is a modern wrapper extending XboxController with Trigger-based event binding. Rather than reading getBButton() in a loop and writing if statements, you call .b() once and attach a command to it — the scheduler handles the rest.
Constructor:
port is 0 for the driver controller or 1 for the operator controller (matches the USB port index in the Driver Station).
Button Trigger methods — each returns a Trigger object you can chain commands onto:
| Method | Button |
|---|---|
.a() | A face button |
.b() | B face button |
.x() | X face button |
.y() | Y face button |
.leftBumper() | Left bumper (LB) |
.rightBumper() | Right bumper (RB) |
.leftTrigger() | Left trigger axis (LT) |
.rightTrigger() | Right trigger axis (RT) |
.start() | Start button |
.back() | Back / Select button |
| Method | Behavior |
|---|---|
.whileTrue(Command command) | Runs the command continuously while the button is held |
.onTrue(Command command) | Runs the command once when the button is first pressed |
.onFalse(Command command) | Runs the command once when the button is released |
.toggleOnTrue(Command command) | Toggles the command on or off each time the button is pressed |
RunCommand lambdas:
| Method | Returns | Description |
|---|---|---|
.getLeftY() | double | Left stick Y axis (−1.0 to 1.0, up = negative) |
.getLeftX() | double | Left stick X axis |
.getRightY() | double | Right stick Y axis |
.getRightX() | double | Right stick X axis |
RunCommand
Full class:edu.wpi.first.wpilibj2.command.RunCommand
RunCommand executes an inline lambda function repeatedly until terminated by an external signal (such as a button being released). It wraps any Runnable — including motor set() calls — so you can use it directly with Trigger binding.
Constructors:
Subsystem requirements argument registers this command with the scheduler so it interrupts other commands using the same subsystem.
Example — arcade drive inside a RunCommand:
InstantCommand
Full class:edu.wpi.first.wpilibj2.command.InstantCommand
InstantCommand runs an assigned code block exactly once, then finishes immediately. The scheduler marks it complete on the same loop tick it starts. This makes it perfect for one-shot actions where you don’t want the command to linger.
Constructor:
- Stopping a motor when a button is released
- Resetting a sensor or encoder
- Toggling a solenoid state
whileTrue vs onFalse Pattern
The motor-hold pattern is used throughout every FRC Academy motor lesson. It pairs.whileTrue() and .onFalse() on the same button to create a clean hold-to-run, release-to-stop behavior:
whileTrue command automatically, then immediately fires the .onFalse() command. The stop InstantCommand runs once, sets the motor to 0.0, and finishes on the same scheduler cycle it starts. The result is a motor that runs at full speed exactly while the button is held and stops cleanly the moment the driver lets go.
FRC Academy uses simplified
RobotContainer-style structures directly inside Robot.java for teaching clarity. In a full robot project, motors and their associated commands are usually wrapped in dedicated Subsystem classes, and binding is done inside a RobotContainer class passed to the CommandScheduler.WPILib Core
TimedRobot, XboxController, DriverStation, PWMSparkMax, and the MotorController interface.
REV Robotics
SparkMax, SparkMaxConfig, MotorType, and the REV hardware configuration API.