UI /

ClosedLoop

UI.ClosedLoop History

Hide minor edits - Show changes to markup

Changed line 34 from:

Now we want to verify how the controller performs if connected to a different system, say x^+ = A x + B u with A = [1 1; 0.2 1], B = [1; 0.8]:

to:

Now we want to verify how the controller performs if connected to a different system, say {$ x^+ = A x + B u $} with {$ A = \begin{bmatrix} 1 & 1 \\ 0.2 & 1 \end{bmatrix} $}, {$ B = \begin{bmatrix} 1 \\ 0.8 \end{bmatrix} $}:

Changed lines 16-18 from:
  • A = [1 1; 0 1], B = [1; 0.5]
  • state constraints [-5; -5] <= x <= [5; 5]
  • input constraints -1 <= u <= 1
to:
  • {$ A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} $}, {$ B = \begin{bmatrix} 1 \\ 0.5 \end{bmatrix} $}
  • state constraints {$ \begin{bmatrix} -5 \\ -5 \end{bmatrix} \le x \le \begin{bmatrix} 5 \\ 5 \end{bmatrix} $}
  • input constraints {$ -1 \le u \le 1 $}
Changed line 15 from:

As an example, consider MPC for a linear system x^+ = A x + B u with following properties:

to:

As an example, consider MPC for a linear system {$ x^+ = A x + B u$} with following properties:

Changed line 52 from:
  • NOTE:* if you change the controller and/or the system in your MATLAB workspace, the change(s) will be *automatically* propagate to the closed-loop object without the need to re-create it. In other words, in the example above we can as well do:
to:

NOTE: if you change the controller and/or the system in your MATLAB workspace, the change(s) will automatically propagate to the closed-loop object without the need to re-create it. In other words, in the example above we can as well do:

August 29, 2013, at 07:24 AM by Michal Kvasnica -
Changed line 18 from:
  • input constraints -1 <= x <= 1
to:
  • input constraints -1 <= u <= 1
July 26, 2013, at 07:51 PM by Michal Kvasnica -
Changed lines 28-29 from:

prediction_model.x.penalty = Penalty([1 0; 0 1], 2); prediction_model.u.penalty = Penalty(1, 2);

to:

prediction_model.x.penalty = QuadFunction([1 0; 0 1]); prediction_model.u.penalty = QuadFunction(1);

May 23, 2013, at 08:20 PM by Michal Kvasnica -
Added lines 1-57:

Closed-loop simulations

MPT3 introduces a special object to represent closed-loop systems, consisting of a dynamical system and an MPC controller:

(:source lang=MATLAB -getcode:)
loop = ClosedLoop(mpc, sys)

where mpc represents an MPC controller (either on-line or explicit MPC), and sys describes the dynamical system.

After a closed-loop object is constructed, you can simulate it by

(:source lang=MATLAB -getcode:)
data = loop.simulate(x0, Nsim)

where x0 is the initial state for the simulation, and Nsim is the number of simulation steps.

As an example, consider MPC for a linear system x^+ = A x + B u with following properties:

  • A = [1 1; 0 1], B = [1; 0.5]
  • state constraints [-5; -5] <= x <= [5; 5]
  • input constraints -1 <= x <= 1
  • prediction horizon 4
  • quadratic cost function with unity weighting matrices
(:source lang=MATLAB -getcode:)
prediction_model = LTISystem('A', [1 1; 0 1], 'B', [1; 0.5]);
prediction_model.x.min = [-5; -5];
prediction_model.x.max = [5; 5];
prediction_model.u.min = -1;
prediction_model.u.max = 1;
prediction_model.x.penalty = Penalty([1 0; 0 1], 2);
prediction_model.u.penalty = Penalty(1, 2);
N = 4;
mpc = MPCController(prediction_model, N);

Now we want to verify how the controller performs if connected to a different system, say x^+ = A x + B u with A = [1 1; 0.2 1], B = [1; 0.8]:

(:source lang=MATLAB -getcode:)
simulation_model = LTISystem('A', [1 1; 0.2 1], 'B', [1; 0.8]);
loop = ClosedLoop(mpc, simulation_model);
x0 = [4; 0];
Nsim = 20;
data = loop.simulate(x0, Nsim)

data = 

       X: [2x21 double]
       U: [1x20 double]
       Y: []
    cost: [1x20 double]

plot(data.X')
  • NOTE:* if you change the controller and/or the system in your MATLAB workspace, the change(s) will be *automatically* propagate to the closed-loop object without the need to re-create it. In other words, in the example above we can as well do:
(:source lang=MATLAB -getcode:)
mpc.N = 10;
data = loop.simulate(x0, Nsim)

and the simulation will automatically use the new controller with prediction horizon 10.