Main Content

mpcstate

MPC controller state

Description

An mpcstate object is a handle object pointing to the current state of an implicit or explicit MPC controller. Use an mpcstate object to initialize and hold the current controller state within a MATLAB® simulation.

The controller state includes the:

  • States of the plant, disturbance, and noise models. These are the states of the built-in state estimator. For more information, see Controller State Estimation.

  • Manipulated variables used in the previous control interval.

  • State covariance matrix of the state estimator.

Before simulation, use mpcstate to obtain a handle object and, if needed, set the initial condition of the controller state. By default the initial controller state is set to the nominal values specified in the related mpc object

During simulation, the controller move function (mpcmove, mpcmoveExplicit, mpcmoveAdaptive or mpcmoveMultiple), also updates the controller state when calculating a new control move. If you use built-in state estimation, then you do not need to modify the controller state at all. If you use custom state estimation then you must use the handle object to provide current states for the plant, disturbance, and noise models, before calling the controller move function.

After the simulation, the handle object reflects the state of the controller at the end of the simulation. For more information about handle objects, see Handle Object Behavior.

Creation

Description

example

xc = mpcstate(mpcobj) returns a handle object pointing to the state of mpcobj and sets the state object properties to their default values.

xc = mpcstate(mpcobj,plant,disturbance,noise,lastMove,covariance) sets the Properties of the state object to specified nondefault values. To leave a specific property to its default value, set the corresponding input argument to [].

Input Arguments

expand all

MPC controller object, specified as either an mpc or explicitMPC object.

Output Arguments

expand all

Handle object pointing to current controller state, returned as an mpcstate object, with the following Properties.

Note

Since xc is a handle object, if you copy it to a new variable, the new variable still points to the current state of the same mpc object. If this state changes, this is reflected in both xc and its copy. To preserve the original state for later use, you can save xc to a MAT-file. During simulation, the controller move function also updates xc when a new control move is calculated. For more information, see mpcmove. For more information about handle objects, see Handle Object Behavior.

Properties

expand all

Plant model state estimates, specified as a vector. The plant state estimate values are in engineering units and are absolute; that is, they include state offsets. By default, the Plant property is equal to the Model.Nominal.X property of the controller used to create the mpcstate object.

If the controller plant model includes delays, the Plant property includes states that model the delays. Therefore the number of elements in Plant is greater than the order of the nondelayed controller plant model.

During a simulation, if you are using custom state estimation, prior to calling the MPC controller move function (mpcmove, mpcmoveExplicit, mpcmoveAdaptive or mpcmoveMultiple), you must set xc.Plant to its best estimate. If you are using built-in state estimation, the MPC controller move function uses a Kalman filter to calculate this estimate and to set xc.Plant, and therefore you do not need to update this property at all.

Disturbance model state estimates, specified as a vector. The disturbance state estimates include the states of the input disturbance model followed by the states of the output disturbance model. By default, the Disturbance property is a zero vector if the controller has disturbance model states and empty otherwise.

To view the input and output disturbance models of your controller, use the getindist and getoutdist functions, respectively.

During a simulation, if you are using custom state estimation, prior to calling the function that calculates the MPC controller move, you must set xc.Disturbance to its best estimate. If you are using built-in state estimation, the MPC controller move function uses a Kalman filter to calculate this estimate and to set xc.Disturbance, and therefore you do not need to update this property at all.

Output measurement noise model state estimates, specified as a vector. By default, the Noise property is a zero vector if the controller has noise model states and empty otherwise.

During a simulation, if you are using custom state estimation, prior to calling the function that calculates the MPC controller move, you must set xc.Noise to its best estimate. If you are using built-in state estimation, the MPC controller move function uses a Kalman filter to calculate this estimate and to set xc.Noise, and therefore you do not need to update this property at all.

Optimal manipulated variable control move from previous control interval, specified as a vector with length equal to the number of manipulated variables. By default, the LastMove property is equal to the nominal values of the manipulated variables.

During a simulation, this property is automatically set by the function that calculates the MPC controller move; therefore you do not need to update it.

When the actual control signals sent to the plant in the previous control interval do not match the calculated optimal value, do not use LastMove to specify the actual control signals. Instead, do so using the MVused property of an mpcmoveopt object. The LastMove property of the mpcstate object is used to store the optimal control move at the previous control interval, and the controller uses the difference between LastMove and MVused to correct the internal state estimation.

Covariance matrix for controller state estimates, specified as an Ns-by-Ns symmetric matrix, where Ns is the sum of the number states contained in the Plant, Disturbance, and Noise fields.

If the controller is employing default state estimation the default covariance matrix is the steady-state covariance computed according to the assumptions in Controller State Estimation. This matrix is static when the controller is time-invariant. For more information, see the description of the P output argument of the kalmd function.

During a MATLAB simulation, do not modify xc.Covariance. If the controller uses custom state estimation, this property is empty and it is not used. Otherwise, xc.Covariance is automatically updated by the function that calculates the MPC controller move.

Object Functions

mpcmoveCompute optimal control action and update controller states
mpcmoveAdaptiveCompute optimal control with prediction model updating
mpcmoveMultipleCompute gain-scheduling MPC control action at a single time instant
mpcmoveExplicitCompute optimal control using explicit MPC

Examples

collapse all

Create a model predictive controller for a single-input-single-output (SISO) plant. For this example, the plant includes an input delay of 0.4 time units, and the control sample time is 0.2 time units.

P = tf(1,[10 1],'InputDelay',0.4);
mpcobj = mpc(P,0.2);
-->The "PredictionHorizon" property is empty. Assuming default 10.
-->The "ControlHorizon" property is empty. Assuming default 2.
-->The "Weights.ManipulatedVariables" property is empty. Assuming default 0.00000.
-->The "Weights.ManipulatedVariablesRate" property is empty. Assuming default 0.10000.
-->The "Weights.OutputVariables" property is empty. Assuming default 1.00000.

Obtain a handle object pointing to the current controller state, initializing all controller states to their default values.

xmpc = mpcstate(mpcobj)
-->Converting the "Model.Plant" property to state-space.
-->Converting model to discrete time.
-->Converting delays to states.
-->Assuming output disturbance added to measured output channel #1 is integrated white noise.
-->The "Model.Noise" property is empty. Assuming white noise on each measured output.
MPCSTATE object with fields
          Plant: [0 0 0]
    Disturbance: 0
          Noise: [1x0 double]
       LastMove: 0
     Covariance: [4x4 double]

The controller state, which is an mpcstate object, contains the controller states only at the current time. Specifically:

  • xmpc.Plant is the current value of the estimated plant states.

  • xmpc.Disturbance is the current value of the disturbance model states.

  • xmpc.Noise is the current value of the noise model states.

  • xmpc.LastMove is the last value of the manipulated variable.

  • xmpc.Covariance is the current value of the estimator covariance matrix.

In this example, the Plant property of the mpcstate object contains the state of the first-order, discretized, transfer function P as well as two additional states to model the two delay intervals. By default, the controller contains a first-order output disturbance model (the Disturbance property is a scalar) and a static gain noise model (the Noise property is empty).

You can access the properties of the controller state object using dot notation. For example, view the default covariance matrix.

xmpc.Covariance
ans = 4×4

    0.0624    0.0000    0.0000   -0.0224
    0.0000    1.0000    0.0000   -0.0000
    0.0000    0.0000    1.0000    0.0000
   -0.0224   -0.0000    0.0000    0.2301

Note that xmpc is a handle object, which always points to the current state of the controller.

isa(xmpc,'handle')
ans = logical
   1

If you copy an mpcstate object into a new variable, the new variable still points to the current state of the same mpc object.

xmpc_copy = xmpc;
xmpc.Disturbance = 0.1;
xmpc.Plant = [0.2 0.3 0.4];
xmpc_copy
MPCSTATE object with fields
          Plant: [0.2000 0.3000 0.4000]
    Disturbance: 0.1000
          Noise: [1x0 double]
       LastMove: 0
     Covariance: [4x4 double]

During simulation, mpcmove updates the internal plant state when a new control move is calculated. Therefore, in general, you do not need to update xmpc, which always points to the current (hence updated) state.

Compute the controller action and update the internal controller states assuming the output signal is 0 and the reference signal is 1.

u = mpcmove(mpcobj,xmpc,0,1)
u = 5.6711
xmpc
MPCSTATE object with fields
          Plant: [0.2105 0.4000 5.6711]
    Disturbance: 0.0674
          Noise: [1x0 double]
       LastMove: 5.6711
     Covariance: [4x4 double]
xmpc_copy
MPCSTATE object with fields
          Plant: [0.2105 0.4000 5.6711]
    Disturbance: 0.0674
          Noise: [1x0 double]
       LastMove: 5.6711
     Covariance: [4x4 double]

For more information about handle objects, see Handle Object Behavior.

Version History

Introduced before R2006a