Methods, Classes, and Helpers
Extract repeated robot behavior into names that teammates can reuse.
Extract repeated robot behavior into names that teammates can reuse.
In this lesson, you will:
Methods turn repeated code into one named behavior. Classes group related data and behavior so an OpMode can read like robot intent rather than a pile of hardware writes.
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.
The mental shift is from lines of code to robot verbs. setDrivePower, applyDeadband, stopDrive, and mapHardware describe what the robot is doing. When the code has verbs, students can review it without tracing every motor line.
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.
Extract one helper at a time. First move duplicate motor writes into setTankPower or setMecanumPower. Then move joystick cleanup into a deadband method. Only then introduce a class that owns the helpers.
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.
MethodsClassesandHelpers.javaJava
private double deadband(double value) {
return Math.abs(value) < 0.05 ? 0.0 : value;
}
private void setTankPower(double left, double right) {
left = Math.max(-1.0, Math.min(1.0, left));
right = Math.max(-1.0, Math.min(1.0, right));
leftMotor.setPower(left);
rightMotor.setPower(right);
}Helpers can hide bugs if they are not tested. Print the values entering and leaving a helper during the first test. If one helper is wrong, every caller will fail the same way, which is still better than five inconsistent copies.
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 methods, classes, and helpers?
0 of 1 answered
Mark this lesson complete — “Enums, Lists, and Team Vocabulary” is up next.