Model Predictive Control

Main.Control History

Hide minor edits - Show changes to markup

Added lines 50-51:

Model Predictive Control (MPC) is also available in the newer Gekko interface with the control option m.options.IMODE=6. A plot of the results can be generated with a plotting package such as Matplotlib. Every time the m.solve() command is called, the solution is time-shifted by one cycle and the MPC calculation repeats with the updated measurements or set points.

Added lines 105-108:

The GUI=True option generates a web-interface where FV, MV, SV, and CV types are included with configurable options.

February 17, 2022, at 03:29 PM by 10.35.117.248 -
Changed line 48 from:

MPC Example with Python GEKKO

to:

MPC with Python GEKKO

February 17, 2022, at 03:29 PM by 10.35.117.248 -
Deleted lines 32-43:

Python Model Predictive Control

Continuous and discrete state space models are used in a Python script for Model Predictive Control.

Download Python MPC Examples

The model1.apm contains a linear first-order differential equation. Other versions are model2.apm (continuous state space) and model3.apm (discrete state space). Each is applied in a model predictive controller to follow a reference trajectory and reach a target value of 7.0.


Added lines 103-114:

Python Model Predictive Control

Continuous and discrete state space models are used in a Python script for Model Predictive Control. A newer version of the APM Python library is Python Gekko.

Download Python MPC Examples

The model1.apm contains a linear first-order differential equation. Other versions are model2.apm (continuous state space) and model3.apm (discrete state space). Each is applied in a model predictive controller to follow a reference trajectory and reach a target value of 7.0.

September 19, 2018, at 03:27 PM by 174.148.126.64 -
Added lines 61-62:
September 19, 2018, at 03:26 PM by 174.148.126.64 -
Changed lines 58-112 from:

The objective is formulated from Controlled Variables (CVs). The CVs may be controlled to a range, a trajectory, maximized, or minimized. The CVs are an expression of the desired outcome for the controller action.

to:

The objective is formulated from Controlled Variables (CVs). The CVs may be controlled to a range, a trajectory, maximized, or minimized. The CVs are an expression of the desired outcome for the controller action.

MPC Example with Python GEKKO

(:source lang=python:) from gekko import GEKKO import numpy as np import matplotlib.pyplot as plt

m = GEKKO() m.time = np.linspace(0,20,41)

  1. Parameters

mass = 500 b = m.Param(value=50) K = m.Param(value=0.8)

  1. Manipulated variable

p = m.MV(value=0, lb=0, ub=100) p.STATUS = 1 # allow optimizer to change p.DCOST = 0.1 # smooth out gas pedal movement p.DMAX = 20 # slow down change of gas pedal

  1. Controlled Variable

v = m.CV(value=0) v.STATUS = 1 # add the SP to the objective m.options.CV_TYPE = 2 # squared error v.SP = 40 # set point v.TR_INIT = 1 # set point trajectory v.TAU = 5 # time constant of trajectory

  1. Process model

m.Equation(mass*v.dt() == -v*b + K*b*p)

m.options.IMODE = 6 # control m.solve(disp=False,GUI=True)

  1. get additional solution information

import json with open(m.path+'//results.json') as f:

    results = json.load(f)

plt.figure() plt.subplot(2,1,1) plt.plot(m.time,p.value,'b-',label='MV Optimized') plt.legend() plt.ylabel('Input') plt.subplot(2,1,2) plt.plot(m.time,results['v1.tr'],'k-',label='Reference Trajectory') plt.plot(m.time,v.value,'r--',label='CV Response') plt.ylabel('Output') plt.xlabel('Time') plt.legend(loc='best') plt.show() (:sourceend:)

June 09, 2017, at 01:01 AM by 10.5.113.159 -
Changed lines 45-49 from:

APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications. The DBS file parameter imode is used to control the simulation mode. This option is set to 6 or 9 for nonlinear control.

 nlc.imode = 6 (simultaneous dynamic control)
 nlc.imode = 9 (sequential dynamic control)
to:

APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications. The DBS file parameter IMODE is used to control the simulation mode. This option is set to 6 or 9 for nonlinear control.

 apm.imode = 6 (simultaneous dynamic control)
 apm.imode = 9 (sequential dynamic control)
Changed lines 51-52 from:
 apm_option(server,app,'nlc.imode',6);
to:
 apm_option(server,app,'apm.imode',6);
Changed line 54 from:
 apm_option(server,app,'nlc.imode',9)
to:
 apm_option(server,app,'apm.imode',9)
Added lines 38-41:

The model1.apm contains a linear first-order differential equation. Other versions are model2.apm (continuous state space) and model3.apm (discrete state space). Each is applied in a model predictive controller to follow a reference trajectory and reach a target value of 7.0.

Added lines 30-37:

Python Model Predictive Control

Continuous and discrete state space models are used in a Python script for Model Predictive Control.

Download Python MPC Examples

June 16, 2015, at 07:03 PM by 45.56.3.184 -
Changed line 42 from:
 apm_option(server,app,'nlc.imode',9);
to:
 apm_option(server,app,'nlc.imode',9)
June 16, 2015, at 07:02 PM by 45.56.3.184 -
Changed lines 35-37 from:
  • NLC.imode = 6 (simultaneous approach)
  • NLC.imode = 9 (sequential approach)
to:
 nlc.imode = 6 (simultaneous dynamic control)
 nlc.imode = 9 (sequential dynamic control)

 % MATLAB example
 apm_option(server,app,'nlc.imode',6);

 # Python example
 apm_option(server,app,'nlc.imode',9);
Deleted lines 46-47:

June 08, 2015, at 10:43 PM by 10.5.113.170 -
Deleted lines 4-7:

Modeling for Dynamic Optimization

One of the benefits derived from a modeling effort is the direct application of the model for optimization. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include excessive dependence on empirical formulations.

Deleted lines 7-8:

June 08, 2015, at 03:21 PM by 45.56.3.184 -
Changed lines 41-42 from:

NLC.imode = 6 (simultaneous approach) NLC.imode = 9 (sequential approach)

to:
  • NLC.imode = 6 (simultaneous approach)
  • NLC.imode = 9 (sequential approach)
June 08, 2015, at 03:20 PM by 45.56.3.184 -
Changed lines 39-41 from:

APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications. The DBS file parameter imode is used to control the simulation mode. This option is set to 6 for nonlinear control.

NLC.imode = 6

to:

APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications. The DBS file parameter imode is used to control the simulation mode. This option is set to 6 or 9 for nonlinear control.

NLC.imode = 6 (simultaneous approach) NLC.imode = 9 (sequential approach)

November 18, 2013, at 11:36 PM by 69.169.137.17 -
Changed line 39 from:

The DBS file parameter imode is used to control the simulation mode. This option is set to 6 for nonlinear control.

to:

APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications. The DBS file parameter imode is used to control the simulation mode. This option is set to 6 for nonlinear control.

November 18, 2013, at 11:36 PM by 69.169.137.17 -
Changed lines 5-7 from:

Nonlinear Control

One of the benefits derived from a modeling effort is the direct application of the model for optimization. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical formulations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.

to:

Modeling for Dynamic Optimization

One of the benefits derived from a modeling effort is the direct application of the model for optimization. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include excessive dependence on empirical formulations.

November 18, 2013, at 11:35 PM by 69.169.137.17 -
Added lines 8-11:

(:html:) <iframe width="560" height="315" src="//www.youtube.com/embed/YHAA-uXhI0E?list=PLLBUgWXdTBDgOlvGgbBDvHXdleSgEi9aj" frameborder="0" allowfullscreen></iframe> (:htmlend:)

November 18, 2013, at 06:10 PM by 69.169.137.17 -
November 18, 2013, at 06:09 PM by 69.169.137.17 -
Added lines 18-31:

MATLAB Toolbox for Model Predictive Control

Model Predictive Control (MPC) predicts and optimizes time-varying processes over a future time horizon. This control package accepts linear or nonlinear models. Using large-scale nonlinear programming solvers such as APOPT and IPOPT, it solves data reconciliation, moving horizon estimation, real-time optimization, dynamic simulation, and nonlinear MPC problems.

Download MATLAB Toolbox for Model Predictive Control

Three example files are contained in this directory that implement a controller for Linear Time Invariant (LTI) systems:

  1. apm1_lti - translate any LTI model into APM format
  2. apm2_step - perform step tests to ensure model accuracy
  3. apm3_control - MPC setpoint change to new target values
November 18, 2013, at 05:33 PM by 69.169.137.17 -
Added lines 1-4:

(:title Model Predictive Control:) (:keywords nonlinear, model, predictive control, moving horizon, differential, algebraic, modeling language:) (:description Tutorial in Excel / Simulink / MATLAB for implementing Model Predictive Control for linear or nonlinear systems.:)

Changed lines 7-8 from:

One of the largest benefits derived from the modeling effort is the direct application of the model for optimization. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical formulations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.

to:

One of the benefits derived from a modeling effort is the direct application of the model for optimization. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical formulations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.

Changed line 17 from:
to:
November 18, 2013, at 05:29 PM by 69.169.137.17 -
Changed lines 3-4 from:

One of the largest benefits derived from the modeling effort is the direct application of the model for optimization. Application of the full nonlinear model directly for control is an elegant but immature field. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical fomulations. These empirical formulations are generally unreliable during abnormal situations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.

to:

One of the largest benefits derived from the modeling effort is the direct application of the model for optimization. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical formulations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.


Model Predictive Control Tutorial

A basic Model Predictive Control (MPC) tutorial demonstrates the capability of a solver to determine a dynamic move plan. In this example, a linear dynamic model is used with the Excel solver to determine a sequence of manipulated variable (MV) adjustments that drive the controlled variable (CV) along a desired reference trajectory.

Download Excel Tutorial File

September 12, 2010, at 03:28 AM by 206.180.155.75 -
Changed lines 3-5 from:

Real-time Optimization and Control

The largest benefit derived from the modeling effort is the direct application of the model for optimization. Application of the full nonlinear model directly for control is an elegant but immature field. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical fomulations. These empirical formulations are generally unreliable during abnormal situations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.

to:

One of the largest benefits derived from the modeling effort is the direct application of the model for optimization. Application of the full nonlinear model directly for control is an elegant but immature field. When solution robustness or speed are concerns, linearizations of the model may be practical. Other compromises of the model include eccessive dependence on empirical fomulations. These empirical formulations are generally unreliable during abnormal situations. APMonitor enables the use of empirical, hybrid, and fundamental models directly in control applications.