Simulation Software For Teaching Dynamic System Behaviour
Simulation Software For Teaching Dynamic System Behaviour
industry, commerce, research, etc., computer simu- used to represent digital electronic circuits, for ex-
lation can also be used as a powerful teaching aid. ample. Another area in which discrete modeling is
It can be used as a graphic means of reinforcing widely used is in the simulation of queue-server
scientific relationships and dynamic system behav- systems such as in supermarkets, manufacturing
ior. In some cases, simulation models can substitute facilities, air traffic control, etc.
for real systems which are too expensive or unsafe Many simulation programs which are used in
to install in teaching laboratories. engineering and scientific applications are written
Most simulation involves dynamic system be- in general purpose high-level languages such as
havior; in other words, the system variables are FORTRAN, C, and Ada. Others are written in lan-
changing with respect to time and the results of the guages designed specifically to handle simulation
simulation are in the form of time histories of the applications, known as simulation languages, which
system behavior. In some cases, the execution of first appeared in the 1950s. Simulation languages
the simulation program is synchronized with the are often divided into two main types. Discrete sim-
real time in which the system actually operates. The ulation languages (DSLs), such as GPSS [1], Sims-
results produced by the computer in these cases cript [2], and Siman [3] are designed specifically
represent in both magnitude and timing the changes for building models of queuing and other discrete
which take place in the real system. This is known systems; and continuous-system simulation lan-
as real-time simulation. Real-time simulation can guages (CSSLs), e.g., ESL [6], ACSL [7], and
take a further step toward realism by interfacing the CSSL4 [8] are used to model continuous systems.
computer to real hardware and, sometimes, a human In addition to these rather general-purpose simula-
operator. When one or more human operators ma- tion languages, special-purpose languages are avail-
nipulate realistic control mechanisms, which gener- able for particular application areas. Electrical cir-
ate input data for a computer simulation, whose cuits, for example, have been the target of a number
outputs are interfaced to actual instruments and of languages such as SPICE [4] for analog circuits
other hardware, the resulting system is called a sim- and VHDL [5] for digital circuits and systems.
ulator. Simulators are widely used for training pi- Other packages address mainly control systems
lots, drivers, and plant operators. In some cases, the analysis and design. The MATLAB system contains
simulation outputs drive hydraulic motion systems a simulation language, SIMULINK and other lan-
which reproduce realistic motion in the simulator guages such as SIMNON also emphasize control
platform. Add realistic computer-generated visual features.
and audio signals, and it can be difficult to distin- The choice of software for a particular applica-
guish simulation from the real thing. In fact, pilots tion will depend on a number of factors. All such
in training fly many more hours in simulators than languages provide ease of use at the cost of flexibil-
they do in real aircraft. Virtual reality is another ity. They do less, but they do it more easily and
application of real-time simulation in which helmets often more effectively. It is important to match the
and special garments are used to provide a visual, software to the needs of the application. Cost and
audible, and tactile interface between a human and availability on a convenient platform are also im-
a simulated environment. portant. The ability to interface to other software
The mathematical models on which simulations packages may also be a factor.
are based take a number of forms. One of the most ESL and similar languages such as ACSL and
important approaches uses sets of differential equa- CSSL4 offer a compromise between specialization
tions to describe the behavior of continuous, or ana- to a particular application field (e.g., SPICE, SIM-
log, systems. These are systems in which the state ULINK) and the complete generality of an HLL
variables vary continuously with time, and the mod- (such as C or FORTRAN). They aim to facilitate
els are called continuous models. For convenience, the simulation of any system which can be modeled
the term ‘‘continuous model’’ is also assumed to using differential equations. For this reason, they
cover cases in which variables are mostly continu- are useful as tools for general dynamic systems
ous but which experience occasional discontinuous analysis and design and as educational tools cov-
changes, such as when a switch operates. ering a range of application areas.
Another form of model is the discrete model Discrete languages assume a system state which
which assumes that the state of a system is un- changes only at discrete instants in time as the result
changed until an event occurs at a particular instant of an event. In between these events, the system
in time which causes an instantaneous change in the state is assumed to be unchanged. Many of these
system state. This is the basis of many of the models applications involve systems which can be de-
scribed in terms of queues and servers such as pro- program solves the differential and other equations
duction lines or supermarket checkout lines. Contin- describing the model over a range of integration
uous languages deal with systems described by dif- time (T) from T Å TSTART to T Å TFIN, where
ferential equations in which the system state is the values of TSTART and TFIN are specified by
considered to change continuously. Thermal, chem- the programmer (TSTART defaults to zero). The
ical, and mechanical systems and many other dy- ESL language, like most CSSLs, separates the defi-
namic phenomena fall into this category. The re- nition of a model into three sections, the INITIAL,
mainder of this article concentrates on continuous DYNAMIC, and TERMINAL sections of the pro-
languages and their applications. gram. Statements in the INITIAL section are exe-
Continuous-system simulation languages take a cuted only at time T Å TSTART; statements in the
lot of the programming effort, and the correspond- DYNAMIC section are executed repeatedly as time
ing potential for making errors, from the implemen- advances in discrete steps (the integration step
tation of a complex simulation. The algorithms length) from T Å TSTART to T Å TFIN; and state-
which solve the differential equations, the sequenc- ments in the optional TERMINAL section are exe-
ing of the program, the management of the simula- cuted once after the simulation run is completed (at
tion time clock, formatting, and generation of output T Å TFIN). The integration step length used in the
tables and graphs—these and many other aspects DYNAMIC section may be set by the user to a fixed
of the simulation process are taken care of by the value or automatically adjusted by the program, de-
CSSL. Modern CSSLs offer additional features pending on the user’s choice of integration algo-
which make them even easier to use. One is user rithm.
interaction, which allows the user to interact with Defining the model is not the only requirement.
a simulation, monitoring values of variables, chang- It is also necessary to specify how and under what
ing parameter values and rerunning the simulation, conditions it should be run. For example, you may
respecifying output requirements, etc. Another is wish simply to run the model once with data values
graphical input, allowing the user to define the sys- written into the program; or maybe you want to run
tem to be simulated by building a block diagram the model repeatedly with parameters entered from
representation. This technique, which is common in the keyboard before each run; or again, you may
electronic circuit simulators when it is referred to wish the program to select different parameter val-
as ‘‘schematic capture,’’ is possible any time there ues as it searches for optimum conditions. This part
exists a complete and unambiguous way of repre- of the process is referred to as the experiment, and
senting the system graphically. Transfer-function the combination of experiment and model forms, a
block diagrams and bond graphs are two examples. study. An ESL program is referred to as a STUDY
Using a graphical preprocessor has an advantage in and it contains a MODEL and an experiment. Note
that CSSL code which is automatically generated that for reasons which are now obscure, STUDY
does not contain syntax errors. and MODEL are required keywords in the ESL pro-
One of the more recently developed CSSLs, de- gram, but the experiment is identified by the context
veloped in Europe to meet the continuous simula- of the program and no keyword is necessary.
tion needs of the European Space Agency, is called As mentioned earlier, the automatic formatting
ESL [6] (the European Space Agency Simulation and generation of tabulated and graphical output is
Language). We shall use ESL to illustrate the use an important part of any CSSL. In ESL, the keyword
of CSSLs in the study of dynamic system behavior. TABULATE, followed by a list of variables to be
Using suitable examples, languages such as ESL tabulated is all that is required to produce a line of
can be used to support courses on differential equa- tabulated output at specified communication inter-
tions, linear and nonlinear systems, analog elec- vals; for example,
tronic circuits, mechanical dynamics, controls,
chemical kinetics, thermal systems, etc. TABULATE T, Y, Y*, Y9, ERR, STATE;
DESCRIPTION OF THE ESL LANGUAGE Graphical output can be produced in one of two
ways. For a quick look at the behavior of a single
Simulations using ESL can be produced either by variable with respect to time or some other variable,
programming using ESL statements or by devel- the PLOT statement is used. For example,
oping a block diagram model of the system using
the ESL graphical input interface, IMP. An ESL PLOT T,Y,0,100,010,30;
will produce a graph of Y versus T on the screen FORTRAN system. This is a convenient technique
with axes representing T from 0 to 100 and Y from for the software developer, because much of the
010 to 30 units. This can be a good diagnostic expression analysis, and most of the diagnostics can
feature because you get a good idea of how a simu- be left to the FORTRAN compiler. The disadvan-
lation is proceeding, from observing both whether tage of this approach is that error messages gener-
Y is behaving the way you think it should and the ated by the FORTRAN compiler often bear little
rate at which the solution proceeds. If, for example, relationship to the CSSL code. A major advantage
it seems to hang at some value of T, or the plotted of the method is that the program can link to FOR-
variable moves beyond its expected limits, you can TRAN libraries and user-written FORTRAN sub-
interrupt the solution from the keyboard and exam- routines which might be needed when the language
ine the values of key variables to see what is causing itself lacks necessary features. A second advantage
the problem. is that modern optimizing compilers generate effi-
A more flexible way of generating graphical out- cient code, keeping execution times low.
put is available for graphs which are generated after The second approach is to implement the lan-
a simulation run or sequence of runs. In this case, guage as an interpreter. This usually involves the
the values of named variables are saved at specified translation of the user’s source code to a form which
intervals into a file (known as a PREPARE file). consists of strings of instructions resembling assem-
The data stored in the file can later be plotted in a bly language (often for a stack-based machine).
variety of ways using the ESL graph-plotting pro- This code is interpreted at run time, one instruction
gram, DISP. When a PREPARE file has been pro- at a time, by the interpreter. Because it is self-con-
duced, DISP commands are used to generate the tained and does not rely on external compilers and
graphs. Several dependent variables (y axis) can be linking loaders, there is more control of error diag-
plotted at a time against a single independent vari- nostics both during translation and at run time. It is
able (x axis) for one or more selected simulation also easier to provide interactive features. Disadvan-
runs. You can leave the scaling of the axes to DISP tages are that there is no linkage to external routines
or you can specify them to suit your needs. You in other languages which reduces flexibility, and
might, for example, be interested in the precise point run times are generally significantly slower. This
at which a variable changes sign. After a quick look would be more noticeable for large models, or for
you can specify an x axis between narrow limits to applications which require many runs of the model
pinpoint the instant at which the sign changes. The at a time such as parametric studies or optimiza-
graphs can be printed on a printer or plotter. tions. The interpreter option is well suited to most
In addition to graphical output in the form of educational purposes; it is generally easier to use
graph plots, many simulation languages also support and provides better diagnostic features.
graphical input in the form of block diagrams. ESL ESL is probably the only CSSL which incorpo-
is no exception, and it allows a model to be de- rates both approaches in a single system. This is
scribed as a block diagram using a program called accomplished as follows. All ESL programs are pro-
IMP. The IMP processor generates an ESL program cessed by a compiler, esl_comp, which converts the
corresponding to the block diagram. A nice feature ESL source code into an intermediate form known
of IMP is that following a simulation run, it is possi- as H-code. H-code resembles an assembly language
ble to produce a block diagram into which graph for a stack-based machine. An interpreter, esl_run,
plots of key variables are inset. can be used to execute the H-code version of the
program. Alternatively a translator program,
esl_tran, can be used to translate the H-code version
The ESL System
of the program to FORTRAN. The resulting FOR-
The complete set of software which forms the ESL TRAN can then be compiled and run using a stan-
system is quite complex. To understand how it dard FORTRAN system. During execution of the
works, it is helpful to know how the majority of program, using either the interpreter or the transla-
CSSLs operate. There are two main approaches, tor, output files are generated by the PREPARE
referred to as the translator approach and the inter- statements in the program, which are used by the
preter approach. Well-known languages such as DISP program to produce graph plots.
ACSL [7] and CSSL4 [8] use a translator which An ESL demonstration disk is available on re-
converts the CSSL program to FORTRAN. The re- quest from Dynamic Software Solutions, the ad-
sulting FORTRAN program is then compiled, dress of which is on the title page. It contains an
linked, loaded, and executed by a conventional ESL system without the compiler and translator. It
also contains a number of ESL examples in com- (1, 17) ESL regards the entire program as a
piled form. This arrangement permits the execution STUDY and the first and last lines of the pro-
of the precompiled examples, but does not support gram show this.
the compilation and execution of new or modified (2, 13) The model, EX1, is defined within
examples. An accompanying set of notes explains these lines.
the features of ESL as they are introduced into suc- (3) The first section of the model consists of
cessive examples. Students at California State Uni- variable declarations. Variables can be real,
versity, Chico, and at Calgary University, Canada, integer or logical and, with some restrictions,
for example, have found that the demonstration disk can also be arrays.
is a great help in learning the language.
(4, 6, 8, 10) The model is separated into sev-
The following sections describe several ESL ex-
eral regions. INITIAL (line 4) introduces
amples. The first three are simple examples which
code which is executed once only, at the initial
are based on examples on the ESL demonstration
value of the independent variable, and estab-
disk.
lishes the initial state of the system. DY-
NAMIC (line 6) introduces the statements de-
ESL Examples fining the model, the differential and related
equations that describe the dynamic behavior
Example 1: Radioactive Decay. The first group of of the system. This code is the most frequently
examples on the demonstration disk deals with vari- executed (several times per integration step).
ations of a simple radioactive decay system which Statements in the STEP (line 8) region are
is described by the first-order differential equation executed once per integration step. This is a
common location for the PLOT statement to
dy/dt Å 00.03y; y(0) Å 200 give the maximum number of data points for
a smooth graph. Note that with variable-step
It is required to solve this equation for 0 õ t õ 100 integration routines these points may not be
s and to produce graphs of y and dy/dt against t equally spaced. The COMMUNICATION
and a tabulation of y against t at intervals of 1 s. (line 10) region, on the other hand, is exe-
An ESL program which does this is listed below. cuted at regular intervals. Each communica-
This is a modified version of several of the examples tion interval (CINT) is made up of one or
on the ESL demonstration disk. The line numbers more integration steps.
are for reference only and are not part of the pro- (7) The differential equation is defined here.
gram. Note the use of Y * to represent dY/dt. You
can also use Y 9 (two separate single quote
1 STUDY characters { ’’ }, not one double quote { 9 })
2 MODEL EX1; and higher-order derivatives. Derivatives need
3 REAL: Y; not be declared by the user; this is handled
4 INITIAL by the system.
5 Y:Å200.0; (9) PLOT produces a graph as the simulation
6 DYNAMIC proceeds, and so it is necessary to specify axis
7 Y*:Å00.3E001*Y; limits in the order x-minimum, x-maximum,
8 STEP y-minimum, y-maximum.
9 PLOT T,Y,0.0,100.0,0.0,200.0; (11) PREPARE saves data for later plotting
10 COMMUNICATION using DISP. %EX1% names the file. Multiple
11 PREPARE %EX1%,T,Y; files with different names could be generated.
12 TABULATE %EX1.TAB%,T,Y; Putting the PREPARE in the COMMUNICA-
13 END EX1; TION region reduces the amount of data
14 --Experiment saved, but may produce less smooth graphs.
15 TFIN:Å100.0; CINT:Å1.0; The alternative is to put it in the STEP region.
16 EX1; (12) TABULATE produces a tabulation of the
17 END_STUDY specified variables in a standard format. Col-
umn headings are automatically generated.
Notes on Example 1 (line numbers appear in paren- Since the tabulation is required at intervals
theses): of 1 time unit, the TABULATE statement is
1 STUDY
(20, 21) PRINT statements produce output to
2 MODEL EX3;
the default output device (normally the
screen). Text to be printed is between % 3 REAL: YD;
signs. Variables whose values are to be printed 4 --Multiplying constant
are separated by commas. 5 CONSTANT REAL: K_1/00.3E-01/;
(22) Another READ, this time with a prompt 6 REAL: Y;
between % signs. The user is invited to input 7 --Integator constant
Y for yes or N for no. 8 CONSTANT REAL: IC_3/3.000/;
9 INITIAL
(23) The TERMINATE causes the program to
finish if the condition NOT Y_E_S is true 10 Y:ÅIC_3;
(i.e., the logical variable, Y_E_S, is false). 11 DYNAMIC
12 YD:ÅK_1 * Y;
(24) If the program is not terminated at line
24, the INTERACT statement passes control 13 Y*:ÅYD;
temporarily to the user who can check the 14 STEP
values of selected variables, or change model 15 PLOT T,Y,0.0,100.000,0.0,3.00000;
or system parameters before continuing exe- 16 COMMUNICATION
cution. 17 PREPARE %ex3%,T,YD,Y;
(25) The END_LOOP transfers control back 18 TABULATE %ex3.tab%,T,Y;
to the start of the LOOP. 19 END ex3;
In this example, the LOOP is simply used as 20 --Experiment
a means of transferring control back to the 21 --
start of the experiment after the INTERACT. 22 --Definition of experiment to be
Additional forms of the LOOP are available carried out on system
which execute the loop a specified number of 23 --Model arguments
times or while a specified condition is true. 24 --Logical repeat variable
25 LOGICAL: Y_E_S;
Example 3: Using the IMP Graphical Inter- 26 --Define integration control
face. IMP provides an optional alternative method 27 TSTART :Å 0.0;
of defining a system model. This is a common way 28 TFIN :Å 100.000;
of representing systems, especially those with com- 29 CINT :Å 1.00000;
ponents described by transfer functions. The prob- 30 DISERR :Å 0.100000E-03;
lem of Example 1 is used to illustrate the basic 31 INTERR :Å 0.100000E-02;
features of IMP. This involves the solution of the 32 ALGO :Å 1;
first-order differential equation 33 NSTEP :Å 1;
34 --
dY/dt Å KY, given Y Å 3.0 at 0, 35 LOOP
and K Å 00.03 36 --Call the model
37 ex3;
This system can be represented graphically by the 38 PRINT %STUDY COMPLETED%;
IMP diagram in Figure 1, which shows that YD, 39 READ %Do you want another run?
the derivative of Y, is integrated (using an IMP (Y/N):%,Y_E_S;
integrator block) and is then multiplied by K in a 40 TERMINATE NOT Y_E_S;
linear Van der Pol equation, an M-File representation model. The model described here deals only with the
written in MATLAB language, or a MEX-File in elevation gimbal control and is linearized around zero
FORTRAN or C may be easier. Furthermore, while elevation angle. The aim is to study the stability of
it supports a range of integration algorithms, none of the payload attitude when a shuttle reaction control
them have the kind of support for handling discontinu- jet is fired. Figure 3 contains a block diagram of the
ities efficiently and accurately which are provided by system. The system includes the following compo-
ESL and similar languages. nents, all of which are easily represented by ESL
statements (some of which are included):
j Representation of digital computational delay: and the numerical integration algorithm is never
required to integrate across a discontinuity—a com-
when (T0TO)/TdúÅ1.0 mon source of errors when precautions are not
taken. In ESL, this process is totally automatic and
then DCOM:ÅTCOM;
transparent to the user.
end_when; Typical graphical outputs of the program are
shown in Figure 4.
Two further applications will demonstrate the
Note the when statements which cause the code versatility of ESL. One concerns a real-time ESL
within the body of the statement to be executed model of six-legged robots moving over an uneven
only when the when condition becomes true. This terrain with an animated graphics display. The other
is equivalent to defining an event time in a discrete is a simulation of a natural-gas extraction platform
language, and it affords a convenient method of which forms part of an operator training simulator.
handling discontinuous events, and especially dis-
crete subsystems. ESL controls the integration step ROBOT SIMULATION
length to ensure accurate timing of the event. In
other words, the step length is chosen so that the A six-legged robot moving over nonflat terrain was
event coincides with the end of an integration step, the basis of a demonstration project to establish the
ability of ESL to support distributed simulation with form to the ESL segment protocol. Real-time syn-
full-color animation [9]. The simulation is based on chronization is at a rate of 10 frames/s.
the walking robot ‘‘Genghis,’’ developed by Brooks The simulation allows the robot to walk forward
[10] at MIT and a similar robot developed later or in reverse, at various speeds; to turn to right or
by Barnes, et al. [11] at the University of Salford, left; and to track a target controlled by the user. The
England. The robot has three legs on each side of robot also adjusts its attitude, to maintain a sensible
its rectangular body, and moves by changing the body height above the surface, as it climbs or de-
angle of each leg with respect to the body. Alpha scends a slope in the terrain. To provide the neces-
motors move a leg forward or backward, and beta sary inputs for the VISTA animation, the simulation
motors raise or lower a leg. must define the positions of 13 different moving
The main output is a real-time full-color anima- robot parts (two for each leg plus the body).
tion of the robot moving across a contoured land- The simulation has recently been extended to
scape using visualization and technical animation support two robots with tracking and collision
(VISTA) software, which was developed by CASA avoidance features. This extended version operates
Space Division, Spain under ESA contract. VISTA on up to six computers and consists of a master
is driven directly from the ESL simulation of the model, two robot segments, two control panels, and
robot and from the interactive user control panel. the VISTA animation.
The control panel provides real-time input which
can control the robot directly by adjusting its speed,
direction and turn, or indirectly by manipulating a GAS PLATFORM TRAINING SIMULATOR
tracking target. The control panel also supports user
control of the position, zoom angle and ‘‘look-at’’ ESL was used in the implementation of an operator
point of the VISTA ‘‘camera.’’ training simulator for the North Morecambe off-
The complete simulation runs on three separate shore gas platform in the Irish Sea. The offshore
computers using the ESL distributed segment proto- platform may be controlled from onshore and off-
col. An ESL simulation runs as the master segment shore Rosemount control systems. The training sim-
on a Sun Sparc, the user interface on an HP 700, ulator embodies both an emulation of the Rose-
and the VISTA animation package on a Silicon mount system using the Cogsys real-time expert
Graphics. The user interface is written mainly in system software and a simulation of the platform
FORTRAN with some low-level C routines to con- written in ESL. The system provides both trainee
and instructor stations and the instructor can set up to and executed in the DOS editor, from a hard
various operational scenarios, to which the trainee disk. The examples, except the two presented in this
must respond correctly. The system grades the per- article, are taken from Speckhart and Green [12]. A
formance of the trainee. The system runs on a Sun README.DOC file gives appropriate instructions.
Sparcstation and an X-windows terminal. Information, software, manuals, and the demonstra-
The following software components are used in tion disk about ESL can be obtained from Dynamic
the simulator: Software Solutions (fax 916-343-4241).
BIOGRAPHIES
Lionel H. Brooks received his PhD at UMIST, England, in 1951. Roy E. Crosbie received his PhD at Liverpool University, En-
He then spent 18 years with the UKAEA in chemical engineering gland, in 1963. He worked for the Marconi Company on radar
research, 13 years with General Atomic, La Jolla, California, on displays and then spent 20 years with the Department of Electri-
the High Temperature Gas Reactor fuel cycle, and 9 years with cal Engineering at the University of Salford, England. He moved
CarboMedics, Austin, Texas, a manufacturer of artificial hearts to California State University, Chico, in 1983 and is currently
and other medical products. Presently he is the marketing director director of research in the College of Engineering, Computer
of DSS and volunteering time as an adjunct professor at CSU Science, and Technology, and a professor of computer and elec-
Chico and as a research associate with the McLeod Institute of trical engineering. He is a former chair of the Department of
Simulation Sciences. He is a member of SCS, SME, and AIChE. Computer Engineering. He is a fellow of the Institution of Electri-
cal Engineers (UK) and of the Society for Computer Simulation.
He is a former president of the Society and currently serves as
chair of the Council of Past Presidents of SCS.