Master Scicos!by 8. July 2008 Contents:
1 What is
Scicos? 1 What is Scicos?Scicos is a blockdiagram based simulation tool, which means that the mathematical model to be simulated is represented with function blocks. Scicos is quite similar to Simulink and LabVIEW Simulation Module. Scicos can simulate linear and nonlinear continuoustime, and discretetime, dynamic systems. You can make the simulation run as fast as the computer allows, or you can make it run with a real or scaled time axis, thus simulating realtime behaviour. Scicos is automtically installed when you install the mathematical tool Scilab. You can not install Scicos independently of Scilab. Here is information about installing Scilab. The homepage of Scicos is at http://scicos.org. 2 About this documentThis tutorial guides you through the basic steps towards mastering Scicos. I have written this document because I did not find a proper, updated tutorial on the Scicos homepage (there are however books about Scicos). I assume that you do all the activities in the blue boxes, as here:
Please send comments or suggestions to improve this tutorial via email to finn.haugen@hit.no. 3 The Scicos environmentFirst:
To launch Scicos:
The figure below shows the Scicos window where you will construct the (block) diagram.
The Scicos window The blocks that is used to build the mathematical model to be simulated are organized in palettes. (When you construct a diagram you simply drag blocks from the palettes to the block diagram.) To display the palettes in a tree structure:
The figure below shows the palettes.
The block palettes To see the individual blocks on a specific palette, click the plus sign in front of the palette.
The figure below shows some of the blocks on the Sources palette.
Some of the blocks on the Sources palette An alternative way to open a specific palette is selecting the palette via the Palette / Palettes menu:
The figure below shows (again) the Sources palette (this time all the blocks are shown).
The Sources palette You can even open the palettes in this way:
It is useful to see the contents of the various palettes. Hence, in the following, the palettes are shown, and comments about selected (assumably) most useful blocks on the palettes are given. Here are comments to selected blocks on the Sources palette shown above:
The Sinks palette:
The Sinks palette Comments to selected blocks in the Sinks palette:
The Linear palette:
The Linear palette Comments to selected blocks in the Linear palette:
The Nonlinear palette:
The Nonlinear palette Comments to selected blocks in the Nonlinear palette:
The Others palette:
The Others palette Comments to selected block on the Others palette:
The Branching palette:
The Branching palette Comments to a selected block on the Branching palette:
4 An example: Simulator of a liquid tankIn this section we will study a premeade simulator of a liquid tank. Then, you will learn how to create a simulator by yourself. You are supposed to have basic knowledge about modeling of dynamic systems, as described in e.g. Dynamic Systems  modelling, analysis and simulation or in any other book about dynamic systems theory. 4.1 Developing the mathematical model of the system to be simulatedThe system to be simulated is a liquid tank with pump inflow and valve outflow, see the figure below. The simulator will calculate and display the level h at any instant of time. The simulation will run in real time, thereby giving the feeling of a "real" system. Actually, since this tank is somewhat sluggish, we will speed up the simulation to have the simulation time running faster than real time, to avoid us waste our precious time. The user can adjust the inlet by adjusting the pump control signal, u. Liquid tank Any simulator is based on a mathematical model of the system to be simulated. Thus, we start by developing a mathematical model of the tank. We assume the following (the parameters used in the expressions below are defined in the figure above):
Mass balance (i.e., rate of change of the mass is equal to the inflow minus the outflow) yields the following differential equation: dm(t)/dt = ρq_{in}(t)  ρq_{out}(t)] (1) or, using the above relations, d[ρAh(t)]/dt = ρK_{u}u(t)  ρK_{v}sqrt[ρgh(t)] (2) We will now draw a mathematical block diagram of the model. This block diagram will then be implemented in the block diagram of the simulator VI. As a proper starting point of drawing the mathematical block diagram, we write the differential equation as a statespace model, that is, as a differential equation having the first order time derivative alone on the left side. This can be done by pulling ρ and A outside the differentiation, then dividing both sides by ρA. The resulting differential equation becomes d[h(t)]/dt = (1/A)*{K_{u}u(t)  K_{v}sqrt[ρgh(t)]} (3) This is a differential equation for h(t). It tells how the time derivative dh(t)/dt can be calculated. h(t) is calculated (by the simulator) by integrating dh(t)/dt with respect to time, from time 0 to time t, with initial value h(0), which we here denote h_{init}. To draw a block diagram of the model (3), we may start by adding an integrator to the empty block diagram. The input to this integrator is dh/dt, and the output is h(t). Then we add mathematical function blocks to construct the expression for dh/dt, which is the right side of the differential equation (3). The resulting block diagram for the model (3) can be as shown in the figure below. Mathematical block diagram of Differential Equation (3) The numerical values of the parameters are as follows:
We will assume that there are level "alarm" limits to be plotted together with the level in the simulator. The limits are
4.2 Downloading and running the simulator
The figure below shows the block diagram of tanksim.cos.
The block diagram of tanksim.cos The figure below shows the simulated pump control signal u. The subsequent figure shows the response in the level h and the level alarm values h_AL and h_AH.
The simulated pump control signal u
The response in the level h and the level alarm values h_AL = 0.1 m and h_AH = 0.9 m 4.3 Studying the simulatorSetting up the simulator
This opens the dialog window shown in the figure below.
The dialog window opened with the Simulate / Setup menu. Most parameters can generally be left unchanged in this dialog window, except the following parameters:
The solver method (i.e. the numerical method that Scicos uses to solve the underlying algebraic and differential equations making up the model) can be selected via the solver parameter, but in most cases the default solver can be accepted.
How does Scicos know what is the time unit in the simulator? Hours? Minutes? Seconds? The answer is that you must define the time unit yourself, and you do it by determining the time unit of the timedependent parameter values, for example whether a mass flow parameter is given in kg/s or kg/min, etc. A general advice is to use seconds. Remember to use the selected time unit consistently in the simulator! Defining model (block) parameters in the ContextModel parameters and simulation parameters can be set in the Context of the simulator. The Context is simply a number of Scilab expressions defining the parameters (or variables) and assigning them values. These parameters are used in the blocks in the diagram.
The Context of tanksim.cos is as follows:
It is actually not necessary to use Context variables in blocks. You can use numerical values directly. But let me give you a good advice: Use Context variables! Because then all the parameter values appears only one place, not scattered around and "hidden" in the block diagram. The Activation clock blockThe Activation clock block activates the Scope blocks and the Display block.
The Activation clock block contains the Init time parameter which in our example is set to the Context variable t_start, and the Period parameter which is set to the Context variable timestep. The period defines the time interval (period) between each time the adjacent blocks are activated.
4.4 Constructing the block diagramYou construct the block diagram by dragging blocks from the relevant palette to the block diagram. Then you connect the blocks (this is done in the natural way using the mouse on the computer). You configure a block by doubleclicking it and entering numerical or (preferably) a Context variable (parameter) name. Here are couple of tips regarding constructing block diagrams:
