Skip to content

Proportional Control (P-Control)

Proportional control is the simplest form of feedback control. It's the foundation for understanding more advanced controllers like PID.


The Core Idea

Try it in Lab 03

See P-control in action with line following. Experiment with different Kp values and observe the behavior. → Line Following tutorial

Output is proportional to error.

correction = Kp × error

Where: - error = desired value − actual value - Kp = proportional gain (tuning parameter) - correction = control output


Why It Works

Imagine steering a car back to the center of the lane:

Situation Error Correction
Slightly off center Small Gentle steering
Far off center Large Strong steering
Perfectly centered Zero No steering needed

The further you are from where you want to be, the harder you push to get back.


Mathematical Representation

In continuous time:

\[u(t) = K_p \cdot e(t)\]

Where: - \(u(t)\) = control signal (motor command) - \(e(t)\) = error signal (setpoint − measured) - \(K_p\) = proportional gain

In discrete time (what your code actually does):

\[u[n] = K_p \cdot e[n]\]

Each loop iteration, you: 1. Measure the current state 2. Calculate error from desired state 3. Multiply by Kp 4. Apply to actuator


Line Following Example

# Desired position: center of line (error = 0)
# Actual position: from sensors (-1.5 to +1.5)

error = robot.sensors.line.get_error()  # e.g., -0.5 (slightly left)
correction = Kp * error                  # e.g., 30 × (-0.5) = -15

left_motor  = base_speed + correction    # 80 + (-15) = 65
right_motor = base_speed - correction    # 80 - (-15) = 95

# Result: right motor faster → robot steers left → reduces error

The Effect of Kp

                    Response to Step Change

    Kp too low                    Kp too high
    ──────────                    ───────────
         ╭─────────────                ╭──╮
        ╱              setpoint ─ ─ ─ ╱    ╲   ╭──
       ╱                             ╱      ╲_╱
    __╱                           __╱

    Slow response                 Oscillation
    Never quite reaches           Overshoots repeatedly


    Kp just right
    ─────────────
         ╭────────────────
       ╱   setpoint ─ ─ ─
    __╱

    Fast response
    Minimal overshoot
Kp Value Behavior Problem
Too low Sluggish, drifts Robot wanders, slow to correct
Too high Oscillates Robot wobbles side to side
Optimal Quick, stable Fast correction, minimal overshoot

Finding Optimal Kp

Method 1: Trial and Error

  1. Start with Kp = 10
  2. Increase until oscillation begins
  3. Back off ~30%

Method 2: Data-Driven (Lab 06 approach)

Try it in Lab 06

Systematically test Kp values, log error data, and find the optimal value with measurements instead of guessing. → Precise Turns tutorial

  1. Test multiple Kp values
  2. Measure average error for each
  3. Plot error vs Kp → find minimum

Method 3: Ziegler-Nichols

  1. Increase Kp until sustained oscillation (Ku)
  2. Measure oscillation period (Tu)
  3. Use: Kp = 0.5 × Ku

Limitations of P-Control

1. Steady-State Error

P-control alone often leaves a small residual error:

        setpoint ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
                         ╭──────────── actual (with offset)
    ___________________╱

    The system stabilizes NEAR the setpoint, not AT it.

Why? If error is zero, correction is zero. But the system might need some correction just to stay in place (e.g., fighting gravity, friction).

Solution: Add Integral term (PI or PID control).

2. Oscillation at High Gains

High Kp causes overcorrection → overshoot → correction the other way → oscillation.

Solution: Add Derivative term (PD or PID control).

3. No Prediction

P-control only reacts to current error. It doesn't anticipate.

Solution: Derivative term predicts based on rate of change.


P-Control in the Bigger Picture

┌─────────────────────────────────────────────────────────────────┐
│                                                                 │
│   P-Control:   correction = Kp × error                          │
│                            ↑                                    │
│                       You are here                              │
│                                                                 │
│   PI-Control:  correction = Kp × error + Ki × ∫error dt         │
│                                              ↑                  │
│                                    Eliminates steady-state      │
│                                                                 │
│   PD-Control:  correction = Kp × error + Kd × d(error)/dt       │
│                                              ↑                  │
│                                    Reduces overshoot            │
│                                                                 │
│   PID-Control: correction = Kp×e + Ki×∫e dt + Kd×de/dt          │
│                                              ↑                  │
│                                    Full control (most common)   │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

For line following, P-control is often sufficient because: - Sensors provide continuous feedback - System is naturally stable - Small steady-state error is acceptable


Code Pattern

# Basic P-control loop
KP = 30
SETPOINT = 0  # Desired error (centered on line)

while True:
    # 1. Measure
    error = robot.sensors.line.get_error()

    # 2. Calculate
    correction = KP * error

    # 3. Apply
    robot.set_motors(
        int(base_speed + correction),
        int(base_speed - correction)
    )

    time.sleep(0.01)  # Control loop rate

Block Diagram

                         ┌─────────────────┐
    setpoint ──(+)──────▶│   Controller    │──────▶ output
               │         │   u = Kp × e    │          │
               │         └─────────────────┘          │
               │                                      │
               │  error                               │
               │                                      ▼
               │                              ┌──────────────┐
               │                              │    Plant     │
               │                              │   (robot)    │
               └──────────────────────────────│              │
                            ◀─────────────────│   feedback   │
                           measured           └──────────────┘

Physical Intuition

Think of P-control like a spring:

  • Stronger spring (high Kp): Snaps back quickly, might bounce
  • Weaker spring (low Kp): Returns slowly, won't bounce
  • Right spring: Returns quickly, settles smoothly

The spring force is proportional to displacement — just like P-control correction is proportional to error.


Applications Beyond Robotics

P-control (and PID) is everywhere:

System Setpoint Measured Correction
Thermostat 22°C Room temp Heater power
Cruise control 100 km/h Speed Throttle
Drone altitude 10 m Height Motor thrust
Audio volume Target level Actual level Gain adjust
Water tank Full Level sensor Pump speed

Further Reading

Math Connection: Differential Equations

P-control creates a first-order linear ODE: $\(\frac{dx}{dt} = -K_p \cdot x\)$ Solution: \(x(t) = x_0 \cdot e^{-K_p t}\) — exponential decay toward setpoint.

Physics Connection: Damped Systems

P-control is analogous to viscous damping in mechanical systems. Higher Kp = higher damping coefficient.