Autonomous State Machines
Represent autonomous as named nonblocking steps.
Represent autonomous as named nonblocking steps.
In this lesson, you will:
A state machine turns autonomous into named steps that run over many loops. It avoids long blocking code and makes it obvious where the routine is stuck.
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.
The active state is the robot’s current promise. It should have one responsibility and one clear reason to transition.
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.
Write the enum, initialize the first state, switch on state in the loop, and transition only when a condition or timeout is met.
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.
AutoState.javaJava
switch (state) {
case DRIVE:
driveForward();
if (atTarget() || runtime.seconds() > 2.0) state = AutoState.DROP;
break;
case DONE:
stopDrive();
break;
}If auto gets stuck, print state, timer, target, measurement, and transition condition. If a state does many jobs, split it.
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.
Check your understanding before moving on.
What is the most important habit in Autonomous State Machines?
0 of 1 answered
Mark this lesson complete — “Actions and Sequencing” is up next.