Traffic Lights: Understanding State Machines
Green, Yellow, Red. Repeat. Traffic lights never get confused. They are Finite State Machines. How we use this logic to automate robot arms.
Traffic Lights: Understanding State Machines
A Traffic Light is simple.
- Green -> Yellow.
- Yellow -> Red.
- Red -> Green. It never goes Green -> Red. It never goes Red -> Yellow. It follows a strict set of rules called a Finite State Machine (FSM).
The Spaghetti Code Problem
New programmers write code like a checklist:
if (button pressed) { lift arm; open claw; spin motor; }
This works for simple things.
But what if you press the “Score” button while the robot is already “Intaking”?
- The arm tries to go up.
- The claw is still trying to grab.
- The robot rips itself apart.
The State Machine Solution
We define States. The robot can only be in one State at a time.
States: INTAKE, TRANSFER, LIFT, SCORE, RESET.
Transitions:
- In
INTAKE:- Button A pressed? -> Go to
TRANSFER. - Button B pressed? -> Ignore (Can’t score while intaking).
- Button A pressed? -> Go to
- In
TRANSFER:- Are we done? -> Go to
LIFT.
- Are we done? -> Go to
- In
LIFT:- Arm extended? -> Go to
SCORE.
- Arm extended? -> Go to
Why It Matters
This makes the robot Idiot-Proof. Even if the driver panics and mashes every button on the controller, the code ignores invalid inputs. “I can’t Score because I am currently Resetting. Request Denied.”
Traffic lights prevent cars from crashing by enforcing order.
State machines prevent robots from crashing by enforcing logic.
If you want to write “Professional” code, stop writing if-else chains and start drawing state diagrams (circles and arrows).
Level Up Your Season
Dominate the competition with our other powerful tools.
FTC Secrets
The most comprehensive analytics platform for FTC. Analyze match data, scout teams, and uncover winning strategies with deep insights.
Analyze Now →FTC Coach
Your hyper-personalized assistant for the season. Master your engineering portfolio and ace judging preparation with AI-powered guidance.
Get Coached →