Java is a general-purpose language, but FRC robot programming uses only a slice of it. The command-based framework and WPILib APIs absorb much of what you would ordinarily write by hand — loops, state machines, conditional polling — so the Java you write directly sits at a higher level. Understanding which constructs you’ll use constantly, which you’ll use occasionally, and which WPILib replaces entirely will help you read and write robot code more efficiently.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spectrum3847/2026-Spectrum/llms.txt
Use this file to discover all available pages before exploring further.
The core pattern: command chaining replaces while loops
The most important conceptual shift from standard Java to FRC code is how continuous behavior is expressed. In ordinary Java, you would write awhile loop to repeat an action as long as a condition holds:
while version blocks all other code from running until the condition changes — a fatal problem on a robot that needs to poll sensors, update motor outputs, and handle driver input simultaneously. The whileTrue version registers a command that the scheduler runs every loop iteration, then cancels automatically when the condition becomes false, without blocking anything else.
This is the pattern used throughout RobotStates.setupStates():
What is frequently used
If/else statements
If/else statements
Conditionals appear constantly in command factories,
periodic() methods, and configuration logic. They decide which command to schedule, which subsystem behavior to activate, and how to interpret sensor data:Logic and arithmetic operators
Logic and arithmetic operators
Operators are used anywhere a calculation or decision is made — computing motor output, clamping sensor values, combining Trigger conditions:Triggers compose with the same operators you use in
if conditions:Classes and objects
Classes and objects
Every subsystem is a class. The Lambda expressions are used everywhere a method accepts a
Robot class instantiates each one and stores it as a static field. Other classes retrieve subsystem references via static getters:Supplier — which is the standard way to pass live config values or sensor readings into commands:Enums for robot states
Enums for robot states
The The The current applied state is also readable from anywhere for telemetry:
State enum defines every valid operating state of the robot. Using an enum instead of integers or strings gives compile-time safety — passing an invalid state is a compile error, not a runtime crash:Coordinator uses a switch on the current state to dispatch behavior to each subsystem:What is moderately used
Standard for loops appear when iterating over a fixed collection of hardware objects or path points — for example, during autonomous path visualization:.stream(), .map(), .collect()) appear in similar contexts as a functional alternative to explicit for loops, particularly when transforming collections.
What is rarely used directly
- Raw while loops
- Raw arrays
Traditional The only place a blocking loop is acceptable is initialization code that runs before the scheduler starts.
while loops are almost never used for robot control because the command scheduler provides equivalent behavior without blocking. The scheduler’s robotPeriodic() is itself an implicit while loop that runs every 20 ms — adding another while inside would stall the scheduler.Before and after: Trigger vs. polling loop
Here is a concrete comparison showing how the same behavior — tracking a target while a button is held and returning to idle when released — looks with a raw polling loop versus the Trigger pattern:Java fundamentals
Review the Java building blocks — variables, loops, classes, enums.
Command-based programming
Deep dive into Commands, Subsystems, Triggers, and the scheduler.
