The next example considers a linear-time invariant system with one output and one input subject to input constraints provided as @@min@@ and @@max@@ filters
(:source lang=MATLAB -getcode:) [@
model = LTISystem('A', [-0.3 -0.8 0.6;1 0 -2.3; 0.3 1.08 0.2], 'B', [-0.8;-0.9; 0.5], 'C', [-0.4 1.8 2.8]);
model.u.min = -9;
model.u.max = 9;
@]
To add limits on the slew rate for the input, the @@deltaMin@@ and @@deltaMax@@ filters are activated and specified as {$ -10 \le \Delta u_k \le 10 $}
(:source lang=MATLAB -getcode:) [@
model.u.with('deltaMin');
model.u.with('deltaMax');
model.u.deltaMin = -7;
model.u.deltaMax = 7;
@]
The penalties are provided as quadratic functions on the states and inputs
(:source lang=MATLAB -getcode:) [@
model.y.penalty = QuadFunction( 10 );
model.u.penalty = QuadFunction( 0.1 );
@]
The online controller is constructed with the horizon 10
(:source lang=MATLAB -getcode:) [@
ctrl = MPCController(model, 10);
@]
The @@ClosedLoop@@ object is created and simulated for 15 samples for the initial condition @@x0 = [-1; -2; 3] @@. Note that for {$\Delta u$} formulation it is required to provide initial condition for the inputs as well @@u0 = 0@@ which is achieved as follows
(:source lang=MATLAB -getcode:) [@
loop = ClosedLoop(ctrl, model);
x0 = [-1; -2; 3];
u0 = 0;
Nsim = 15;
data = loop.simulate(x0, Nsim, 'u.previous', u0)
@]
In the figure below one can see the closed loop trajectories of the MPC subject to input rate constraints. The first subfigure corresponds to the output of the system, the second subplot represent the input (with constraints in dashed line) and the third subplot shows input rate (with constraints in dashed line).
(:source lang=MATLAB -getcode:) [@
subplot(3, 1, 1);
plot(1:Nsim, data.Y, 'linewidth', 2); title('output');
subplot(3, 1, 2);
stairs(1:Nsim, data.U, 'linewidth', 2); title('input');
hold on;
plot( 1:Nsim, model.u.min*ones(1,Nsim), 'k--', 1:Nsim, model.u.max*ones(1,Nsim), 'k--');
subplot(3, 1, 3);
stairs(1:Nsim, [u0, diff(data.U) ], 'linewidth', 2); title('differences of input');
hold on;
plot( 1:Nsim, model.u.deltaMin*ones(1,Nsim), 'k--', 1:Nsim, model.u.deltaMax*ones(1,Nsim), 'k--');
@]
%width=500% Attach:fdeltaMinMax.jpg %%