Simulate an MPC controller in closed loop with a linear plant
Use the Model Predictive Control Toolbox™
sim
function to simulate the closed-loop or open-loop response of an MPC
controller with constraints and weights that do not change at run time. The MPC controller can
be implicit or explicit, the controlled plant must be linear and time-invariant, and you must
specify the reference and disturbance signals in advance. By default, the plant used in the
simulation is the one in MPCobj.Model.Plant
, but you can use a different
plant model to assess the controller robustness to model mismatch.
To run simulink models programmatically instead, see sim
(Simulink).
sim(
simulates the closed-loop system formed by the plant model specified in
mpcobj
,Ns
,r
)mpcobj.Model.Plant
and by the MPC controller mpcobj
,
in response to the specified reference signal, r
. The MPC controller can
be either a traditional MPC controller (mpc
) or explicit MPC controller
(explicitMPC
). The simulation runs for the specified number of
simulation steps, Ns
. sim
plots the simulation
results.
sim(___,
specifies
additional simulation options. This syntax allows you to alter the default simulation
options, such as initial states, input/output noise, and unmeasured disturbances, plant
mismatch, etc. It also allows you to simulate the plant in open loop. You can use
SimOptions
)SimOptions
with any of the previous input combinations.
[
suppresses plotting and instead returns:y
,t
,u
,xp
,xc
,SimOptions
] = sim(___)
the sequence of plant outputs y
,
the time sequence t
(equally spaced by
mpcobj.Ts
),
the manipulated variables u
generated by the MPC
controller,
the sequence xp
of states of the model of the plant used for
simulation,
the sequence xmpc
of states of the MPC controller (provided by
the state observer),
and the simulation options object, SimOptions
.