WestlakeLEARN
FTC / Java

First Tech Challenge

FTC / Java

01 · Java for FTC
  • OpMode Anatomy and Hello Robot
  • Variables, Math, and Decisions
  • Methods, Classes, and Robot Helpers
02 · FTC Hardware Essentials
  • Hardware Map and RobotHardware
  • Motors, Servos, and Sensors
  • IMU, Encoders, and Bulk Caching
03 · TeleOp and Mecanum
  • Robot-Centric Mecanum Drive
  • Field-Centric Driving
  • Driver Ergonomics and Safe TeleOp
04 · Subsystems and Commands
  • Subsystem Lifecycle
  • Enums and Finite State Machines
  • Command-Based OpModes
05 · From Timed Steps to Actions2/3
  • Timed and Encoder Autonomous
  • Autonomous State Machines
  • Actions and Sequencing
06 · PID and Feedforward
  • PID Basics
  • Feedforward and PIDF
  • Dashboard Tuning Workflow
07 · Motion Profiling
  • Motion Profile Concepts
  • Implementing a Profiled Mechanism
  • Testing Profiles and Failure Modes
08 · OpenCV and AprilTags
  • VisionPortal Camera Setup
  • OpenCV Color and Region Processors
  • AprilTags and Field Pose
09 · Setup and Tuning
  • Road Runner 1.0 Install and Drive Class
  • Feedforward Tuning
  • Localization and Validation
10 · Trajectories, Actions, and MeepMeep
  • Action Builder and Trajectories
  • MeepMeep Preview
  • Full Road Runner Autonomous
11 · Git, Debugging, and Competition Readiness
  • Git Workflow for FTC Teams
  • Telemetry-First Debugging
  • Competition Readiness Checklist
12 · Driver Control
  • Driver Control
13 · Autonomous Build
  • Simple Autonomous
14 · Debugging
  • Debugging with Telemetry

05 / From Timed Steps to Actions

Autonomous State Machines

Use states to sequence non-blocking autonomous routines.

70 minAutonomousFrom Timed Steps to Actions

You will

  1. 01Represent auto steps as enum states.
  2. 02Advance states using completion conditions.
  3. 03Avoid long blocking sleeps in complex routines.

Why Autonomous State Machines matters

This lesson is about sequencing decisions without a human driver. Autonomous code must know where it starts, what it is trying to accomplish, how each step ends, and what safe behavior happens when a step fails.

Starting point

State machines make auto visible

A state machine names each part of autonomous. Instead of one long chain of sleeps, the loop checks the current state, does the needed work, and transitions when the step is complete.

Non-blocking code can still respond

When autonomous code avoids long blocking calls, it can keep updating telemetry, checking sensors, and stopping safely if the OpMode ends.

Build path

Teach autonomous as a progression from timed steps to encoder checks to state machines and actions. Each layer should preserve the same core habits: explicit state, telemetry for the active step, timeout or finish condition, and a final safe stop.

For this specific lesson, students should first restate the goal in robot terms, then identify the value or behavior they expect to observe, then run the smallest test that proves the idea. The lesson should feel like a guided lab: predict, run, observe, explain, and only then extend.

AutoStateMachine.java · Java

enum AutoState {
    DRIVE_TO_SPIKE,
    DROP_PIXEL,
    PARK,
    DONE
}

AutoState state = AutoState.DRIVE_TO_SPIKE;

while (opModeIsActive() && state != AutoState.DONE) {
    switch (state) {
        case DRIVE_TO_SPIKE:
            driveForward();
            if (atTarget() || runtime.seconds() > 2.0) state = AutoState.DROP_PIXEL;
            break;
        case DROP_PIXEL:
            openClaw();
            state = AutoState.PARK;
            break;
        case PARK:
            strafeToPark();
            if (atPark()) state = AutoState.DONE;
            break;
    }
}

Debugging and failure modes

Autonomous failures are easier to diagnose when the robot reports why it moved on or stopped. Print the selected branch, active state, elapsed time, target, measurement, and stop reason. If those values are missing, the team is debugging a story with half the pages torn out.

Practice

Rewrite a timed autonomous as an enum-based state machine. Print the active state on every loop.

Checks

  • Each state has one responsibility.
  • Transitions are explicit and readable.
  • The DONE state stops all motors.

Check your understanding

Module check

What does an autonomous state machine make easier to debug?

0 of 1 answered

References

FIRST FTC DocsOfficial FTC SDK and robot programming documentation.Game Manual 0Community FTC programming, control, and robot design reference.Learn Java for FTCFTC-focused Java fundamentals by Alan G. Smith.

Finished reading?

Mark this lesson complete.

You'll move on to “Actions and Sequencing” next.

Timed and Encoder AutonomousActions and Sequencing