Simulating NCS Systems - Example

This example shows how to simulate a networked control model. The ouput a simulation consists of four plots

Contents

Define the Control System

The plant is a model of a batch reactor, which the dynamics are linearized and given in continuous-time as

$$ \dot{x}_p=A_px_p +B_p\hat{u} $$

$$ y = C_px_p $$

where

Ap=[1.38     -0.2077     6.715   -5.676;
    -0.5814  -4.29         0      0.675;
    1.067     4.273     -6.654    5.893;
    0.048     4.273      1.343   -2.104];

Bp=[0       0;
    5.679   0 ;
    1.136  -3.146;
    1.136   0 ];

Cp=[1 0 1 -1;
    0 1 0  0];

Next we define the controller, which is given as

$$ \dot{x}_c=A_cx_c +B_c\hat{y} $$

$$ u = C_cx_c + D_c\hat{y} $$

where

Ac=zeros(2);

Bc=[0 1;
    1 0];

Cc=[-2 0 ;
    0  8];

Dc=[0 -2;
    5  0];

Create an 'ncs' Object

Now we are ready to create a ncs object. Since we want to compare two different protocols, we must create two seperate ncs objects. To do so, we will first initialize an ncs object by specifying the number of inputs and outputs the plant has. Then we will specifiy the plant, controller and network properties using the variables defined above.

ncs1 = ncs(2,2);
ncs1 = ncs1.setPlant(Ap,Bp,Cp);
ncs1 = ncs1.setController('C-LTI uWired',Ac,Bc,Cc,Dc);

In the command above we specified 'uWired' when the controller was set. This means that the controller is directly connected to the actuators and the controller commands can be continuously applied to the plant. Next we will specify the network nodes and protocol wer are intrerested in.

txIntvls = [1e-3 0.05];     % [min,max] bounds on the sampling time
delays   = [0 0.02];        % [min,max] bounds on the delay
ncs1 = ncs1.setNetwork('tPoly',[txIntvls delays]);
ncs1 = ncs1.setNetwork('nodesU',{blkdiag(1,1),blkdiag(1,1)});
ncs1 = ncs1.setNetwork('nodesY',{blkdiag(1,0),blkdiag(0,1)});
ncs1 = ncs1.setNetwork('protocol','RR');

The network node specification above indicates that each of the plant outputs share network access. The first node contains the first plant output and the second node contains the second node output. How the nodes are granted access to the network is determined by the protcol specified.

Plot Robust Stability Regions

Finally, to generate the data for plotting the simulation results we simply plug each of the ncs variables into the following function

simOut = ncs1.simulateNcs;
      Simulation Progress: 100% complete 

The above simulation can also be done via the ncsEditor GUI by loading the NCS from ncsExamples.mat into the GUI and clicking on the 'Simulate NCS' button.