Skip to main content

Section 4.1 Introduction to Reactive Control and State Machines

In Chapter 3, we studied global path planning algorithms like A*, which calculate an entire path from start to goal before the robot ever turns its wheels. This global approach works well in static, fully known environments. However, real-world environments are dynamic and unpredictable: a human worker walks across a factory floor, a soccer ball rolls into a VEX competition lane, or a door closes unexpectedly.
Reactive Navigation focuses on rapid, local decision-making. Instead of storing a full map or computing complex paths, a reactive robot reads its real-time sensor data and immediately maps those inputs directly to actuator commands: sensors such as distance and IR readings feed into behavior logic built from if/elif/else rules, which in turn drives the actuators (drive motors) directly, with no map or planner in between.
Figure 4.1.1. A reactive controller maps sensor readings directly through behavior rules to actuator commands.

Subsection 4.1.1 Real-World & VEX Robotics Applications

  • Real-World Example (Warehouse AGVs & Vacuum Robots): Automated Guided Vehicles (AGVs) in Amazon fulfillment centers use global planners to navigate between aisles. However, if a box falls off a shelf into the robot’s path, a high-frequency reactive loop triggers an instant emergency stop or quick dodge without waiting for the central server to re-calculate a whole new map.
  • VEX Robotics Example (Over Under / High Stakes Competitions): During the autonomous period, a VEX robot driving toward a scoring zone might detect another robot blocking its path via its VEX Distance Sensor. A reactive behavior allows the VEX robot to pivot or back off instantly to avoid an illegal collision or entanglement penalty, regardless of its original pre-programmed trajectory.

Subsection 4.1.2 Structuring Reactive Logic: Finite State Machines (FSM)

When writing reactive code, raw if/else statements can quickly turn into disorganized "spaghetti code." To prevent this, roboticists organize reactive control using a Finite State Machine (FSM).
Figure 4.1.2. A two-state finite state machine transitions between driving forward and turning left based on the measured obstacle distance.
An FSM breaks the robot’s behavior into a set of discrete, mutually exclusive states (e.g., DRIVE_FORWARD, TURN_LEFT, REVERSE). The robot remains in its current state until a specific sensor reading triggers a transition to a new state.
Consider a two-state FSM built from just DRIVE_FORWARD and TURN_LEFT. While in DRIVE_FORWARD, the robot keeps driving forward as long as the front distance reading stays at or above 0.5 meters; the moment that distance drops below 0.5 meters, it transitions to TURN_LEFT. While in TURN_LEFT, the robot keeps turning in place as long as the front distance stays below 0.5 meters; once the distance rises back to 0.5 meters or more, it transitions back to DRIVE_FORWARD.
  • State 1: DRIVE_FORWARD (Default State)
    • Action: The robot drives straight, searching for an endpoint.
    • Transition Trigger: Sensor value (distance < threshold) = TRUE.
    If the condition is met, the system transitions to State 2.
  • State 2: OBSTACLE_DETECTED (The Reaction State)
    A non-blocking state to quickly check the situation and decide the next move.
  • State 3: TURN_LEFT (Correction State)
    Once the rotation is complete, the robot returns to the Default State.

Subsection 4.1.3 Why FSMs Minimize Cognitive Load

  1. Isolation: You only need to think about what the robot should do right now in its active state (e.g., while in TURN_LEFT, the motors are set to spin in place).
  2. Predictable Transitions: State changes happen strictly based on explicit conditions (e.g., distance < 0.5m), making troubleshooting simple during VEX lab testing.

Subsection 4.1.4 Section 4.1 Interactive Exercises

Subsubsection 4.1.4.1 Exercise 4.1.2: CodeLens Trace β€” Basic FSM State Switch

Step through the execution of this FSM to watch how state switches occur dynamically as simulated sensor readings change.

Reading Questions 4.1.5 Reading Questions

Check your understanding

1. Exercise 4.1.1: FSM Transition Conceptual Check.

Why are reactive Finite State Machines (FSMs) commonly used alongside global path planners in dynamic, changing environments?
  • Global path planning algorithms calculate paths faster than FSMs.
  • Incorrect. Global planners are computationally heavier and take longer to re-compute than simple state transitions.
  • Reactive FSMs respond immediately to immediate sensor changes without needing a full pre-computed map.
  • Correct! Reactive state machines allow robots to immediately react to unpredictable local changes (like moving obstacles) without needing a pre-built map.
  • FSMs remember the exact 3D shape of every obstacle they encounter.
  • Incorrect. FSMs are memoryless reactive loops; they do not construct 3D maps.
  • FSMs do not require any sensors to make decisions.
  • Incorrect. Reactive control relies heavily on real-time sensor feedback.
You have attempted of activities on this page.