ModelPredictiveController

ModelPredictiveController[sspec,cost,cons]

computes the model predictive controller for the system specification sspec that minimizes the cost function cost and satisfies the constraints cons.

ModelPredictiveController[,"prop"]

returns the value of the property "prop".

Details

  • Model predictive control is also known as MPC.
  • A model predictive controller is computed by minimizing a cost function of state and control input over a finite horizon while allowing for constraints on both inputs and states. These constraints are often important to guarantee that the controller can be implemented safely.
  • The resulting controller has a simple piecewise affine form , where is the feedback control input and is the state of the system. These can easily be deployed in microcontrollers and used for fast processes.
  • A regulator aims to maintain the system at an equilibrium position despite disturbances pushing it away. Typical examples include maintaining an inverted pendulum in its upright position or maintaining an aircraft in level flight.
  • The MPC regulator is specified as the feedback that minimizes the cost subject to the system dynamics in sspec and constraints cons. The cost becomes small when both state and feedback control input become small.
  • 1-norm, weighted integral absolute error (IAE)
    squared 2-norm, weighted integral squared error (ISE) or weighted "energy"
    -norm, weighted peak value
  • The cost is specified in the cost Association with the following keys:
  • η"Horizon"integer time horizon
    q"StateWeight"matrix cost on states
    r"InputWeight"matrix cost on inputs
    p"StateInputWeight"matrix cost on cross-coupled states and inputs
    m"Norm"1, 2 or
  • A tracker aims to track reference signals despite disturbances . Typical examples include a cruise control system for a car or path tracking for a robot.
  • The MPC tracker is specified as the feedback that minimizes a cost subject to the system dynamics in sspec and constraints cons. The cost becomes small when both predicted error and the incremental feedback control input become small.
  • 1-norm, weighted integral absolute error (IAE)
    squared 2-norm, weighted integral squared error (ISE) or weighted "energy"
    -norm, weighted peak value
  • The terms in the cost function expressions are the following:
  • η"Horizon"integer time horizon
    qe"ErrorWeight"matrix cost on errors
    r_Delta"InputIncrementWeight"matrix cost on input increments
    peΔ"ErrorInputIncrementWeight"matrix cost on cross coupled errors and input increments
    m"Norm"1, 2 or
  • The constraints cons for both the regulator and tracker problems are formulated in terms of the state variables x, input variables u and output variables y. These can be defined using StateSpaceModel[{a,b,c,d},x,u,y,].
  • Constraints that hold for a particular time instant where :
  • xmin<=xi[k]<=xmaxconstraint on the value at time
    Δxmin<=xi[k2]-xi[k1]<=Δxmaxconstraint on the increment from time to time
  • Constraints that hold for all time instants k where :
  • xmin<=xi<=xmaxconstraint on the value for all k
    min<=α1.x1++αn.xn+β<=maxconstraint on a linear combination for all k
    xminxxmaxconstraint on all the values for all k
  • The weight matrices , and can be specified as follows:
  • qconstant weights {q,,q,q}
    {{q},qη}varying end weight {q,,q,qη}
    {q0,q1,,qη}varying weights {q0,q1,,qη}
  • ModelPredictiveController works for discrete-time linear systems that can be specified using StateSpaceModel[,SamplingPeriodτ].
  • The system specification sspec can have the following forms:
  • StateSpaceModel[]linear control input and linear state
    AffineStateSpaceModel[]linear control input and nonlinear state
    NonlinearStateSpaceModel[]nonlinear control input and nonlinear state
    SystemModel[]general system model
    <||>detailed system specification given as an Association
  • The detailed system specification can have the following keys:
  • "InputModel"sysany one of the models
    "FeedbackInputs"Allthe feedback inputs uf
    "TrackedOutputs"Nonethe tracked outputs yref
  • The feedback inputs can have the following forms:
  • {num1,,numn}numbered inputs numi used by StateSpaceModel, AffineStateSpaceModel and NonlinearStateSpaceModel
    {name1,,namen}named inputs namei used by SystemModel
    Alluses all inputs
  • ModelPredictiveController returns a SystemsModelControllerData object cd that can be used to extract additional properties using the form cd["prop"].
  • ModelPredictiveController[,"prop"] can be used to directly get the value of cd["prop"].
  • Closed-loop system properties:
  • "ClosedLoopPoles"poles of the linearized "ClosedLoopSystem"
    "ClosedLoopSystem"system csys
    {"ClosedLoopSystem", cspec}detailed control over the form of the closed-loop system
    "ControllerModel"model cm
    "FeedbackGains"gain matrix κ or its equivalent
    "FeedbackGainsModel"model gm
    "FeedbackRegions"regions from which the feedback is feasible
    "QuasiClosedLoopSystem"closed-loop assembled with "QuasiFeedbackGains"
    "QuasiFeedbackGains"feedback gains that depend only on initial values
    "QuasiFeedbackGainsModel"systems model of "QuasiFeedbackGains"
    "OptimalCost"optimal value of
  • Infinite horizon problem properties:
  • "MaximalLQRInvariantRegion"maximal region with LQR feedback gains
    "MaximalStabilizableRegion"maximal region K_infty TemplateBox[{{(, O}, infty, LQR}, Subsuperscript]) that can be steered into
    "MinimalFiniteHorizon"minimal horizon at which states in K_infty TemplateBox[{{(, O}, infty, LQR}, Subsuperscript]) enter
  • Basic design properties:
  • "Design"type of controller design
    "DesignModel"model used for the design
    "DesignModelSamplingMethod"sampling method used to obtain "DesignModel"
    "DesignModelSamplingPeriod"sampling period of "DesignModel"
    "Horizon"horizon η
    "Norm"1-, squared 2-, or -norm
  • Input model properties:
  • "FeedbackInputs"inputs uf of sys used for feedback
    "InputModel"input model sys
    "InputsCount"number of inputs u of sys
    "OpenLoopPoles"poles of "DesignModel"
    "OutputsCount"number of outputs y of sys
    "SamplingPeriod"sampling period of sys
    "StatesCount"number of states x of sys
    "TrackedOutputs"outputs yt of sys that are tracked
  • The diagram of the regulator layout.

    The diagram of the tracker layout.

Examples

open allclose all

Basic Examples  (2)

Solve the infinite horizon regulator problem for a system with states {x1,x2} and control input u:

Specify the cost :

And the state and input constraints:

Compute the resulting MPC controller:

The closed-loop system:

The regions with feasible feedback:

The simulation of the closed-loop system from different initial points in the feasible region:

Solve the finite horizon regulator problem for a system with states {x1,x2} and control input u:

Specify the cost :

And the state and input constraints:

Compute the resulting MPC controller:

The closed-loop system:

The response of the closed-loop system to an input sequence:

The quasi closed-loop system:

The response of the quasi closed-loop system to an input sequence:

Scope  (43)

Basic Uses  (5)

Solve the regulator problem for a discrete-time system with states {x1,x2} and control input u:

Minimize :

Constrain the states and the control input :

Compute the controller:

The closed-loop system:

The response of the closed-loop system:

The closed-loop system from above:

It consists of the input model, feedback gains and comparator:

The order of the subsystems:

Simulate the closed-loop system from a nonzero initial condition:

Start from a different initial condition:

A multiple-input system with inputs {u1,u2}:

The cost:

The constraints:

Compute the controller:

The controller is a DiscreteInputOutputModel:

It is essentially a series of piecewise functions:

And has the two states as inputs:

A system with sampling period of 0.1:

The cost:

The constraints:

Compute the controller:

The output response:

Plot the response at the sampling instants:

Plot it as a function of time:

The controller data object from above:

Compute the controller effort by first obtaining the controller model and closed-loop system:

The output response to an input sequence:

The controller effort along with the control bounds :

Norm  (4)

Compute a controller that minimizes a 1-normed cost:

The controller is a DiscreteInputOutputModel:

It is a series of piecewise functions:

Compute a controller that minimizes a -normed cost:

The controller is a DiscreteInputOutputModel:

It is a series of piecewise functions:

Compute a controller that minimizes a squared 2-normed cost:

The controller is a DiscreteInputOutputModel:

It is a series of piecewise functions:

Compute a controller that minimizes a squared 2-normed cost for an infinite horizon:

The controller is a NonlinearStateSpaceModel:

With no state variables:

And is a piecewise function of the states of the input model:

Tracking  (4)

Solve the tracking problem for a discrete-time system with states {x1,x2} and control input u:

The cost:

The constraints:

Compute the tracking controller:

The closed-loop system:

The closed-loop response:

The closed-loop system from above:

Its response to a nonconstant step-like reference signal:

The response does not exceed the upper limit of 5:

The response to a sinusoidal reference:

Compare the responses with different norms:

The controllers for the different norms:

The closed-loop systems:

The responses:

The responses of the 1- and -norm are the same because it is a single input and single output system:

The error norms of the 2- and 1-norm responses:

Compare the norms for a multiple-output system:

The cost specifications for the different norms:

The controllers:

The closed-loop systems:

The responses:

The difference between the responses of the 1- and -norm costs:

Plant Models  (8)

The controller for a system specified as a StateSpaceModel:

A system specified as an AffineStateSpaceModel:

The controller:

It is computed based on a linear approximation:

The feedback gains are the same:

A nonlinear system with nonzero operating points:

The controller:

It is computed based on a linear approximation:

The nonzero operating points cause the gains to be different:

A controller for a system specified as a NonlinearStateSpaceModel:

A system specified as a continuous-time SystemModel:

The complete system specification includes the sampling as well:

The cost:

The constraints specified in terms of formal variables:

The controller:

The constraints can also sometimes be specified using the variable labels:

The controller:

The feedback gains are the same:

A system with feedback and exogenous inputs:

The complete system specification:

The cost includes only the feedback input cost:

The constraints include only constraints on the feedback input:

The controller:

The feedback gains model has the two states {x1,x2} as inputs and u1 as output:

A system with multiple outputs:

The complete system specification to track only the first output:

The cost includes only the error of the tracked output:

The constraints:

The controller:

Only the first output is tracked:

A SystemModel with multiple inputs:

The feedback input specified using the variable names:

The feedback input index:

It is the first input of the linearized StateSpaceModel:

Constraints  (5)

The constraints specified as a logical expression:

The constraints specified as a list:

The constraints specified with vector and scalar inequality constraints:

The constraints specified for specific :

Constraints that include control rates:

Compute the controller data:

The response of the closed-loop system:

The controller effort:

The control rates are in the limit :

Properties  (17)

The list of available properties can be computed from the controller data object:

A specific property can be computed directly:

A list of properties can also be computed:

The feedback gains:

It is a series of piecewise functions:

Which are affine in the states:

It can be used to compute the feedback gains model:

Obtain the feedback gains model directly:

It can be used to compute the controller model:

And the closed-loop system:

The optimal cost:

It is a sum of three piecewise functions:

They are the optimal costs at each instant:

And are quadratic:

Sort them from the smallest to the largest instant:

The optimal cost at each instant is piecewise quadratic:

The optimal cost for a 1-norm problem:

The optimal cost at each instant is piecewise linear:

The optimal cost for an -norm problem:

The optimal cost at each instant is piecewise linear:

The optimal cost for an -horizon problem:

It is piecewise quadratic:

The regions of interest in an -horizon problem:

The "MaximalLQRInvariantRegion" is contained within "MaximalStabilizableRegion":

"MaximalStabilizableRegion" is essentially the same as "FeedbackRegions":

"FeedbackRegions" is composed of multiple convex subregions:

"MaximalStabilizableRegion" is a single convex region:

The closed-loop poles of an -horizon problem is a piecewise function:

The closed-loop poles of a finite horizon problem is a series of piecewise functions:

The quasi feedback gains:

They are piecewise functions:

That depend only on the initial state of the system:

The quasi feedback gains model:

It is computed from the quasi feedback gains:

The quasi closed-loop system:

It is computed from the quasi feedback gains model:

Basic design properties:

Input model properties:

Obtain all the properties as an Association:

Or a Dataset:

Applications  (2)

Design a controller to automate the administration of anesthesia in a patient: »

A model of the pharmacokinetic (PK) characteristics:

A model of the pharmacodynamic (PD) characteristics:

A model of the relationship between the Bispectral Index (BIS) and using the Hill equation:

A plot showing the nonlinear characteristics of the Hill equation:

The compartmental model with as input and as output:

A discrete-time approximation of the model:

Set up the cost to track the output:

Compute for fully awake and moderately but not deeply hypnotic BIS values:

Specify the constraint to prevent the patient from going into a deep hypnotic state:

Compute the controller:

The closed-loop system:

Compute to achieve a BIS value of , which puts the patient in a moderate hypnotic state:

The plot of the automated process:

The BIS plot:

Design a controller to improve an isothermal continuous stirred-tank reactor process: »

A model of the system with states and inputs :

Compute a discrete-time approximation of the model:

The response of the open-loop system:

Design an MPC controller:

The closed-loop system:

The response of the closed-loop system:

Compare the open and closed-loop responses:

The controller effort:

Properties & Relations  (3)

LQRegulatorGains is a special case of the squared 2-norm, infinite horizon problem:

ModelPredictiveController with no constraints gives essentially the same result:

LQRegulatorGains does not take constraints into consideration:

ModelPredictiveController takes state and control constraints into consideration:

Consequently, LQRegulatorGains has only one set of feedback gains:

While the feedback gains of ModelPredictiveController are a piecewise function:

It also computes the region where the feedback is feasible:

Compute the bounds of the feasible region:

Simulate the LQR closed-loop system from , which is outside the feasible region:

The control constraint is violated:

The closed-loop system's response with the MPC controller from an unfeasible initial value :

The responses of the LQR and MPC closed-loop systems from a feasible initial value :

The controller response shows that the LQR controller again violates the control constraints:

An MPC controller is computed by solving multiple multiparametric optimization problems:

A function to compute the quadratic cost:

A function to assemble the constraints:

A function to assemble the variables:

Solve the optimization problems for the various instances:

ModelPredictiveController gives essentially the same result:

Possible Issues  (2)

1- and -norms with -horizon are not supported:

Change it to a squared 2-norm problem:

Or a finite horizon problem:

Constraints for the horizon problem cannot include and terms:

Specify constraints using the state and input variables:

Or make the horizon finite:

Wolfram Research (2022), ModelPredictiveController, Wolfram Language function, https://reference.wolfram.com/language/ref/ModelPredictiveController.html.

Text

Wolfram Research (2022), ModelPredictiveController, Wolfram Language function, https://reference.wolfram.com/language/ref/ModelPredictiveController.html.

CMS

Wolfram Language. 2022. "ModelPredictiveController." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ModelPredictiveController.html.

APA

Wolfram Language. (2022). ModelPredictiveController. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ModelPredictiveController.html

BibTeX

@misc{reference.wolfram_2022_modelpredictivecontroller, author="Wolfram Research", title="{ModelPredictiveController}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/ModelPredictiveController.html}", note=[Accessed: 09-August-2022 ]}

BibLaTeX

@online{reference.wolfram_2022_modelpredictivecontroller, organization={Wolfram Research}, title={ModelPredictiveController}, year={2022}, url={https://reference.wolfram.com/language/ref/ModelPredictiveController.html}, note=[Accessed: 09-August-2022 ]}