Sesi 04 dari 16

Model Reference
Adaptive Control (MRAC)

Kontroller yang "mengejar" perilaku model ideal — belajar dari kesalahan dan menyesuaikan diri secara terus-menerus, seperti murid yang mengikuti mentor terbaiknya.

Arsitektur MRAC MIT Rule Lyapunov Stability Desain Orde-1 Desain Orde-2 Simulasi Suhu
🏛️
Topik 4.1
Arsitektur MRAC
🎓 Analogi — Magang dengan Mentor Terbaik

Bayangkan magang di perusahaan kelas dunia. Ada Mentor (Reference Model) — pakar yang selalu melakukan pekerjaan dengan sempurna. Kamu sebagai magang (Plant) berusaha meniru mentor. Ada juga supervisor (Adaptive Law) yang terus membandingkan kerjamu dengan mentor dan memberi saran koreksi. Semakin lama, kerjamu semakin mirip mentor!

Arsitektur MRAC — 4 Komponen Utama
📐 Reference Model

Mendefinisikan perilaku ideal yang diinginkan. Output-nya (y_m) adalah "target" yang harus dikejar plant.

🏭 Plant (Sistem Nyata)

Sistem yang dikontrol. Parameter-nya tidak diketahui persis atau berubah. Output-nya (y_p) dibandingkan dengan y_m.

🎛️ Adaptive Controller

Menghitung sinyal kontrol u(t) menggunakan parameter θ yang terus di-update. Struktur kontroller tetap, nilainya yang berubah.

🔄 Adaptation Law

Aturan update parameter θ berdasarkan error e = y_m − y_p. Inilah "jantung" MRAC.

↑ error e = y_m − y_p mengalir ke Adaptation Law → update θ → update Controller ↑
📐 Skema MRAC — Persamaan Dasar
Reference model : ẋ_m = A_m·x_m + B_m·r(t)
Plant : ẋ_p = A·x_p + B·u(t)  (A,B tidak diketahui persis)
Error : e(t) = y_m(t) − y_p(t)
Control signal : u(t) = θ₁·r(t) + θ₂·y_p(t)
Adaptation law : θ̇ = −γ · e · φ   (MIT Rule)
🧪
Topik 4.2
MIT Rule — Hukum Adaptasi Pertama
🎯 Analogi — Koreksi Bidikan Secara Gradual

Atlet panah yang baru latihan tidak langsung bisa menembak sempurna. Setelah setiap tembakan, dia melihat berapa jauh meleset (error), lalu mengkoreksi bidikan proporsional dengan kesalahan. Jangan koreksi terlalu besar (overshoot), jangan terlalu kecil (lambat). MIT Rule bekerja persis begini — koreksi parameter proporsional dengan error!

MIT Rule dikembangkan di MIT (1958) untuk autopilot pesawat. Idenya sederhana: minimasi cost function J = ½e² menggunakan gradient descent.

📐 Derivasi MIT Rule
Cost function : J(θ) = ½ · e²(t)
Gradient descent: dθ/dt = −γ · ∂J/∂θ
                   = −γ · e · ∂e/∂θ

Sensitivitas : ∂e/∂θ = ∂y_m/∂θ − ∂y_p/∂θ
                   ≈ −∂y_p/∂θ = −φ (vektor regresi)

MIT Rule: dθ/dt = −γ · e(t) · φ(t)
ParameterArtiPengaruh
γ (gamma)Learning rate / adaptation gainBesar γ = adaptasi cepat tapi bisa osilasi. Kecil γ = lambat tapi stabil.
e(t)Error: y_m − y_pSemakin besar error, semakin agresif update
φ(t)Regressor vector (sinyal input/output)Arah update parameter

⚠️ Kelemahan MIT Rule

MIT Rule tidak memiliki jaminan stabilitas formal. Jika γ terlalu besar atau ada gangguan besar, sistem bisa tidak stabil. Solusinya: gunakan Lyapunov-based adaptation law (topik berikutnya).

🛡️
Topik 4.3
Lyapunov-Based Adaptation Law
⚡ Analogi — Energi Bola yang Menggelinding

Bayangkan bola di dalam mangkuk. Bola punya energi (ketinggian). Jika energinya selalu berkurang seiring waktu, bola pasti akan berhenti di titik terendah (stabil). Lyapunov menggunakan ide ini: definisikan "energi" sistem (Lyapunov function V), lalu buktikan bahwa V selalu menurun (V̇ ≤ 0). Jika terbukti, sistem pasti stabil!

📐 Lyapunov Stability untuk MRAC
Definisikan Lyapunov function:
V(e, θ̃) = ½·e² + (1/2γ)·θ̃²  θ̃ = θ − θ* (parameter error)

Syarat stabilitas: V̇ ≤ 0

V̇ = e·ė + (1/γ)·θ̃·θ̃̇
= e·(A_m·e + B_m·θ̃·φ) + (1/γ)·θ̃·θ̇

Pilih adaptation law: θ̇ = −γ·e·B_m·φ

Maka: V̇ = e·A_m·e ≤ 0   ✅ STABIL!

✅ Perbedaan MIT Rule vs Lyapunov-based

  • MIT Rule: Intuitif, sederhana, tidak ada jaminan stabilitas formal
  • Lyapunov-based: Ada bukti matematis stabilitas, lebih kompleks tapi aman untuk infrastruktur kritis
  • Untuk aplikasi safety-critical (pembangkit listrik, reaktor), selalu gunakan Lyapunov-based!
1️⃣
Topik 4.4
Desain MRAC untuk Sistem Orde-1

Sistem paling sederhana untuk memulai: plant orde-1 dengan satu parameter yang tidak diketahui.

📐 MRAC Orde-1: Kontrol Kecepatan Pompa
Plant : ẏ_p = −a·y_p + b·u   (a,b tidak diketahui)
Ref Model: ẏ_m = −a_m·y_m + b_m·r

Controller: u = θ₁·r + θ₂·y_p

Error : e = y_m − y_p

Update law (Lyapunov):
θ̇₁ = γ₁ · e · r
θ̇₂ = γ₂ · e · y_p
🌡️
Topik 4.5
Simulasi MRAC: Kontrol Suhu Instalasi Kritis
🏭 Skenario: Kontrol Suhu Ruang Server BSSN

Ruang server harus dijaga di 20°C. Parameter sistem (thermal mass, insulasi) berubah karena renovasi gedung. MRAC harus menyesuaikan diri secara otomatis tanpa perlu rekonfigurasi manual.

Python 🐍 — mrac_temperature.py
import numpy as np
import matplotlib.pyplot as plt

# ==========================================
# MRAC: KONTROL SUHU RUANG SERVER
# ==========================================

dt = 0.5      # time step (detik)
T  = 500      # durasi simulasi
t  = np.arange(0, T, dt)
N  = len(t)

# --- REFERENCE MODEL: sistem ideal orde-1 ---
a_m  = 0.5    # parameter model referensi
b_m  = 0.5
r    = 20.0   # setpoint suhu 20°C
y_m  = np.zeros(N); y_m[0] = 28.0   # suhu awal 28°C

for k in range(1, N):
    dy_m = -a_m * y_m[k-1] + b_m * r
    y_m[k] = y_m[k-1] + dy_m * dt

# --- PLANT: sistem nyata dengan parameter berubah ---
# Awalnya: a=0.4, b=0.3. Setelah renovasi (t=200): a=0.6, b=0.5
a_plant = np.where(t < 200, 0.4, 0.6)
b_plant = np.where(t < 200, 0.3, 0.5)

# --- MRAC PARAMETERS ---
gamma1 = 0.04   # learning rate untuk theta1
gamma2 = 0.04   # learning rate untuk theta2

y_p  = np.zeros(N); y_p[0] = 28.0
th1  = np.zeros(N); th1[0] = 1.0   # inisialisasi theta1
th2  = np.zeros(N); th2[0] = 0.0   # inisialisasi theta2
u_mrac = np.zeros(N)
e_arr  = np.zeros(N)

for k in range(1, N):
    # Hitung sinyal kontrol
    u_mrac[k] = th1[k-1] * r + th2[k-1] * y_p[k-1]
    
    # Update plant
    noise = 0.1 * np.random.randn()  # noise sensor
    dy_p  = -a_plant[k] * y_p[k-1] + b_plant[k] * u_mrac[k] + noise
    y_p[k] = np.clip(y_p[k-1] + dy_p * dt, 15, 40)
    
    # Hitung error
    e = y_m[k] - y_p[k]
    e_arr[k] = e
    
    # Update parameter (Lyapunov-based)
    th1[k] = th1[k-1] + gamma1 * e * r * dt
    th2[k] = th2[k-1] + gamma2 * e * y_p[k-1] * dt
    
    # Saturasi parameter (mencegah drift)
    th1[k] = np.clip(th1[k], 0.1, 5.0)
    th2[k] = np.clip(th2[k], -3.0, 3.0)

# --- PLOT ---
fig, axes = plt.subplots(3, 1, figsize=(12, 9))

axes[0].plot(t, y_m, 'b--', lw=2, label='Reference Model (ideal)')
axes[0].plot(t, y_p, 'orange', lw=1.5, label='Plant (sistem nyata)')
axes[0].axhline(20, color='lime', ls=':', label='Setpoint 20°C')
axes[0].axvline(200, color='red', ls='--', alpha=0.7, label='Renovasi gedung')
axes[0].set_ylabel('Suhu (°C)')
axes[0].set_title('MRAC: Kontrol Suhu Ruang Server')
axes[0].legend(fontsize=9); axes[0].grid(alpha=0.3)

axes[1].plot(t, th1, 'cyan', lw=1.5, label='θ₁ (feedforward gain)')
axes[1].plot(t, th2, 'magenta', lw=1.5, label='θ₂ (feedback gain)')
axes[1].axvline(200, color='red', ls='--', alpha=0.7)
axes[1].set_ylabel('Nilai Parameter')
axes[1].set_title('Evolusi Parameter MRAC (Adaptasi Otomatis)')
axes[1].legend(); axes[1].grid(alpha=0.3)

axes[2].plot(t, np.abs(e_arr), 'tomato', lw=1.5, label='|Error| (°C)')
axes[2].axvline(200, color='red', ls='--', alpha=0.7)
axes[2].fill_between(t, 0, np.abs(e_arr), alpha=0.2, color='tomato')
axes[2].set_xlabel('Waktu (detik)'); axes[2].set_ylabel('|Error| (°C)')
axes[2].set_title('Error Tracking: Semakin Kecil = Semakin Baik')
axes[2].legend(); axes[2].grid(alpha=0.3)

plt.tight_layout(); plt.show()

print(f"\n📊 Ringkasan:")
print(f"Error rata-rata sebelum renovasi: {np.mean(np.abs(e_arr[20:int(200/dt)])):.3f}°C")
print(f"Error rata-rata setelah adaptasi : {np.mean(np.abs(e_arr[int(300/dt):])):.3f}°C")
print(f"Parameter akhir: θ₁={th1[-1]:.3f}, θ₂={th2[-1]:.3f}")

📊 Apa yang Terjadi dalam Simulasi?

  • Fase 1 (t = 0–200): MRAC belajar dan konvergen — error berkurang, parameter mencapai nilai optimal
  • Renovasi (t = 200): Parameter sistem berubah drastis. Tanpa adaptif, sistem akan gagal!
  • Fase 2 (t = 200–500): MRAC re-adapts otomatis — θ₁ dan θ₂ bergeser ke nilai baru, error kembali kecil
  • Inilah kekuatan MRAC: tanpa campur tangan manusia, sistem menyesuaikan diri sendiri!

🧠 Kuis Pemahaman Sesi 4

1. Dalam MRAC, apa fungsi "Reference Model"?

2. Mengapa Lyapunov-based adaptation law lebih disukai dibanding MIT Rule untuk infrastruktur kritis?

3. Jika learning rate γ terlalu besar pada MRAC, apa yang akan terjadi?