Skip to lesson
Westlake RoboticsLearn
Vault

FIRST Tech Challenge

Loading progress…

  • 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.

Java Foundations for FTCFoundations

In this lesson, you will:

  • Explain variables, types, and units in FTC robot terms.
  • Connect the Java idea to telemetry or hardware behavior.
  • Write 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.

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.

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.

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.

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.
  • The test record includes the setup, prediction, and observed result.
  • A teammate can repeat the check from the saved evidence without guessing.

Reflection check

Check your understanding before moving on.

A target is measured in encoder ticks. Which variable name best prevents a unit mistake?
Why should joystick deadband be applied before multiplying by a drive scale?

0 of 2 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.
Loading lesson progress
Previous lessonWhat an OpMode DoesNext lessonIf Statements and Loop Flow