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

Methods, Classes, and Helpers

Extract repeated robot behavior into names that teammates can reuse.

Module 1: Java Foundations for FTCFoundations

In this lesson, you will:

  1. 01Explain methods, classes, and helpers 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

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.

Robot mental model

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.

Implementation walkthrough

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);
}

Common mistakes and debugging

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.

Practice

Refactor a TeleOp so the main loop contains no raw motor setPower calls. All drivetrain writes must go through one helper method.

Checkpoint

  • Repeated motor writes are removed.
  • Helper names describe robot behavior.
  • Main loop is easier to read after refactor.

Reflection check

Check your understanding before moving on.

What is the FTC reason to learn methods, classes, and helpers?

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 — “Enums, Lists, and Team Vocabulary” is up next.

If Statements and Loop FlowEnums, Lists, and Team Vocabulary