Skip to content

Java Foundations & VS Code

Veer Bajaj
Veer BajajAuthor

Welcome to FRC Java programming! This guide covers the essential programming concepts you need to know before we start writing code for the robot, and explains how our projects are structured in VS Code.


Java is the official programming language used by Team 5171 to program our robots.

Variables are containers that store data. In Java, you must declare the type of data a variable holds:

int speedRPM = 5000; // Integer (whole numbers)
double motorOutput = 0.75; // Double (decimal/fractional numbers)
boolean isIntakeRunning = true; // Boolean (true or false)

Conditionals allow the robot to make decisions based on sensor feedback:

// If the intake sensor detects a note, run the feeder
if (noteSensor.get()) {
feederMotor.set(0.5);
} else {
feederMotor.set(0.0);
}

2. Object-Oriented Programming (OOP) in FRC

Section titled “2. Object-Oriented Programming (OOP) in FRC”

Java is an Object-Oriented language. We represent physical parts of the robot as Objects created from blueprints called Classes.

For example, we might write a ShooterSubsystem class (the blueprint) that controls the physical shooter. To use it, we instantiate (create) it:

// Create a new instance (object) of the ShooterSubsystem
ShooterSubsystem shooter = new ShooterSubsystem();
// Call a method on the shooter object
shooter.setTargetRPM(3500);
  • Class: The template or file (e.g. DriveDrivetrain.java).
  • Object: The actual instantiated mechanism (e.g. m_drivetrain).
  • Methods: Functions belonging to a class that perform actions (e.g. drive(double xSpeed, double ySpeed)).

We write our robot code in VS Code using the WPILib Extension (indicated by the red W icon in the top right corner).

my-robot-project/
├── build.gradle # Dependencies and compile configurations
└── src/
└── main/
└── java/
└── frc/
└── robot/
├── Robot.java # Core robot lifecycle entrypoint
├── RobotContainer.java # Button bindings and command map
├── subsystems/ # Blueprints for mechanisms (hardware)
└── commands/ # Instructions telling mechanisms what to do
  1. build.gradle: Tells the compiler which libraries we need (like WPILib, REVLib, or Phoenix).
  2. Robot.java: The entrypoint. It runs a loop 50 times per second (robotPeriodic()) to read sensors and update motors.
  3. RobotContainer.java: The “brains” of the configuration. This is where we instantiate our subsystems, define autonomous routines, and bind controller buttons to commands (e.g., “Hold button A to run intake”).