主要内容

DataDrivenMPCState

MPC controller state

Since R2026a

Description

An DataDrivenMPCState object is a handle object pointing to the current state of a DataDrivenMPC object. Use a DataDrivenMPCState object to initialize and hold the current state of a data-driven MPC controller within a MATLAB® simulation.

To initialize and hold the state of an implicit or explicit MPC controller, use mpcstate instead.

The state of a data-driven MPC controller consists in its past input and output trajectory. Before simulation, use DataDrivenMPCState to obtain the handle object pointing to the current controller state. Then, make sure that the PastInputBuffer and PastOutputBuffer properties of the DataDrivenMPCState are populated with the correct values that reflect the plant inputs and outputs before the simulation (the default values are zeroes). During simulation, mpcmove updates the controller state when calculating a new control move. 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

xc = DataDrivenMPCState(ddobj) returns a handle object pointing to the state of ddobj. The controller state, consisting of the past input and output trajectory, is initialized to zero.

example

xc = DataDrivenMPCState(ddobj,PastInputBuffer,PastOutputBuffer) initializes the PastInputBuffer and PastOutputBuffer properties with custom input and output trajectories.

Input Arguments

expand all

Data-driven model predictive controller, specified as a DataDrivenMPC object. To create a data-driven MPC controller, use DataDrivenMPC.

Example: ddobj = DataDrivenMPC((0.5-rand(100,1))*2,lsim(tf(1,[1 1]),(0.5-rand(100,1))*2,0.1*(1:100)',0),0.1); creates the DataDrivenMPC object ddobj from the input signal (0.5-rand(100,1))*2, and the output signal obtained by supplying the input signal to the LTI plant tf(1,[1 1]), with a time vector 0.1*(1:100)', a sample time of 0.1 seconds, and an initial state of 0.

Buffer containing past input trajectory, specified as a matrix with as many columns as the number of inputs and as many rows as the value of ddobj.PastSteps1. This argument sets the PastInputBuffer property.

Buffer containing past output trajectory, specified as a matrix with as many columns as the number of outputs and as many rows as the value of ddobj.PastSteps1. This argument sets the PastOutputBuffer property.

Output Arguments

expand all

Handle object pointing to current controller state, returned as a DataDrivenMPCState object.

Note

Because 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, the change 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

Buffer containing past input trajectory, returned as a matrix with as many columns as the number of inputs and as many rows as the value of ddobj.PastSteps1.

This property is read-only, and defaults to a zero-valued matrix. To initialize it, use the PastInputBuffer argument.

The rows of PastInputBuffer represent the input values for the intervals from time kddobj.PastSteps (top row) to the time k2 (bottom row), where k indicates the current time.

During simulation, mpcmove updates this property when calculating a new control move.

Buffer containing past output trajectory, returned as a matrix with as many columns as the number of outputs and as many rows as the value of ddobj.PastSteps1.

This property is read-only, and defaults to a zero-valued matrix. To initialize it, use the PastOutputBuffer argument.

The rows of PastOutputBuffer represent the output values for the intervals from time kddobj.PastSteps (top row) to the time k2 (bottom row), where k indicates the current time.

During simulation, mpcmove updates this property when calculating a new control move.

Object Functions

mpcmoveCompute optimal control action and update controller states

Examples

collapse all

Create a DataDrivenMPC object.

ddobj = DataDrivenMPC(rand(50,1),rand(50,1),0.1);

Set the PastSteps property.

ddobj.PastSteps = 4;

Get a handle pointing to the state of ddobj.

xdd = DataDrivenMPCState(ddobj)
xdd = 
  DataDrivenMPCState with properties:

     PastInputBuffer: [3×1 double]
    PastOutputBuffer: [3×1 double]

Display the PastInputBuffer property.

xdd.PastInputBuffer
ans = 3×1

     0
     0
     0

Initialize the controller state with custom input and output buffers and create a new handle.

xdd = DataDrivenMPCState(ddobj,-ones(3,1),ones(3,1))
xdd = 
  DataDrivenMPCState with properties:

     PastInputBuffer: [3×1 double]
    PastOutputBuffer: [3×1 double]

Display the PastInputBuffer property.

xdd.PastInputBuffer
ans = 3×1

    -1
    -1
    -1

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

isa(xdd,'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.

xdd_copy = xdd;

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

Compute the controller action and update the internal controller states, assuming the previous input is 0 and the previous output is 2.

u = mpcmove(ddobj,xdd,0,2)
u = 
0.0018

Display the PastInputBuffer and PastOutputBuffer properties of the xdd object side by side.

[xdd.PastInputBuffer xdd.PastOutputBuffer]
ans = 3×2

    -1     1
    -1     1
     0     2

Now display the PastInputBuffer and PastOutputBuffer properties of the xdd_copy object side by side.

[xdd_copy.PastInputBuffer xdd_copy.PastOutputBuffer]
ans = 3×2

    -1     1
    -1     1
     0     2

The output is the same. xdd_copy points to the same state as xdd.

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

Version History

Introduced in R2026a