An autonomous robot runs one loop: sense, update a map, plan, act, then sense again. Send three robots into the same room. In the dead end, only the robot with the whole loop and a map reaches the goal.
Pick a robot and a room, and watch who reaches the yellow goal. Then we build, piece by piece, the loop, the four-module stack, the pose, the map, and the state machine that runs it all.
You need what a probability is and a little Python. We build the rest from zero.
Lesson 1 of 15 in our follow-along of Stanford AA 274A, Principles of Robot Autonomy I. Every idea is re-taught here in our own words and devices. Next: Lesson 2, Rigid-Body Transforms.
Robot
Room
Illustrative toy on a 16 by 10 grid. Pink cells are the true room. The reflex and the full stack sense the 8 cells around them; purple is what they have mapped. The full stack plans with breadth-first search and treats unknown cells as free.
Chapter 0
Push two robots off their line and see which one comes back
A welding arm in a car plant makes the same weld ten thousand times a shift. Move the car body 2 cm and the arm welds air. It replays a fixed list of joint angles and never checks the result.
Now picture a self-driving car at a four-way stop. A cyclist edges out. A van double-parks. No script lists every such scene. The car decides anyway, and decides again a tenth of a second later.
The arm is automated: it runs a fixed plan with no feedback. This is open-loop control. The car is autonomous: it senses, decides, acts, then senses again to see what its action did. This is closed-loop control.
The robot drives 10 steps of 1 m toward the yellow goal. A side wind pushes it on every step. Choose a loop, set the wind, then press Drive.
Illustrative toy. Each step adds the set push plus a small random gust of up to 0.02 m. The closed-loop robot measures its side offset after each step and steers it out on the next. The goal ring has a 0.25 m radius.
Work the number. The wind pushes 0.1 m sideways on each of 10 steps. The open-loop robot never corrects, so it ends 10 × 0.1 = 1.0 m off. The closed-loop robot removes each push on the next step. Only the last push remains: about 0.1 m.
The symptom is a robot that works in the demo and fails in a new room. To measure it, move the start or add a push, and record the final error over many runs. The fix is to close the loop: sense the result and correct.
Chapter 1
Ride one packet of data around the loop and watch it change type at every arrow
Every autonomous robot runs one loop, many times a second. It has three beats, wrapped around the real world.
The move changes the world, so the next See measures a new scene. The data also changes type on every arrow. Each lesson in this series builds one of those arrows.
Press Step to move the packet one arrow, or Play. Then set the loop rate and watch the ruler: each tick is one look at the world.
Illustrative sizes: a 640 by 480 colour frame, about 200 tracked features, a 20-point path. The car speed is fixed at 13.4 m/s (30 mph).
How far does the robot move blind between two looks? Call the speed v, in metres per second. Call the loop rate f: how many full loops run each second, in hertz. Call the blind distance d.
d equals v divided by f.
Divide the speed v by the loop rate f. The result d is how far the robot travels before it sees the effect of its last decision.
A car at 30 mph moves v = 13.4 m/s. At f = 10 Hz, d = 13.4 / 10 = 1.34 m. At f = 2 Hz, d = 6.7 m, longer than the car.
| Beat | Data in, data out | Lessons |
|---|---|---|
| See, perceive | pixels, ranges, then features and detections | 7 to 10 |
| Think, localize | features and motion, then a pose and a map | 11 to 14 |
| Think, plan | a map and a goal, then a path | 3 to 5 |
| Act, control | a path, then motor commands | 2, 6 |
| Coordinate | every module, then one behaviour | 1, 15 |
The symptom is a robot that weaves or overshoots at speed. To measure it, stamp the time at each stage; the slowest stage sets f. The fix is to speed up that stage or to drive slower, so d stays short.
Chapter 2
Pick a module and read what it takes in and what it hands on
The loop is the rhythm. The autonomy stack is the machinery that makes it. AA 274A splits it into four modules.
Data rises from the sensors; decisions come down to the motors. Pick a module to light its input and its output.
Illustrative sizes for a robot with one 640 by 480 colour camera at 30 Hz.
Data shrinks as it rises. One 640 by 480 colour frame holds 640 × 480 × 3 = 921,600 bytes. At 30 frames a second that is 27.6 MB/s. The pose is 3 numbers of 4 bytes, 30 times a second: 360 B/s. The stack cuts the data about 77,000 times between the camera and the pose.
The executive does not sit in the data flow. It sits around it and sets each module's mode. The data type on each arrow is a contract. If two modules agree on it, a team can replace one module without touching the other.
The symptom is a robot that drives to the wrong place while every module passes its own tests. To measure it, log the data on each arrow with its units and coordinate frame. A classic case: localization reports centimetres and the planner reads metres. The fix is to write each contract down, with units and frame, and check it at the boundary.
Chapter 3
Drive a robot, then try to slide it sideways and meet the rule that forbids it
Every module needs to know where the robot is. The smallest set of numbers that pins a robot down is its configuration. The course calls these numbers the generalized coordinates.
For a wheeled robot on a flat floor, three numbers do it. Call the position on the floor x and y, in metres. Call the heading, the direction the robot faces, θ (theta), measured from the x axis. Position plus heading is the pose. Collect the three in one column called ξ (xi).
xi equals the column x, y, theta.
Write down where the robot stands, x and y, and the way it faces, theta. Stack the three in a column. That column is the pose xi.
With made-up numbers: the robot stands 1 m along and 2 m across, facing 30°. Then ξ = [1 m, 2 m, 30°].
A point on a map needs only x and y. A robot also needs θ, because a wheeled robot can only drive the way it faces. Drive forward at speed v for a short time Δt (delta-t), and the robot moves along its heading.
x-prime equals x plus v delta-t cos theta, and y-prime equals y plus v delta-t sine theta.
Multiply the speed v by the time delta-t to get the distance driven. Split that distance along x with cos theta and along y with sine theta. Add each part to the old x and y.
From the pose above, take v = 0.5 m/s and Δt = 1 s. The distance is 0.5 m. x′ = 1 + 0.5 × 0.866 = 1.433 m. y′ = 2 + 0.5 × 0.5 = 2.25 m.
Set the heading and speed, then press Drive for one second of motion. Press Slide to push it sideways. Switch off grip to see a robot on ice.
Illustrative toy. A slide is a push of 0.2 m/s to the robot's left for 1 s.
A rolling wheel cannot slide along its axle. So the robot's sideways speed must be zero. Call the rates of change of x and y ẋ and ẏ (x-dot and y-dot), in metres per second. This is the no-slip constraint.
x-dot sine theta minus y-dot cos theta equals zero.
Take the velocity, x-dot and y-dot. Work out how much of it points sideways to the heading theta. That sideways part must be zero.
Driving forward at 30°: x-dot = 0.433 and y-dot = 0.25 m/s. 0.433 × 0.5 − 0.25 × 0.866 = 0.2165 − 0.2165 = 0. Allowed. A sideways push of 0.2 m/s gives −0.2: forbidden.
The symptom is a planned path with a sideways step that the robot cannot follow. To measure it, compute the no-slip value along the path; any point far from zero is not drivable. The fix is to plan with the motion model, as Lessons 2 and 5 do.
Chapter 4
Store one apartment four ways and ask each map for a route
A robot that knows its pose still needs to know what is around it: the walls, the doors, the kitchen. That knowledge is a map. You can store one apartment four ways, and each way answers different questions.
Pick a map, then press Ask for a route from the bedroom to the kitchen. On the grid, change the cell size and watch the cell count.
Illustrative 12 m by 8 m apartment with 15 cm walls and 1 m doors. The grid route is a breadth-first search over free cells.
| Map | Stores | Good for | Bad for |
|---|---|---|---|
| Occupancy grid | a chance of "occupied" in every cell | exact paths, collision checks | memory in big spaces |
| Topological | places as nodes, connections as edges | fast routes between rooms | distance and shape |
| Feature | sparse landmarks: corners with a descriptor | finding yourself again | "is this spot free?" |
| Semantic | labels: wall, door, kitchen, person | reasoning about what things are | routes, without a metric layer |
A grid's memory grows fast. Call the number of cells N. Call the room's length and width Lx and Ly, in metres, and the side of one cell r.
N equals L-x over r, times L-y over r.
Count the cells that fit along the length, L-x over r. Count the cells across the width, L-y over r. Multiply. Halving r makes four times as many cells.
The 12 m by 8 m apartment at r = 0.05 m: 240 × 160 = 38,400 cells. At r = 0.025 m: 480 × 320 = 153,600 cells.
The symptom is a robot that runs out of memory or plans slowly in a large building. To measure it, compute N against your memory and planning budget. The fix is to mix maps: a topological map for the long route, a fine grid for the last few metres.
Chapter 5
Fire laser readings at one cell and watch its evidence add up
A laser beam flies out and stops at a wall. That is a hit for the cell where it stopped. The cells it passed through each get a miss. One reading can be wrong: a beam can bounce or catch a passing leg. So a cell must not flip to "occupied" on one hit. It must weigh the evidence.
The cell keeps p, the chance that it is occupied. Multiplying chances together after every reading is awkward. The trick is to store the log-odds ℓ (ell) instead.
ell equals the natural log of p over one minus p.
Divide the chance of occupied, p, by the chance of free, one minus p. Take the natural log. Even odds give ell = 0.
With made-up numbers: a hit reading is 70% sure. ℓ = ln(0.7 / 0.3) = ln 2.33 = 0.85. A miss reading is about 40% sure: ln(0.4 / 0.6) = −0.41, which we round to −0.40.
Now each reading adds its own log-odds. Call the cell's value after reading t ℓt, and the reading's evidence Δℓ (delta-ell): +0.85 for a hit, −0.40 for a miss.
ell-t equals ell-t-minus-one plus delta-ell.
Keep a running total ell. When a reading arrives, add its delta-ell. Nothing is ever multiplied.
Start at 0. Hit: 0 + 0.85 = 0.85. Hit: 0.85 + 0.85 = 1.70. Miss: 1.70 − 0.40 = 1.30.
To read the cell, turn ℓ back into a chance, using e, the number 2.718.
p equals one over one plus e to the minus ell.
Raise e to minus ell. Add one. Take one over the result. The answer p always stays between 0 and 1.
ℓ = 1.30: e−1.30 = 0.273, so p = 1 / 1.273 = 0.79. The cell is 79% sure it is occupied.
Press Hit or Miss. Watch the log-odds marker move by a fixed step and the chance bar bend. Lower the trust in a hit and count how many hits it now takes.
Illustrative sensor: a miss is about 40% sure (Δℓ = −0.40). The cell counts as "sure" above p = 0.8.
| Reading | ℓ | p |
|---|---|---|
| none yet | 0.00 | 0.50 |
| hit, +0.85 | 0.85 | 0.70 |
| hit, +0.85 | 1.70 | 0.85 |
| miss, −0.40 | 1.30 | 0.79 |
One stray miss moves the cell from 85% to 79%. It does not wipe out two hits. Lesson 12 builds the full grid on this rule.
The symptom is a ghost wall: a person stood still for a minute, and the map still shows them after they leave. To measure it, count cells above 0.8 that are free in the real room. The fix is to clamp ℓ between limits, such as −3.5 and +3.5, so a cell can change its mind.
Chapter 6
Fire sensor inputs at a parking gate and trace every state it passes through
A robot bumps a wall. Something must say "stop driving forward, start backing up". That is the executive's job. Its oldest and clearest tool is the finite state machine (FSM): a model whose output depends on its whole input history, squeezed into one state.
An FSM has six parts.
At each tick t the machine reads input it in state st. Two rules then fire. The first gives the command ot.
o-t equals o of i-t and s-t.
Look up the row for the input i-t and the state s-t. Send the command o-t written in that row.
The gate is down (s-t) and a car is waiting (i-t). The row says raise, so o-t = raise.
The second rule picks the state for the next tick, st+1.
s-t-plus-one equals n of i-t and s-t.
In the same row, read the next state. Store it as s-t-plus-one. Wait for the next tick and repeat.
Down with a car waiting: s-t-plus-one = raising. Raising with "gate at top": s-t-plus-one = up, and the command becomes hold.
AA 274A traces a parking gate. It has 4 states (down, raising, up, lowering), 3 commands (raise, lower, hold) and starts down. With 6 inputs, its full table has 4 × 6 = 24 rows. Most of them say "hold and stay", so we write only the 8 that matter.
| Tick | State st | Input it | Output ot | Next st+1 |
|---|---|---|---|---|
| 0 | down | no car | hold | down |
| 1 | down | car waiting | raise | raising |
| 2 | raising | not at top | raise | raising |
| 3 | raising | gate at top | hold | up |
| 4 | up | car not passed | hold | up |
| 5 | up | car passed | lower | lowering |
| 6 | lowering | not at bottom | lower | lowering |
| 7 | lowering | gate at bottom | hold | down |
Press Auto-run for one car, or fire inputs yourself. Then switch on the stuck sensor and run again.
The table above, run live. The stuck sensor never reports "gate at top", so the machine never sees that the arm arrived.
In code, an FSM is a state variable and a lookup. The table form keeps transitions as data, so adding a state adds a row, not a branch.
python # (state, input) -> (output, next_state); a missing key means hold and stay TABLE = { ('down', 'car waiting'): ('raise', 'raising'), ('raising', 'not at top'): ('raise', 'raising'), ('raising', 'gate at top'): ('hold', 'up'), ('up', 'car passed'): ('lower', 'lowering'), ('lowering', 'not at bottom'): ('lower', 'lowering'), ('lowering', 'gate at bottom'): ('hold', 'down'), } def step(state, inp): return TABLE.get((state, inp), ('hold', state)) # o(i, s) and n(i, s) in one lookup
The symptom is a machine that hangs: the motor keeps raising an arm that is already up. To measure it, log how long the machine stays in each state. The fix is a timeout: if raising lasts longer than the arm ever needs, move to a fault state and call for help.
Chapter 7
Merge equal states step by step, then group and wire the rest
The gate had 4 states. A real self-driving stack has hundreds, and each new state can add a transition from many others. Three tools keep the machine small enough for a person to check.
Two states are equivalent if they give the same output for every input and move to equivalent states for every input. Equivalent states merge with no change in behaviour. The test runs in rounds:
This machine reads 3 bits and outputs 1 if they were 010 or 110. Press Split to run one round. Same letter means same group.
A classic textbook sequence detector. It restarts after every 3 bits. Its output is 1 only on the third bit.
Group related states into a super-state. A "navigate" super-state can hold follow-path, avoid-obstacle and recover. The rest of the system sees one state: navigating. Work the number: an emergency stop must fire from every one of 200 states. Flat, that is 200 arrows. With all 200 inside one "running" super-state, it is 1 arrow.
| Pattern | Wiring | In ROS SMACH |
|---|---|---|
| Cascade | machine 1's output is machine 2's input | Sequence |
| Parallel | one input feeds both; outputs side by side | Concurrence |
| Feedback | a machine's output returns to its own input | Iterator |
An FSM also has a hard ceiling. It has finite memory, so it cannot count without limit. It cannot check that a string of any length has balanced brackets. For robot behaviour, finite is usually right. When it is not, reach for planning or learning, as Lesson 15 does.
The symptom is a state diagram nobody can read and a bug nobody can find. To measure it, count states and transitions, and look for states that act the same. The fix is reduction first, then hierarchy, then small machines wired together.
Chapter 8
Run every module at once, then break the room and watch the executive react
This is the hero's room with every module on show. On each tick the robot runs one full loop:
Press Run. Tap a cell to add or remove a real obstacle, even mid-run. Wall off the goal and watch the executive stop the robot.
Illustrative toy. A planning tick thinks and does not move. Unknown cells count as free when planning, so the robot tries the short way first.
Watch the dead end. The plan runs straight into the cup, because the robot has not seen it yet. Each new purple cell on the path forces a REPLAN. The robot needs 31 moves and 6 replans to get out and round. The reflex robot in the hero never gets out, because it keeps no map of where it has been.
The symptom is a robot that drives into a wall it saw a second ago, or freezes with a path in front of it. To measure it, log the executive's mode and the plan on every tick. The fix lives in the executive: replan whenever the map changes the path, and stop cleanly in BLOCKED when no path exists.
Chapter 9
Keep the terms, the numbers, the code and the map of the series in one place
An autonomous robot closes a loop: sense, think, act, many times a second. Four modules make the loop: perception, localization, planning and control, and an executive that picks the behaviour. They pass a pose and a map between them. The executive is often a finite state machine.
| Term | Meaning | Number to remember |
|---|---|---|
| Closed loop | sense the result, then correct | 10 pushes of 0.1 m: 1.0 m off open loop, 0.1 m closed |
| Blind distance | d = v / f | 13.4 m/s at 10 Hz: 1.34 m |
| Pose | ξ = [x, y, θ] | 3 numbers for a wheeled robot |
| No-slip | ẋ sin θ − ẏ cos θ = 0 | sideways speed 0 |
| Grid size | N = (Lx/r)(Ly/r) | 12 m by 8 m at 5 cm: 38,400 cells |
| Log-odds | ℓ = ln(p/(1 − p)), add per reading | hit, hit, miss: 0.79 |
| FSM | (S, I, O, n, o, s0) | gate: 4 states, 24 table rows |
| Reduction | merge equivalent states | 010/110 detector: 7 to 4 states |
python def tick(robot, world): seen = robot.sense(world) # perception: the 8 cells around robot.belief.update(seen) # map: add log-odds per cell pose = robot.localize() # localization: xi = (x, y, theta) if robot.path is None or robot.belief.blocks(robot.path): robot.path = bfs(robot.belief, pose, robot.goal) # planning robot.mode = 'BLOCKED' if robot.path is None else 'REPLAN' return # a thinking tick robot.move_to(robot.path.pop(1)) # control: one step robot.mode = 'REACHED' if pose == robot.goal else 'NAVIGATE' # executive
| Module | Lessons | What you build |
|---|---|---|
| Control and kinematics | 2, 6 | transforms, wheeled models, PID and LQR |
| Planning | 3, 4, 5 | A* on a grid, RRT, trajectory optimization |
| Perception | 7, 8, 9, 10 | LiDAR and ICP, cameras, RANSAC, learned perception |
| Localization and SLAM | 11, 12, 13, 14 | factor graphs, occupancy maps, Kalman filters, particle filters |
| Executive and beyond | 1, 15 | this lesson; then imitation, VLAs, world models |
Based on Stanford AA 274A, Principles of Robot Autonomy I. This page re-teaches the course's first lesson in our own words, devices and toy numbers.
Now press Present or Teach and explain from memory: the loop, the four modules, the pose, the log-odds update and the gate's table. Then go back to the three robots, pick the dead end, and say why only one gets through.