WestlakeLEARN
FTC · Java

FIRST Tech Challenge

FTC · Java

  • What an OpMode Does
  • Variables, Types, and Units
  • If Statements and Loop Flow
  • Methods, Classes, and Helpers
  • Enums, Lists, and Team Vocabulary

Variables, Types, and Units

Use Java variables to name robot measurements and commands clearly.

Module 1: Java Foundations for FTCFoundations

In this lesson, you will:

  1. 01Explain variables, types, and units in FTC robot terms.
  2. 02Connect the Java idea to telemetry or hardware behavior.
  3. 03Write a small test that proves the concept before using it in match code.

Concept narrative

A variable is a named claim about the robot: a joystick value, a distance, an encoder count, a target, or a motor output. The type tells Java what kind of value is allowed, but the name and unit tell teammates what the value means.

This lesson should be read as a robotics lesson first and a programming lesson second. The code matters because it lets the team create repeatable behavior under match pressure. Students should slow down long enough to name the inputs, outputs, assumptions, and safety limits before they touch the robot.

Robot mental model

Robot code becomes fragile when units are implied. A variable named distance is weaker than distanceCm. A variable named power is weaker than leftDrivePower. Students should learn to encode intent in names before math gets complicated.

A good mental model gives the team a shared language. When a driver, builder, and programmer can point to the same behavior and use the same words, debugging gets calmer and code review becomes useful instead of personal.

Implementation walkthrough

Start with telemetry-only variables, then calculate a scaled value, then clamp it. The important walkthrough is the transformation: raw input becomes processed input, processed input becomes output, output becomes hardware command.

Keep the implementation staged. First create the smallest version that compiles. Then add telemetry that proves it is running. Then connect one hardware device or one decision. Finally, repeat the test from a cold init so the team knows it was not a lucky hot reload.

VariablesTypesandUnits.javaJava

double rawDrive = -gamepad1.left_stick_y;
double driveCommand = Math.abs(rawDrive) < 0.05 ? 0.0 : rawDrive;
double scale = gamepad1.left_bumper ? 0.35 : 0.85;
double leftPower = driveCommand * scale;

telemetry.addData("raw drive", rawDrive);
telemetry.addData("drive command", driveCommand);
telemetry.addData("left power", leftPower);

Common mistakes and debugging

Unit bugs are quiet. Inches mixed with centimeters, degrees mixed with radians, and ticks mixed with mechanism positions all compile. Use telemetry labels with units and do not convert inside a long expression where nobody can see it.

Use the five-value debugging habit: input, state, target, measurement, output. If one of those values is missing, add it before rewriting logic. The goal is to make the robot tell the truth about what it thinks is happening.

Practice

Read a joystick axis, store it as rawDrive, apply a deadband into driveCommand, scale it into leftPower and rightPower, and print every stage.

Checkpoint

  • Variable names include meaning.
  • Telemetry labels include units where needed.
  • Raw and processed values are visible separately.

Reflection check

Check your understanding before moving on.

What is the FTC reason to learn variables, types, and units?

0 of 1 answered

References

Learn Java for FTCFTC-focused Java book and exercises by Alan G. Smith.FIRST FTC DocsOfficial SDK, Robot Controller, and programming reference.Game Manual 0FTC community reference for programming, controls, and robot design.

Finished reading?

Mark this lesson complete — “If Statements and Loop Flow” is up next.

What an OpMode DoesIf Statements and Loop Flow