Skip to content

JuliaControl/ModelPredictiveControl.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2,532 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModelPredictiveControl.jl

Build Status codecov Aqua QA doc-stable doc-dev arXiv

An open source model predictive control package for Julia.

The package depends on ControlSystemsBase.jl for the linear systems, JuMP.jl for the optimization and DifferentiationInterface.jl for the derivatives.

๐Ÿ› ๏ธ Installation

To install the ModelPredictiveControl package, run this command in the Julia REPL:

using Pkg; Pkg.add("ModelPredictiveControl")

๐Ÿš€ Getting Started

To construct model predictive controllers (MPCs), we must first specify a plant model that is typically extracted from input-output data using system identification. The model here is linear with one input, two outputs and a large time delay in the first channel (a transfer function matrix, with $s$ as the Laplace variable):

$$\mathbf{G}(s) = \frac{\mathbf{y}(s)}{\mathbf{u}(s)} = \begin{bmatrix} \frac{2e^{-20s}}{10s + 1} \\[3pt] \frac{10}{4s +1} \end{bmatrix}$$

We first construct the plant model with a sample time $T_s = 1$ s:

using ModelPredictiveControl, ControlSystemsBase
G = [ tf( 2 , [10, 1])*delay(20)
      tf( 10, [4,  1]) ]
Ts = 1.0
model = LinModel(G, Ts)

Our goal is controlling the first output $y_1$, but the second one $y_2$ should never exceed 35:

mpc = LinMPC(model, Mwt=[1, 0], Nwt=[0.1])
mpc = setconstraint!(mpc, ymax=[Inf, 35])

The keyword arguments Mwt and Nwt are the output setpoint tracking and move suppression weights, respectively. A setpoint step change of five tests mpc controller in closed-loop. The result is displayed with Plots.jl:

using Plots
ry = [5, 0]
res = sim!(mpc, 40, ry)
plot(res, plotry=true, plotymax=true)

StepChangeResponse

See the manual for more detailed examples.

โœจ Features

๐ŸŽฏ Model Predictive Control Features

  • ๐Ÿญ๏ธ Plant Model: Linear or nonlinear models exploiting multiple dispatch.
  • โ›ณ๏ธ Objectives: Tracking for inputs/outputs, move suppression, terminal costs, and economic costs.
  • โณ๏ธ Horizons: Distinct prediction/control horizons with custom move blocking.
  • ๐Ÿ“ธ Linearization: Auto-differentiation for exact Jacobians.
  • โš™๏ธ Adaptive MPC: Manual model updates or automatic successive linearization.
  • ๐ŸŽ๏ธ Explicit MPC: Specialized for unconstrained problems.
  • ๐Ÿšง Bounds: Soft/hard limits on inputs, outputs, increments, and terminal states.
  • ๐Ÿšซ Contraints: Soft/hard custom linear and nonlinear inequality constraints.
  • ๐Ÿ” Feedback: Internal model or state estimators (see features below).
  • ๐Ÿ“ก Feedforward: Integrated support for measured disturbances.
  • ๐Ÿ”ฎ Preview: Custom predictions for setpoints and measured disturbances.
  • ๐Ÿ“ˆ Offset-Free: Automatic model augmentation with integrators.
  • ๐Ÿ“Š Visuals: Easy integration with Plots.jl.
  • ๐Ÿงฉ Solvers: Optimization via JuMP.jl (quadratic & nonlinear) and derivatives via DifferentiationInterface.jl.
  • ๐Ÿ“ Transcription: Direct single/multiple shooting and trapezoidal/orthogonal collocation.
  • ๐Ÿฉบ Troubleshooting: Detailed diagnostic information about optimum.
  • โฑ๏ธ Real-Time: Optimized for low memory allocations with soft real-time utilities.
  • ๐Ÿ“Ÿ๏ธ Embedded: Lightweight C code generation via LinearMPC.jl.

๐Ÿ”ญ State Estimation Features

  • ๐Ÿ”๏ธ Estimators: Many Kalman filters, Luenberger, and Moving Horizon Estimator (MHE).
  • ๐ŸŽ›๏ธ Customization: Ability to use custom/external state estimates.
  • ๐ŸŒŠ Disturbances: Estimate unmeasured disturbances via integrators on inputs/outputs.
  • ๐Ÿ›ฃ๏ธ Bumpless Transfer: Smooth transitions from manual to automatic control.
  • โŒš๏ธ Timing: Estimators available in filter (current) or predictor (delayed) forms.
  • ๐Ÿท๏ธ MHE Types: Formulations for both linear (quadratic optimization) and nonlinear plants.
  • ๐Ÿ›ก๏ธ MHE Constraints: Tunable soft/hard constraints on state and noise estimates.