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

Methods, Classes, and Helpers

Extract repeated robot behavior into names that teammates can reuse.

Java Foundations for FTCFoundations

In this lesson, you will:

  • Explain methods, classes, and helpers 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

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.

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.

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.

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.

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

What is the main safety benefit of routing all tank-drive writes through setTankPower?
When should duplicate motor writes become a helper method?

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 lessonIf Statements and Loop FlowNext lessonEnums, Lists, and Team Vocabulary