How a Robot Sees, Thinks and Acts

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.

Send three robots into one room

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

Automation Is Not Autonomy

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.

Push a robot off its line

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.

0.10 m

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 definition. Automation replays a fixed plan open loop. Autonomy closes the loop: the robot senses, decides and acts, again and again, in a world nobody scripted.

The failure, as symptom, measurement and fix

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.

The road

  1. The loop: see, think, act, and how fast it must turn.
  2. The stack: four modules and the data contract on each arrow.
  3. The pose: three numbers for where the robot is, and the rule that limits them.
  4. Four maps: one apartment stored four ways.
  5. One map cell: how evidence adds up in log-odds.
  6. The executive: a finite state machine, traced on a parking gate.
  7. Small machines: reduction, hierarchy and composition.
  8. The full stack: the hero's gridworld with every module shown (its full version).
  9. The field guide: terms, numbers, code, the series map and the credit.
What makes a self-driving car autonomous rather than automated?

Chapter 1

See, Think, Act: The Loop That Never Stops

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.

  1. See. Sensors produce raw numbers: camera pixels, laser ranges, wheel ticks.
  2. Think. The robot finds things in the data (perception), works out where it is (localization) and chooses a path (planning).
  3. Act. The controller turns the path into motor commands. The robot moves.

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.

Ride one packet around the loop

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.

10 Hz

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.

Say it aloud

d equals v divided by f.

d
d the blind distance: how far the robot moves in one loop, in metres.
v
v the speed, in metres per second.
f
f the loop rate: full loops per second, in hertz. The slowest stage of the loop sets it.
In plain words

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.

With numbers

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.

BeatData in, data outLessons
See, perceivepixels, ranges, then features and detections7 to 10
Think, localizefeatures and motion, then a pose and a map11 to 14
Think, plana map and a goal, then a path3 to 5
Act, controla path, then motor commands2, 6
Coordinateevery module, then one behaviour1, 15

The failure, as symptom, measurement and fix

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.

What kind of data leaves Think and enters Act?

Chapter 2

The Autonomy Stack: Four Modules and Their Contracts

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.

  1. Perception turns raw sensor data into meaning: features, detections, labelled regions.
  2. Localization and SLAM answers "where am I, and what does the world look like?" It outputs a pose and a map.
  3. Planning and control turns the map and a goal into a path, then into motor commands that follow it.
  4. The executive chooses which behaviour runs now (explore, approach, stop, recover) and handles failures.

Read one module's contract

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 failure, as symptom, measurement and fix

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.

What does Localization and SLAM take in, and what does it hand on?

Chapter 3

State: Three Numbers Called the Pose

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).

Say it aloud

xi equals the column x, y, theta.

ξ
xi the pose: the robot's whole configuration as one list of numbers.
x
x the position along the room, in metres.
y
y the position across the room, in metres.
θ
theta the heading: the angle from the x axis to the way the robot faces.
⊤
transpose write the list as a column, not a row.
In plain words

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 numbers

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.

Say it aloud

x-prime equals x plus v delta-t cos theta, and y-prime equals y plus v delta-t sine theta.

x′
x-prime the new x after the step, in metres.
y′
y-prime the new y after the step, in metres.
v
v the forward speed, in metres per second.
Δt
delta-t the length of the step, in seconds.
cos θ
cos theta the share of the motion that goes along x.
sin θ
sine theta the share of the motion that goes along y.
In plain words

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.

With numbers

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.

Drive the robot, then try to slide it

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.

30°
0.5 m/s

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.

Say it aloud

x-dot sine theta minus y-dot cos theta equals zero.

ẋ
x-dot how fast x changes, in metres per second.
ẏ
y-dot how fast y changes, in metres per second.
sin θ
sine theta with cos theta, it picks out the sideways part of the velocity.
cos θ
cos theta the other half of that sideways direction.
0
zero the rule: no sideways speed at all.
In plain words

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.

With numbers

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 failure, as symptom, measurement and fix

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.

Why is a wheeled robot's pose (x, y, θ) and not just (x, y)?

Chapter 4

Four Ways to Store the World

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.

Ask four maps for one route

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.

0.25 m

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.

MapStoresGood forBad for
Occupancy grida chance of "occupied" in every cellexact paths, collision checksmemory in big spaces
Topologicalplaces as nodes, connections as edgesfast routes between roomsdistance and shape
Featuresparse landmarks: corners with a descriptorfinding yourself again"is this spot free?"
Semanticlabels: wall, door, kitchen, personreasoning about what things areroutes, 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.

Say it aloud

N equals L-x over r, times L-y over r.

N
N the number of cells in the grid.
Lx
L-x the room's length, in metres.
Ly
L-y the room's width, in metres.
r
r the cell size: the side of one square cell, in metres.
In plain words

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.

With numbers

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 failure, as symptom, measurement and fix

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.

You need room-to-room directions with as little memory as possible, and no exact distances. Which map fits?

Chapter 5

How One Map Cell Makes Up Its Mind

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.

Say it aloud

ell equals the natural log of p over one minus p.

ℓ
ell the log-odds: any number: below 0 leans free, above 0 leans occupied, 0 means "no idea".
ln
the natural log it turns multiplying into adding.
p
p the chance the cell is occupied, from 0 to 1. One minus p is the chance it is free.
In plain words

Divide the chance of occupied, p, by the chance of free, one minus p. Take the natural log. Even odds give ell = 0.

With numbers

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.

Say it aloud

ell-t equals ell-t-minus-one plus delta-ell.

ℓt
ell-t the cell's log-odds after reading t.
ℓt−1
ell-t-minus-one the log-odds before this reading. It starts at 0.
Δℓ
delta-ell this reading's evidence: +0.85 for a hit, −0.40 for a miss.
In plain words

Keep a running total ell. When a reading arrives, add its delta-ell. Nothing is ever multiplied.

With numbers

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.

Say it aloud

p equals one over one plus e to the minus ell.

p
p the chance the cell is occupied, back on the 0 to 1 scale.
e−ℓ
e to the minus ell 2.718 raised to minus ell: large when ell is negative, small when it is positive.
In plain words

Raise e to minus ell. Add one. Take one over the result. The answer p always stays between 0 and 1.

With numbers

ℓ = 1.30: e−1.30 = 0.273, so p = 1 / 1.273 = 0.79. The cell is 79% sure it is occupied.

Fire readings at one cell

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.

70%

Illustrative sensor: a miss is about 40% sure (Δℓ = −0.40). The cell counts as "sure" above p = 0.8.

Readingℓp
none yet0.000.50
hit, +0.850.850.70
hit, +0.851.700.85
miss, −0.401.300.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 failure, as symptom, measurement and fix

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.

Why does a map cell add log-odds instead of storing a yes-or-no value?

Chapter 6

The Executive: A Finite State Machine

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.

  1. A finite set of states S: the modes, such as down or raising.
  2. A set of inputs I: what it can sense each tick.
  3. A set of outputs O: what it can command.
  4. A next-state function n: from the input and the state, the next state.
  5. An output function o: from the input and the state, the command.
  6. An initial state s0.

At each tick t the machine reads input it in state st. Two rules then fire. The first gives the command ot.

Say it aloud

o-t equals o of i-t and s-t.

ot
o-t the command sent at tick t: raise, lower or hold.
o
o the output function: a lookup from (input, state) to a command.
it
i-t the input read at tick t, such as "car waiting".
st
s-t the state at tick t, such as "down".
In plain words

Look up the row for the input i-t and the state s-t. Send the command o-t written in that row.

With numbers

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.

Say it aloud

s-t-plus-one equals n of i-t and s-t.

st+1
s-t-plus-one the state the machine moves to for the next tick.
n
n the next-state function: a lookup from (input, state) to a state.
it
i-t the same input as in the first rule.
st
s-t the same current state.
In plain words

In the same row, read the next state. Store it as s-t-plus-one. Wait for the next tick and repeat.

With numbers

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.

TickState stInput itOutput otNext st+1
0downno carholddown
1downcar waitingraiseraising
2raisingnot at topraiseraising
3raisinggate at topholdup
4upcar not passedholdup
5upcar passedlowerlowering
6loweringnot at bottomlowerlowering
7loweringgate at bottomholddown

Run the parking gate

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 failure, as symptom, measurement and fix

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.

The gate is up and the sensor says "car not passed". What are the output and the next state?

Chapter 7

Keeping State Machines Small

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.

1. State reduction

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:

  1. Put every state in one group.
  2. Split the states by their outputs.
  3. Split again any group whose members move to different groups on some input.
  4. Stop when no group splits. Each group is one state.

Shrink a 7-state machine

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.

2. Hierarchy

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.

3. Composition

PatternWiringIn ROS SMACH
Cascademachine 1's output is machine 2's inputSequence
Parallelone input feeds both; outputs side by sideConcurrence
Feedbacka machine's output returns to its own inputIterator

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 failure, as symptom, measurement and fix

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.

When are two FSM states equivalent?

Chapter 8

The Full Stack in One Gridworld

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:

  1. Perception senses the 8 cells around the robot.
  2. Mapping writes them into the belief grid.
  3. Localization reports the pose. Here it is exact; Lessons 13 and 14 remove that gift.
  4. Planning runs a breadth-first search over cells not known to be blocked.
  5. Control turns the next path cell into one move.
  6. The executive picks the mode: PLAN, NAVIGATE, REPLAN, REACHED or BLOCKED.

Run the whole stack

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.

4
PERCEPTION
waiting
MAP
waiting
LOCALIZATION
waiting
PLANNING AND CONTROL
waiting
EXECUTIVE
waiting

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 failure, as symptom, measurement and fix

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

Field Guide

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.

TermMeaningNumber to remember
Closed loopsense the result, then correct10 pushes of 0.1 m: 1.0 m off open loop, 0.1 m closed
Blind distanced = v / f13.4 m/s at 10 Hz: 1.34 m
Poseξ = [x, y, θ]3 numbers for a wheeled robot
No-slipẋ sin θ − ẏ cos θ = 0sideways speed 0
Grid sizeN = (Lx/r)(Ly/r)12 m by 8 m at 5 cm: 38,400 cells
Log-oddsℓ = ln(p/(1 − p)), add per readinghit, hit, miss: 0.79
FSM(S, I, O, n, o, s0)gate: 4 states, 24 table rows
Reductionmerge equivalent states010/110 detector: 7 to 4 states

Checklist for any robot you build

The core, in code

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

Where each lesson sits on the stack

ModuleLessonsWhat you build
Control and kinematics2, 6transforms, wheeled models, PID and LQR
Planning3, 4, 5A* on a grid, RRT, trajectory optimization
Perception7, 8, 9, 10LiDAR and ICP, cameras, RANSAC, learned perception
Localization and SLAM11, 12, 13, 14factor graphs, occupancy maps, Kalman filters, particle filters
Executive and beyond1, 15this lesson; then imitation, VLAs, world models

Keep going

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.

The takeaway. Autonomy is a loop, not a module. Get the data contract on each arrow right, keep the belief honest, and let a small state machine decide what runs.

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.

Principles of Robot Autonomy I · Stanford AA 274A · Lesson 1: The See-Think-Act Loop and the Autonomy Stack
Next: Rigid-Body Transforms · Back to Gleams