MPC

MPC Controller

Advanced
Live-Beispiel starten Kostenlos · ohne Anmeldung · läuft im Browser

Der MPCController-Block ist ein zeitdiskreter modellprädiktiver Regler (Model Predictive Control) für lineare Zustandsraummodelle. Bei jedem Simulationsschritt löst der Block ein quadratisches Optimierungsproblem (QP) mit Nebenbedingungen über einen endlichen Prädiktionshorizont mittels eines Mehrotra-Prädiktor-Korrektor-Primal-Dual-Interior-Point-Verfahrens und wendet den ersten berechneten Stelleingriff u[0]u[0] an.

Im Gegensatz zu einem LQR-Regler, der eine unbeschränkte Rückführung u=−Kxu = -\mathbf{K}\mathbf{x} liefert, berücksichtigt MPC Stellgrößenbeschränkungen (umin⁡≤u≤umax⁡u_{\min} \le u \le u_{\max}) und Zustandsgrenzen (xmin⁡≤x≤xmax⁡x_{\min} \le x \le x_{\max}) direkt. Bleibt die Endkostenmatrix P\mathbf{P} leer, berechnet der Block die stabilisierende Lösung der diskreten algebraischen Riccati-Gleichung (DARE).

Mathematisches Modell

x[k+1]=Ax[k]+Bu[k]\mathbf{x}[k+1] = \mathbf{A} \mathbf{x}[k] + \mathbf{B} u[k]
min⁡u[0],…,u[N−1]∑k=0N−1(x[k]TQx[k]+Ru[k]2)+x[N]TPx[N]\min_{u[0], \dots, u[N-1]} \sum_{k=0}^{N-1} \left( \mathbf{x}[k]^T \mathbf{Q} \mathbf{x}[k] + R u[k]^2 \right) + \mathbf{x}[N]^T \mathbf{P} \mathbf{x}[N]

Unter den Randbedingungen:

  • umin⁡≤u[k]≤umax⁡u_{\min} \le u[k] \le u_{\max}
  • xmin⁡≤x[k]≤xmax⁡\mathbf{x}_{\min} \le \mathbf{x}[k] \le \mathbf{x}_{\max} (optional)

Ein- & Ausgänge

Direction ID Label Typ Status
→ In in1 x₀ number Required
→ In in2 x₁ number Optional
→ In in3 x₂ number Optional
→ In in4 x₃ number Optional
→ In in5 x₄ number Optional
→ In in6 x₅ number Optional
→ In in7 r₀ number Optional
→ In in8 r₁ number Optional
→ In in9 r₂ number Optional
→ In in10 r₃ number Optional
→ In in11 r₄ number Optional
→ In in12 r₅ number Optional
← Out out u number Output
← Out valid Valid number Output
← Out status Status number Output
← Out iterations Iterations number Output
← Out cost Cost number Output

Parameter

Parameter Label Typ Standardwert Beschreibung
nx Number of States (nₓ) number 2 Number of states in the model (1-6). Determines how many x inputs are used.
horizon Prediction Horizon (N) number 10 Number of steps to predict. Longer horizon → better performance but more computation.
A A (nₓ×nₓ) matrix 1 0.1; 0 1 State transition matrix. Rows separated by ';'. Example: '1 dt; 0 1' for double integrator with dt=0.1
B B (nₓ×1) matrix 0.005; 0.1 Input matrix. One entry per state. Example: 'dt²/2; dt' for double integrator
sampleTime Sample Time number 0.1
Q Q (nₓ×nₓ) matrix 10 0; 0 1 State cost matrix. Diagonal entries penalize state deviations. Larger = faster settling.
R R (1×1) matrix 1 Input cost weight. Larger R = gentler control effort. Must be positive.
P Terminal Cost P (nₓ×nₓ) matrix Optional terminal cost. If empty, computed automatically from DARE (infinite-horizon LQR cost-to-go).
uMin Input Min number -100 Lower bound on control input u
uMax Input Max number 100 Upper bound on control input u
xMin State Min (per state) matrix Optional lower bounds on states (1×nₓ matrix). Leave empty to disable state constraints.
xMax State Max (per state) matrix Optional upper bounds on states (1×nₓ matrix). Leave empty to disable state constraints.
slackWeight State Slack Weight number 10000 Penalty weight for soft state constraints. Values > 0 guarantee solver feasibility under disturbances. Set to 0 for hard constraints.
reference Enable Reference Tracking boolean false When enabled, ref0..ref(n-1) inputs are used for offset-free tracking. The controller regulates the deviation from reference.

Hinweise & Best Practices

  • Warm-Starting: Das optimale Regeltrajekt wird schrittweise weitergeschoben und im diskreten Zustand zwischengespeichert, wodurch die Mehrotra-QP-Konvergenz auf 2-3 Iterationen pro Schritt sinkt.
  • Weiche Beschränkungen: Zustandsgrenzen werden durch Schlupfvariablen mit quadratischer und linearer Strafe abgefedert, sodass der Regler auch bei externen Sprüngen niemals unlösbar (infeasible) wird.

Verwandte Blöcke