# Model-Predictive Control (MPC)

## Introduction

Model-Predictive Control refers to the process of using a prediction model to simulate the future response of the controlled system, and an optimizer to optimize the future control signal trajectory to optimize a cost function over the simulation, subject to constraints. When an optimal trajectory is found, the first control input from this trajectory is applied to the controlled system, a new measurement is obtained, the estimate of the current state is updated and the process is repeated. An MPC controller is thus a model-based feedback controller capable of incorporating constraints, making it a generally applicable advanced control method.

The prediction model used by the optimizer may be either linear or nonlinear, and the same applies to the state observer. The following documentation will demonstrate how to setup, tune and simulate MPC controllers.

The workflow for designing an MPC controller is roughly split up into

- Specifying the dynamics. This can be done in several ways:
- Using
`LinearMPCModel`

for standard linear MPC. - Using
`RobustMPCModel`

for linear MPC with robust loop shaping, including integral action etc. - Using a
`FunctionSystem`

that accepts a nonlinear discrete-time dynamics function with signature`(x,u,p,t) -> x⁺`

, or a continuous-time function with signature`(x,u,p,t) -> ẋ`

. Learn more under Discretization.

- Using
- Defining a state observer.
- Specifying an MPC solver.
- Defining an MPC problem containing things like
- Prediction horizon
- State and control constraints
- The dynamics and the observer

The currently defined problem types are

`LQMPCProblem`

: Linear Quadratic MPC problem. The cost is on the form $z^T Q_1 z + u^T Q_2 u$ where $z = C_z x$ are the controlled outputs.`QMPCProblem`

: Quadratic Nonlinear MPC problem. The cost is on the form $x^T Q_1 x + u^T Q_2 u$.`GenericMPCProblem`

: An MPC problem that allows the user to specify arbitrary costs and constraints, sometimes referred to as*economic MPC*. This documentation uses the terms, linear-quadratic, nonlinear-quadratic and generic MPC to refer to different variations of the MPC problem.

See docstrings and examples for further information. The following sections contains details around each step mentioned above. See the Getting started section below to navigate the topic.

## Getting started

The MPC documentation is divided into the two main sections

each of which has its own references to help you get started.

Common references for both sections are provided under MPC Details

Here are some quick links to help you navigate the documentation:

**Examples**: see examples provided under either MPC with quadratic cost functions or MPC with generic cost and constraints.**State observers/ state estimation**: see Observers.**Integral action**: see Integral action.**Discretization**: to convert continuous-time dynamics to discrete time, see Discretization**Constraints**: see Constraints and MPC with model estimated from data**Reference handling and reference preview**: see Getting started: Linear system**Disturbance modeling**: see Disturbance modeling and rejection with MPC controllers, Mixed-sensitivity $\mathcal{H}_2$ design for MPC controllers and model augmentation in RobustAndOptimalControl.jl**Tuning an MPC controller**: see Integral action and robust tuning and Mixed-sensitivity $\mathcal{H}_2$ design for MPC controllers