The Controllers lesson in FRC Academy teaches you how to wire up Xbox controllers so your robot can respond to human input. You’ll define twoDocumentation 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 objects — one for the driver (USB port 0) and one for the operator (USB port 1) — import the class from WPILib, and declare both as private final fields inside your robot class. By the end of this lesson, your robot code will be ready to accept event bindings like .whileTrue() and .onFalse() on any button.
What You’ll Learn
- Importing
CommandXboxControllerfromedu.wpi.first.wpilibj2.command - Declaring
private finalcontroller fields inline inside the robot class - Binding buttons with
.whileTrue()and.onFalse()for event-driven command execution - Understanding driver vs. operator port assignments and why they must be different
- The difference between
CommandXboxControllerand the legacyXboxControllerclass
Guided Steps
The FRC Academy app walks you through four steps in the in-editor popup. Each step shows an instruction and the exact line of code to type.Import CommandXboxController from WPILib
Add the import statement at the top of your file so Java knows where to find the class.
Declare driverController on port 0
Inside the robot class body, declare the driver’s controller as a
private final field assigned to USB port 0.Declare operatorController on port 1
Below the driver declaration, add a second controller for the operator on port 1.
The Solution
Here is the complete, verified solution that the FRC Academy Code Review modal checks against:The solution includes a
TimedRobot import and an empty robotInit() override. FRC Academy verifies your code line-by-line against this exact solution, so be sure your whitespace and field names match.Key Classes
CommandXboxController vs XboxController
CommandXboxController vs XboxController
CommandXboxController (from edu.wpi.first.wpilibj2.command) is the modern WPILib class designed for the Command-Based robot paradigm. Its buttons return Trigger objects, which means you can attach command bindings directly:XboxController (from edu.wpi.first.wpilibj) is the older class that only reads raw boolean/axis values. It does not support .whileTrue() or .onFalse() event binding and is not suitable for use with CommandScheduler. Use CommandXboxController for all new robot projects.Port Assignments
FRC uses USB port numbers to identify controllers plugged into the Driver Station laptop:| Port | Assigned To | Convention |
|---|---|---|
0 | Driver controller | Primary driving, left/right joystick movement |
1 | Operator controller | Secondary mechanisms, button-bound subsystem commands |
API: CommandXboxController
Full class reference for CommandXboxController, RunCommand, and InstantCommand