Fast loops inside slow ones
A balancing robot corrects its motors a thousand times a second but decides where to go only once a second. Why not do everything at 1 kHz?
About 30 min · 3 goals · Checked by automated tests
1.Why should I care?
Computing time is a budget. Spend it where the physics is fast (currents, wheel speeds, balance) and save it where the world changes slowly (goals, routes). Getting this split wrong gives either a sluggish robot or an overloaded processor.
- ◇ Explain why low-level control loops run faster than planning loops.
- ◇ Choose an update rate from how quickly the controlled quantity can change.
- ◇ Calculate how many inner-loop updates happen per outer-loop decision.
2.Discover
Open the Robotics Workbench and run a motion with the default controller. Find the controller's update period, then make it ten times slower and run again. Describe what changes in the tracking and why.
Can't use the interactive? Read a description instead
In the Robotics Workbench, slowing the controller update period by ten times makes the tracked motion lag and overshoot the target path, because corrections arrive too late for the arm's dynamics.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
A robot's motor-current loop runs at 1000 Hz and its path planner at 5 Hz. How many current-loop updates happen between two planner updates?
4.Predict
A wheel's speed can change noticeably in 5 ms. Roughly how often should its speed controller run?
Guess first. Being wrong here is how the surprise works.
5.Understand
Rates follow the physics
Each loop should run several times faster than the quantity it controls can change. Motor current changes in microseconds to milliseconds, so current loops run at 10–20 kHz. Wheel speed changes in milliseconds (1 kHz). A robot's position on a map changes over tenths of a second (10–100 Hz). Goals change over seconds (1 Hz or less).
Cascaded loops
Layers are usually cascaded: the planner sends a path, a position loop turns it into speed targets, and a speed loop turns those into motor commands. Each inner loop treats its setpoint as constant between outer updates, which only works if the inner loop is much faster.
The cost of running fast
Running everything at the highest rate wastes processor time and energy, and heavy jobs such as vision may simply not finish in 1 ms. Splitting rates lets each job get the time it needs, often on different processors: a microcontroller for fast loops, a larger computer for perception and planning.
Explain it another way
Driving a car: your hands make tiny steering corrections all the time, your eyes check the lane every moment, and you decide which road to take only at junctions.
For a cascade to behave, each inner loop's closed-loop bandwidth should be roughly 5–10 times that of the loop around it. Sample rates are then chosen around 10–20 times each loop's bandwidth.
Updates per decision = inner rate ÷ outer rate. A 1 kHz speed loop under a 10 Hz planner runs 1000 ÷ 10 = 100 times per planning step. Its period is 1/1000 s = 1 ms.
Drone flight controllers typically run attitude loops at hundreds of hertz to a few kilohertz on a microcontroller, while a companion computer handles mapping and route planning far more slowly.
Worked example 1
A planner runs at 5 Hz and a position loop at 200 Hz. How many position updates per plan, and what is the position loop's period?
200 ÷ 5 = 40 position updates per plan. Period = 1/200 s = 5 ms.
Common mix-ups
- Faster is always better, so run every loop as fast as possible.
✓ Each loop needs a rate matched to its dynamics. Over-fast loops waste computing; heavy jobs may not even finish in time. - The update rate is a software detail you can choose later.
✓ Rates decide processors, buses and stability, so they belong on the block diagram from the start.
6.Watch
→ Notice which parts of the car's software react within milliseconds and which plan seconds ahead.
A university lab shows an autonomous car's layered system, where perception, planning and low-level control each play their part.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
A current loop runs at 20 kHz. What is its period, in microseconds?
Practice 3
Which job should run at the highest rate?
Practice 4
Why must an inner speed loop be much faster than the position loop around it?
Practice 5
A team moves the wheel PID from the main computer (which also runs vision) onto a small microcontroller. What is the main benefit?
8.Apply it
For a line-following robot, list four loops (motor current, wheel speed, line tracking, lap strategy). Give each a rate with a one-line justification based on how fast its quantity changes, and calculate the updates per decision between each pair.
9.Reflect
Concepts: Real-time computing on robots · Robot system architecture