---
id: wiki-2026-0508-control-theory
title: Control Theory
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Feedback Control, Cybernetics, Automatic Control]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [control, feedback, dynamical-systems, robotics, distributed-systems]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: Python/MATLAB/C++
  framework: scipy.signal / control / Drake
---

# Control Theory

## 매 한 줄
> **"매 system output 의 desired trajectory 의 driving 의 feedback law 설계"**. Watt centrifugal governor (1788) → Wiener cybernetics (1948) → Kalman state-space (1960) → 2026 MPC + neural-augmented control. 매 robotics/aerospace + 매 distributed systems (TCP congestion, autoscaling, DB connection pool) 의 unified framework.

## 매 핵심

### 매 Control taxonomy
- **Open-loop**: 매 feedback X — 매 disturbance 의 fragile.
- **Closed-loop**: 매 measurement → error → adjust — 매 robust.
- **PID**: 매 industry workhorse — 매 95% controllers in field.
- **State-space**: 매 multi-input/multi-output (MIMO) — 매 Kalman/LQR.
- **MPC** (Model Predictive Control): 매 optimization-based — 매 Tesla autopilot, ABB.
- **Adaptive/Robust**: 매 H∞, gain scheduling — 매 plant uncertainty.
- **Reinforcement learning**: 매 model-free policy — 매 simulator-trained.

### 매 PID 분해
- **P (proportional)**: 매 current error 의 비례 — 매 stiffness.
- **I (integral)**: 매 accumulated error 의 누적 — 매 steady-state offset 의 elimination.
- **D (derivative)**: 매 error rate 의 — 매 damping (overshoot 감소).

### 매 Stability
- **Lyapunov stability**: V(x) > 0, V̇(x) < 0 → asymptotic.
- **Routh-Hurwitz**: 매 polynomial coefficient 의 root location 검사.
- **Bode/Nyquist**: 매 frequency-domain phase/gain margin.
- **Pole placement**: 매 closed-loop pole 의 LHP 의 위치.

### 매 응용
1. **Robotics**: 매 manipulator joint control, drone attitude.
2. **Datacenter**: 매 autoscaling (PID on queue depth), thermal control.
3. **Networking**: 매 TCP cubic, BBR — 매 congestion control as control problem.
4. **DB**: 매 connection pool sizing, adaptive query throttling.
5. **Game AI**: 매 NPC steering (Reynolds), camera follow.

## 💻 패턴

### PID Controller (basic)
```python
class PID:
    def __init__(self, kp, ki, kd, dt, output_clip=(None, None)):
        self.kp, self.ki, self.kd, self.dt = kp, ki, kd, dt
        self.integral = 0.0; self.prev_error = 0.0
        self.lo, self.hi = output_clip
    def step(self, setpoint, measurement):
        error = setpoint - measurement
        self.integral += error * self.dt
        derivative = (error - self.prev_error) / self.dt
        u = self.kp*error + self.ki*self.integral + self.kd*derivative
        self.prev_error = error
        if self.lo is not None: u = max(self.lo, u)
        if self.hi is not None: u = min(self.hi, u)
        return u
```

### Anti-Windup PID (production)
```python
class PIDAntiWindup(PID):
    def step(self, setpoint, measurement):
        error = setpoint - measurement
        derivative = (error - self.prev_error) / self.dt
        u_unclamped = self.kp*error + self.ki*self.integral + self.kd*derivative
        u = u_unclamped
        if self.lo is not None: u = max(self.lo, u)
        if self.hi is not None: u = min(self.hi, u)
        # 매 saturation 의 integral 의 stop — 매 windup 방지
        if u == u_unclamped:
            self.integral += error * self.dt
        self.prev_error = error
        return u
```

### LQR (Linear Quadratic Regulator)
```python
import numpy as np
import scipy.linalg as la

def lqr(A, B, Q, R):
    # 매 minimize ∫ x'Qx + u'Ru dt subject to ẋ = Ax + Bu
    P = la.solve_continuous_are(A, B, Q, R)
    K = np.linalg.solve(R, B.T @ P)
    return K  # u = -Kx
```

### Kalman Filter
```python
class KalmanFilter:
    def __init__(self, A, B, H, Q, R, x0, P0):
        self.A, self.B, self.H, self.Q, self.R = A, B, H, Q, R
        self.x, self.P = x0, P0
    def predict(self, u):
        self.x = self.A @ self.x + self.B @ u
        self.P = self.A @ self.P @ self.A.T + self.Q
    def update(self, z):
        S = self.H @ self.P @ self.H.T + self.R
        K = self.P @ self.H.T @ np.linalg.inv(S)
        self.x += K @ (z - self.H @ self.x)
        self.P = (np.eye(len(self.x)) - K @ self.H) @ self.P
```

### Autoscaler as PID Controller
```python
# 매 distributed system 의 control-theory 적용
class PIDAutoscaler:
    def __init__(self, target_p99_ms=100, kp=0.05, ki=0.001, kd=0.5):
        self.target = target_p99_ms
        self.pid = PIDAntiWindup(kp, ki, kd, dt=10.0, output_clip=(2, 200))
    def desired_replicas(self, current_replicas, observed_p99_ms):
        # 매 latency 의 setpoint 위로 → 매 replicas 의 추가
        delta = self.pid.step(self.target, observed_p99_ms) * -1  # invert sign
        return max(2, round(current_replicas + delta))
```

### MPC Skeleton (cvxpy)
```python
import cvxpy as cp

def mpc_step(A, B, x0, Q, R, N=10, x_ref=None):
    nx, nu = A.shape[0], B.shape[1]
    x = cp.Variable((nx, N + 1))
    u = cp.Variable((nu, N))
    cost, cons = 0, [x[:, 0] == x0]
    x_ref = np.zeros(nx) if x_ref is None else x_ref
    for k in range(N):
        cost += cp.quad_form(x[:, k] - x_ref, Q) + cp.quad_form(u[:, k], R)
        cons += [x[:, k + 1] == A @ x[:, k] + B @ u[:, k]]
        cons += [cp.norm(u[:, k], "inf") <= 1.0]  # control limit
    cp.Problem(cp.Minimize(cost), cons).solve()
    return u.value[:, 0]  # 매 first action only — 매 receding horizon
```

### Bode Stability Margin
```python
from scipy import signal

def stability_margins(num, den):
    sys = signal.TransferFunction(num, den)
    w, mag, phase = signal.bode(sys)
    # gain margin: phase = -180° 의 frequency 에서 1/|G|
    # phase margin: |G| = 1 의 frequency 에서 phase + 180°
    return {"bode": (w, mag, phase)}
```

## 매 결정 기준
| 시스템 | Approach |
|---|---|
| SISO, slow | PID (anti-windup + clamp) |
| MIMO, linear | LQR + Kalman |
| Constraints + nonlinear | MPC |
| Plant unknown | RL or adaptive control |
| Distributed scaling | PID on metric (queue/p99) |
| Game AI steering | PD (no integral, snappy) |

**기본값**: 매 PID + anti-windup — 매 production 의 80% case.

## 🔗 Graph
- 부모: [[Cybernetics Foundations|Cybernetics]]
- 변형: [[MPC]]
- 응용: [[Robotics]]
- Adjacent: [[Reinforcement Learning]] · [[Chaos Theory in Systems]]

## 🤖 LLM 활용
**언제**: 매 PID gain 의 starting point suggestion, 매 state-space derivation, 매 controller code scaffold.
**언제 X**: 매 safety-critical (avionics/medical) 의 final certification — 매 formal verification 영역.

## ❌ 안티패턴
- **No anti-windup**: 매 saturated actuator 의 integral 의 explosion.
- **No derivative filter**: 매 measurement noise 의 D term 의 amplification.
- **Tuning without model**: 매 Ziegler-Nichols 의 marginal stability 의 risk.
- **PID for highly nonlinear**: 매 gain scheduling 또는 MPC 의 더 적합.
- **No anti-aliasing**: 매 fast dynamics 의 sample rate 의 violation.

## 🧪 검증 / 중복
- Verified (Åström _Feedback Systems_ 2.5, Ogata _Modern Control_ 5e, Kalman 1960).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — PID/LQR/Kalman/MPC + autoscaler bridge |
