Variables, Types, and Units
Use Java variables to name robot measurements and commands clearly.
Use Java variables to name robot measurements and commands clearly.
In this lesson, you will:
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 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.
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);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.
Check your understanding before moving on.
What is the FTC reason to learn variables, types, and units?
0 of 1 answered
Mark this lesson complete — “If Statements and Loop Flow” is up next.