Quantcast

Documentation Center

  • Trial Software
  • Product Updates

mpcmove

Optimal control action

Syntax

u = mpcmove(MPCobj,x,ym,r,v)
[u,Info] = mpcmove(MPCobj,x,ym,r,v)
[u,Info] = mpcmove(MPCobj,x,ym,r,v,Options)

Description

u = mpcmove(MPCobj,x,ym,r,v) computes the optimal manipulated variable moves, u(k). u(k) is calculated given the current estimated extended state, x(k), the measured plant outputs, ym(k), the output references, r(k), and the measured disturbances, v(k), at time k. Call mpcmove repeatedly to simulate closed-loop model predictive control.

[u,Info] = mpcmove(MPCobj,x,ym,r,v) returns additional information regarding the model predictive controller in the second output argument Info.

[u,Info] = mpcmove(MPCobj,x,ym,r,v,Options) overrides default constraints and weights settings in MPCobj with the values specified by Options, an mpcmoveopt object. Use Options to provide run-time adjustment in constraints and weights during the closed-loop simulation.

Input Arguments

MPCobj

mpc object that defines the model predictive controller.

x

mpcstate object that contains the following:

  • Estimated plant model states, x(k|k-1)

  • Estimated input and output disturbance model states, xd(k|k-1)

  • Estimated measurement noise model states, xm(k|k-1)

  • Last controller moves, u(k-1)

To initialize x, use x = mpcstate(MPCobj) and modify default properties as needed.

You may need to change the value of x before using it at the next time step under certain circumstances. Suppose that the optimal value for u calculated in the previous call to mpcmove was not used in the plant for some reason (e.g., saturation). You must replace LastMove with the values actually used.

mpcmove updates all four properties of x to prepare for an mpcmove call at the next time step. For example, it copies the recommended u values into the LastMove field.

To retain the original contents of x, create a copy of it before calling mpcmove.

ym

1-by-nym vector of current measured output values at time k.

nym is the number of measured outputs.

r

p-by-ny array of future reference values for the outputs, where p is the prediction horizon and ny is the number of outputs. The ith row of r defines the reference values at time k+i, for i = 1,...,p.

The first row must contain the reference signal at time k+1. Additional rows represent known future references and are optional (future values are unknown in most applications). If you supply fewer than p rows of data, mpcmove duplicates the last row to fill the array.

You cannot preview the reference signal (also referred to as look-ahead and anticipation) if r contains a single row. To support reference previewing, supply at least two rows of data for r.

v

p-by-nmd array of current and future measured disturbance, where p is the prediction horizon and nmd is the number of measured disturbances used in feed-forward control. The ith row of v defines the measured disturbance values at time k+i-1, for i = 1,...,p.

The first row must contain the current measured disturbance values. Additional rows represent known future values and are optional (future values are unknown in most applications). If you supply fewer than p rows of data, mpcmove duplicates the last row to fill the array.

You cannot preview the measured disturbance signal (also referred to as look-ahead and anticipation) if v contains a single row. To support disturbance previewing, supply at least two rows of data for v.

Options

mpcmoveopt object that overrides constraints and weights in MPCobj. This approach is computationally efficient to simulate run-time changes in controller tuning and limit values. The same behavior can be found in a Simulink® MPC Controller block when supplied with controller tuning and limit input signals.

Output Arguments

u

1-by-nu array of optimal manipulated variable moves, where nu is the number of manipulated variables.

mpcmove holds u at its most recent successful solution if the QP solver fails to find a solution for the current time k.

Info

Information regarding the model predictive controller.

Info is a structure with the following fields:

  • Uoptp+1-by-nu array containing the optimal manipulated variable adjustments (moves),where p is the prediction horizon and nu is the number of manipulated variables.

    The first row is the same as u, which is to be applied at the current time k. Uopt(i,:) contains the predicted optimal values at time k+i-1, for i = 1,...,p+1.

    mpcmove does not calculate optimal control moves at time k+p and therefore it sets Uopt(p+1,:) to NaN.

  • Yoptp+1-by-ny array containing the predicted output variable sequence, where p is the prediction horizon and ny is the number of outputs.

    The first row contains the current outputs at time k after state estimation. Yopt(i,:) contains the values at time k+i-1, for i = 1,...,p+1.

  • Xoptp+1-by-nx array containing the predicted state variable sequence, where p is the prediction horizon and nx is the number of states.

    The first row contains the current states at time k as determined by state estimation.Xopt(i,:) contains the values at time k+i-1, for i = 1,...,p+1.

  • Toptp+1-by-1 vector of time intervals where Topt(1)=0 (representing the current time) and Topt(i)=Ts*(i-1), where Ts=MPCobj.Ts, the controller sample time and for i = 1,...,p+1.

    Use when plotting Uopt, Yopt and/or Xopt sequences.

  • Slack — Slack variable, ε, used in constraint softening.

    Slack is a scalar that may have the following values:

    • 0 — All constraints were satisfied for the entire prediction horizon

    • >0 — At least one soft constraint is violated and represents the worst-case soft constraint violation (scaled by your ECR values for each constraint) when more than one constraints are violated.

      See Optimization Problem for details.

  • Iterations — QP solution result.

    Iterations is a scalar integer that may have the following values:

    • >0 — Number of iterations needed to solve the quadratic programming (QP) problem that determines the optimal sequences.

    • 0 — QP problem could not be solved in the allowed maximum number of iterations.

    • -1 — QP problem was infeasible. A QP problem is infeasible if no solution can satisfy all the hard constraints.

    • -2 — Numerical error occurred when solving the QP problem.

  • QPCode — QP solution status.

    QPCode is a String that may have the following values:

    • 'feasible' — Optimal solution was obtained (Iterations > 0)

    • 'infeasible' — QP solver detected a problem with no feasible solution (Iterations = -1) or a numerical error occurred (Iterations = -2)

    • 'unreliable' — QP solver failed to converge (Iterations = 0)

  • Cost — Cost of the objective function.

    Cost quantifies the degree to which the controller has achieved its objectives and is a non-negative scalar value. Cost is only meaningful when QPCode is 'feasible'.

    See Optimization Problem for details.

Examples

expand all

Analyze Closed-Loop Response

Perform closed-loop simulation of a plant with one MV and one measured OV.

Define a plant model and create a model predictive controller with MV constraints.

ts = 2;
Plant = ss(0.8,0.5,0.25,0,ts);
MPCobj = mpc(Plant);
MPCobj.MV(1).Min = -2;
MPCobj.MV(1).Max = 2;
-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10.
-->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2.
-->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000.
-->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000.
-->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000.

Initialize an mpcstate object for simulation. Use the default state properties.

x = mpcstate(MPCobj);
-->Integrated white noise added on measured output channel #1.
-->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.

Set the reference signal. There is no measured disturbance.

r = 1;

Simulate the closed-loop response by calling mpcmove iteratively.

t = [0:ts:40];
N = length(t);
y = zeros(N,1);
u = zeros(N,1);
for i = 1:N
		% simulated plant and predictive model are identical
		y(i) = 0.25*x.Plant;
		u(i) = mpcmove(MPCobj,x,y(i),r);
end

y and u store the OV and MV values.

Analyze the result.

[ts,us] = stairs(t,u);
plot(ts,us,'r-',t,y,'b--');
legend('MV','OV');

Modify the MV upper bound as the simulation proceeds using an mpcmoveopt object.

MPCopt = mpcmoveopt;
MPCopt.MVMin = -2;
MPCopt.MVMax = 2;

Simulate the closed-loop response and introduce the real-time upper limit change at eight seconds (the fifth iteration step).

x = mpcstate(MPCobj);
y = zeros(N,1);
u = zeros(N,1);
for i=1:N
		% simulated plant and predictive model are identical
		y(i) = 0.25*x.Plant;
		if i == 5
			MPCopt.MVMax = 1;
		end
		u(i) = mpcmove(MPCobj,x,y(i),r,[],MPCopt);
end

Analyze the result.

[ts,us] = stairs(t,u);
plot(ts,us,'r-',t,y,'b--');
legend('MV','OV');

Evaluate Scenario at Specific Time Instant

Define a plant model.

ts = 2;
Plant = ss(0.8,0.5,0.25,0,ts);

Create a model predictive controller with MV and MVRate constraints. The prediction horizon is ten intervals. The control horizon is blocked.

MPCobj = mpc(Plant, ts, 10, [2 3 5]);
MPCobj.MV(1).Min = -2;
MPCobj.MV(1).Max = 2;
MPCobj.MV(1).RateMin = -1;
MPCobj.MV(1).RateMax = 1;
-->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000.
-->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000.
-->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000.

Initialize an mpcstate object for simulation from a particular state.

x = mpcstate(MPCobj);
x.Plant = 2.8;
x.LastMove = 0.85;
-->Integrated white noise added on measured output channel #1.
-->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.

Compute the optimal control at current time.

y = 0.25*x.Plant;
r = 1;
[u,Info] = mpcmove(MPCobj,x,y,r);
-->Integrated white noise added on measured output channel #1.
-->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.

Analyze the predicted optimal sequences.

[ts,us] = stairs(Info.Topt,Info.Uopt);
plot(ts,us,'r-',Info.Topt,Info.Yopt,'b--');
legend('MV','OV');

plot ignores Info.Uopt(end) as it is NaN.

Examine the optimal cost.

Info.Cost
ans =

    0.0793

Alternatives

  • Use sim for plant mismatch and noise simulation when not using run-time constraints or weight changes.

  • Use mpctool to graphically and interactively combine model predictive design and simulation.

  • Use the MPC Controller block in Simulink and for code generation.

More About

expand all

Tips

  • mpcmove updates x.

  • If ym, r or v is specified as [], mpcmove uses the appropriate MPCobj.Model.Nominal value instead.

  • To view the predicted optimal behavior for the entire prediction horizon, plot the appropriate sequences provided in Info.

  • To determine the optimization status, check Info.Iterations and Info.QPCode.

See Also

| | | | | |

Was this topic helpful?