H2T Example: Power Network System

Alberto Guiggiani - Aug 2013 alberto.guiggiani@imtlucca.it

     >>> Tutorial available online at > http://dysco.imtlucca.it/h2t/power-network-system.html

Contents

This example will show how to:

     * Model the HYCON2 benchmark "Power Network System" (see PnPMPC toolbox v0.9 manual for details > http://sisdin.unipv.it/pnpmpc/phpinclude/PnPMPC-toolbox_0_9manual.pdf ).
     * Build the H2T object and use it to check and set parameters required for PnPMPC and MPT toolboxes.
     * Use H2T object to build decentralized PnPMPC controllers.
     * Use h2T object to build two MPT controllers with different level of aggression, and compare closed-loop trajectories.

Requirements:

     * WIDE toolbox v1.2 (download > http://ist-wide.dii.unisi.it/pages/file_toolbox/Release%201.2.zip )
     * PnPMPC toolbox v0.9 (download > http://sisdin.unipv.it/pnpmpc/phpinclude/PnPMPC-toolbox_0_9.zip )
     * MPT3 toolbox (download http://control.ee.ethz.ch/~mpt/3/Main/Installation?action=download&upname=install_mpt3.m )

Run

         >> showdemo PNS_start

to open help, or

         >> echodemo PNS_start

for an interactive demo.

Build physical model

clear, clc
PNS_build

LSmodel

% Build LSmodel
model = LSmodel(sys, 0, name_external_inputs, name_external_outputs);

for i = 1:length(name_external_inputs)/2
    model = model.set_sig_lim(name_external_inputs((i-1)*2+1),-DrefMIN(i),DrefMAX(i));
end
for i = 1:length(name_external_outputs)/4
    model = model.set_sig_lim(name_external_outputs((i-1)*4+1),-DtetaMIN(i),DtetaMAX(i));
end

model
Large scale model (total order=16, 4 subsystem(s), 1 summator(s)):
  --- Subsystems -----------
    M1: 3 inputs, 4 outputs, order=4, name="Area 1"
    M2: 4 inputs, 4 outputs, order=4, name="Area 2"
    M3: 4 inputs, 4 outputs, order=4, name="Area 3"
    M4: 3 inputs, 4 outputs, order=4, name="Area 4"
  --- Summators -----------------
    Sum1: 1 inputs, name = "S1"
  --- External Inputs -----------
    IN01: Pref1            X  (min=-0.5,max=0.5)
    IN02: PL1              X 
    IN03: Pref2            X  (min=-0.65,max=0.65)
    IN04: PL2              X 
    IN05: Pref3            X  (min=-0.65,max=0.65)
    IN06: PL3              X 
    IN07: Pref4            X  (min=-0.55,max=0.55)
    IN08: PL4              X 
  --- External Outputs ----------
    OUT01: delta1          X  (min=-0.1,max=0.1)
    OUT02: omega1          X 
    OUT03: Pm1             X 
    OUT04: Pv1             X 
    OUT05: delta2          X  (min=-0.1,max=0.1)
    OUT06: omega2          X 
    OUT07: Pm2             X 
    OUT08: Pv2             X 
    OUT09: delta3          X  (min=-0.1,max=0.1)
    OUT10: omega3          X 
    OUT11: Pm3             X 
    OUT12: Pv3             X 
    OUT13: delta4          X  (min=-0.1,max=0.1)
    OUT14: omega4          X 
    OUT15: Pm4             X 
    OUT16: Pv4             X 
 

H2T object

h2t_obj = h2t(model);

Control parameters

% State Weights
Q = diag([500 0.01 0.01 10 500 0.01 0.01 10 500 0.01 0.01 10 500 0.01 0.01 10]);

% Input weights
R = 10;

% PnPMPC-specific parameters (see help createCtrlPnPMPC4lsmodel)
m = [ 1 -1 2 -1 3 -1 4 -1 ];
p = [ 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 ];
k = { [8 8 8 6], [20 20 20 20] };
sdp = sdpsettings('verbose', 0);

h2t_obj
h2t_obj = 

  h2t with properties:

         weights: []
              nx: 16
              nu: 8
              ny: 16
               N: []
              Ts: 1
             Net: [8x16 logical]
              X0: []
              Mc: []
               k: []
               m: []
               p: []
     sdpsettings: []
    installedTBX: {'WIDE'  'PnPMPC'  'MPT'}
               M: [1x1 LSmodel]

PnPMPC decentralized controllers

% Check parameters required for PnPMPC
h2t_obj.checkParameters('PnPMPC')

% Set generic parameters
h2t_obj.setParameters('PredictionHorizon', 15, 'StateWeights', Q, 'InputWeights', R)

% Set PnPMPC toolbox parameters
h2t_obj.setParameters('k', k, 'm', m, 'p', p, 'sdpsettings', sdp)

% Build controllers
%                               >>> WARNING <<<
% If you get a java exception, simply run the next command again
%                               >>> WARNING <<<
ctrl_pnpmpc = h2t_obj.buildController('PnPMPC')

% Set zero-terminal constraint
for i = 1:4
    ctrl_pnpmpc(i) = ctrl_pnpmpc(i).zeroTerminal(Q((1:4),(1:4)), R);
end

% Controllers ready, can compute control action with uRH method
u = ctrl_pnpmpc(1).uRH(0.05*rand(4,1),[],[],[],sdpsettings('verbose',0));
------------------------------

Checking options for PnPMPC toolbox...

For details type:
	help createCtrlPnPMPC4lsmodel

Required:
	 - Prediction horizon: MISSING!
		 Use .setParameters('PredictionHorizon',Value)
	 - k parameter: MISSING!
		 Use .setParameters('k',Value)
	 - Input types: MISSING!
		 Use .setParameters('m',Value)
	 - Output types: MISSING!
		 Use .setParameters('p',Value)

Facultative:
	 - YALMIP sdpsettings: MISSING!
		 Use .setParameters('sdpsettings',Value)
		 (type 'help sdpsettings' for infos)
------------------------------

Prediction horizon updated with N=15.

State weights updated.

Input weights updated.

k parameter updated.

Input types updated.

Output types updated.

Sdpsettings updated.

------------------------------

Building PnPMPC controller...
LSS: Time continuous system, discretize with sampletime= 1
CREATECTRLPNP: Controller Area 4 done
CREATECTRLPNP: Controller Area 3 done
CREATECTRLPNP: Controller Area 2 done
CREATECTRLPNP: Controller Area 1 done

SUCCESS

------------------------------

ctrl_pnpmpc = 

  1x4 pnpmpc array with properties:

    N
    A
    B
    Hxc
    Kxc
    Hv
    Kv
    M
    Hd
    Kd
    Z
    Aij
    Xj
    couplingA
    Exo

MPT controller

% Check parameters required for MPT controller
h2t_obj.checkParameters('MPT')

% Set parameters for soft controller
h2t_obj.setParameters('StateWeights', 1, 'InputWeights', 1)

% Build MPT controller
ctrl_mpt = h2t_obj.buildController('MPT')

% Perform closed-loop simulation for 15 secs
x0 = 0.1*rand(16,1);
closedloop_data = ctrl_mpt.simulate(x0, 15)

% Plot states and inputs evolution
figure(1)
subplot(211)
plot(closedloop_data.X')
title('Soft controller')
ylabel('States')
subplot(212)
plot(closedloop_data.U')
ylabel('Inputs')
xlabel('Time')

% Change parameters to build an aggressive controller
h2t_obj.setParameters('StateWeights', 10, 'InputWeights', 0.1)
ctrl_mpt_aggressive = h2t_obj.buildController('MPT')

% Compare closed-loop evolutions
closedloop_data_aggressive = ctrl_mpt_aggressive.simulate(x0, 15)

% Plot states and inputs evolution for soft controller
figure(2)
subplot(211)
plot(closedloop_data_aggressive.X')
title('Aggressive controller')
ylabel('States')
subplot(212)
plot(closedloop_data_aggressive.U')
ylabel('Inputs')
xlabel('Time')
------------------------------

Checking options for MPT toolbox...

For details type:
	help MPCController

Required:
	 - Sampling time: OK
	 - Prediction horizon: OK

Facultative:
	 - Weights: OK

------------------------------

State weights updated.

Input weights updated.

------------------------------

Building MPT controller...

SUCCESS

------------------------------
MPC controller (horizon: 15)

closedloop_data = 

       X: [16x16 double]
       U: [8x15 double]
       Y: [16x15 double]
    cost: [1x15 double]


State weights updated.

Input weights updated.

------------------------------

Building MPT controller...

SUCCESS

------------------------------
MPC controller (horizon: 15)

closedloop_data_aggressive = 

       X: [16x16 double]
       U: [8x15 double]
       Y: [16x15 double]
    cost: [1x15 double]