forked from LearningToOptimize/LearningToControlClass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobust_Control.jl
More file actions
364 lines (238 loc) · 9.41 KB
/
Robust_Control.jl
File metadata and controls
364 lines (238 loc) · 9.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
### A Pluto.jl notebook ###
# v0.20.19
using Markdown
using InteractiveUtils
# ╔═╡ 6527df00-c3c9-11f0-13e2-7d05788e7333
md"""
# Robust Control
### Ensuring stability and performance under **model uncertainty**, **unmodeled dynamics**, and **external disturbances**
In real-world systems including temperature control systems, vehicles, chemical processes, and financial models, our mathematical models are *never* exact.
Parameters drift, sensors degrade, actuators saturate, and disturbances appear in unexpected ways.
**Robust control** is the branch of control theory that explicitly accounts for these uncertainties and guarantees acceptable performance *even under worst-case conditions*.
This notebook walks through:
1. What model uncertainty means and how it is represented
2. Stochastic vs worst-case philosophies
3. LQG and stochastic robustness
4. H∞ (H-infinity) worst-case robustness
5. μ-synthesis and structured uncertainty
6. Robust trajectory optimization
7. A temperature-control example contrasting LQG and H∞ controllers
"""
# ╔═╡ efd5146a-fe33-48fb-9048-e60b9373a461
md"""
# ## 1. What Is Model Uncertainty?
Even if we write a model
$x_{k+1} = A x_k + B u_k$
we know that in reality:
- The matrix **A** is not exact
- The matrix **B** is not exact
- There are disturbances, offsets, nonlinearities, bias, noise
This leads to a more realistic model:
$x_{k+1} = (A + \Delta A)x_k + (B + \Delta B)u_k + w_k$
Where:
- **$ΔA, ΔB$**: unknown deviations from the nominal model
- **$w_k$**: disturbance or process noise
- **$v_k$**: measurement noise (if sensors are used)
The goal of robust control is to design a controller **u_k** that works for all allowed $ΔA, ΔB, w_k$.
Different robust-control frameworks differ by **how uncertainty is assumed to behave**.
"""
# ╔═╡ 3fb8940e-3ef7-43b0-90bc-38bd320120e7
md"""
# 2. Two Philosophies of Robustness
Robust control is centered around two fundamentally different interpretations of uncertainty:
---
## **2.1 Stochastic Approaches (example: LQG)**
These assume that uncertainties behave like **random variables** with known distributions.
Example assumptions:
- Process noise \($w_k \sim \mathcal{N}(0, Q)$\)
- Measurement noise \($v_k \sim \mathcal{N}(0, R)$\)
You design:
- A **Kalman filter** to optimally estimate the state from noisy measurements
- An **LQR** controller to compute optimal control inputs
Together they form the **LQG controller**.
### Strengths
- Optimal when noise statistics are correct
- Very strong performance in predictable environments
### Weaknesses
- Not robust to **worst-case disturbances**
- Sensitive when the real noise distribution deviates from assumptions
---
## **2.2 Worst-Case Approaches (example: H∞)**
Here uncertainty is treated as **an adversary** that tries to degrade performance.
Instead of assuming a distribution, we assume a **bound**:
$\|\Delta A\| \le \bar{\Delta A}, \quad \|\Delta B\| \le \bar{\Delta B}, \quad \|w_k\| \le w_{\max}$
The controller is designed so that:
- Even the **worst choice** of disturbances cannot destabilize the system
- Performance measures remain within acceptable bounds
### Strengths
- Guaranteed performance under worst conditions
- Robust to modeling errors
### Weaknesses
- More conservative
- Can sacrifice performance during nominal conditions
"""
# ╔═╡ bb01c629-ffd9-4d40-b505-0a76f779f500
md"""
# 3. Detailed Stochastic Example: LQG Modeling
We begin with a discrete-time stochastic system:
$x_{k+1} = A x_k + B u_k + w_k,
\quad w_k \sim \mathcal{N}(0, Q)$
and noisy observations:
$y_k = C x_k + v_k,
\quad v_k \sim \mathcal{N}(0, R)$
### Inside LQG:
1. **Kalman filter** produces an optimal state estimate
2. **LQR** computes
$u_k = -K \hat{x}_k$
3. LQG = LQR + Kalman filter
This is conceptually robust to *random* noise, but not robust to **bounded, structured uncertainties** in A or B.
"""
# ╔═╡ fd8746c9-42ca-4ecb-8040-17960982b533
md"""
# 4. Worst-Case Formulation: H∞ Control
### Core idea:
The controller competes against an adversarial disturbance that tries to maximize the output energy.
We want the induced L2 gain from disturbance input \($w$\) to regulated output \($z$\) to satisfy:
$\|T_{zw}\|_\infty < \gamma$
Where:
- \($T_{zw}$\) is the closed-loop transfer function
- \($\gamma$\) is the worst-case amplification bound
Smaller \($\gamma$\) = more robust to disturbances.
---
## State-space model:
$\dot{x} = A x + B_u u + B_w w$
$z = C_z x + D_{zu} u + D_{zw} w$
$y = C_y x + D_{yu} u + D_{yw} w$
The H∞ control problem finds a controller \($u(t)$\) that makes the system robust against the worst possible disturbance input \($w(t)$\).
This yields:
- Guaranteed stability under model uncertainty
- Guaranteed bound on performance degradation
"""
# ╔═╡ 35ae220e-f0e8-407c-b957-5ebf869c0c47
md"""
# ## 5. μ-Synthesis: Handling Structured Uncertainty
### Why H∞ is not enough
H∞ is great for unknown but “norm-bounded” uncertainties (i.e., “anything with size < δ”).
But many real systems have **structured uncertainty**, e.g.:
- Sensor bias
- Actuator saturation
- Temperature-dependent parameters
- Known block-diagonal uncertainty structures
- Gain drift only in one channel
H∞ cannot capture these structures.
---
## μ-synthesis solves:
$\mu < 1$
where **μ** (mu) is the structured singular value.
### What μ measures:
It measures whether structured uncertainty Δ can destabilize the system:
- If μ < 1 → stable under all allowed Δ
- If μ ≥ 1 → system might become unstable
---
## D–K Iteration (the μ-synthesis algorithm)
### Step 1: **D-step**
Compute a scaling matrix \($D$\) that upper-bounds the effect of structured uncertainty.
### Step 2: **K-step**
Design an H∞ controller using that scaling.
### Repeat:
D → K → D → K
until convergence.
μ-synthesis produces controllers that are:
- More robust than H∞
- Less conservative
- Explicitly account for structured uncertainty
"""
# ╔═╡ 82075bd8-4908-4b4e-9f7b-b616386d59a5
md"""
# 6. Robust Trajectory Optimization
Worst-case robust control can be formulated as a **min-max game**:
$\min_{u_{0:T}} \max_{\Delta A, \Delta B, w_{0:T}}
\sum_{t=0}^{T} x_t^\top Q x_t + u_t^\top R u_t$
subject to:
$x_{t+1} = (A + \Delta A)x_t + (B + \Delta B)u_t + w_t$
with bounds:
$\|\Delta A\| \le \bar{\Delta A}, \quad
\|\Delta B\| \le \bar{\Delta B}, \quad
\|w_t\| \le w_{\max}$
Interpretation:
- **Controller (minimizer)** chooses u(t) to keep performance good
- **Nature (maximizer)** chooses worst possible disturbance
This viewpoint unifies many robust control methods:
- Online robust MPC
- H∞ design
- Adversarial learning
- Distributionally-robust optimization
"""
# ╔═╡ 3e1b18e2-06b6-4299-8d58-202c99d399ef
md"""
# 7. Temperature Control Example: LQG vs H∞
We consider a scalar thermal process:
$\frac{dx}{dt} = -a(x - x_\text{set}) + b u + w_{\text{process}}$
where:
- \($x$\): system temperature
- \($x_\text{set}$\): desired temperature
- \($a > 0$\): thermal dissipation rate
- \($b$\): actuator effectiveness (heater/cooler)
- \($w_{\text{process}}$\): external heat disturbances
### Disturbance model:
$w_{\text{process}}(t) = 2\sin(0.5t) + \text{Gaussian noise}$
### Measurement:
$y = x + v_{\text{meas}}, \quad v_{\text{meas}} \sim \mathcal{N}(0, 15^2)$
---
## **LQG Controller**
- Assumes noise is Gaussian with known covariance
- Kalman filter estimates the temperature
- LQR regulates temperature
**Good performance under expected/stochastic conditions**.
---
## **H∞ Controller**
- Assumes worst-case disturbance with bounded magnitude
- Gains chosen to attenuate worst disturbances
- No assumption of sinusoid or Gaussian behavior
**More conservative, but guaranteed to perform well under extreme disturbance conditions.**
---
## Outcome Comparison:
### LQG:
- Excellent tracking when noise is reasonably small
- Vulnerable to persistent sinusoidal disturbances
- Not robust to model mismatch (e.g., actuator weakening)
### H∞:
- Very stable under persistent oscillations
- Handles sudden changes and worst-case heat pulses
- Slightly worse nominal tracking due to conservative nature
"""
# ╔═╡ bcc3e98a-d94d-4d1c-945c-11f770b12bae
md"""
---
# Final Message
This notebook provides an introduction to robust control, covering:
- Stochastic vs worst-case uncertainty
- LQG, H∞, μ-synthesis
- Structured vs unstructured uncertainty
- Min-max robust trajectory optimization
- Realistic temperature control example
"""
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.11.6"
manifest_format = "2.0"
project_hash = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
[deps]
"""
# ╔═╡ Cell order:
# ╠═6527df00-c3c9-11f0-13e2-7d05788e7333
# ╠═efd5146a-fe33-48fb-9048-e60b9373a461
# ╠═3fb8940e-3ef7-43b0-90bc-38bd320120e7
# ╠═bb01c629-ffd9-4d40-b505-0a76f779f500
# ╠═fd8746c9-42ca-4ecb-8040-17960982b533
# ╠═35ae220e-f0e8-407c-b957-5ebf869c0c47
# ╠═82075bd8-4908-4b4e-9f7b-b616386d59a5
# ╠═3e1b18e2-06b6-4299-8d58-202c99d399ef
# ╠═bcc3e98a-d94d-4d1c-945c-11f770b12bae
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002