Model Predictive Control

IIA4117, Fall 2023, University of South-Eastern Norway, Campus Porsgrunn.

This is an advanced control course that is offered to the master students at the University of Southeastern Norway. The course is taught in the fall semester every year. The language used for teaching is English.

This is the official homepage of the course. In this page, the students can find the videos, lecture notes, exercises, project work description and other necessary documents and files used in the course.

Important note:  Canvas will be used only for submission of the tasks (lab journals, reports, source codes etc.) by the students.

Many of the videos are recorded live during the classroom while the teaching session is going on. The videos are recorded with the hope that it will provide a basis for the students to watch the whole lectures (multiple times) outside the teaching hours.

Instructor:  Roshan Sharma, PhD, Associate Professor

                      email: roshan.sharma@usn.no , room: B-250b

Study point: 5 credits

Exam: Written final exam (60%), project work (40%)

Information about the course, exam, project work, learning outcomes, expectations from this course etc.

 

See video:   course-structure-expectations-learning-outcomes

 

 

Download lecture notes as pdf                                 Download previous exams-solutions here                     New à Download exam solution for 2023 final exam

 

About group project work:               

Choice 1: (Download group project description here – Lab Helicopter Unit)                         Choice 2: (Download group project description here – Oil well drilling)

 

Note: For the group project work, there are two choices (two case studies). Each group must select ONLY ONE between these two choices, and work with the group project work.

Deadline for the submission of the report for the project work is 04 December, kl. 23:59. Please submit your group project report in Canvas. One report per group.

 

 

The following table lists the course syllabus and all the links to videos and other documents                                                         

Dates

Description

Links to videos

Preliminary

requirements

Install Simulink/MATLAB in your computers/laptops at home before coming to the first lecture.

The installation key for MATLAB/Simulink will be sent to your USN student email address.

Matlab-installation

See video:   course-structure-expectations-course info

 

Lecture 1:

 

 

 

 

Aug. 17

(Room A289)

Time: 09:15 – 12:00

Overview of the course                  

tree-diagram

Brief Introduction

introduction

Revision on dynamic models: Different types of dynamic models suitable for optimal control.

model-types

Linearization of nonlinear models

Cont. models + linearization

Example of dynamic model + linearization + discretization:

·        Inverted pendulum model, process description

·        Linearization of pendulum model

·        Integration/Discretization

 

Pendulum-description

 

linearization-pendulum

 

Integration-discretization

Simulation of dynamic models in Simulink:

·        Openloop simulation of nonlinear model of Inverted Pendulum using Simulink,   download simulator here

·        Real-time simulation of  nonlinear model of Inverted Pendulum using Simulink,    download simulator here (run the file IVP_real_time.slx)

·        Openloop simulation of linear model of Inverted Pendulum using Simulink,

       

Download real-time pacer files here

 

 

simulation-nonlinear-pend

 

Realtime-simulation-pend

 

 

 

simulation-linear-pend

 

LabWork 1:

 

 

Aug. 24

(Room A289)

Time: 08:30 – 12:00

From this year there will be two case studies for group project and hence two case studies for labwork 1.

Please choose ONE of them (no need to do both of them).

 

Case study 1:

Simulation of dynamic model of two degrees of freedom (2DOF) helicopter model in Simulink

(Doing this labwork 1 will help you in your project work.)

 

                 Description of the helicopter unit + mathematical model of 2DOF helicopter

                  download the pdf here

Helicopter Description

                 Explanation of the real unit by the teacher in the classroom

 

                 Labwork tasks,      download it here  for case study 1

 

Case Study 2:

Simulation of Oil well drilling

Download the labwork description here for case study 2

 

                Description of the oil well drilling process

 

Inspiration 1: Here is a video of a simulator for performing openloop simulations for the oil well drilling process for pipe connection procedure.

 

Oil-well-drilling-description

 

Openloop-simulation-demo-Drilling

 

Some useful videos you can see before starting labwork tasks

simulation-nonlinear-pend

simulation-linear-pend

Realtime-simulation-pend

Subsystem-IOports-simulink

Info: Submit a lab journal with your implementation in canvas (screen shots of your implementation + little description of your results)

Deadline: Sep 7, 2023 (kl. 23:59) for campus students,                   Sep. 14, 2023 (kl. 23:59) for online students

 

Inspiration 2:  Download simulator here   (openloop simulation of non linear helicopter model) 

   (After downloading and extracting: Run the file “openloop_simulator.slx). Point MATLAB to the extracted folder path.

Inspiration 3: Download (comparison of linear vs. nonlinear helicopter model) simulator

(Extract the zip file to a location. Point MATLAB to the extracted folder path. First run the file initialization_file.m. This loads all the needed parameters and matrices into the MATLAB workspace. Then open the file nonlinear_linear_comparison.slx”. Play around by changing the input voltages. Please also read the comments written in the main simulink file.

 

Note: These simulators were made in Simulink/MATLAB 2017 version. It might not work with other versions of MATLAB since they are compiled versions.

 

For those of you who could not open the simulator because of different MATLAB version:

·         This is how the implementation looks like. See here.

·         This is how the comparison of the linear vs nonlinear model looks like. See here.

·         This is the control signals plots. See here.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Lecture 2:

 

 

 

 

 

Aug. 31

(Room A289)

Time: 08:30 – 12:00

Introduction: the connection

introduction

Introduction to mathematical optimization, different types and their general formulation (objective functions, constraints and bounds).

optimization-types

Let’s first look into static optimization to get us started.

Example: Optimal operation of oil refinery.

·        Oil refinery, process description

·        QP problem formulation

·        Converting to standard QP form/structure

 

 

refinery-description

 

refinery-Problem Formulation

 

Refinery-standarQP

Solving oil refinery QP problem using qpOASES:

a)     Pre-requirements:

·        Installation of solver qpOASES,     download  qpOASES here

·        Installation of C++ compiler (for older MATLAB version),   download tdm64-gcc-compiler

·        From 2017b and newer version of MATLAB, please download this compiler here

(Right click on the download link and choose ‘save link as’. Save it to a desired location in your PC. Just double click it after downloading and follow the instructions on the screen)

·        Testing/Compilation of qpOASES

 

b)     Solving refinery problem in Simulink

 

 

 

 

qpOASES-installation

 

tdm64-gcc-installation (older version)

 

 

 

 

 

compiling-qpOASES

 

 

refinery-qpOASES

Dynamic optimal control and performance index, concept of prediction horizon, Linear Quadratic (LQ) optimal control

dynamic-optimal-control

Exercise 1: static optimization (to help you learn how to use qpOASES in Simulink)

                                        Download exercise 1 here

 

Info: Submit a lab journal with your implementation in canvas (screen shots of your implementation + little description of your results)

Deadline: Sep. 14, 2023 (kl. 23:59) for campus students,                   Sep. 21, 2023 (kl. 23:59) for online students

 

Lecture 3:

 

Sep. 7

(Room A289)

Time: 08:30 – 12:00

Useful matrices and their structure, kronecker product

Useful-matrices-structure

 

Efficient formulation of LQ optimal control problem: using Kronecker product formulation.

            

Handling bounds and inequality constraints

Classroom videos

 

Part 1

 

Part 2

 

Part 3

Videos with software

 

Formulation: H & c

 

Formulation: Ae, be

 

Handling bounds and inequality constraints

 

LQ and qpOASES

 

Data extraction from z vector

Example: LQ optimal control of inverted pendulum

                 Problem formulation with linear pendulum model

                 Efficient transformation into standard QP problem

                 Solution using qpOASES in Simulink

Download the simulator here

(After downloading and extracting: Run the file “LQ_IVP_simulink.slx”). Point MATLAB to the extracted folder path.

Please see lecture notes Chapter 3.5. It also contains codes. Don’t forget to read the comments in between the codes for more clarification.

 

(Play around with simulator)

Exercise 2: Implement your own LQ optimal controller for the linear inverted pendulum model in Simulink

Download exercise 2 here      

Info: Submit a lab journal with your implementation in canvas (screen shots of your implementation + little description of your results)

Deadline: Sep. 21, 2023 (kl. 23:59) for campus students,                   Sept. 28, 2023 (kl. 23:59) for online students

   

 

  

Lecture 4:

 

Sep. 14

(Room A289)

Time: 08:30 – 12:00

 

The connection

Connection

Predictive control:

·        Introduction (optimal control problem vs. predictive control, the difference)

·        The sliding horizon strategy (introduce the feedback property)

(sliding horizon + optimal control problem = model predictive control)

 

Introduction

Sliding-horizon

Example of a racing car.

Car-racing-example

Concept about: Warm Start, Parallel-pool, shrinking horizon strategy

Warm start

State feedback MPC and its algorithm.

State-feedback-MPC

 

 

Example of linear MPC in Simulink:

Apply sliding horizon strategy to LQ optimal control of inverted pendulum to make linear MPC

 

Download the simulink simulator here  

(Extract the zip file to a desired location. Point MATLAB to the extracted folder path. First run the file initialization_script.m. This loads all the needed parameters and matrices into the MATLAB workspace. Then open the file linear_MPC_IVP.slx”. Play around by changing the setpoint for x2 (the cart position). Please also read the comments written in the main simulink file.

linear-MPC-pendulum-example-in-Simulink

Linear MPC in scripting language (e.g. in MATLAB, but same idea also applies for Python or Julia):

Linear MPC in MATLAB + Execution time needed to run linear MPC for inverted pendulum in MATLAB (for comparison later on in lecture 5)

linear-MPC-pendulum-example-in-MATLAB+execution-time

Exercise 3: (no submission required):  By modifying your implementation from exercise 2 (LQ optimal control), make a linear MPC for controlling the inverted pendulum?

(to help you learn how to implement sliding horizon strategy).

 

 

Lecture 5:

 

 

Sep. 21

(Room A289)

Time: 08:30 – 12:00

 

Reduction of the size of the LQ optimal control problem

Introduction

a)     Lagrangian method

Lagrangian method

 

a)     QR factorization

QR-facto-part1

QR-facto-part2

b)     Elimination of unknowns by grouping of control inputs.

control-input-grouping

MPC with reduced size of the optimal control problem:

Example: Linear MPC with reduced size of optimal control  for inverted pendulum 

(comparison of the execution time needed to run the MPC)

 

reduced-MPC-speed-comparison

Feasibility, hard constraints vs. soft constraints

Constraint relaxation for ensuring feasibility: Slack variables and modified LQ optimal control problem

feasibiltiy-constraint-relaxation

Exercise: Continue working with exercise 3

 

Lecture 6:

 

 

Sep. 28

(Room A289)

Time: 08:30 – 12:00

Formation of student groups

 

The connection: Why should we estimate the states?

Why-estimate-states?

Output feedback MPC, block diagram , algorithm for output feedback MPC

Output-feedback-MPC

State Estimation: Introduction, example

State-estimation-intro

Apriori/ Aposteriori estimates

Apriori-aposteriori-estimates

Kalman Filter Algorithm

Kalman-filter-algorithm

Combined State and disturbance estimation (by augmentation)

State-Dist-Estimation

Examples and demonstration: Estimation of states of the helicopter process (simulator)

                                                         Estimation of states of the helicopter process (real unit)

Download linear Kalman filter simulator for helicopter (unzip and open the file  linear_Kalman_heli.slx , run this file)

Download Unscented Kalman filter simulator for helicopter just so that you can play around (unzip and open the file  UKF_heli.slx , run this file). For your project work, you can design a linear Kalman filter yourself.

Do you see the difference between the behaviors of these two filters/estimators?

Remember: In this course, we do not learn the theories about Kalman filters in detail. It is assumed that you know at least about the linear Kalman filter from previous courses.

State-estimation-Simulator

State-estimation-RealProcess

Exercise (no submission required): Connecting the real helicopter units to laptops using Simulink.

Download the NI-DAQ-mx and install it on your laptops. If you already have NI-DAQ-mx installed on your laptops (say for example with LabVIEW), then you don’t need to install it again. (optional for year 2023)

 

Lecture 7:

 

Oct. 5

(Room A289)

Time: 08:30 – 12:00

Steady state offset, model mismatch, uncertainties, unaccounted disturbances

(Lets apply a linear MPC to the nonlinear model of the plant and see what happens)

Offset-model-mismatch-uncertainty

 

Integral action, Offset free MPC:

-         Integral action with disturbance model augmentation

-         Delta u formulation for integral action

-         MPC + I control, adding output integrators

Integral-action-dist-model-aug

 

Delta-u-formulation

 

MPC + I control

Features of MPC

Feasibility, Stability, Robustness and Implementation

Features-challenges-MPC

 

Improving Stability: Infinite horizon optimal control, terminal cost, terminal constraints.

Stability-infinite-horizon

Handling computational time delay:

    - As input-output delay

    - Sampled-data MPC

Computational-delay-as-io-delay

 

Sampled-data-MPC

Control hierarchy and commercial predictive controllers

Hierarchy-commercial-MPC

Exercise:  Continue working with your group project    (Download group project description here)

 

 

Nonlinear MPC (seen as a nonlinear programming/optimization control problem):

Nonlinear optimization: Introduction, nonlinear objectives and constraints

Feasible solution, feasible region (example to plot feasible region), global/local solutions

 

Intro-feasible-region Local-global solutions

 

Convexity and conditions for optimality

Convexity-optimality-conds

 

Active/Inactive constraints, KKT conditions

KKT-conditions

 

Solvers for nonlinear optimization: MATLAB optimization toolbox (fmincon solver), OPTI toolbox (open source)

Algorithms for solving NLPs: Sequential Quadratic Programming (SQP), GRG

Source code for the basic general example of a continuous-circulation dryer. This code shows the basic use of fmincon solver. Unzip the file to a desired location and run the file dryer_main.m file.

fmincon-syntax

 

algorithms-for-NLP

Lecture 8:

 

 

Oct. 12

(Room A289)

Time: 08:30 – 12:00

Note: The source code explained in the videos in this section are little bit difficult to read due to screen resolution. I suggest that you print out the source code and look at it while watching the videos for this section.

At first:

Formulation of nonlinear optimal control problem

Simple Example: Nonlinear optimal control of the pressure at the bottom of a tank (analogous to drilling operation)

Download the MATLAB source codes here  for nonlinear optimal control problem (unzip and run the file main_file_tankPressure_NL_control.m)

 

Secondly:  Nonlinear Optimal control problem +  sliding horizon strategy = Nonlinear MPC

Use the sliding/receeding horizon strategy to the nonlinear optimal control problem to make a nonlinear MPC.

Simple Example continued: Nonlinear Model Predictive control of the pressure at the bottom of the tank ( i.e. application of sliding horizon strategy for the simple example above)

Download the MATALB source code here for nonlinear MPC (unzip and run the file main_file_tankPressure_MPC.m)

 

 

 

 

NL-optimal-control-formulation

 

NL-optimal-control-example-fmincon-tank-pressure

 

 

 

 

 

 

 

Nonlinear-MPC-example

 

Improving speed of nonlinear MPC by control input grouping

Download the MATALB source code here for nonlinear MPC with control input grouping (unzip and run the file main_file_tankPressure_MPC_grouping.m)

See the lecture notes

Section 8.8.2

 

Exercise (no submission required):  By modifying the NMPC code for the tank example, design a nonlinear MPC for disturbance rejection. Change the inflow in your simulation (i.e. introduce disturbance). Is the controller able to reject the disturbance?

 

Lecture 9:

 

Oct. 19

(Room A289)

Time: 08:30 – 12:00

 

Introduction to multi-objective optimization (MOO) problems       

multi-objective-opt-intro

Common methods used for solving MOO.

·        Weighted sum method                          

 

weighted-sum

·        Epsilon-constraint method                      

epsilon-constraint

·        Goal attainment method                          

goal-attainment

·        Lexicographic or hierarchical method     

hierarchical-lexico

·        Introduction to evolutionary algorithms 

evolutionary-algo-intro

Application of MOO

 

·        Water flooded reservoir planning

reservoir-planning

·        Olive oil extraction

olive-oil-ext-example

Basic introduction to Utopia tracking MPC with application to thin oil-rim reservoir

utopia-mpc-intro

Exercise:  Continue working with your group project

 

Oct. 26

Continue working with your group project

 

Deadline for the submission of report for group project work is 04 December, kl. 23:59. Please submit your group project report in Canvas. One report per group should be submitted.

 

Nov. 2

Continue working with your group project

 

Nov. 9

Continue working with your group project

 

Nov. 16

Continue working with your group project

 

Nov. 23

Continue working with your group project

(If any group wants to show the demonstration of applying linear MPC to real lab helicopter units to me, please do it this day at kl. 09:30, room A-289). Send me email if your group plans to do so.