Skip to lesson
Westlake RoboticsLearn
Vault

FIRST Tech Challenge

Loading progress…

  • Subsystem Lifecycle
  • Enums and Finite State Machines

Subsystem Lifecycle

Read, decide, write, reset for each mechanism.

Robot ArchitectureIntermediate

In this lesson, you will:

  • Separate read, periodic, write, and reset.
  • Give each mechanism an owner.
  • Expose simple public methods.

Concept narrative

A subsystem is the owner of a mechanism. It stores state, reads sensors, calculates targets or outputs, writes hardware, and knows how to reset safely.

Robot mental model

The OpMode should not know arm servo math or lift PID internals. It should ask the subsystem for robot-level behavior such as goToIntake or goToScore.

Implementation walkthrough

Create one subsystem with fields for state and target. Add read, periodic, write, and reset. Call them in the same order every loop.

WSubsystem.javaJava

public abstract class WSubsystem {
    public abstract void read();
    public abstract void periodic();
    public abstract void write();
    public abstract void reset();
}

Common mistakes and debugging

If a motor is written in multiple places, ownership is broken. If telemetry shows stale readings, read may be happening too late. If reset is dangerous, the subsystem lacks a safe default.

Your browser does not support embedded video. Use the open-video link below.
0:00 / 0:00
Give one subsystem ownership of one mechanismOpen video Download captions
Video transcriptRead or search the narration

You already know that a subsystem should own one mechanism. Let's follow an arm request through the same read, periodic, write, and reset rhythm used in the lesson, then see why direct motor writes from other classes break that ownership. TeleOp and autonomous both need the arm, but neither one should write the arm motor directly. They ask for a state such as up, down, or idle. The arm subsystem stores that intent and owns the final hardware write. This gives us one place to answer the important questions: What state was requested? What output did that state produce? What limits changed the output? And what happens on STOP? In this fixture, request only changes the desired state. It does not wait and it does not touch the motor. Then read captures the encoder position, periodic turns the requested state into one bounded teaching output, and write sends that output to the motor exactly once. At the bottom, reset returns the state and pending output to idle and zero. Normal exits always call the finally block and share the same cleanup path. The power values are examples. We have different states and can request a next state. The important note here is the ownership shape, not the numbers. If we read this lifecycle from left to right, a caller requests intent on what we want to do, and the subsystem reads its inputs. Then it calculates the pending output and performs one hardware write. Cleanup resets the owner and writes zero. This is intentionally small. You do not need a giant framework before writing a good fundamental subsystem. You need a clear owner, a small state vocabulary for places an arm can go or whether a shooter is spinning, a consistent loop order, one final write, telemetry, and an explicit reset behavior. Now imagine TeleOp writes 0.4 and a helper writes -0.2 later in the same loop. Both pieces of code can look reasonable by themselves, but the last write wins. Telemetry inside the first writer may even claim the correct value while the motor receives something else afterward. The fix is to remove the competing write, not add more guesses into your system. Search the project for every use of the motor and route behavior through the subsystem. During the season, build this ownership map with the other programmers who add features to the same mechanism. Everyone needs to use the same vocabulary in the same way. Confusing two different states is a common teamwork-code error. Subsystems should help with organization and management.

Practice

Convert one current mechanism into a lifecycle subsystem and remove raw mechanism writes from the OpMode.

Checkpoint

  • Mechanism writes live in one subsystem.
  • Reset is safe.
  • The OpMode loop is shorter.
  • 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 purpose of separating read, periodic, and write in a subsystem?
Which code should own direct writes to an arm motor?

0 of 2 answered

References

FIRST FTC DocsOfficial SDK, Robot Controller, and programming reference.Game Manual 0FTC community reference for programming, controls, and robot design.
Loading lesson progress
Previous lessonPlan and Test a Vision-Selected AutonomousNext lessonEnums and Finite State Machines