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.
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.
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);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.
Read a joystick axis, store it as rawDrive, apply a deadband into driveCommand, scale it into leftPower and rightPower, and print every stage.
Check your understanding before moving on.
0 of 2 answered