Atlas Robotics
Robot ControlIntermediate

The robot control loop: sense, think, act

Atlasbot · 26/6/2026 · 11 min read

The robot control loop: sense, think, act

Whether it's a 500,000 VND vacuum cleaner robot or a few hundred million industrial AMR, almost every robot control system runs according to the same original model: Sense → Think → Act (Sensor → Processing → Control), repeating continuously dozens to hundreds of times per second.

Key concepts

Sense: reads raw data from hardware — encoder value, acceleration from IMU, distance from ultrasonic/LiDAR sensor. This is the "looking at the real world" step.

Think (Processing): from sensor data, calculate and make decisions — whether there are obstacles ahead, whether to turn left or go straight, how much the motor speed needs to increase or decrease. This step contains algorithms such as PID, path planning, or simply some comparison statements.

Act (Control): sends command to actuator — set PWM for motor driver, turn on/off relay. This is the only step that actually works against the physical world.

After the Act step, the real world changes (the robot has moved a little), the loop returns to the Sense step to read the new state.

How it works

The easiest way to get a feel for this model is to look at a pseudocode for a robot that dodges obstacles with a front-facing ultrasonic sensor:

loop (runs at a fixed frequency, e.g. 50Hz):
    # Sense
    distance = doc_cam_bien_sieu_am()

    # Think
    if distance < NGUONG_AN_TOAN:
        lenh = "RE_PHAI"
    else:
        lenh = "DI_THANG"

    # Act
    gui_lenh_toi_driver_dong_co(lenh)

    doi_den_chu_ky_tiep_theo()

Loop rate determines how quickly the robot "reacts". If the loop runs at 10Hz, the robot only updates its decision once every 100ms — with a robot moving at 1m/s, that means it can go another 10cm before reacting to a new obstacle that appears.

Technical details

Formulas

Generalize the above example into the formula reaction distance — the distance the robot travels during the "blind" time between two loop updates:

Khoang_cach_phan_ung = Toc_do_robot × Chu_ky_vong_lap
                      = Toc_do_robot / Tan_so_vong_lap

For example: robot 1.5 m/s, obstacle avoidance loop running 20Hz (50ms cycle)
Reaction distance = 1.5 × 0.05 = 0.075m = 7.5cm

For example: same speed, lower frequency to 5Hz (200ms cycle)
Reaction distance = 1.5 × 0.2 = 0.3m = 30cm — 4 times worse

Parameters

A complete robot system is essentially many nested Sense-Think-Act loops, each running at a frequency appropriate to the nature of the work:

Loop layerTypical frequencyWhere to run?
PID motor speed/position500Hz – 1kHzMCU (needs low, deterministic latency)
Avoid local obstructions10 – 50HzMCU or MPU
Object recognition/vision AI10 – 30HzMPU with GPU (Jetson)
global path planning~1Hz or when there is a large changeMPU runs ROS2/Nav2

Practical applications

The reaction distance formula above is the basis for the actual safe calculation: if the emergency stop sensor (bumper/safe LiDAR) only detects obstacles within a range of 20cm, and the safety loop runs at a frequency that causes the reaction distance to exceed 20cm at the maximum speed the robot is running, the system cannot be considered safe — the robot can crash into an obstacle before reacting even though the sensors and code are "functioning properly". This is why the safety loop always needs to run much faster than the normal logic loop, and the maximum allowable speed of the robot must be limited based on this exact calculation, not just on the mechanical capabilities of the motor.

Practical example

def khoang_cach_phan_ung(toc_do_ms, tan_so_hz):
    chu_ky = 1 / tan_so_hz
    return toc_do_ms * chu_ky

for f in [5, 10, 20, 50]:
    d = khoang_cach_phan_ung(1.5, f)
    print(f"Tan so {f}Hz -> khoang cach phan ung = {d*100:.1f}cm")
Output:
Tan so 5Hz -> khoang cach phan ung = 30.0cm
Tan so 10Hz -> khoang cach phan ung = 15.0cm
Tan so 20Hz -> khoang cach phan ung = 7.5cm
Tan so 50Hz -> khoang cach phan ung = 3.0cm

Doubling the loop frequency always cuts the reaction distance exactly in half — this linear inverse relationship is a quick calculation tool when it comes to deciding the minimum safe loop frequency for a given robot speed.

Common mistakes

When a robot "reacts slowly" or "jumps", the cause almost always lies in one of three steps:

  • Sense is slow or blocked — the sensor returns data late, is noisy (needs filtering, e.g. moving average, Kalman filter), or worse, the sensor reading code is blocked (blocking I/O) causing the whole loop to wait — similar to the "callback blocking executor" problem learned in the ROS2 section, just different at the application layer.
  • Think is time-consuming — the processing algorithm is too heavy for the required loop frequency (eg: running heavy AI inference right in the high-frequency safety loop) — need to optimize the algorithm or separate it and run it in a separate lower frequency loop.
  • Act has delay — motor driver responds slowly, or communication between MCU and driver is blocked (eg: use low speed I2C/UART for commands that need immediate response).
  • Not considering the reaction distance when choosing the robot's maximum speed — as mentioned in the Practical Application section, setting the maximum speed without comparing it with the actual safety loop frequency is a serious design flaw, not a normal code error.

Conclusion

Understanding the Sense-Think-Act model helps localize errors much faster than digging through each line of code — always asking yourself "which step is the problem?" before debugging further, and always consider the reaction distance when designing the speed/frequency for the safety loop. The next article in this category delves into PID — the most common algorithm located in the "Think" step of the motor speed control loop.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

The robot control loop: sense, think, act — Atlas Robotics