Discrete-Time MPC


DT_MPC_notes

1. Introduction

1.1 Background Info

This is a simple Single-Input Single-Output (SISO) feedback control system

sys

with the parameters

  • r(t) Reference Signal

  • u(t) Control Input Signal

  • y(t) Output Signal

  • err(t) Defined Error Function

We want the Output Signal y(t) to approach the Reference Signal r(t)

err_graph

What can we do to optimize this system?

  • In terms of Output Result

    The smaller the Je is, the better the performance

    Je=0t[err(τ)]2dτ
  • In terms of Energy Consumption

    The smaller the Ju is, the less energy consumed in control

    Ju=0t[u(τ)]2dτ
  • If we want to optimize both

    We could minimize the following Optimization Objective under the constraints you set

    Notice that q and r are weights of regulation

    J=0t{q[err(τ)]2+r[u(τ)]2}dτ

We could extend function to express the optimization objective of a Multi-Input Multi-Output (MIMO) system

  • State-Space Representation of MIMO System

    X˙(t)=AX(t)+BU(t)Y(t)=CX(t)

    with the parameters

    • X(t) State Matrix

    • U(t) Control Input Matrix

    • Y(t) Output Matrix

    • A,B,C Weight Matrices

  • Optimization Objective in Matrix Form

    J=0t(ETQE+UTRU)dτ

    with the parameters

    • E(t) Error Matrix

    • U(t) Control Input Matrix

    • Q,R Diagonal Weight Matrices

 

 

1.2 What is Model Predictive Control

Also known as Receding Horizon Control

Using models to predict the performance of system within a period of time in the future for optimal control

Generally, MPC uses discrete state-space expressions

  • System state at time step (k+1) depends on state and input at time step k

    Xk+1=AXk+BUk

[Workflow at Time Step k]

mpc workflow demo

  • Step 1

    Measure / Estimate current system state

  • Step 2

    Predict based on what we have at time step k

    • Plan the moves

      u(k|k),u(k+1|k),u(k+2|k),...,u(k+p|k) Control Horizon

    • Predict the state

      x(k|k),x(k+1|k),x(k+2|k),...,x(k+p|k) Predictive Horizon

    • Optimization Objective

      (Of course, add some constraints if you want to)

      (eq.1)J=i=kp1(EiTQEi+UiTRUi)+EpTFEp

      with one extra term

      • (EpTFEp) Terminal Cost

      • F Diagonal Weight Matrix

      • E Error Matrix

        E=YR

  • Step 3

    Only Apply u(k|k)

    Then move one step further

 

 

 

2. Basic Mathematical Model

A common solution to optimize MPC is Quadratic Programming (QP), the goal is to write the problem in the form of QP

2.1 Quadratic Programming

Basic form of quatratic program is below

minZTQZ+CZ

where ZRn, diagonal weight matrix QRn×n, weight matrix CR1×n

  • ZTQZ Quadratic Term

  • CZ Linear Term

For the Quadratic Term

Q=[q1000q2000qn]Z=[z1z2zn]

Then we could expand it as below

ZTQZ=q1z12+q2z22++qnzn2

Minimizing this equation is a least square problem and we've had a lot of mature solutions with MATLAB or Python...

  • Active Set qpOASES

  • Augmented Lagrangian OSQP

  • Interior Point CVXOPT

  • Generic Quadratic Programming Solver Library

    qpsolvers

Yeah, this is good ()

 

 

2.2 Basic Optimization Objective

Given the following MIMO System

(eq.2)x(k+1)=Ax(k)+Bu(k)(eq.3)y=x

The state matrix x(k) and control input matrix u(k) are defined as

x(k)=[x1(k)x2(k)xn(k)]Rnu(k)=[u1(k)u2(k)un(k)]Rn

For this system, at time step k, we organize the planned moves and predicted states as below (see 1.2 - Step 2)

Assume having N future time steps

(eq.4)Xk=[x(k|k)x(k+1|k)x(k+2|k)x(k+(N1)|k)]RN×nUk=[u(k|k)u(k+1|k)u(k+2|k)u(k+(N1)|k)]RN×n

Assume Reference Signal R=[0], then according to (eq.3) the error matrix err is

err=yr=x[0]=x

With the above information, the Optimization Objective Function (see eq.1) is defined as below

(eq.5)J(k)=i=0N1[x(k+i|k)TQx(k+i|k)Weighted Sum of Error+u(k+i|k)TRu(k+i|k)Weighted Sum of Input]+x(k+N|k)TFx(k+N|k)Weighted Sum of Terminal Cost

Since u(k|k) is what we want to find (see 1.2 - Step 3), the controller should be about u rather than x

So we need to somehow get rid of it

 

 

2.3 Equation of Predicted Future States

We use eq.2 to expand all future states predicted at time step k

(Assume xk is the initial condition at time step k)

(eq.6-1)x(k|k)=xkx(k+1|k)=Ax(k|k)+Bu(k|k)(eq.6-2)=Axk+Bu(k|k)x(k+2|k)=Ax(k+1|k)+Bu(k+1|k)=A[Axk+Bu(k|k)]+Bu(k+1|k)(eq.6-3)=A2xk+ABu(k|k)+Bu(k+1|k)x(k+N1|k)=Ax(k+(N1)|k)+Bu(k+(N1)|k)(eq.6-4)=ANxk+AN1Bu(k|k)++Bu(k+(N1)|k)

Rewrite the above expansion into matrix form using eq.4 definitions

[x(k|k)x(k+1|k)x(k+2|k)x(k+(N1)|k)]=[IAA2AN]Mxk+[0000B000ABB00AN1BAN2BAN3BB]C[u(k|k)u(k+1|k)u(k+2|k)u(k+(N1)|k)](eq.7)Xk=Mxk+CUk

 

 

2.4 Reduced Optimization Objective

We can rewrite all terms in eq.5 into matrix form

  • Weighted Sum of Error & Weighted Sum of Terminal Cost

    i=0N1x(k+i|k)TQx(k+i|k)Weighted Sum of Errorx(k+N|k)TFx(k+N|k)Weighted Sum of Terminal Cost

    We can rewrite the above two terms together into Matrix Form, again, using eq.4 definitions

    i=0N1x(k+i|k)TQx(k+i|k)+x(k+N|k)TFx(k+N|k)=[x(k|k)x(k+1|k)x(k+2|k)x(k+(N1)|k)]]T[Q0000Q0000Q0000F]Q¯[x(k|k)x(k+1|k)x(k+2|k)x(k+(N1)|k)](eq.8)=XkTQ¯Xk
  • Weighted Sum of Input

    i=0N1u(k+i|k)TRu(k+i|k)Weighted Sum of Input=[u(k|k)u(k+1|k)u(k+2|k)u(k+(N1)|k)]T[R0000R0000R0000R]R¯[u(k|k)u(k+1|k)u(k+2|k)u(k+(N1)|k)](eq.9)=UkTR¯Uk
  • Reduced Optimization Objective

    Plugin eq.7 eq.8 & eq.9 back to eq.5

    J(k)=XkTQ¯Xk+UkTR¯Uk=(Mxk+CUk)TQ¯(Mxk+CUk)+UkTR¯Uk=(xkTMT+UkTCT)Q¯(Mxk+CUk)+UkTR¯Uk=xkTMTQ¯Mxk+{xkTMTQ¯CUk+UkTCTQ¯Mxk}+UkTCTQ¯CUk+UkTR¯Uk=xkT(MTQ¯MG)xk+2xkT(MTQ¯CE)Uk+UkT(CTQ¯C+R¯)HUk

    [Final Form] Optimization Objective with only Uk Terms

    You'll also find that eq.10 perfectly fits the basic form of Quadratic Program in 2.1

    (eq.10)J(k)=xkTGxkConstant Term+2xkTEUkLinear Term+UkTHUkQuadratic Term