Open usim_demo.m in the Editor
Run in the Command Window

Uncertain Simulink® Blocks

In this demo we use the uncertain Simulink® blocks, USS System and MultiPlot Graph, in Robust Control Toolbox™ to simulate uncertain systems.

Contents

Introduction

The model consists of an uncertain plant in feedback with a sensor. The plant has two sources of uncertainty. It consists of a first order system with an uncertain pole between -10 and -4. It also has a multiplicative input uncertainty of 25% at low frequency rising to 100% uncertainty at 130 rad/sec. The feedback path has a cheap sensor which is modeled by a first order filter at 20 rad/s and an uncertain gain which ranges between 0.1 and 2. The Simulink model usim_model is shown below.

unc_pole = ureal('unc_pole',-5,'Range',[-10 -4]);
plant = ss(unc_pole,5,1,1);
input_unc = ultidyn('input_unc',[1 1]);
wt = makeweight(0.25,130,2.5);
sensor_gain = ureal('sensor_gain',1,'Range',[0.1 2]);
open_system('usim_model')

Robust Control Uncertain Simulink Blocks

The USS System and MultiPlot Graph blocks are found in the RCTblocks library. The USS System allows uncertain systems (e.g., USS objects) to be used in Simulink models. MultiPlot Graph is a plotting window that provides for multiple responses on the same plot. The RCTblocks library is shown below

open('RCTblocks')

Robust Control Uncertain Simulink Blocks Helper Functions

Three helper functions are used to interact with Robust Control Toolbox uncertain Simulink blocks. They are: usimfill, usiminfo, and usimsamp.

usimsamp generates a random instance of all USS System blocks in a Simulink model. In this example, usimsamp is used to generate random instances of the uncertain components: input_unc, sensor_gain, unc_pole. These instances are returned in the structure data. Samples of input_unc can lead to systems with large separation between the nominal and perturbed dynamics. To prevent slow simulation times, the samples of input_unc are bandwidth limited to 50 rad/s.

usimfill inserts a common string name into the "Uncertainty Variable Name" dialog box of all USS System blocks in a Simulink model. In this example, the string "data" (corresponding to the random instances generated by usimsamp) is substituted into three USS System blocks.

usiminfo finds USS System blocks within a specified Simulink model and checks for their consistency. See the usiminfo help for details.

Consistency of the Uncertain Model

The uncertain Simulink model usim_model contains three USS System blocks. usimsamp and usimfill assume that the uncertain variables are defined consistently through out the Simulink model. The command usiminfo can be used to check the consistency of the uncertain objects. Note that a flag value of 1 indicates that the uncertain object data is consistent.

cflag = usiminfo('usim_model')
cflag =

     1

Simulating the Uncertain Model

The following is an example of how to generate random instances for the uncertain Simulink model usim_model and simulate the response.

bandwidth = 50;
usimfill('usim_model','data'), % places character string 'data' in the
                               % dialog box 'Uncertainty Variable Name'
                               % of all USS blocks in |usim_model|
for i=1:10;
   % Generate random instance of the uncertain values in the Simulink model
   data = usimsamp('usim_model',bandwidth)
   sim('usim_model',10,simset('MaxStep',.05));   % simulate response
end
data = 

      input_unc: [1x1 ss]
       unc_pole: -5.2241
    sensor_gain: 0.6118


data = 

      input_unc: [1x1 ss]
       unc_pole: -5.3694
    sensor_gain: 0.8085


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.8484
    sensor_gain: 1.8272


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.3894
    sensor_gain: 1.9465


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.7919
    sensor_gain: 0.3056


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.0956
    sensor_gain: 1.6670


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.2510
    sensor_gain: 1.5323


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.0851
    sensor_gain: 0.4062


data = 

      input_unc: [1x1 ss]
       unc_pole: -4.7427
    sensor_gain: 1.0114


data = 

      input_unc: [1x1 ss]
       unc_pole: -6.5905
    sensor_gain: 1.3710

Automating Random Simulations

Alternatively, you can automate generating random instances of the uncertainty by overloading the InitFcn of usim_model. The InitFcn is reset back to empty at the end of the run.

close_system('usim_model',0)
open_system('usim_model')
set_param('usim_model','InitFcn','data=usimsamp(gcs,bandwidth);');
for i=1:10;
   sim('usim_model',10);        % simulate response
end
set_param('usim_model','InitFcn','');

Linearization of Uncertain Simulink Model

The following is an example of how to generate linearizations of the random instances of usim_model. The random instances are generated as before and the command linmod is called for each sample. A Bode plot of the 10 transfer functions is shown.

clear sys
for i=1:10;
   data = usimsamp('usim_model',bandwidth);
   [a,b,c,d] = linmod('usim_model');
   sys(:,:,i) = ss(a,b,c,d);
end
bode(sys)
title('10 Linearizations of usim\_model');