Skip to lesson
Westlake RoboticsLearn
Vault

FIRST Tech Challenge

Loading progress…

  • Simple Autonomous
  • Encoder Autonomous
  • Autonomous State Machines
  • Actions and Sequencing
  • Plan and Test a Vision-Selected Autonomous

Encoder Autonomous

Use motor feedback for measured movement.

Autonomous FoundationsAutonomous

In this lesson, you will:

  • Reset/read encoders.
  • Move toward target ticks.
  • Use timeout and stop reason.

Concept narrative

Encoder autonomous improves timed movement by measuring motor rotation. It still does not prove field position, but it gives code a feedback signal.

Robot mental model

Encoders tell how far shafts turned, not whether the robot perfectly moved on the field. Wheel slip and collisions still matter.

Implementation walkthrough

Reset or record starting ticks, compute a target, drive while error remains and timeout has not passed, then stop. Print current ticks and reason for exit.

EncoderAuto.javaJava

int start = leftMotor.getCurrentPosition();
int target = start + 900;
String exitReason = "stopped";
runtime.reset();

try {
    while (opModeIsActive()) {
        int error = target - leftMotor.getCurrentPosition();
        if (error <= 0) {
            exitReason = "target";
            break;
        }
        if (runtime.seconds() >= 2.0) {
            exitReason = "timeout";
            break;
        }

        setDrivePower(0.25, 0.25);
        telemetry.addData("target", target);
        telemetry.addData("position", leftMotor.getCurrentPosition());
        telemetry.addData("error", error);
        telemetry.addData("elapsed s", runtime.seconds());
        telemetry.update();
    }
} finally {
    stopDrive();
}

telemetry.addData("exit", exitReason);
telemetry.update();

Common mistakes and debugging

Wrong target signs, unreset encoders, and run-mode confusion are common. If ticks do not change, check wiring and mode before rewriting logic.

Practice

Drive to a target tick count with a timeout and report whether the target or timeout ended the step.

Checkpoint

  • Encoder position moves toward the predicted target sign.
  • The step exits on target, timeout, or STOP and reports which condition occurred.
  • Drive output is guaranteed to return to zero for every exit condition.
  • Telemetry records target, position, error, elapsed time, and exit reason.
  • A teammate can repeat the low-power test from the saved setup and result.

Reflection check

Check your understanding before moving on.

What must the encoder autonomous code do after reaching the target or timing out?
Why is one drive encoder’s tick count not proof of field position?

0 of 2 answered

References

FIRST FTC DocsOfficial SDK, Robot Controller, and programming reference.Learn Java for FTCFTC-focused Java book and exercises by Alan G. Smith.Game Manual 0FTC community reference for programming, controls, and robot design.
Loading lesson progress
Previous lessonSimple AutonomousNext lessonAutonomous State Machines