model predictive controller -凯发k8网页登录
model predictive controller
description
a model predictive controller uses linear plant, disturbance, and noise models to estimate the controller state and predict future plant outputs. using the predicted plant outputs, the controller solves a quadratic programming optimization problem to determine control moves.
for more information on the structure of model predictive controllers, see mpc prediction models.
creation
syntax
description
creates a model predictive controller object based on the discrete-time prediction model
mpcobj
= mpc(plant
)plant
. the controller, mpcobj
, inherits its
control interval from plant.ts
, and its time unit from
plant.timeunit
. all other controller properties are default values.
after you create the mpc controller, you can set its properties using dot
notation.
if plant.ts = -1
, you must set the ts
property of the controller to a positive value before designing and simulating your
controller.
creates a model predictive controller based on the specified plant model and sets the
mpcobj
= mpc(plant
,ts
)ts
property of the controller. if plant
is:
a continuous-time model, then the controller discretizes the model for prediction using sample time
ts
a discrete-time model with a specified sample time, the controller resamples the plant for prediction using sample time
ts
a discrete-time model with an unspecified sample time (
plant.ts
=–1
), it inherits the sample timets
when used for predictions.
specifies the following controller properties. if any of these values are omitted or
empty, the default values apply.mpcobj
= mpc(plant
,ts
,p
,m
,w
,mv
,ov
,dv
)
p
sets thepredictionhorizon
property.m
sets thecontrolhorizon
property.w
sets theweights
property.mv
sets themanipulatedvariables
property.ov
sets theoutputvariables
property.dv
sets thedisturbancevariables
property.
creates a model predictive controller object based on the specified prediction model
set, which includes the plant, input disturbance, and measurement noise models along
with the nominal conditions at which the models were obtained. when you do not specify a
sample time, the plant model, mpcobj
= mpc(model
)model.plant
, must be a discrete-time
model. this syntax sets the model
property of the
controller.
creates a model predictive controller based on the specified plant model and sets the
mpcobj
= mpc(model
,ts
)ts
property of the controller to ts
. if
model.plant
is a discrete-time lti model with an unspecified
sample time (model.plant.ts
= –1
), it inherits the
sample time ts
when used for predictions.
specifies additional controller properties. if any of these values are omitted or empty,
the default values apply.mpcobj
= mpc(model
,ts
,p
,m
,w
,mv
,ov
,dv
)
input arguments
plant
— plant prediction model
lti model | identified linear model
plant prediction model, specified as either an lti model or a linear system identification toolbox™ model. the specified plant corresponds to the
model.plant
property of the controller.
if you do not specify a sample time when creating your controller,
plant
must be a discrete-time model. for prediction,
plant
is discretized or resampled if needed using
mpcobj.ts
as sample time. delays, if present, are incorporated
in the resulting discrete time model.
for more information on mpc prediction models, see mpc prediction models.
note
direct feedthrough from manipulated variables to any output in
plant
is not supported.
example: tf(10,[1 10])
model
— prediction model
structure
prediction model, specified as a structure with the same format as the model
property of the controller. if you do not specify a sample time when creating your
controller, model.plant
must be a discrete-time model.
for more information on mpc prediction models, see mpc prediction models.
properties
ts
— controller sample time
positive scalar
controller sample time, specified as a positive finite scalar. the controller uses a
discrete-time model with sample time ts
for prediction. the time
unit is inherited from plant.timeunit
.
example: mpcobj.ts = 0.1
predictionhorizon
— prediction horizon
10
delay-dependent steps (default) | positive integer
prediction horizon steps, specified as a positive integer. the product of
predictionhorizon
and ts
is the prediction
time; that is, how far the controller looks into the future.
if you specify a prediction horizon that is not larger than the number of steps
necessary to cover the longest delay among all the input-output channels, nd =
max(mpcobj.model.plant.iodelay(:))/mpcobj.ts
, then the software
automatically increases the prediction horizon by floor(nd)
.
example: mpcobj.predictionhorizon = 15
controlhorizon
— control horizon
2
(default) | positive integer | vector of positive integers
control horizon, specified as one of the following:
positive integer, m, between
1
and p, inclusive, where p is equal topredictionhorizon
. in this case, the controller computes m free control moves occurring at times k through k m-1, and holds the controller output constant for the remaining prediction horizon steps from k m through k p-1. here, k is the current control interval.vector of positive integers [m1, m2, …], specifying the lengths of blocking intervals. by default the controller computes m blocks of free moves, where m is the number of blocking intervals. the first free move applies to times k through k m1-1, the second free move applies from time k m1 through k m1 m2-1, and so on. using block moves can improve the robustness of your controller. the sum of the values in
controlhorizon
must match the prediction horizon p. if you specify a vector whose sum is:less than the prediction horizon, then the controller adds a blocking interval. the length of this interval is such that the sum of the interval lengths is p. for example, if p=
10
and you specify a control horizon ofcontrolhorizon
=[1 2 3]
, then the controller uses four intervals with lengths[1 2 3 4]
.greater than the prediction horizon, then the intervals are truncated until the sum of the interval lengths is equal to p. for example, if p=
10
and you specify a control horizon ofcontrolhorizon
=[1 2 3 6 7]
, then the controller uses four intervals with lengths[1 2 3 4]
.
for more information on manipulated variable blocking, see .
example: mpcobj.controlhorizon = 3
model
— prediction model and nominal conditions
structure
prediction model and nominal conditions, specified as a structure with the following fields. for more information on the mpc prediction model, see mpc prediction models and controller state estimation.
plant
— plant prediction model
lti model | identified linear model
plant prediction model, specified as either an lti model or a linear system identification toolbox model.
note
direct feedthrough from manipulated variables to any output in
plant
is not supported.
example: mpcobj.model.plant = ss(-1,1,1,0)
disturbance
— model describing expected unmeasured disturbances
lti model
model describing expected unmeasured disturbances, specified as an lti model. this model is required only when the plant has unmeasured disturbances. you can set this disturbance model directly using dot notation or using the function.
by default, input disturbances are expected to be integrated white noise. to model the signal, an integrator with dimensionless unity gain is added for each unmeasured input disturbance, unless the addition causes the controller to lose state observability. in that case, the disturbance is expected to be white noise, and so, a dimensionless unity gain is added to that channel instead.
example: mpcobj.model.disturbance = tf(5,[1
5])
noise
— model describing expected output measurement noise
lti model
model describing expected output measurement noise, specified as an lti model.
by default, measurement noise is expected to be white noise with unit variance. to model the signal, a dimensionless unity gain is added for each measured channel.
example: mpcobj.model.noise = zpk(0,-1,1)
nominal
— nominal operating point at which plant model is linearized
structure
nominal operating point at which plant model is linearized, specified as a structure with the following fields.
field | description | default |
---|---|---|
x | plant state at operating point, specified as a column vector
with length equal to the number of states in
| zero vector |
u | plant input at operating point, including manipulated variables
and measured and unmeasured disturbances, specified as a column vector
with length equal to the number of inputs in
| zero vector |
y | plant output at operating point, including measured and
unmeasured outputs, specified as a column vector with length equal to
the number of outputs in | zero vector |
dx | for continuous-time models, | zero vector |
manipulatedvariables
— manipulated variable information, bounds, and scale factors
structure array
manipulated variable (mv) information, bounds, and scale factors, specified as a
structure array with nmv elements, where
nmv is the number of manipulated
variables. to access this property, you can use the alias mv
instead
of manipulatedvariables
.
note
rates refer to the difference δu(k)=u(k)-u(k-1). constraints and weights based on derivatives du/dt of continuous-time input signals must be properly reformulated for the discrete-time difference δu(k), using the approximation du/dt ≅ δu(k)/ts.
each structure element has the following fields.
min
— mv lower bound
-inf
(default) | scalar | vector
lower bound for a given manipulated variable, specified as a scalar or vector.
by default, this lower bound is -inf
.
to use the same bound across the prediction horizon, specify a scalar value.
to vary the bound over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final bound is used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(1).min =
-5
max
— mv upper bound
inf
(default) | scalar | vector
upper bound for a given manipulated variable, specified as a scalar or vector.
by default, this upper bound is inf
.
to use the same bound across the prediction horizon, specify a scalar value.
to vary the bound over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final bound is used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(1).max =
5
minecr
— mv lower bound softness
0
(default) | nonnegative scalar | vector
softness of the lower bound for a given manipulated variable. a larger equal concern for relaxation (ecr) value indicates a softer constraint, specified as a nonnegative scalar or vector. by default, mv lower bounds are hard constraints.
to use the same ecr value across the prediction horizon, specify a scalar value.
to vary the ecr value over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final ecr value is used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(1).minecr =
0.01
maxecr
— mv upper bound
0
(default) | nonnegative scalar | vector
softness of the upper bound for a given manipulated variable. a larger equal concern for relaxation (ecr) value indicates a softer constraint, specified as a nonnegative scalar or vector. by default, mv upper bounds are hard constraints.
to use the same ecr value across the prediction horizon, specify a scalar value.
to vary the ecr value over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final ecr value is used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(1).maxecr =
0.01
ratemin
— mv rate of change lower bound
-inf
(default) | nonpositive scalar | vector
lower bound for the rate of change of a given manipulated variable, specified
as a nonpositive scalar or vector. the mv rate of change is defined as
mv(k) -
mv(k-1), where k is the
current time. by default, this lower bound is -inf
.
to use the same bound across the prediction horizon, specify a scalar value.
to vary the bound over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final bound is used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(1).ratemin =
-2
ratemax
— mv rate of change upper bound
inf
(default) | nonnegative scalar | vector
upper bound for the rate of change of a given manipulated variable, specified
as a nonnegative scalar or vector. the mv rate of change is defined as
mv(k) -
mv(k-1), where k is the
current time. by default, this lower bound is inf
.
to use the same bound across the prediction horizon, specify a scalar value.
to vary the bound over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final bound is used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(1).ratemax =
2
rateminecr
— mv rate of change lower bound softness
0
(default) | nonnegative finite scalar | vector
softness of the lower bound for the rate of change of a given manipulated variable. a larger equal concern for relaxation (ecr) value indicates a softer constraint, specified as a nonnegative finite scalar or vector. by default, mv rate of change lower bounds are hard constraints.
to use the same ecr value across the prediction horizon, specify a scalar value.
to vary the ecr values over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final ecr values are used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(2).rateminecr =
0.01
ratemaxecr
— mv rate of change upper bound softness
0
(default) | nonnegative finite scalar | vector
softness of the upper bound for the rate of change of a given manipulated variable. a larger equal concern for relaxation (ecr) value indicates a softer constraint, specified as a nonnegative finite scalar or vector. by default, mv rate of change upper bounds are hard constraints.
to use the same ecr value across the prediction horizon, specify a scalar value.
to vary the ecr values over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final ecr values are used for the remaining steps of the prediction horizon.
example: mpcobj.manipulatedvariables(2).ratemaxecr =
0.01
target
— mv targets
'nominal'
(default) | scalar | vector
targets for a given manipulated variable, specified as a scalar, vector, or as
'nominal'
(default). when target
is
'nominal'
, then the manipulated variable targets correspond
to mpcobj.model.nominal.u
.
to use the same target across the prediction horizon, specify a scalar value.
to vary the target over the prediction horizon from time k to time k p-1, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final value is used for the remaining steps of the prediction horizon.
you might want to set target values for some manipulated variables, along with corresponding nonzero cost function weights, for economic or operational reasons, whenever you have more manipulated variables than plant outputs. for more information, see and .
example: mpcobj.manipulatedvariables(2).target = [0.3
0.2]
name
— mv name
string | character vector
name of a given manipulated variable, specified as a string or character
vector. this is a read-only property. to modify the names of manipulated
variables, use mpcobj.model.plant.inputname
.
example: mpcobj.manipulatedvariables(2).name
units
— mv units
""
(default) | string | character vector
units of a given manipulated variable, specified as a string or character
vector. this is a read-only property. to modify the units of manipulated
variables, use mpcobj.model.plant.inputunit
.
example: mpcobj.manipulatedvariables(2).units
scalefactor
— mv scale factor
1
(default) | positive finite scalar
scale factor of a given manipulated variable, specified as a positive finite scalar. specifying the proper scale factor can improve numerical conditioning for optimization. in general, use the amplitude of the operating range of the manipulated variable. for more information, see .
example: mpcobj.manipulatedvariables(1).scalefactor =
10
type
— mv type
'continuous'
(default) | 'integer'
| 'binary'
| vector
type of a given manipulated variable, specified as:
'continuous'
— this indicates that the manipulated variable is continuous.'binary'
— this restricts the manipulated variable to be either 0 or 1.'integer'
— this restricts the manipulated variable to be an integer.a vector containing all the possible values — this restricts the manipulated variable to the specified values, for example
mpcobj.mv(1).type = [-1,0,0.5,1,2];
.
by default, the type is set to
'continuous'
.
for more information, see .
example: mpcobj.manipulatedvariables(1).type =
'binary'
outputvariables
— output variable information, bounds, and scale factors
structure array
output variable (ov) information, bounds, and scale factors, specified as a
structure array with ny elements, where
ny is the number of output variables. to
access this property, you can use the alias ov
instead of
outputvariables
.
each structure element has the following fields.
min
— ov lower bound
-inf
(default) | scalar | vector
lower bound for a given output variable, specified as a scalar or vector. by
default, this lower bound is -inf
.
to use the same bound across the prediction horizon, specify a scalar value.
to vary the bound over the prediction horizon from time k 1 to time k p, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final bound is used for the remaining steps of the prediction horizon.
example: mpcobj.outputvariables(1).min = -10
max
— ov upper bound
inf
(default) | scalar | vector
upper bound for a given output variable, specified as a scalar or vector. by
default, this upper bound is inf
.
to use the same bound across the prediction horizon, specify a scalar value.
to vary the bound over the prediction horizon from time k 1 to time k p, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final bound is used for the remaining steps of the prediction horizon.
example: mpcobj.outputvariables(1).max = 10
minecr
— ov lower bound softness
1
(default) | nonnegative finite scalar | vector
softness of the lower bound for a given output variable. a larger equal concern for relaxation (ecr) value indicates a softer constraint, specified as a nonnegative finite scalar or vector. by default, ov upper bounds are soft constraints.
to avoid creating an infeasible optimization problem at run time, it is best practice to use soft ov bounds.
to use the same ecr value across the prediction horizon, specify a scalar value.
to vary the ecr value over the prediction horizon from time k 1 to time k p, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final ecr value is used for the remaining steps of the prediction horizon.
example: mpcobj.outputvariables(1).minecr = 5
maxecr
— ov upper bound softness
1
(default) | nonnegative finite scalar | vector
softness of the upper bound for a given output variable. a larger equal concern for relaxation (ecr) value indicates a softer constraint, specified as a nonnegative finite scalar or vector. by default, ov lower bounds are soft constraints.
to avoid creating an infeasible optimization problem at run time, it is best practice to use soft ov bounds.
to use the same ecr value across the prediction horizon, specify a scalar value.
to vary the ecr value over the prediction horizon from time k 1 to time k p, specify a vector of up to p values. here, k is the current time and p is the prediction horizon. if you specify fewer than p values, the final ecr value is used for the remaining steps of the prediction horizon.
example: mpcobj.outputvariables(1).maxecr = 10
name
— ov name
string | character vector
name of a given output variable, specified as a string or character vector.
this is a read-only property. to modify the names of output variables, use
mpcobj.model.plant.outputname
example: mpcobj.outputvariables(2).name
units
— ov units
""
(default) | string | character vector
units of a given output variable, specified as a string or character vector.
this is a read-only property. to modify the names of output variables, use
mpcobj.model.plant.outputunit
.
example: mpcobj.outputvariables(2).units
scalefactor
— ov scale factor
1
(default) | positive finite scalar
scale factor of a given output variable, specified as a positive finite scalar. specifying the proper scale factor can improve numerical conditioning for optimization. in general, use the operating range of the output variable. for more information, see .
example: mpcobj.outputvariables(1).scalefactor =
20
disturbancevariables
— input disturbance variable information and scale factors
structure array
disturbance variable (dv) information and scale factors, specified as a structure
array with nd elements, where
nd is the total number of measured and
unmeasured disturbance inputs. the order of the disturbance signals within
disturbancevariables
is the following: the first
nmd entries relate to measured input
disturbances, the last nud entries relate to
unmeasured input disturbances.
to access this property, you can use the alias dv
instead of
disturbancevariables
.
each structure element has the following fields.
name
— dv name
string | character vector
dv name, specified as a string or character vector. this is a read-only
property. to modify the names of disturbance variables, use
mpcobj.plant.inputname
.
example: mpcobj.disturbancevariables(1).name
units
— ov units
""
(default) | string | character vector
ov units, specified as a string or character vector. this is a read-only
property. to modify the units of disturbance variables, use
mpcobj.model.plant.inputunit
.
example: mpcobj.disturbancevariables(1).units
scalefactor
— dv scale factor
1
(default) | positive finite scalar
dv scale factor, specified as a positive finite scalar. specifying the proper scale factor can improve numerical conditioning for optimization. for more information, see .
example: mpcobj.disturbancevariables(1).scalefactor =
15
weights
— standard cost function tuning weights
structure
standard cost function tuning weights, specified as a structure. the controller applies these weights to the scaled variables. therefore, the tuning weights are dimensionless values.
the format of outputweights
must match the format of the
weights.outputvariables
property of the controller object. for
example, you cannot specify constant weights across the prediction horizon in the
controller object, and then specify time-varying weights using
mpcmoveopt
.
weights
has the following fields. the values of these fields
depend on whether you use the standard or alternative cost function. for more
information on these cost functions, see .
manipulatedvariables
— manipulated variable tuning weights
row vector | array
manipulated variable tuning weights, which penalize deviations from mv
targets, specified as a row vector or array of nonnegative values. the default
weight for all manipulated variables is 0
.
to use the same weights across the prediction horizon, specify a row vector of length nmv, where nmv is the number of manipulated variables.
to vary the tuning weights over the prediction horizon from time k to time k p-1, specify an array with nmv columns and up to p rows. here, k is the current time and p is the prediction horizon. each row contains the manipulated variable tuning weights for one prediction horizon step. if you specify fewer than p rows, the weights in the final row are used for the remaining steps of the prediction horizon.
if you use the alternative cost function, specify
weights.manipulatedvariables
as a cell array that contains
the
nmv-by-nmv
ru matrix. for example,
mpcobj.weights.manipulatedvariables = {ru}
.
ru must be a positive semidefinite
matrix. varying the ru matrix across the
prediction horizon is not supported. for more information, see .
example: mpcobj.weights.manipulatedvariables = [0.1
0.2]
manipulatedvariablesrate
— manipulated variable rate tuning weights
row vector | array | cell array
manipulated variable rate tuning weights, which penalize large changes in
control moves, specified as a row vector or array of nonnegative values. the
default weight for all manipulated variable rates is
0.1
.
to use the same weights across the prediction horizon, specify a row vector of length nmv, where nmv is the number of manipulated variables.
to vary the tuning weights over the prediction horizon from time k to time k p-1, specify an array with nmv columns and up to p rows. here, k is the current time and p is the prediction horizon. each row contains the manipulated variable rate tuning weights for one prediction horizon step. if you specify fewer than p rows, the weights in the final row are used for the remaining steps of the prediction horizon.
note
it is best practice to use nonzero manipulated variable rate weights. if all
manipulated variable rate weights are strictly positive, the resulting qp
problem is strictly convex. if some weights are zero, the qp hessian could be
positive semidefinite. to keep the qp problem strictly convex, when the
condition number of the hessian matrix
kδu is larger than
1012, the quantity 10*sqrt(eps)
is added to each diagonal term. see .
if you use the alternative cost function, specify
weights.manipulatedvariablesrate
as a cell array that
contains the
nmv-by-nmv
rδu matrix. for example,
mpcobj.weights.manipulatedvariablesrate = {rdu}
.
rδu must be a positive semidefinite
matrix. varying the rδu matrix across
the prediction horizon is not supported. for more information, see .
example: mpcobj.weights.manipulatedvariablesrate = [0.1
0.1]
outputvariables
— output variable tuning weights
vector | array
output variable tuning weights, which penalize deviation from output
references, specified as a row vector or array of nonnegative values. the default
weight for all output variables is 1
.
to use the same weights across the prediction horizon, specify a row vector of length ny, where ny is the number of output variables.
to vary the tuning weights over the prediction horizon from time k 1 to time k p, specify an array with ny columns and up to p rows. here, k is the current time and p is the prediction horizon. each row contains the output variable tuning weights for one prediction horizon step. if you specify fewer than p rows, the weights in the final row are used for the remaining steps of the prediction horizon.
if you use the alternative cost function, specify
weights.outputvariables
as a cell array that contains the
ny-by-ny
q matrix. for example, mpcobj.weights.outputvariables
= {q}
. q must be a positive semidefinite matrix.
varying the q matrix across the prediction horizon is not
supported. for more information, see .
example: mpcobj.weights.outputvariables = [1
1]
ecr
— slack variable tuning weight
1e5
(default) | positive scalar
slack variable tuning weight, specified as a positive scalar. increase or decrease the equal concern for relaxation (ecr) weight to make all soft constraints harder or softer, respectively.
example: mpcobj.weights.ecr = 1e4
optimizer
— qp optimization parameters
structure
qp optimization parameters, specified as a structure with the following fields. the
first four fields, algorithm
,
activesetoptions
, interiorpointoptions
and
mixedintegeroptions
, are related to the built in solvers. if you
chose to use a custom solver for simulation (by setting
customsolver
to true
) these four fields are
ignored for simulation. likewise, if you chose to use a custom solver for code
generation (by setting customsolvercodegen
to
true
) these four fields are ignored for code generation.
for more information on the supported qp solvers, see qp solvers.
algorithm
— qp solver algorithm
'active-set'
(default) | 'interior-point'
qp solver algorithm, specified as one of the following:
'active-set'
— solve the qp problem using the kwik active-set algorithm.'interior-point'
— solve the qp problem using a primal-dual interior-point algorithm with mehrotra predictor-corrector.
for applications that require solving qp problems, you can also access the active-set and interior-point algorithms using the and functions, respectively.
example: mpcobj.optimizer.algorithm =
'interior-point'
activesetoptions
— active-set qp solver settings
structure
active-set qp solver settings, specified as a structure. these settings apply
only when algorithm
is 'active-set'
, and
the type
property of all manipulated variables is
'continuous'
.
you can specify the following active-set optimizer settings.
maxiterations
— maximum number of iterations
'default'
(default) | positive integer
maximum number of iterations allowed when computing the qp solution, specified as one of the following:
'default'
— the mpc controller automatically computes the maximum number of qp solver iterations as , where:nc is the total number of constraints across the prediction horizon.
nv is the total number of optimization variables across the control horizon.
the default
maxiterations
value has a lower bound of120
.positive integer — the qp solver stops after the specified number of iterations. if the solver fails to converge in the final iteration, the controller:
freezes the controller movement if
usesuboptimalsolution
isfalse
.applies the suboptimal solution reached after the final iteration if
usesuboptimalsolution
istrue
.
note
the default maxiterations
value can be very large
for some controller configurations, such as those with large prediction
and control horizons. when simulating such controllers, if the qp solver
cannot find a feasible solution, the simulation can appear to stop
responding, since the solver continues searching for a solution until the
number of iterations reach maxiterations
.
example: mpcobj.optimizer.activesetoptions.maxiterations =
2000
constrainttolerance
— tolerance used to verify that inequality constraints are satisfied
1e-6
(default) | positive scalar
tolerance used to verify that inequality constraints are satisfied by
the optimal solution, specified as a positive scalar. a larger
constrainttolerance
value allows for larger
constraint violations.
example: mpcobj.optimizer.activesetoptions.constrainttolerance =
1e-5
usewarmstart
— option indicating whether to warm start each qp solver iteration
true
(default) | false
option indicating whether to warm start each qp solver iteration by passing in a list of active inequalities from the previous iteration, specified as a logical value. inequalities are active when their equal portion is true.
example: mpcobj.optimizer.activesetoptions.usewarmstart =
true
interiorpointoptions
— interior-point qp solver settings
structure
interior-point qp solver settings, specified as a structure. these settings
apply only when algorithm
is
'interior-point'
, and the type
property
of all manipulated variables is 'continuous'
.
you can specify the following interior-point optimizer settings.
maxiterations
— maximum number of iterations
50
(default) | positive integer
maximum number of iterations allowed when computing the qp solution, specified as a positive integer. the qp solver stops after the specified number of iterations. if the solver fails to converge in the final iteration, the controller:
freezes the controller movement if
usesuboptimalsolution
isfalse
.applies the suboptimal solution reached after the final iteration if
usesuboptimalsolution
istrue
.
example: mpcobj.optimizer.interiorpointoptions.maxiterations =
30
constrainttolerance
— tolerance used to verify that equality and inequality constraints are satisfied
1e-6
(default) | positive scalar
tolerance used to verify that equality and inequality constraints are
satisfied by the optimal solution, specified as a positive scalar. a larger
constrainttolerance
value allows for larger
constraint violations.
example: mpcobj.optimizer.interiorpointoptions.constrainttolerance
= 1e-5
optimalitytolerance
— termination tolerance for first-order optimality (kkt dual residual)
1e-6
(default) | positive scalar
termination tolerance for first-order optimality (kkt dual residual), specified as a positive scalar.
example: mpcobj.optimizer.interiorpointoptions.optimalitytolerance
= 1e-5
complementaritytolerance
— termination tolerance for first-order optimality (kkt average complementarity residual)
1e-8
(default) | positive scalar
termination tolerance for first-order optimality (kkt average complementarity residual), specified as a positive scalar. increasing this value improves robustness, while decreasing this value increases accuracy.
example: mpcobj.optimizer.interiorpointoptions.complementaritytolerance
= 1e-6
steptolerance
— termination tolerance for decision variables
1e-8
(default) | positive scalar
termination tolerance for decision variables, specified as a positive scalar.
example: mpcobj.optimizer.interiorpointoptions.steptolerance =
1e-7
mixedintegeroptions
— mixed-integer qp solver settings
structure
mixed-integer qp solver settings, specified as a structure. this setting apply
when any manipulated variable has a type
property which is
not 'continuous'
. in this case, a built it mixed-integer kwik
algorithm that implements a branch and bound method is used.
you can specify the following mixed-integer qp optimizer settings.
maxiterations
— maximum number of iterations
1000
(default) | positive integer
maximum number of iterations allowed when computing the mixed-integer qp solution, specified as a positive integer. the mixed-integer qp solver stops after the specified number of iterations. if the solver fails to converge in the final iteration, the controller:
freezes the controller movement if
usesuboptimalsolution
isfalse
.applies the suboptimal solution reached after the final iteration if
usesuboptimalsolution
istrue
.
example: mpcobj.optimizer.mixedintegeroptions.maxiterations =
500
constrainttolerance
— tolerance used to verify that equality and inequality constraints are satisfied
1e-6
(default) | positive scalar
tolerance used to verify that equality and inequality constraints are
satisfied by the optimal solution, specified as a positive scalar. a larger
constrainttolerance
value allows for larger
constraint violations.
example: mpcobj.optimizer.mixedintegeroptions.constrainttolerance
= 1e-5
discreteconstrainttolerance
— tolerance used to verify that constraints on the discrete manipulated variables are satisfied
1e-6
(default) | positive scalar
tolerance used to verify that constraints in the discrete manipulated
variables are satisfied by the optimal solution, specified as a positive
scalar. a larger discreteconstrainttolerance
value
allows for larger constraint violations.
example: mpcobj.optimizer.mixedintegeroptions.discreteconstrainttolerance
= 1e-5
roundingatrootnode
— option to round the solution at the root node
1
(default) | 0
option to round the solution at the root node, specified as a boolean.
when roundingatrootnode
=1
, the
solver rounds the solution of the relaxed qp problem solved at the root node
of the search tree, so that discrete constraints are satisfied. then, an
additional qp is solved with respect to the remaining (continuous)
variables. if such a qp has a feasible solution, the corresponding cost is
used as a valid upper-bound on the optimal solution of the original
mixed-integer problem. having such an upper-bound may eliminate entire
subtrees in the rest of the execution of the solver and accelerate the
solution of the following qp relaxations. unless the number of iterations
maxiterations
is small, it is worth setting
roundingatrootnode
=1
. otherwise,
setting roundingatrootnode
=0
avoids
solving the additional qp.
example: mpcobj.optimizer.mixedintegeroptions.roundingatrootnode
= true
maxpendingnodes
— maximum number of pending nodes
1000
(default) | positive scalar
this is the maximum number of pending qp relaxations that can be stored.
it determines the memory allocated to store all pending qp relaxations,
which is proportional to
(2*m 3*nd)*maxpendingnodes
,
where m is the number of inequality constraints, and
nd is the number of discrete variables. if the number
of pending relaxations exceeds maxpendingnodes
then the
solver is stopped with status code -3
,
-4
or -5
.
example: mpcobj.optimizer.mixedintegeroptions.maxpendingnodes =
2000
minoutputecr
— minimum value allowed for output constraint ecr values
0
(default) | nonnegative scalar
minimum value allowed for output constraint equal concern for relaxation (ecr)
values, specified as a nonnegative scalar. a value of 0
indicates that hard output constraints are allowed. if either of the
outputvariables.minecr
or
outputvariables.maxecr
properties of an mpc controller are
less than minoutputecr
, a warning is displayed and the value
is raised to minoutputecr
during computation.
example: mpcobj.optimizer.minoutputecr =
1e-10
usesuboptimalsolution
— option indicating whether a suboptimal solution is acceptable
false
(default) | true
option indicating whether a suboptimal solution is acceptable, specified as a
logical value. when the qp solver reaches the maximum number of iterations without
finding a solution (the exit option is 0
), the
controller:
freezes the mv values if
usesuboptimalsolution
isfalse
applies the suboptimal solution found by the solver after the final iteration if
usesuboptimalsolution
istrue
to specify the maximum number of iterations, depending on the value of
algorithm
, use either
activesetoptions.maxiterations
or
interiorpointoptions.maxiterations
.
example: mpcobj.optimizer.usesuboptimalsolution =
true
customsolver
— option indicating whether to use a custom qp solver for simulation
false
(default) | true
option indicating whether to use a custom qp solver for simulation, specified
as a logical value. if customsolver
is
true
, the user must provide an
mpccustomsolver
function on the matlab® path.
this custom solver is not used for code generation. to generate code for a
controller with a custom solver, use
customsolvercodegen
.
if customsolver
is true
, the
controller does not require the custom solver to honor the settings in either
activesetoptions
or
interiorpointoptions
.
you can also use the function to automatically configure
mpcobj
to use the active-set algorithm of (optimization toolbox) as a custom qp solver for both simulation and code
generation.
for more information on using a custom qp solver see, qp solvers.
example: mpcobj.optimizer.customsolver = true
customsolvercodegen
— option indicating whether to use a custom qp solver for code generation
false
(default) | true
option indicating whether to use a custom qp solver for code generation,
specified as a logical value. if customsolvercodegen
is
true
, the user must provide an
mpccustomsolvercodegen
function on the matlab path.
this custom solver is not used for simulation. to simulate a controller with a
custom solver, use customsolver
.
you can also use the function to automatically configure
mpcobj
to use the active-set algorithm of (optimization toolbox) as a custom qp solver for both simulation and code
generation.
for more information on using a custom qp solver see, qp solvers.
example: mpcobj.optimizer.customsolvercodegen =
true
notes
— user notes
{}
(default) | cell array of character vectors
user notes associated with the mpc controller, specified as a cell array of character vectors.
example: mpcobj.notes = {'longitudinal controller'; 'version
2.1'}
userdata
— user data
[]
(default) | any matlab data
user data associated with the mpc controller, specified as any matlab data, such as a cell array or structure.
example: mpcobj.userdata = {'parameters',0.2,[3
4]'}
history
— controller creation date and time
vector
this property is read-only.
controller creation date and time, specified as a vector with the following elements:
history(1)
— yearhistory(2)
— monthhistory(3)
— dayhistory(4)
— hourshistory(5)
— minuteshistory(6)
— seconds
use datestr(mpcobj.history)
to display the controller creation
date as a character vector.
example: mpcobj.history = datevec(now)
object functions
build mex file that solves an mpc control problem | |
compute closed-loop dc gain from output disturbances to measured outputs assuming constraints are inactive at steady state | |
compare two mpc objects | |
convert implicit mpc controller to explicit mpc controller | |
parameters for plotsection | |
optimization options for explicit mpc generation | |
bounds on explicit mpc control law parameters | |
get property values from mpc object | |
create data structures for mpcmovecodegeneration | |
obtain kalman gains and model for estimator design | |
obtain mixed input/output constraints from model predictive controller | |
retrieve unmeasured input disturbance model | |
retrieve i/o signal names from mpc plant model | |
retrieve unmeasured output disturbance model | |
compute optimal control action and update controller states | |
compute optimal control with prediction model updating | |
plot responses generated by mpc simulations | |
examine mpc controller for design errors and stability problems at run time | |
calculate the value of a performance metric and its sensitivity to the diagonal weights of an mpc controller | |
set or modify mpc object properties | |
configures an mpc object to use the qp solver from optimization toolbox as a custom solver | |
modify a model predictive controller’s state estimator | |
set mixed input/output constraints for model predictive controller | |
modify unmeasured input disturbance model | |
set i/o signal names in mpc plant model | |
modify unmeasured output disturbance model | |
terminal weights and constraints | |
simulate an mpc controller in closed loop with a linear plant | |
size and order of mpc controller | |
convert unconstrained mpc controller to state-space linear system form | |
convert unconstrained mpc controller to linear transfer function form | |
compute steady-state value of mpc controller plant model state for given inputs and outputs |
examples
create mpc controller with specified prediction and control horizons
create a plant model with the transfer function .
plant = tf([1 1],[1 2 0]);
the plant is siso, so its input must be a manipulated variable and its output must be measured. in general, it is good practice to designate all plant signal types using either the setmpcsignals
command, or the lti inputgroup
and outputgroup
properties.
specify a sample time for the controller.
ts = 0.1;
define bounds on the manipulated variable, , such that .
mv = struct(min=-1,max=1);
mv
contains only the upper and lower bounds on the manipulated variable. in general, you can specify additional mv properties. when you do not specify other properties, their default values apply.
specify a 20-interval prediction horizon and a 3-interval control horizon.
p = 20; m = 3;
create an mpc controller using the specified values. the fifth input argument is empty, so default tuning weights apply.
mpcobj = mpc(plant,ts,p,m,[],mv);
-->"weights.manipulatedvariables" is empty. assuming default 0.00000. -->"weights.manipulatedvariablesrate" is empty. assuming default 0.10000. -->"weights.outputvariables" is empty. assuming default 1.00000.
algorithms
to minimize computational overhead, model predictive controller creation occurs in two
phases. the first happens at creation when you use the
mpc
function, or when you change a controller property. creation
includes basic validity and consistency checks, such as signal dimensions and nonnegativity of
weights.
the second phase is initialization, which occurs when you use the object for the first time in a simulation or analytical procedure. initialization computes all constant properties required for efficient numerical performance, such as matrices defining the optimal control problem and state estimator gains. additional, diagnostic checks occur during initialization, such as verification that the controller states are observable.
by default, both phases display informative messages in the command window. you can turn these messages on or off using the function.
alternative functionality
you can also create model predictive controllers using the mpc designer app.
version history
introduced before r2006ar2018b: support for implementing economic mpc using a linear mpc controller has been removed
support for implementing economic mpc using a linear mpc controller has been removed. implement economic mpc using a nonlinear mpc controller instead. for more information on nonlinear mpc controllers, see .
if you previously saved a linear mpc object configured with custom cost or constraint
functions, the software generates a warning when the object is loaded and an error if it
is simulated. to suppress the error and warning messages and continue using your linear
mpc controller, mpcobj
, without the custom costs and constraints, set
the iseconomicmpc
option to false
.
mpcobj.iseconomicmpc = false;
to implement your economic mpc controller using a nonlinear mpc object:
create an
nlmpc
object.convert your custom cost function to the format required for nonlinear mpc. for more information on nonlinear mpc cost functions, see .
convert your custom constraint function to the format required for nonlinear mpc. for more information on nonlinear mpc constraints, see .
implement your linear prediction model using state and output functions. for more information on nonlinear mpc prediction models, see .
see also
apps
functions
- | | | | | | | | | | | |
objects
- | | |
blocks
- | |
topics
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)