Interacting Modelica Using a Named Pipe for Hardware-In-The-Loop Simulation

Interacting Modelica Using a Named Pipe for Hardware-In-The-Loop Simulation

Interacting Modelica using a Named Pipe for Hardware-in-the-loop Simulation Interacting Modelica using a Named Pipe for Hardware-in-the-loop Simulation Arno Ebner Anton Haumer Dragan Simic Franz Pirker Arsenal Research Giefinggasse 2, 1210 Vienna, Austria phone: +43 50550 6663, fax: +43 50550 6595, e-mail: [email protected] Abstract tion for the system model considering the initial val- ues. The paper presents a concept and an implementation In some cases the user or other applications have to of Modelica simulation interaction using the operat- interact with the simulation, for example to: ing system inter-process communication method of • Start or interrupt the simulation the Named Pipe. The main aim of this presented • Change parameters or variables during the simu- work is to implement a hardware-in-the-loop simula- lation tion (HILS) environment based on Dymola which • Communicate with other applications, for exam- runs on a normal Microsoft Windows Personal Com- ple with another simulation environment puter. • Exchange data with an input/output-card or a pe- An energy storage test bench is connected by an ana- ripheral communication interface logue and digital data input/output card with the Dy- • Build up a hardware-in-the-loop simulation envi- mola simulation computer. With this proposed sys- ronment tem, particularly long-time simulations with sample rates up to 30 Hz can be executed very cost effective. Hardware-in-the-loop (HIL) is the integration of real Typical applications are simulations of drive cycles components and system models in a common simu- to test energy storage systems in electrified vehicles lation environment [1]. This means that some parts such as batteries or fuel cells. Other application ex- of a system, which should be tested, are virtual and amples are the verification of battery models, ther- other parts are real. HIL simulations are an important mal management models or battery management sys- method for the development of mechatronic systems. tem (BMS) models. An important advantage of HIL is that it allows func- In this paper all methods used for implementation are tion tests of mechatronic systems or components of such systems under simulated real conditions. There- described in detail. Especially the concept of inter- fore HIL helps to save cost and time compared to process communication and the concept for real-time conventional test runs on a real prototype. and simulation time synchronization is discused. There are three important consideations for the im- An application example which uses the provided plementation of a hardware-in-the-loop simulation: concept is also shown at in this paper. In this exam- • The simulation of the dynamic system, in other ple a longitudinal simulation of a vehicle is pre- words the mathematical or physical models must sented. The startup phase of the internal combusting be processed in real-time. engine model and a short drive cycle in combination • There must be synchronization between the time with a connected real battery is shown. in the real world (the so called real-time) and the digital simulation-time of the simulation tool. • The simulation tool must be able to communicate 1 Introduction e.g. with others applications or an I/O communi- cation interface. The traditional approach for simulating technical or physical systems is to describe real systems in The Monitoring, Energy and Drives division at Ar- mathematical models. These systems are described senal Research does research and development on with discrete equations or with continuous algebraic components for Hybrid Electric Vehicles (HEV`s) and differential equations. The simulation environ- and electrified auxiliaries for vehicles. For that they ment has a solver algorithm which generates a solu- acquire know-how in the simulation of electric The Modelica Association 261 Modelica 2006, September 4th – 5th A. Ebner, A. Haumer, D. Simic, F. Pirker drives, of energy storage systems and in vehicular client calls the CreateFile() or CallNamedPipe() simulations. A great deal of simulation models was function to connect to an instance of the Named built up in Modelica and simulated with Dymola [2], Pipe. ReadFile() and WriteFile() functions allow [3]. In order to verify and validate the implemented reading and writing to a specified Named Pipe. models and the developed system components, a In the presented work the Dymola process corre- connection to a hardware-in-the-loop simulation en- sponds to the server process, which generates the vironment has to be implemented. pipe and waits for a connection with a client (for in- In that way in the provided paper an interaction of a stance the I/O process). This process then executes Modelica/Dymola simulation with components out- the simulation steps, puts data in the communication side of the simulation tool is shown. At this proposed pipe and gets data from the client process. HIL system the Dymola application runs on a stan- dard Microsoft Windows Personal Computer. Actu- ally two important processes run on the simulation 3 Implementations in Modelica and PC: one process is the Dymola application and one process provides the input and output functionality Time Synchronisation for the peripheral card. Details on implementation for both tasks, first for the Dymola application using The described mechanism of inter-process commu- external functions and furthermore for the peripheral nication is implemented as an external function writ- card application are given below. ten in ANSI/ISO C. At Arsenal Research two main C functions for the communication of Modelica with This two processes communicate together using the other processes using Named Pipes are developed. inter-process communication (IPC) methods pro- vided by the operating system. In the proposed case The AllocateResources() function creates and con- the tasks communicate via a so-called Named Pipe nects a Named Pipe. The function PipeIO() com- mechanism. Through the first-in first-out behavior of putes a string from the simulation variables array the Named Pipe communication method there is an calculated by Dymola and writes this string in the implicit synchronization between the two processes. Named Pipe. Then the function gets the data string In this paper is described how to create and to open, from the Named Pipe and computes an array of Real how to write to and how to read from the Named variables for the Dymola simulation solvers. Pipe and how to close it. In Figure 1 the flow chart of the functionalities of the server process is shown. Specifically, the function AllocateResources() and the function PipeIO() are 2 Inter-process Communication with described. For these functions a static library is build. This library is linked to the model using the Named Pipes function definitions. In Dymola a wrapper function to convert the external C function to a Modelica The IPC method that is used in this work is the so- function is defined. called Named Pipe mechanism. This IPC method is available both on UNIX systems and on Microsoft For a working HILS it is important, that the simula- Windows systems. The semantic and the function tion time in the simulation application is synchro- calls differ in the operating systems but the concepts nized with the real time. This synchronisation in are the same [4], [5]. Only the implementation on a Modelica is achieved by using the when clause in an Microsoft Windows operating system is shown in this algorithm statement: paper. ... Named Pipes are designed for the communication when (time >= SimuNext) then between the pipe server and one or more pipe clients. (SimuNext, input) := PipeIO(time, output); They have first-in first-out behavior and can be ac- end when; cessed like a file. In this short code fragment time means the simula- Stdio.h standard C library functions for file handling, tion time in Dymola and SimuNext means the real- such as fopen(), fclose(), fread() or fwrite() can be time. input means an array of Real variables taken used to deal with Named Pipes. However, the usage from external C code to Modelica and output means of Microsoft Windows Software Development Kit an array of Real variables taken from Modelica to (SDK) functions gives a more powerful access on the external C code. functionalities of Named Pipes. Specifically, using the SDK a pipe server calls the CreateNamedPipe() function to create an instance of a Named Pipe. The The Modelica Association 262 Modelica 2006, September 4th – 5th Interacting Modelica using a Named Pipe for Hardware-in-the-loop Simulation Figure 2: Flow chart of the client process. Figure 3: Icon and parameter settings of the Pipe block. Figure 1: Flow chart of the server process, which All inter-process and simulation time synchroniza- runs as an external function call of Dymola. tion functionality are combined in the so called Pipe block. This block is shown in figure 3. The simulation process gets the real-time informa- tion from the client process via the Named Pipe IPC. As long as the real-time is greater than the simula- tion time in Dymola a new inter-process communica- 4 Application Example: Hardware- tion cycle get processed and the function PipeIO() in-the-loop Energy Storage Test gets called. As long as the real-time is smaller than Bench the simulation time new simulation steps of the Dy- mola solver get executed. The HILS environment presented in this paper is a In figure 2 the client process of Named Pipe IPC is very cost efficient system which is based on a nor- shown. In this process the data in- and output func- mal Windows PC platform. tions and the calculation of real-time information for The communication between the simulation PC and the simulation application using functions from the the energy storage test bench is realized by an ana- ANSI/ISO C library time.h are executed.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us