Decision
What do you do at a crossroads? You don’t just “go straight”, you decide based on the road. How does a robot do that?
A robot is moving around a warehouse. Is there a wall in front? Is there an opening to the right? Has it picked up the load or not? Is its battery low? Every situation needs a different decision.
Programming these decisions with a structure called a “state machine” is much cleaner than chains of “if-then”. The robot is in only one state at a time (searching, carrying, charging...) and moves to the next state when a condition is met.
Robots work with rule-based decision making: they read sensor data, check conditions written in advance and pick the right action. Simple robots use an “if-else” chain. More complex ones use a “finite state machine” (FSM) — the robot is in only one “state” at a time and switches between states when conditions are met.
🤖 State Machine — Warehouse Robot:
[SEARCHING] → is there a load ahead? → Yes → [LOADING]
[LOADING] → has the load been picked up? → Yes → [CARRYING]
[CARRYING] → reached the target? → Yes → [DROPPING]
[DROPPING] → dropped? → Yes → battery < 20%? → Yes → [CHARGING]
→ No → [SEARCHING]A traffic light is a state machine too! Red → Green → Yellow → Red... Each state changes after a set time. A car follows the rule “is the light red? → stop, is it green? → go”.
What do you do in the morning until you leave for school? Write the steps: wake up → did the alarm ring? → yes → get up → is breakfast ready? → yes → eat → ... That’s a state machine too!
Draw a state machine for a robot that solves a maze. States: move ahead, check left, check right, turn back. What should the transition conditions be?
What is a state machine (FSM)?