This is a quick introduction to optimal control and nonlinear model predictive control. It also includes code generation for a NMPC controller. For a recorded webinar, follow this link: http://goo.gl/c5zFgN
Real Time Code Generation for Nonlinear Model Predictive Control
1. Real Time Code Generation for
Nonlinear Model Predictive Control
Behzad Samadi
Department of Research and Development
2. Model Predictive Control (MPC)
What is MPC?
MPC is a closed loop implementation of optimal control.
Why not use a PID?
PID controllers do not perform well for highly nonlinear systems.
To control a multi-input multi-output (MIMO) system, many
PID controllers in different loops are required.
Tuning PID controllers is not an easy task, especially when
there are state and input constraints.
3. Why MPC?
MPC can handle constraints on inputs and states.
MPC can be designed for MIMO nonlinear systems.
Tuning an MPC controller is more intuitive compared to a set
of PID controllers.
MPC is a systematic, model based approach.
There are tools for generating code for MPC controllers
automatically.
Nonlinear
System Model
MPC Controller
Code
Automatic
Code Generation
4. Example
A race driver needs to look forward! (prediction)
Minimize a cost function at each time instant depending on the
current situation (closed loop optimal control)
Optimization constraints:
Vehicle’s dynamic behavior
Limited power
No skidding
Following the road
Avoiding collision
5. MPC Applications
Chemical process control
Oil refineries
Pulp and paper
Mechatronics
Robotics
Washing machines
Automotive
Engine controllers
Aerospace
Aircraft control
Spacecraft formation and attitude control
Power generation
Computational biology
6. Nonlinear Model
Consider the following nonlinear system:
˙x(t) =f (x(t), u(t))
x(t0) =x◦
where:
x(t) is the state vector
u(t) is the input vector
7. Optimal Control Problem
minimize
u
J(x0, t0) = φ(x(tf )) +
tf
t0
L(x(τ), u(τ))dτ
subject to ˙x(t) = f (x(t), u(t))
x(t0) = x◦
gi (x(t), u(t)) = 0, for i = 1, . . . , ng
hi (x(t), u(t)) ≤ 0, for i = 1, . . . , nh
8. Barrier Method
Using a particular interior-point algorithm, the barrier method,
the inequality constraints are converted to equality constraints:
minimize
u,α
φ(x(tf )) +
tf
t0
L(x(τ), u(τ)) − rT
α(τ) dτ
subject to ˙x(t) = f (x(t), u(t))
x(t0) = x◦
gi (x(t), u(t)) = 0, for i = 1, . . . , ng
hi (x(t), u(t)) + αi (t)2
= 0, for i = 1, . . . , nh
where α(t) ∈ Rnh is a vector slack variable and the entries of
r ∈ Rnh are small positive numbers.
(Boyd and Vandenberghe 2004)
(Diehl, Ferreau, and Haverbeke 2009)
9. Discretization
Discretize the problem into N steps from t0 to tf :
minimize
u,α
φd (xN) +
N−1
k=0
L(xk, uk) − rT
αk
subject to xk+1 = fd (xk, uk)
x0 = x◦
gi (xk, uk) = 0, for i = 1, . . . , ng
hi (xk, uk) + α2
ik = 0, for i = 1, . . . , nh
where ∆τ = tf −t0
N and:
φd (xN) =
φ(x(tf ), tf )
∆τ
fd (xk, uk) = xk + f (xk, uk)∆τ
14. Model Predictive Control
This is optimal control but what is MPC?
MPC is the optimal controller in the loop:
1. Measure/estimate the current state xn.
2. Solve the optimal control problem to compute uk for
k = n, . . . , n + N − 1.
3. Return un as the value of the control input.
4. Update n.
5. Goto step 1.
MPC is implemented in real time.
15. Continuation/GMRES Method
Step 1: Compute xk and λk as functions of uk, αk and νk,
given the following equations:
xk+1 = fd (xk, uk)
x0 = xn
λk = Hx (xk, uk, αk, λk+1, νk)
λN =
∂
∂xN
φd (xN)
(Ohtsuka 2004)
17. Continuation/GMRES Method
Continuation method: Instead of solving F(x, U) = 0, find U
such that:
˙F(x, U) = AsF(x, U)
where As is a matrix with negative eigenvalues.
Now, we have:
Fx ˙x + FU
˙U = AsF(x, U)
GMRES: To compute ˙U using the following equation, which is
linear in ˙U, we use the generalized minimum residual (GMRES)
algorithm.
FU
˙U = AsF(x, U) − Fx f (x, u)
To compute U at any given time, we need to have an initial
value for U and then use the above ˙U to update it.
(Ohtsuka 2004)
19. Example
Dynamic equations:
M¨x =u1 cos(θ) + u2 cos(θ)
M¨y =u1 sin(θ) + u2 sin(θ)
I ¨θ =u1r − u2r
Variables:
Variable Type Unit
x position m
y position m
θ orientation rad
u1 force N
u2 force N
(Seguchi and Ohtsuka 2003)
21. References
Boyd, S.P., and L. Vandenberghe. 2004. Convex Optimization.
Cambridge Univ Pr.
Diehl, Moritz, Hans Joachim Ferreau, and Niels Haverbeke. 2009.
“Efficient Numerical Methods for Nonlinear MPC and Moving
Horizon Estimation.” In Nonlinear Model Predictive Control,
391–417. Springer.
Ohtsuka, Toshiyuki. 2004. “A Continuation/GMRES Method for
Fast Computation of Nonlinear Receding Horizon Control.”
Automatica 40 (4). Elsevier: 563–74.
Seguchi, Hiroaki, and Toshiyuki Ohtsuka. 2003. “Nonlinear
Receding Horizon Control of an Underactuated Hovercraft.”
International Journal of Robust and Nonlinear Control 13 (3-4).
Wiley Online Library: 381–98.