What Is a Robot, Anyway? Unpacking the Core Loop of Sense-Plan-Act
If you’ve ever watched a robot vacuum zigzag across your living room floor without tumbling down the stairs, or seen a campus delivery robot swerve to avoid a group of students, or built a small obstacle-avoiding car out of Lego EV3 parts, you’ve already witnessed the core magic of robotics. That magic isn’t a sci-fi style artificial brain, and it doesn’t require a humanoid form to work. At its heart, every functional robot runs on a simple, repeating three-step closed loop called Sense-Plan-Act, or SPA for short. This chapter will break down each part of that loop with real, familiar examples, walk you through your first ever robot control simulation using only Python’s built-in tools, and map out exactly what you’ll learn in the rest of this book—no advanced math or fancy programming experience required.
---
1.1 The Sense Step: Giving Robots "Senses" Like Yours
The first step of the SPA loop is Sense: the robot collects raw data about the world around it and its own internal state, using tools called sensors. If you think of a robot as a body, sensors are its eyes, ears, skin, and even its sense of balance. Just like you use your eyes to see a couch in front of you and your feet to feel if the floor is slippery, robots use different sensors for different jobs, depending on what they need to do.
Take the robot vacuum you might have at home: its most basic sensors are cliff sensors and bumper sensors. Cliff sensors are tiny infrared emitters and receivers mounted on the bottom of the robot: they shoot a low-power infrared beam down at the floor, and measure how much of that beam bounces back. If the robot is on a hard, flat surface like tile or wood, most of the beam bounces back, and the sensor knows the floor is solid. If the robot rolls up to a staircase, the beam shoots down into empty air and bounces back almost nothing, so the sensor triggers a “cliff detected” signal. Bumper sensors are even simpler: they’re physical spring-loaded switches mounted on the front and sides of the robot. If the robot bumps into a chair leg or a wall, the switch compresses and sends a “collision detected” signal. More advanced robot vacuums also have ultrasonic sensors (which work like bat sonar, shooting high-frequency sound waves and measuring the echo to calculate distance to objects) and even tiny cameras to recognize furniture and avoid pet waste.
Delivery robots you see on college campuses have even more sophisticated sensors. Most use LIDAR (Light Detection and Ranging), a spinning sensor that shoots out hundreds of laser pulses per second and measures how long they take to bounce back off surrounding objects. By combining all those measurements, the LIDAR can build a 360-degree point cloud map of everything within 30 meters of the robot, so it can see sidewalks, pedestrians, and potholes in the dark. They also have IMUs (Inertial Measurement Units), tiny chips that measure acceleration, rotation, and tilt, so the robot knows if it’s going uphill, sliding on ice, or tilting because it hit a curb. Some even have GPS to know its global location, and cameras to read stop signs and crosswalks.
The raw data from these sensors is messy and unusable on its own: a LIDAR might return thousands of individual distance measurements per second, an IMU might jitter with tiny vibrations from the robot’s wheels, and a camera might capture glare from the sun. The Sense module’s job is to clean up that raw data and turn it into meaningful, structured information the robot can use to make decisions. This process is called sensor filtering and feature extraction. For example, the Sense module might average 10 consecutive ultrasonic distance readings to eliminate random noise, then compare the filtered distance to a 10cm threshold to output a simple binary signal: “obstacle within 10cm: yes/no”. For a LIDAR, the Sense module might cluster thousands of point cloud measurements into distinct objects: “chair at (2.3m, 1.1m), wall at (0m, 5m), person at (1.8m, 0.5m)”.
To put this in math terms, the most common calculation the Sense module does for distance sensors is the time-of-flight formula for sound or laser pulses: $$d = \frac{v \times t}{2}$$ Where $d$ is the distance to the object, $v$ is the speed of the wave (343 m/s for sound, 299,792,458 m/s for light), and $t$ is the time it takes for the wave to travel to the object and bounce back. The division by 2 accounts for the round trip of the wave. For example, if an ultrasonic sensor measures an echo time of 0.01 seconds, the distance to the object is $\frac{343 \times 0.01}{2} = 1.715$ meters.
For Lego robotics fans, you’ve already used the Sense step if you’ve ever programmed an EV3 or Spike Prime robot to use its ultrasonic or color sensor. When you write a block of code that says “if ultrasonic sensor distance < 10cm, turn on the red LED”, you’re programming the robot’s Sense module to turn raw sensor data into a decision trigger.
> 📱 *Digital Edition Sidebar: Try it yourself!* > Grab your phone’s voice assistant (Siri, Google Assistant, etc.) and say “what’s the weather today?” The microphone on your phone is the Sense module: it collects raw audio waves of your voice, filters out background noise, and converts it to text the assistant can understand. That’s the exact same process your robot uses to turn sensor data into usable information.
---
1.2 The Plan Step: Giving Robots the Ability to Make Decisions
Once the Sense module has turned raw sensor data into structured information about the world, the Plan module takes over to decide what the robot should do next. This is the “brain” of the robot, and contrary to what sci-fi movies would have you believe, it doesn’t need to be a super advanced AI to work. Most basic robots use simple, rule-based logic (if-else statements) that even a middle schooler could write.
Let’s go back to the robot vacuum example. Its Plan logic might look like this: 1. If the cliff sensor triggers → Immediately reverse for 1 second, then turn right 90 degrees 2. If the bumper sensor triggers → Reverse for 0.5 meters, then turn left or right 90 degrees at random 3. If the ultrasonic sensor detects an obstacle less than 1 meter ahead → Slow down to 0.2 m/s, turn right 30 degrees 4. If none of the above are true → Move forward at 0.5 m/s to clean the floor
That’s it. No fancy neural networks, no complex reasoning—just a set of simple rules that let the robot clean an entire room without falling down the stairs or getting stuck in a corner. For Lego EV3 obstacle-avoiding cars, the Plan logic is even simpler: “if ultrasonic distance < 10cm → reverse for 1 second, turn left 90 degrees; else → move both wheels forward”. For delivery robots, the Plan logic is more complex: it has to calculate the shortest path from the delivery location to the customer’s door, avoid moving pedestrians, obey traffic rules, and adjust for uneven sidewalks, but the core principle is the same: take in structured information about the world, and output a decision for what to do next.
The Plan module is also where the math you’ll learn in this book comes to life. For example, if a robot needs to move from point A (x=2, y=3) to point B (x=7, y=8), the Plan module can use the Pythagorean theorem to calculate the straight-line distance between the two points: $$distance = \sqrt{(x_B - x_A)^2 + (y_B - y_A)^2} = \sqrt{(7-2)^2 + (8-3)^2} = \sqrt{25 + 25} \approx 7.07 \text{ meters}$$ It can also use trigonometry to calculate the angle the robot needs to turn to face point B: $$\theta = \arctan\left(\frac{y_B - y_A}{x_B - x_A}\right) = \arctan\left(\frac{5}{5}\right) = 45^\circ$$ These are the exact same calculations you use in middle school math class, but now they’re being used to tell a robot where to go.
You can visualize the Plan module’s decision-making process with a simple flow chart, like the one for the robot vacuum below: ```mermaid graph TD A[Start Plan Cycle] --> B{Cliff sensor triggered?} B -->