| Model Predictive Control Toolbox | |
| Provide feedback about this page |
Syntax
Description
u=mpcmove(MPCobj,x,ym,r,v) computes the current input move u(k), given the current estimated extended state x(k), the vector of measured outputs ym(k), the reference vector r(k), and the measured disturbance vector v(k), by solving the quadratic programming problem based on the parameters contained in the MPC controller MPCobj.
x is an mpcstate object. It is updated by mpcmove through the internal state observer based on the extended prediction model (see getestim for details). A default initial state x for the first call at time k=0 can be simply defined as:
[u,Info]=mpcmove(MPCobj,x,ym,r,v) also returns the structure Info containing details about the optimal control calculations. Info has the following fields.
To plot the optimal input trajectory, type:
The optimal output and state trajectories can be plotted similarly. The input, output, and state sequences Uopt, Yopt, Xopt, Topt correspond to the predicted open-loop optimal control trajectories solving the optimization problem described in Optimization Problem. The optimal trajectories might also help understand the closed-loop behavior. For instance, constraints that are active in the open-loop optimal trajectory only at late steps of the prediction horizon might not be active at all in the closed-loop MPC trajectories. The sequence of optimal manipulated variable increments can be retrieved from MPCobj.MPCData.MPCstruct.optimalseq.
QPCode returns either 'feasible', 'infeasible' or 'unreliable' (the latter occurs when the QP solver terminates because the maximum number of iterations MPCobj.Optimizer.MaxIter is exceeded; see qpdantz). When QPCode='infeasible', then u is obtained by shifting the previous optimal sequence of manipulated variable rates (stored in MPCobj.MPCData.MPCstruct.optimalseq inside the MPC object MPCobj), and summing the first entry of this sequence to the previous vector of manipulated moves. You may set up different backup strategies for handling infeasible situations by discarding u and replacing it with a different emergency decision-variable vector.
r/v can be either a sample (no future reference/disturbance known in advance) or a sequence of samples (when a preview / look-ahead / anticipative effect is desired). In the latter case, they must be an array with as many rows as p and as many columns as the number of outputs/measured disturbances, respectively. If the number of rows is smaller than p, the last sample is extended constantly over the horizon, to obtain the correct size.
The default for y and r is MPCobj.Model.Nominal.Y. The default for v is obtained from MPCobj.Model.Nominal.U. The default for x is mpcstate(MPCobj,MPCobj.Model.Nominal.X,0,0,U0) where U0 are the entries from MPCobj.Model.Nominal.U corresponding to manipulated variables.
To bypass the MPC Controller block's internal estimator and use your own state observer to update the MPC state yourself, you can for instance use the syntax:
xp=x.plant; xd=x.dist; xn=x.noise; % Save current state% Now call to your state update function:
u=mpcmove(MPCobj,x,ym,r,v); % x will be updated
[xp,xd,xn]=my_estimator(xp,xd,xn,ym); % States get updated
x.plant=xp;x.dist=xd;x.noise=xn;
Examples
Model predictive control of a multi-input single-output system (see the demo MISO.M). The system has three inputs (one manipulated variable, one measured disturbance, one unmeasured disturbance) and one output.
% Open-loop system parameters% True plant and true initial statesys=ss(tf({1,1,1},{[1 .5 1],[1 1],[.7 .5 1]}));x0=[0 0 0 0 0]';% MPC object setupTs=.2; % sampling time% Define type of input signalsmodel.InputGroup=struct('Manipulated',1,'Measured',2,'Unmeasured ',3);% Define constraints on manipulated variableMV=struct('Min',0,'Max',1);Model=[]; % Reset structure ModelModel.Plant=sys;% Integrator driven by white noise with variance=1000Model.Disturbance=tf(sqrt(1000),[1 0]);
p=[]; % Prediction horizon (take default one)m=3; % Control horizonweights=[]; % Default value for weightsMPCobj=mpc(Model,Ts,p,m,weights,MV);% Simulate closed loop system using MPCMOVETstop=30; %Simulation timexmpc=mpcstate(MPCobj); % Initial state of MPC controllerx=x0; % Initial state of Plantr=1; % Output reference trajectory% State-space matrices of Plant model[A,B,C,D]=ssdata(c2d(sys,Ts));YY=[];XX=[];RR=[];for t=0:round(Tstop/Ts)-1,XX=[XX,x];% Define measured disturbance signalv=0;if t*Ts>=10, v=1; end% Define unmeasured disturbance signald=0;if t*Ts>=20, d=-0.5; end% Plant equations: output update% (note: no feedrthrough from MV to Y, D(:,1)=0)y=C*x+D(:,2)*v+D(:,3)*d;YY=[YY,y];% Compute MPC lawu=mpcmove(MPCobj,xmpc,y,r,v);% Plant equations: state updatex=A*x+B(:,1)*u+B(:,2)*v+B(:,3)*d;end% Plot resultsplot(0:Ts:Tstop-Ts,YY);grid
See Also
mpc, mpcstate, sim, setestim, getestim
| Provide feedback about this page |
![]() | mpchelp | mpcprops | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |