Simulink and VC-based Hardware-in-the-loop Real-time Simulation ...

2 downloads 0 Views 151KB Size Report
Abstract:A distributed hardware-in-the-loop real-time simulation platform is structured by frequently-used Matlab/Simulink and. Visual C++ 6.0. Simulink models ...
Simulink and VC-based Hardware-in-the-loop Real-time Simulation for EV Hongxu Chen State Key laboratory of Automotive Safety and Energy, Tsinghua University, Beijing, P. R. China Abstract:A distributed hardware-in-the-loop real-time simulation platform is structured by frequently-used Matlab/Simulink and Visual C++ 6.0. Simulink models for fuel cell city bus are built up, and then are all transformed to C++ code by Real-Time Workshop (RTW). Simulation is implemented in the context of VC by loading C++ code generated before. The problems of real time operating environment, CAN communication, and state equation solving with variable parameters are resolved. By combining model-based design characteristic of Simulink and VC utility system, co-simulation is carried out, and their mutual support has been enhanced obviously. In conclusion, the solutions for electric vehicle’s design, real-time simulation, and rapid prototype testing are provided. Keywords:hardware-in-the-loop; real time; simulation; electric vehicle

basis to structure Hardware-in-the-loop Real-time Simulation platform, and they have been built up in Simulink as figure 2. Importantly, data flow direction of these models should be same as the energy flow direction of physical system. For the quick search in VC later, it had better name the input and output variables clearly in the course of modeling like figure 2.

1. INTRODUCTION Design procedure of EV is necessary to be flexible, rapid, and cost effective. Distributed hardware-in-the-loop real-time simulation platform provides a feasible solution to the development of controllers and research of items which are difficult to be modeled. It will reduce both time and cost of new product development [1] [2]. Vehicle is in a closed-loop of person, vehicle and road, and driving behaviors will affect on the vehicle operation. However, different people have different driving habits, so a uniform driver model is impossible to be built. As a result, driver is always in the loop in a simulation platform. On the other hand, Vehicle Control Unit (VCU) and its control strategy is the core of vehicle control. So, VCU is also in the loop as hardware [3]. In order to establish the connection of virtual models and actual parts, real time environment is necessary to be established. At the moment, special simulation computer and software are adopted to set up the context of real-time simulation by automobile enterprises. However, both of them are so expensive [4] [5]. In this paper, a distributed hardware-in-the-loop real-time simulation platform for fuel cell city bus will be established under windows environment only with a personal computer and general simulation software (Simulink and VC). We built Simulink models for vehicle and components, and designed interfaces for Vehicle Control Unit (VCU) in the loop and driver in the loop functions. Structure of this platform is shown in figure 1.

Figure 1: Structure of distributed hardware-in-the-loop real-time simulation platform

2. VIRTUAL VEHICLE DEVELOPMENT 2.1 Models in Simulink Vehicle models include models of fuel cell engine, battery, DC/DC, electric motor, tire and so on. All of them are the 2.2 Establishment of Real Time Environment

Figure 2: Vehicle Models

In order to carry out the simulation under a real time environment, all of the Simulink models should be transformed to C++ code by RTW (Real-Time Workshop).

And then, real time simulation will be implemented in the context of VC. 2.2.1 Introduction about RTW RTW is a toolbox in Matlab/Simulink, it provides an environment in which Simulink models can be automatically transformed to target code. Various code formats are supported by RTW, but only C++ code is chosen in this system. Importantly, all of these codes are optimized in this transformation process, and these transformational codes are transplantable, revisable and personalized. So, extended functions based on these codes can be implemented in VC by user. 2.2.2 C++ Code Generation Before model transforming, some basic configurations should be accomplished. First, solver type of the Simulink models should be set as fixed-step in Configuration Parameters Settings in the context of Simulink. Simulation precision is determined by fixed-step size, which is also set by user in Configuration Parameters Settings. Smaller fixed-step size begets higher precision provided that there is enough time to compute models and communicate with hardware. In this system, fixed-step size has been set as 10 millisecond. Second, several solver algorithms, like Dormand-Prince, Runge-Kutta, Heun, and Euler, are provided by Simulink, and one of them should be chosen. Third, System target file should be set as ‘Visual C/C++ Project Makefile only for the Real-time Workshop Embedded Coder’ in RTW, and language should be set as C++. Last, software environment should support the continuous time simulation. After these configurations, a new folder will be created in the root directory of Matlab once press ‘Build’. Suffixes of the files contained in this new folder are ‘.cpp’ and ‘.h’, and all of these files can be directly loaded in VC.

execution (namely T ) will be accurately timed by executing a delay function as figure 3. In this system, the interval (namely T ) has been set as 10ms, namely   T . After these, real time environment based on windows environment has been established. 2.3 Communication After establishing real time environment in the context of VC, virtual models communicating with actual parts comes true. In this platform, a PCI CAN card is adopted for virtual vehicle to communicate with other hardware in real time according to CAN2.0 protocol. By loading Dynamic Link Library (DLL) in VC, CAN card can be called to initialize, open, close, reset, send data and receive data by C++ code. In the new generated files, input and output variables of vehicle models are global variables. So, the output variables which need to be sent can be found out accurately by searching for their names, and then, they will be packaged to message. After receiving message, input variables can be modified by the same way. Two threads, one in charge of sending message, another receiving, are built in the context of VC respectively. Efficiency of resource allocation is raised by this multithreaded program so that high-speed data transmission is put into truth in this platform.

2.2.3 Codes Execution The meaning of real time simulation is that the time ruler (  ) in simulation is equal to the actual time ( T ). In this system,  has been set as 10ms in Simulink, which is a fixed-step size. Simulation is implemented in the context of VC by loading C++ code generated before. Once the function named rt_OneStep (), which is involved in the executable file “ert_main.cpp”, executes, one step (namely  ) vehicle models perform. Generally,  is much bigger than the actual time that vehicle models performing one step costs. So, a special measure will be adopted to let rt_OneStep () execute in accordance with a fixed time. Some functions to timing have been provided by Windows, and time measurement can be implemented by these functions. Above all, clock frequency of timer in PC can be obtained by calling a function named QueryPerformanceFrequency () in VC. And then, two count values can be gained at the beginning of rt_OneStep () execution and at the end time of it respectively by calling another function named QueryPerformanceCounter (). Last, the actual time that vehicle models performing one step costs can be calculated by the two count values and clock frequency. Furthermore, the interval of rt_OneStep ()

Figure 3: Program execution order

During the time ‘T’, rt_OneStep () executes once firstly, and then, RX and TX threads will start to work for a certain time, last, a delay function will be executed to wait until next circulation starts. Figure 3 points out the program execution order in simulation cycles.

2.4 Solving of State Equation with Variable Parameters 2.4.1 Problem Description PNGV battery model, shown in the figure 4, is adopted in virtual vehicle. The state equation is as follows.

  1  0 U  0  U   C  1  pb   pb I   pb      L U  0  C R  U pp   1  pp pp pp      C pp     U pb   U L    1  1U    R p 0 I L   U OC   pp  



(1)



returned to the output ‘y’. Hereto, this invariable parameters state equation is solved in VC. In VC, independent variables including A, B, C, D, and u are easily modified during solving process, so coefficient matrixes of PNGV battery model can be changed in real time, and state equation with variable parameters is readily solved. Algorithms to solving state equation are generated from Simulink model in this approach. State parameters are changed in real time in VC. So, it will increase the efficiency of modeling.

U OC : Open circuit battery voltage I L : Battery load current I PP : Current through polarization resistance U L : Battery terminal voltage R p 0 : Battery internal ohm resistance

R pp : Battery internal polarization resistance C pp : Shunt capacitance around Rp

Figure 5: PNGV battery model with S-Function

C pb : OCV difference resulting from current accumulation + UPoUPb +

RPo

CPb

IL

+

Uoc UL RPp

+

IPp

CPpUPp

Figure 4: PNGV battery model

R p 0 , R pp , C pp and C pb are all variable parameters due to the intrinsic properties of Electrode, electrolyte, and dissepiments. So, a state equation with variable parameters should be solved in virtual vehicle models. Generally, this equation can be easily solved by adding an S-Function in Simulink like figure 5. However, codes in S-Function can not be transformed to C++ code by RTW directly. So, it should be solved in VC.

3. VCU AND DRIVER IN THE LOOP Driver operational environment, including ignition key, pedals, PRND, and displays, is provided by Driver Aid module. Auxiliary information like driving cycle, vehicle speed, and key component operation conditions is also presented in the Driver Aid Interface, which is programmed by Labview. During simulation, driver should control the virtual vehicle by shifting and operating accelerator and brake pedals to follow the objective speed that is set in driving cycle. In order to check out the function of VCU in the loop, a VCU mainly based on Infineon XC167 has been developed. VCU should accomplish real-time control by receiving operation signal from driver, sending instructions to component controllers, and receiving state signals from virtual vehicle. The function and inputs/outputs of VCU is present as figure 6.

2.4.2 Solving Method First, a state equation model only with invariable parameters is built in Simulink. Importantly, coefficient matrixes of this state equation and PNGV battery model are homeotypic. Second, this state equation model is transformed to C++ codes according to the method discussed before, and a VC project named project1 is built to load them. Third, function ‘y=f (A, B, C, D, u)’, independent variables of which are the coefficient matrixes and input vector, is built in projec1. Once the function named rt_OneStep () executes, one step this invariable parameters state equation is solved, and output of it is

Figure 6: Layered structure for VCU

4. SIMULATION RESULT The simulation result is showed in figure 7. This test shows that the developed Driver Aid Module and VCU in the loop are functioning pretty well, the effects of driver behavior and vehicle control algorithm to vehicle

V e h ic le S p e e d (k m / h )

performance and fuel economy can then be thoroughly analyzed. 100 Objective Actual

50

SOC

0 0.56 0.54

M o t o r T o rq u e (N . m )

0.52 500 0

D C / D C C u rre n t (A )

200

FC P ower (k W )

-500 400

50

0 100

B a t t e ry C u rre n t (A )

0 1000

0

-1000

0

100

200

300

400 time (s)

500

600

700

Figure 7: Simulation result

5. CONCLUSION A distributed hardware-in-the-loop real-time simulation platform is structured under normal PC and Windows environment. With help of frequently-used Matlab/Simulink and Visual C++ 6.0, this approach makes it easier and much more cost effective for engineers to use real time simulation tools during EV development and vehicle control unit verification.

References [1] Dan Wei. The Power Source Parameter and Control Strategy Optimization of a Plug-in Fuel Cell Hybrid City Bus: [master's thesis]. Beijing: Department of Automotive Engineering Tsinghua University,2008 [2] Zhanning Qi. The Real-time Simulation and System Optimization for Fuel Cell Hybrid Bus: [doctoral dissertation]. Beijing: Department of Automotive Engineering Tsinghua University,2004 [3] Zonghua Li. Distributed Hardware-in-the-loop Real-time Simulation and Research on Control Strategy for Fuel Cell City: [master's thesis]. Beijing: Department of Automotive Engineering Tsinghua University,2006 [4] Jim Ledin, Simulation Engineering. Berkeley: CMP Media LCC, 2003 [5] Thomas Brendecke, Ferit Kucukay. Virtual real-time environment for automatic transmission control units in the form of hardware-in-the-loop. Int. J. of Vehicle Design, 28(1/2/3): 84~102, 2002

800