Copyright © IFAC Advances in Control Education. Tokyo. Japan. 1994
EDUCATIONAL SIMULATION SOFTWARE IN OBERON A. H. GLATTFELDER., K. REIMANN··
X. QIU.,
W. SCHAUFELBERGER· and
"Automatic Control Laboratory, Swiu Federal Jrutitute of Technology Zurich, ETH Zentrum, CH809£ Zurich, Switzerland. E-mail: qiuGaut.u.ethz.ch "" Rector'. Office, Sww Federal lrutitute of Technology Zurich, ETH Zentrom, CH-809£ Zurich, Switzerland
Abstract. Oberon is a new powerful object oriented procramming environment from ETH. It has been e.pecially developed for single user worlcatationa and is freely available. ~ these basic ideas make it also very well suited for applications in control engineering, a program to investigate this possibility was launched a little more than a year ago. First and very encouraging results in the area of simulation are presented in the paper where it is shown that a continuoua and a diacrcte time as well as a discrete event simulator have been realized. Key Worda. Control Engineering Simulations; Discrete Event Dynamic System Simulation; Oberon; Object Oriented Simulation
1. INTRODUCTION
different simulators that will be described in the following have been realized.
Simulation plays an important role in control engineering education by providing insight into system behaviour that can not be obtained otherwise and that complements the one gained by theoretical analysis and by experiments. A sound education in modelling and simulation is therefore an important part of most basic courses. Usually existing simulation packages (i. e. Matlab/Simulink or ACSL) are used in student assignments and classroom presentations. As will be shown in the sequel, simple simulation environments for continuous, discrete time and event driven systems can be implemented easily on modern personal computers and are therefore available for education .
2. GRAPHICAL OUTPUT Oberon has been designed and implemented as a basic system for a single user workstation. It contains many of the features needed for control engineering design, but some are missing. For example no special emphasis has been placed on graphical output which is an absolute necessity for plotting simulation results, Nyquist and Bode-plots etc. A corresponding module has therefore been implemented as Ob2DGraphs. It is introduced here by showing the definition module automatically generated by the Brow!er from the implementation. This also demonstrates the usual way of documenting the modules added to the system. Ob2DGraphs has been implemented to offer some sophisticated routines for showing two dimensional graphs. It supports linear and logarithmic scaling for both dimensions. Scaling and labelling of the axes is done automatically. XYFrame, Gruph and Curve are the new abstract data types with procedures for creation, handling etc. One or more curves may be specified in one graph with different colors and a frame may contain several graphs.
Oberon, the innovative language and system designed by Wirth N. and Gutknecht J. (1992) at ETH has been chosen as the basis for the implementation of educational simulation systems mainly for the following reasons: • the system runs on Macintosh 11, MS-Dos 386 (PC-compatible) and SUN workstations • it is object oriented and extremely compact (distributed on a single disk) • it is freely available • it is well documented • with small exceptions, the source code is also available
DEFINmON Ob2DGrapha;
Oberon is a successor to Modula-2, providing all its facilities for data abstraction and in addition a means for type extension through which object orientation becomes possible. On this basis three
IMPORT Dhplay. Fonts;
107
range-: Range; Icale-: SHORTINT; label-: LabelStr1ng ;
.
~I '-'
END;
...
Color-·SHORTINT ; Curve-·POINTER TO CurveDesc; Curveo.sc-·RECORD graph- : Graph; color-, Ityle-: SHORTINT ; symbol- : CHAR;
-
I
~"""W:."""_"'fI"'_
IE:;:J~~ ........... ~ ••
END ;
Graph*·POINiER TO GraphDelc; GraphDesc-.RECORD frame- : XYFrame; prect-, rect-: RectArea; grid-: BOOl.EAN; axis- : ARRAY 2 OFAxisType;
Fig. 1. Simple parameter tuning experiment using the continuous simulator.
END;
XYFrame*·POINiER TO XYFrameo.sc ; XYFrameDesc*·RECORD (Display.FrameDesc) firltGraph* : Graph; restore- : RestoreProc; close- : CloseProc; END;
PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE
ClearCurve- (c: Curve); ClearFrame-(F: XYFrame) ; ClearGraph*(g : Graph); Clole* ; DefiDeCurve-(g :Graph;ViR c :Curve); DefiDeGraph*(ViR g :Graph; . . . ) ; DravGraph*(g : Graph); DravLegend*(c:Curve ;x, y : INTEGER); FrameExhu*(F:XYFrame) : BOOl.EAN; OpenFrame-(ViR F: XYFrame); Plot*(c: Curve;nevX.nevY :REAL); PlotCurve*(c : Curve; poiDt : INTEGER); PlotSym*(ch:CH4R;l.Y : INTEGER); Redef1neCurve*(c: Curve; .. . ); RedefineGraph*(g : Graph; ... ); RemoveCurve-(ViR c : Curve); RemoveFrame-(ViR F: XYFrame) ; R_oveGraph-(ViR g : Graph); ReletCurve-(g :Graph; c :Curve); SetCloseProc-(F:XYFrame;cp :CloseProc); SetRestoreProc-(F :XYFrame;rp : ReltoreProc);
END Ob2DCraphl .
PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE
DeclKV-(ViR x.acale :REAL ;name:Name); o.clSV*(ViR x.xDot.xO : REAL); InitStateMonitora-; OpenPlotFrame-; SetScope-(XmiD.Xmax ,Ymin,Ymax :REAL) ; Run-; Run4gaiD-; RunContinue-;
END S1muBa...
The two commands "SimuBase.OpenPlotFrame" and "SimuBase.Run" are listed as follows: PROCEDURE OpenPlotFrame-; BEGIN IF -OC .FrameExista(XYframe) THEN OG . OpenFrame(XYframe) ; OC .SetReatoreProc(XYframe.ReatoreProc); OC .SetCloaeProc(lYframe. CloaeProc); DefineCraph; ELSE
ClearGraph; DefineCraph; END; END OpenPlotFrame;
PROCEDURE Run-; ViR iDdex, a~n: LONGINT; BEGIN tmiD :·0.0; tmax:· period; time :. tmin; index :. 0; s1muLen :. ENTIER«tmax-tm1n)/dt)+2; InitStateMonitora; Model ; InitState; OpenPlotFrame ; DravGraph; WHILE time < tmax DO RungeKutta(dt) ; UpdateKV(iDdex) ; monitorVariableHead . time[index] :. time; DravPoiDt; INC(iDdex);
3. A CONTINUOUS SIMULATOR The first implementation is a reduced version of the simulation environment ModelWorks (Fischlin et al., 1990) that has been in use at ETH for many years. It is based on the idea, that the compiler already available on the machine shall also be used in simulations. Figure 1 shows the simulator in action and also its integration into the environment.
END;
END Run;
The definition module of SimuBase, the small simulator that has been built on top of Oberon is shown next . The differential equations are programmed in "Dynamic", States and Measurable variables are defined in "Model".
The simulation equations are entered as follows , a two term controller with gains kp and ki is shown. These gains may be adjusted at run time through simple procedures which are not shown here: MODULE Main ; IMPORT S1muBaae;
DEFINITION SimuBaae; IMPORT OG : .0b2DCraphs; ViR Dynamic- : PROCEDURE; Model- : PROCEDURE; dt., period- : REAL; t1me*, tmax*, tmin*: REAL;
PROCEDURE Dynamic ; BEGIN xlDot .• -xl + x2 ; x2D0t :. -x2 + x3 ;
108
u :- kp*(1 .0-x1) + x4; x3Dot :- -x3 + u ; x4Dot :- k1-(1-x1) ; y :- xl; END DynUl1c; PROCEDURE Model *; V1R xO. acal.: REAL; BEGIN xO :- 0 .0; S1muB... . S.tScope(0 .0.20.0.0.0.2 .0); S1muB... . DeclSV(x1. x1Dot. xO); S1ImB... . D.clSV(x2. x2Dot. %0); S1muB... . D.clSV(x3. x3Dot. %0); S1ImB... . D.clSV(x4. x4Dot. %0); acal. :- 1.0; SimuB... . DeclMV(y. acal •• My"); S1ImB .... DeclMV(u. acal •• MU"); END Mod.l;
~
~
._......... ----... --~
~
--
~
Fig. 2. Simulation with FPU, the configurator for discrete time systems. Due to the high sampling rate the curves are almost continuous. Time constant of PT1: 100 [sI , sampling time: 1 [sJ .
PROCEDURE Ibm*; BEGIN S1ImB... . Model :- Model; S1ImB.... DynUlic :- Dynamic; S1ImB... . Run; END Ibm; END Main.
..... r..
The chain of procedure calls may be traced back from the simulation equations in Module Main. As an example "SetScope" from Module SimuBase is used in "Model" and "SetScope" uses Module Ob2DGraphs. Procedure "Run" from SimuBase invokes "OpenPlotFrame" which uses Ob2DGraphs extensively.
hit
_
4. A DISCRETE TIME SIMULATOR Starting from the ideas of a freely configurable discrete time system as described in Kolb et al. (1991) a first version of FPU was also realized in Oberon. It simulates discrete time systems composed of blocks. Figure 2 shows the corresponding system in operation. Object orientation has been very useful for the implementation of BlockSim, it has allowed us to use the underlying Draw system of Oberon directly by extending the types to blocks and signals.
Fig. 3. Single server queue with different serving times.
DEFINITION Simulation;
IMPOIT Vi.v.ra. D1aplay; 'lYPE
Craph*-POINTER TO CraphDeac; CraphD.ac--RECOIlD (ItemD.ac) END; Handl.r*-PI\OCEDUl\E(x : It.m); Item*-POINTER TO ItemDeac; ItemDeac--RECORD time*: REAL; handle* : Handl.r; END; Queue*-POINTER TO ItemDeac;
5. AN EVENT ORIENTED SIMULATION TOOLBOX Object oriented systems are very well suited for event driven si mul at ions. The handling of the event calendar and of the waiting queues can be made available in a small tool box. The one we use was implemented and made available to us by J . Gutknecht. Small programs, making use of the tool box, are used for the simulations. Figure 3 shows a study of a queuing system.
PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCEDURE PROCFDURE PRDCFDURE Pl\OCEDURE PROCEDURE PROCEDURE
The automatically generated definition module is (graphic procedures and random nwnbers eliminated):
Cr.at.*(VAR q : Queu.); DelEv.nt*(x: Item); Empty*(VAl\ q : Queu.): BOOLEAN; C.tEv.nt*(VAl\ x : Item); C.tItem*(VAl\ q : Qu.ue; VAl\ x: Item) ; Init*; PutEv.nt*(x : Item); Putltem*(VAl\ q : Queu.; x : Item) ; S.l.ction*(VAR a:ARRAY OF REAL) :INTEGER; Simulate*(T: REAL);
END Simulation . 109
graphical system representation in the Draw system was done in about three months .
6. APPLICATION EXAMPLE An interesting application example for the continuous simulator is the simulation of a small hydro power station from the upstream water level to the power delivered to a stiff or isolated grid net. The model is of order eight. Modelling and simulations were done during a graduate course on the use of computers in control.
9. EDUCATIONAL USE Educational use of the simulators shown above is twofold: • The simulators may be used in teaching like all other simulation environments. Results may be compared with results obtained from other systems like Matlab/Simulink. It may be of special interest to compare graphic~l system definitions to textual ones. • As the source code is available there is a unique opportunity to discuss it with the students. The programs are so concise, that they may easily be analyzed in detail in the classroom.
7. IMPLEMENTATION To provide insight, the module structure and the number of lines in the source code of each module are given for the three simulators and Ob2DGraphs: Continuous time simulator SimuBase 455 Main 143 Discrete time simulator Lists 43 Signals 585 Blocks 143 ActionLists 164 StepGenerators 214 Sine Generators 214 Controllers 279 Models 266 Scopes 518 Plot 136 File 112 Main 14
10. AVAILABILITY The Oberon system is available through anonymous ftp from ETH and includes source code for most modules of Oberon. The files described above and used for the simulations in the paper are available (source code) from the authors.
Discrete event simulator Simulation 137 Main 70 Ob2DGraphs 970
11. CONCLUSION From this it becomes evident, that the simulators become extremely small and compact. This allows discussion of the corresponding code in the classroom, thus providing insight into the software engineering aspects of CACSD.
It is shown in the paper that Oberon, the new object oriented programming environment by N. Wirth and J . Gutknecht provides a useful base for the implementation of simulation environments. Three such systems are briefly introduced, namely a continuous and a discrete time as well as a discrete event oriented simulator. As Oberon and the simulators are freely available, this provides new and interesting possibilities for teaching.
8. EXPERIENCE Oberon has been used in a graduate course in spring 1993 for the first time with control engineering students in the classroom. First experiences show, that it takes two to three hours to master the basic facilities of the sYStem and to be able to develop and run progr~. The new style of object oriented programming requires additional time, exercises were done on the implementation of simple data bases and bars for analog readout of simulation results in addition to the simulators shown here. Oberon has also been successfully used in several control engineering student's projects. The one that will be briefly summarized here consisted in producing stand alone simulations for the training of operators of small hydro power stations in developing countries. The simulations have to run on generally available MS-DOS computers, where the structure of the system and of the controller may be chosen from a set of given structures. Developing the simulations and connecting them to a
12. REFERENCES Fischlin A., Roth 0 ., Gyalistras D., Ulrich M. and Nemecek T . (1990). ModelWorks - An Interactive Simulation Environment for Personal Computers and Workstations. Report NT. 8, Systems Ecology Group, ETHZ. Kolb P., Rickli M., Schaufelberger W. and Maier G. (1991). Discrete Time Simulations and Experiments with FPU and Block-Sim on IBMPC's. Proc. IFAC ACE '91 , Boston, 47-52. Wirth N. and Gutknecht J . (1992) . PROJECT OBERON - The Design of an Operating System and Compiler . Addison-Wesley, New York.
110