Online Control of Thermo-Optical Plant via OpenModelica

The paper deals with the web-based implementation of the thermo-optical plant control. The control of the plant is based on the open-source Modelica-based modeling and simulation environment OpenModelica which originally is not designed for web-based applications. The paper shows one possible way how to circumvent this limitation.


I. INTRODUCTION
Experimental work is an inseparable part of engineering education at universities. Experiments help to understand theory, relations between incurred tasks and problems and they give a hand to form, confirm and reject hypotheses that lead to the problem solution. In spite of the fact that some experimental work can be accomplished using various animations and simulators, the best possibility is to offer students the work with real devices. Unfortunately, such experiments cannot be usually available for the whole day. The rooms with experiments are usually opened only during limited time. It means that except of travelling to the university buildings students also need to check the availability of laboratories. Therefore there arises a question how to offer and deliver experiments to all students whenever they need them. One possibility is to use Internet as a medium and to provide experimental work via remote access to the laboratory.
The paper demonstrates one possible way of remote control of the thermo-optical plant presented in the next section.

II. PLANT
The considered thermo-optical laboratory plant uDAQ28/LT (Fig.1) presents a system that is very suitable for all forms of the education process because of its easy manipulation and a good portability. It can be connected to the control computer via a USB interface and no special A/D card is required. It enables to control two physical variables -the temperature inside a plastic cylinder and the intensity of a light source.
The plant [5] has three inputs -the bulb voltage (the heat & light source), the ventilator voltage (system cooling) and the light diode voltage (the second possible light source). There also exist two parameter inputs for adjusting the sampling period and the time constant of the built in derivative filter. The user can use eight measured outputs: the system temperature measured by a PT100 sensor, the light intensity (both measured directly, or with a preliminary filtration by the filter of the 1st order) and The high number of measured outputs enables to accomplish a variety of experiments. However, students mostly control only the light intensity that can be influenced by the voltage on the light diode or the temperature inside the plastic cylinder that is influenced by the bulb heating and the ventilator cooling. The temperature is usually controlled by the bulb voltage with the ventilator being considered as a disturbance factor. Of course, the control when the temperature is influenced by the bulb heating and the ventilator cooling at the same time together is also possible. In addition to control, students also have to solve tasks that are connected with the plant identification, input-output data manipulation and communication with outer computer environment.
The communication with the computer runs via the string exchange. The data transfer rate is 250kbit/s. The plant enables to use a sampling period 40-50 ms whereas considering the dynamics of the presented system 1 second it should be sufficient for its quasi-continuous control. The whole plant is supplied by 12V/2A DC external adapter.
III. OPENMODELICA ONLINE SUPPORT OpenModelica [3] (developed on the base of open and free technologies) enables to model and simulate the behavior of the dynamical systems. In this way it is similar to Matlab, LabView or SciLab.
It is to say that OpenModelica is usually used for computations that are accomplished on the computer locally. However, the increased expansion of Internet together iJOE -Volume 8, Special Issue 3: "REV2012/1", November 2012 SPECIAL FOCUS PAPER ONLINE CONTROL OF THERMO-OPTICAL PLANT VIA OPENMODELICA with the growing support of online education raised a question how to exploit capabilities of OpenModelica for these purposes, too. In such a case, one installation of OpenModelica placed on the remote server could serve for several clients whereby the client can be represented by a person or an application.
We started to test OpenModelica for various online interactive examples and simulations. Later we tried to use it for a remote experiment, too. Such approach is also presented in this paper.

A. Experiment running
The communication with the server is provided via the web browser form where the user enters all necessary parameters that are sent later to the OpenModelica engine installed on the server. The same web page can also be used for the result visualization.
Each user that wants to run experiment has to log in into the web application environment and to start with allocation of a time slot for the experiment. Without this reservation the experiment cannot be executed. It should ensure that in each moment only one user will have the full access to the experimental plant.
Then according to preferences specified by the user the application builds the control structure for the experimental work. Only then the experiment can be executed.
The created application requires accomplishing following tasks in parallel:  Accepting the data from the plant that are in successive steps saved to variables and globally available in the application. Afterwards they can be used for continuous visualization of experimental results e.g. in the form of graphical dependences.  Enabling the change of controller parameters during the run of experiments.  Following the simulation time that was specified by the user or by the application.  Receiving information messages that are sent by the plant model.
The experiment can be stopped by two ways. It can be done manually by the user who presses the Stop button. The experiment is also concluded after the predefined simulation time elapses. In both cases all running processes are ended and the experiment report is completed by the last measured experimental values. The communication between the server and the client side is closed only after the results are visualized on the client side. Later, the client can send new data that the server has to process again.

B. Web Application
The structure of the whole application is sketched in Fig.2. It consists of 3 main parts.
The presentation and application layer is realized using PHP scripting language that is widely used for the development of dynamical web applications.
The simulation layer was built using Python scripting language. The main motivation for the change of the programming language was the fact that PHP (in contrast to Python) doesn't allow building of native multithreading applications. Since we need to accomplish several tasks in parallel one possible choice how to realize them all at once was the selection of the programming language that supports multi-threading in the native manner. We didn't want to use any alternative solution for PHP (e.g. cURL extension).
Except of that Python programming language has the ability to cooperate with CORBA interface that can be used for communication with OpenModelica environment.
The presentation layer defines the appearance and layout of the client application using Smarty templates. It helps to manage requests and responses for users. The data that are visualized in the presentation layer are dynamically prepared in the application layer.
The application layer processes the requests from users and ensures that the user receives the corresponding feedback information. After the user starts the experiment and data are sent to the server, they have to be transformed to the form that can be understood by OpenModelica. This layer also support data manipulation using MySQL databases and takes care about export of experimental results to various formats according to the specification of the user. The simulation layer covers the communication between the real plant and OpenModelica environment that is used for the control of the remote experiment. Open-Modelica is running in the interactive mode that enables to change parameters during the experiment. Without this feature it would be not possible.
Before running the experiment the simulation layer creates its control structure on the base of requirements from user. It consists from several model components that are summarized in Fig.3.
The structure of all model components, their nesting and connection results from the Modelica language possibilities. However, there are 2 essential parts: The omReadWrite block covers the communication with the thermo-optical plant. Its task is to write and to read data from the system. The functionality requires importing the driver that ensures approach to the real device. The driver was written in C language using the open source libusb library [2] that enables an unified approach to USB interface based equipments on the user level.
The UdaqCont model block describes the block scheme that is used for the experiment control. It consists from two main blocks: The Udaq model block allows to specify and set inputs and outputs of the plant. This block is written in Modelica language and defines an interface between the real plant and control algorithm calculations that are realized in the OpenModelica environment.
The Controller model block enables to compute the value of control signal according to the chosen control algorithm. The application also allows running the experiment without a controller. This setting permits to measure step responses of the physical system and to identify its dynamics. In such a case the Controller model block is substituted by the open loop connection.

C. User Interface
The online experiment can be realized using Web portal shown in Fig.4. After registration and login it enables user  to allocate time slot for experiment  to set suitable parameters  to select type of experiment (open loop, control structure with PID controller or control structure with own control algorithm)  to follow results in form of graphical dependencies  to export numerical results to various graphical or text formats that can be used outside of the presented web portal.
Our aim was to enable users to use not only a set of predefined controllers but also to be able to experiment with own control algorithm that is set up according to personal preferences.
Since the structure of the OpenModelica file describing the controller is quite complicated we decided to facilitate the design as much as possible. The structure requires specifying parameters, inputs, outputs and all other variables of the controller at the beginning of the controller model description. Their number depends on the type of the controller and therefore has to be flexible.
The implemented graphical user interface (Fig.5) allows adding a new parameter or variable by simple click-  ing on a button whereby the user can define its type, name and in the case of the parameter its default value, too. The keywords for various types of parameters and variables are predefined and therefore the risk of misspelling is minimized. Variables have no associated values since their values are changed in each time step of the experiment. By specifying parameters and variables the structure of the controller model starts to be created (Fig.6 -blue  sections). Finally, the controller algorithm equations have to be determined. We used the classical text area input element (Fig.5) for their definition. The syntax of equa-SPECIAL FOCUS PAPER ONLINE CONTROL OF THERMO-OPTICAL PLANT VIA OPENMODELICA Figure 6. The resulting controller code for OpenModelica V. CONCLUSIONS The implementation of the presented remote control of experiment was realized in frame of diploma work. Our purpose is to support "learning by doing" method that helps students to understand better the problem they meet. In this case it was necessary to master not only programming techniques, algorithmization, way of communication but also all topics connected with control of the real plant.
ACKNOWLEDGMENT Authors thank to Zoltán Magyar for his help and discussions.