Level 2 · Builder · Advanced middle school to early high school. Basic algebra. · about 25 min
Respond in proportion
Push hard when you're far away, gently when you're close: the proportional rule.
You'll be able to
- State the proportional rule: effort = gain × gap.
- Predict how a robot driven by the proportional rule slows as it approaches a target.
- Explain why a proportional controller often leaves a small leftover gap, and calculate it.
- Read and run a short Python loop that simulates a robot approaching a wall.
Builds on
01The problem
A robot needs to park 30 cm in front of a wall, using a distance sensor on its nose. The first idea is simple: "if the gap is more than zero, drive forwards at full speed; otherwise stop."
On the bench it is a disaster. The robot arrives at full speed, can't stop instantly, rolls past the target, notices, reverses at full speed, overshoots the other way and rattles back and forth. Change the rule to "always drive slowly" and it no longer rattles, but it now takes far too long to cross the room.
What we want is obvious to anyone who has parked a bike: go quickly when the target is far away and ease off as it gets close. How do we turn that instinct into a rule a robot can follow, with numbers?
Watch the idea in action
before you read on
A short, verified video on exactly this idea. Pause whenever you want, then carry on with the explanation below.
A short, friendly first look at PID that you can watch before any of the maths.
→ Focus on the proportional part: a bigger gap gives a bigger correction.
7 min 44 s · captions on YouTube · source
Nothing loads from YouTube until you press play.
02The idea
The proportional rule
The idea from Level 1 was to measure the gap between where the robot is and where it wants to be. Now we use the size of that gap to decide how hard to act:
effort = gain × gap
The gain is a number you choose. With a gain of 0.5 per second, a robot 70 cm from its target drives at 0.5 × 70 = 35 cm/s; at 10 cm it drives at 5 cm/s; at the target it stops. The robot slows down smoothly as it gets close, without anyone telling it when to brake. Because the effort is in proportion to the gap, this is called proportional control, often shortened to "P control".
The rule also handles going too far. If the robot overshoots, the gap becomes negative, so the effort becomes negative and the robot backs up.
Choosing the gain
The gain is a trade-off you make as the designer.
- A small gain gives gentle, slow movement. The robot is calm but takes a long time.
- A larger gain reacts strongly to small gaps, so the robot gets there quicker and resists pushes better.
- Too large a gain can make the robot overshoot, especially when it only checks its sensor every so often. Between checks it keeps acting on an old, too-big gap and sails past.
There is no single right gain. Engineers pick one by testing, which is exactly what the lab lets you do.
The leftover gap
Here is a surprise. Many systems need a steady effort just to stay where they are: a motor holding an arm up against gravity, or a heater keeping a room warm against the cold outside. With the proportional rule, effort only exists when there is a gap. So the system settles where the gap is just big enough to produce the effort it needs, and never quite reaches the target.
In the lab's model, a gain called Kp sets the effort, and the output settles at Kp ÷ (1 + Kp) of the target. With Kp = 3 it settles at 3 ÷ 4 = 0.75, leaving a gap of 0.25. A bigger gain shrinks the leftover gap but never removes it completely. Later levels show how engineers remove it.
A first program
Robots run their rules as a loop. Here is the parking robot in Python, using a version of the rule that closes a fixed fraction of the gap on each check:
distance = 100.0 # cm from the wall
target = 30.0 # where we want to stop
gain = 0.5 # close half of the remaining gap each step
for step in range(6):
print(step, round(distance, 1))
gap = distance - target
distance = distance - gain * gapRunning it prints:
0 100.0
1 65.0
2 47.5
3 38.8
4 34.4
5 32.2Each step the gap halves: 70, 35, 17.5 and so on. The robot gets close fast at first and then creeps in.
Recap
The proportional rule sets effort = gain × gap, so a robot pushes hard when far away and gently when close. The gain trades speed against calm behaviour, and if something keeps pushing back, a proportional controller settles with a small leftover gap.
03See it move
Predict before you experiment
With Kp = 2 the line levels off with a gap of about 0.33 below the target. If you raise Kp to 9, what happens to that leftover gap?
04The maths
Where does the leftover gap come from?
In the lab's model the output settles where the effort the controller provides exactly matches the effort the system needs to stay there. For the lab's system, holding an output y takes an effort of y (its gain K is 1). The controller provides Kp × gap = Kp × (1 − y) when the target is 1. Setting them equal:
y = Kp × (1 − y)
y + Kp × y = Kp
y = Kp ÷ (1 + Kp)
So the leftover gap is
gap = 1 − y = 1 ÷ (1 + Kp)
Some values:
- Kp = 1: gap = 1 ÷ 2 = 0.5
- Kp = 3: gap = 1 ÷ 4 = 0.25
- Kp = 9: gap = 1 ÷ 10 = 0.1
Each time you want the gap ten times smaller, you need roughly ten times the gain, which eventually means a motor that can't deliver it.
The step-by-step version
The Python loop uses the rule once per check. Each check closes a fraction g of the gap, so the gap is multiplied by (1 − g) every step:
new gap = (1 − g) × old gap
With g = 0.5 the gap halves. With g = 1 the robot jumps straight to the target in one step. With g bigger than 1, (1 − g) is negative: the robot jumps past the target. With g bigger than 2, each jump is bigger than the last and the robot rattles further and further away.
05Worked example
A parking robot uses speed = 0.5 per second × gap. It starts 100 cm from a wall and should stop at 30 cm. What is its speed at the start, and what is its speed when it is 40 cm from the wall?
Show the worked solution
At the start. gap = 100 cm − 30 cm = 70 cm. speed = 0.5 per second × 70 cm = 35 cm/s.
At 40 cm from the wall. gap = 40 cm − 30 cm = 10 cm. speed = 0.5 per second × 10 cm = 5 cm/s.
What this shows. Nobody programmed a "brake here" point. The robot slowed from 35 cm/s to 5 cm/s on its own because the gap shrank. Doubling the gain to 1 per second would double both speeds: 70 cm/s at the start and 10 cm/s near the end.
06Your experiment
- Open the feedback lab and press Reset. Check that the controller is set to P.
- Set Kp to 1. Read where the closed-loop line levels off by the end of the run.
- Repeat for Kp = 2, Kp = 3 and Kp = 9.
- For each Kp, work out the leftover gap (1 minus where the line levels off) and also calculate 1 ÷ (1 + Kp).
- Watch how quickly the line rises for each Kp, not just where it ends.
Record: Make a list with one line per Kp: the level the line reaches, the leftover gap you read, and 1 ÷ (1 + Kp). Then write one sentence about how the speed of the rise changed as Kp grew.
07Guided practice
In the lab's model, what leftover gap does a P controller with Kp = 3 leave when the target is 1?
Hint
Use gap = 1 ÷ (1 + Kp).
Answer
1 ÷ (1 + 3) = 0.25. The output levels off at 0.75.
Change the Python loop so that gain = 0.25. Starting at 100 cm with a target of 30 cm, where is the robot after one step?
Hint
The gap is 70 cm, and one step closes a quarter of it.
Answer
100 − 0.25 × 70 = 100 − 17.5 = 82.5 cm.
Now try gain = 1.5 in the same loop. Where is the robot after one step, and what has gone wrong?
Hint
Work out 100 − 1.5 × 70 and compare it with the 30 cm target.
Answer
100 − 1.5 × 70 = −5 cm. The robot has jumped 35 cm past the target: too much gain makes it overshoot.
08Check your understanding
09Technical challenge
In the feedback lab's model (target 1, K = 1), a P controller leaves a leftover gap of 1 ÷ (1 + Kp). What value of Kp leaves a gap of exactly 0.05?
10Engineering & research
Proportional control is everywhere. A camera gimbal turns harder the further it is from level; a drone tilts more the further it has drifted; the cruise control in many cars pushes the accelerator in proportion to how far below the set speed it is. Real designs almost always add more to the rule, which you will meet at the next levels, but the proportional part usually does most of the work.
In Tactiverge's proposed TV-01 study, two robot arms would hold a soft object between them. One simple idea such a study could test is a proportional rule on force: if a force sensor says one gripper is pulling harder than intended, ease off in proportion to the difference. Whether that is good enough when the camera loses sight of the object is exactly the kind of question TV-01 asks. The study has not been carried out, so there are no results yet.
Feedback · as a Builder
The robot acts in proportion to the gap between where it is and where it wants to be: push hard when far away, gently when close. A plain proportional rule often leaves a small leftover gap.
Something unclear or not working here? Tell us.
Original Tactiverge material, not yet externally reviewed by educators. CC BY 4.0.