Skip to main content
onepocketRobotics

Robotics Fundamentals

The Sense–Think–Act Loop

The single loop that runs inside every robot: sense the world, decide what to do, act, then sense again. Learn why it must repeat, how fast and what breaks when it doesn't.

beginner · 12 min read

Lesson content

Every robot runs one loop, over and over, from the moment it is switched on: read the sensors, decide what to do, drive the actuators, then read the sensors again, because the world has now changed, partly because of what the robot just did.

The loop never stops: each action changes the world the robot senses next.

Definition

Sense–think–act cycle

One pass around the loop: take a reading, compute a response, command an output. Robots run thousands of these per minute.

Formal definition

The perception–cognition–action cycle. In classical AI robotics it appeared as the sense–plan–act (SPA) paradigm, in which sensing built a world model, a planner produced a sequence of actions and an executor carried them out.

Why is it a loop and not a line?

Because acting changes the very world you were reasoning about.

Drive forward and the wall is now closer than the reading you planned with. Close a gripper and the part may have shifted inside it. Every action makes your last measurement slightly out of date.

A robot that acted on one measurement and never looked again would be navigating on a memory that gets staler every millisecond.

Closing the loop swaps a hard problem for an easy one. Instead of being exactly right once, the robot only has to be roughly right, over and over. That is a far easier thing to engineer.

One pass, in detail

  1. Sense

    Read the sensors and convert raw values into meaningful quantities: encoder counts into joint angles, a laser scan into distances. This stage also includes filtering and fusion.

  2. Think

    Compare where the robot is with where it should be and compute a response. This may be a single subtraction and a multiply (a P controller) or a full re-plan. The structure is the same either way.

  3. Act

    Send commands to the actuators (a voltage, a target velocity, a joint trajectory point) and let the physical world do the rest.

  4. Wait

    Sleep until the next tick. A loop that runs as fast as it possibly can is not a controlled loop: variable timing changes the effective gains, so the period must be regular.

How fast that loop needs to run is not a matter of taste. It is set by how quickly the thing you are controlling can change. The rule of thumb is the same one that governs sampling.

The math

Run the loop several times faster than the fastest thing you are trying to control. Too slow and the robot is always reacting to a world that has already moved on.

f_loop ≥ 10 × f_system

f_loop
control loop rate, in Hz
f_system
the fastest meaningful change in the thing being controlled, in Hz

With real numbers

A robot vacuum at 0.3 m/s that must stop within 5 cm has roughly 0.17 s of margin, so ~10 Hz is fine.
A balancing robot falls over in about 0.3 s, so its inner loop runs at 100–500 Hz.
A quadcopter's attitude changes in tens of milliseconds, so its rate loop runs at 500–1000 Hz.
Same loop, three orders of magnitude apart. The physics chose the number, not the programmer.

Example

The loop in a wall-following robot, once

Sense: the side rangefinder reads 24 cm.
Think: the target is 20 cm, so the error is +4 cm. Too far out. Steer slightly toward the wall.
Act: slow the left wheel by 5%.
Wait: 20 ms.

Next time round, the reading is 22 cm. The error is smaller, so the correction is smaller too.

Nothing in that description is clever. There is no map, no plan, no model of the building. And yet the robot follows a wall it has never seen, around corners nobody programmed.

What happens when one stage is missing is a useful way to see what each contributes.

No sense

What you get
A machine that repeats, blind
Example
A cam-driven packing machine

No think

What you get
A reflex, with no goal
Example
A light-seeking toy that just steers toward brightness

No act

What you get
A monitoring system, not a robot
Example
A security camera

No repeat

What you get
One decision, acted on forever
Example
A thrown ball

Three architectures have been built on this loop. Modern robots use all three at once, at different rates.

Deliberative (sense–plan–act)

Build a full world model, plan a complete solution, then execute it.

Powerful for problems needing lookahead, such as routing and task sequencing. Too slow to be the only loop, because the world changes while you are planning.

Reactive

Map sensor readings straight to actions, with no model in between.

Fast and robust. Rodney Brooks's insight in the 1980s was that a lot of competent behaviour needs no model at all. Obstacle avoidance is the classic case.

Hybrid (three-layer)

A slow deliberative planner on top, a fast reactive layer underneath and an executive between them.

What essentially every real robot runs. Nav2's global planner, local planner and controller are exactly this, at 1 Hz, 20 Hz and 50 Hz.

Loop period must be regular, not just fast

Here is the reason, which is arithmetic rather than philosophy.

A derivative term divides by the time step. An integral term multiplies by it. So if the loop period wanders between 5 ms and 20 ms, those gains wander with it, by a factor of four. A controller you tuned perfectly yesterday starts hunting.

That is why real control loops live in a dedicated real-time thread with no memory allocation, no logging and no blocking calls.

And it is why jitter, not average latency, is what usually breaks a loop. A steady 20 ms is fine. A random 5-to-20 ms is not.

Doing heavy perception inside the control loop.

Run vision, planning and mapping in their own slower loops and let the fast loop use their most recent output. Layers exist for exactly this reason.

Making the loop as fast as the CPU allows.

Faster than the sensors update buys nothing but noise amplification. Match the rate to the physics and to the sensor's bandwidth.

Forgetting that the act stage takes time too.

Actuator lag and communication delay sit inside the loop and behave like phase lag. Measure the whole round trip, not just the compute.

Key takeaway

  • Sense, think, act, then sense again, because acting changed the world you measured.
  • Closing the loop lets a robot be approximately right repeatedly instead of exactly right once.
  • Loop rate is set by the physics: roughly ten times the fastest change you must control.
  • Regularity matters as much as speed, because jitter changes your effective gains.
  • Real robots layer a slow deliberative planner over a fast reactive loop and run both at once.

Finished this lesson?

Guest progress is saved on this device.

The Sense–Think–Act Loop | OnepocketRobotics