You are currently viewing 使用TSMaster从零打造车辆控制器HIL实时仿真

Building Vehicle Controller HIL Real-Time Simulation from Scratch with TSMaster

Real-time simulation occupies an important position in the development and testing of automotive components. Usually, to realize real-time simulation and hardware-in-the-loop testing, it is inevitable to deal with NI, Veristand, Dspace and other big-name software or hardware products, which are costly and have certain entry barriers, and are not conducive to large scale promotion. The emergence of TSMaster has broken such a situation.


Overview

First of all, explain the real-time simulation in real-time simulation, it does not require how fast the simulation speed should be, but the deterministic requirements for the moment of return results of the simulation calculation tasks. For example, a task in the ECU has an execution period of 5 ms, and the basic requirement for real-time is that the task must be executed within the current 5 ms, and cannot be postponed to the next 5 ms cycle, which is only the most basic requirement. Because of the limited computing resources of the ECU processor, there are numerous tasks with different cycles that need to be completed within the specified time, which is why it is necessary to use a real-time system to perform the simulation tasks, and the real-time system completely simulates the operating environment of the ECU controller.

First of all, explain the real-time simulation in real-time simulation, it does not require how fast the simulation speed should be, but the deterministic requirements for the moment of return results of the simulation calculation tasks. For example, a task in the ECU has an execution period of 5 ms, and the basic requirement for real-time is that the task must be executed within the current 5 ms, and cannot be postponed to the next 5 ms cycle, which is only the most basic requirement. Because of the limited computing resources of the ECU processor, there are numerous tasks with different cycles that need to be completed within the specified time, which is why it is necessary to use a real-time system to perform the simulation tasks, and the real-time system completely simulates the operating environment of the ECU controller.


II. ECU embedded code and TSMaster applet integration

We will build a real-time simulation environment for ABS algorithms based on TSMaster from scratch step by step. The ABS algorithm will be automatically generated as embedded code through Simulink, and it will be run as an applet in TSMaster's real-time environment. We first save the model as a separate file and then need to modify the path so that the code generation is placed in this new path. We then need to make some changes to the model to allow it to generate the embedded code. First we need to remove the oscilloscope and other useless controls, then we need to remove the CarSim s function and convert the s function interface to in and out.

In order to generate the embedded code correctly, we also need to do some modifications on the code generation, open the configuration, first is the stop time, set to inf, then is salvar, again using the fixed step length, step we use the industry common 5 milliseconds. Next comes the code generation link, Target file is naturally ert, we also need to go to the interface, where the continuous time hook, because the wheel cylinder pressure model is used in the middle of the transfer function, is a continuous state, then press Ctrl + B to generate the code, and soon the code is generated. Then in this code, we need to copy and paste ABS.c.h and some other header files into the middle of TSMaster's applet folder to participate in the compilation process.


III. Real-time simulation of vehicle model out of RT

Whether our ABS algorithm is in the TSMaster applet or in the real ECU hardware, its operation necessarily requires the input of signals such as wheel speed provided by the external environment, and its output must be applied to the external environment, in this case the vehicle and other controllers. Obviously, we need a vehicle model to participate in the simulation process, and in general, this vehicle model is the RT version of CarSim.

Based on our earlier discussion of the real-time nature of HIL simulation, we can also use a non-RT version of CarSim and simply call CarSim-related API functions in real-time to move the entire vehicle model to a personal computer. The CarSim Controller, which is equivalent to the RT version of CarSim, can simulate the vehicle model on a PC with high accuracy.

Based on the TSMaster software platform, we can easily intervene in any variable of the ECU algorithm. It is important to note that CarSim Controller is only one of the millions of ways to make a dynamics software CarSim real-time. Based on this principle, other dynamics software such as Carmaker can also be controlled in real time.

Fourth, the specific implementation of ECU HIL simulation

We have described above the ABS algorithm simulation and the vehicle model run, their function is not simply to draw curves and collect operation data, but has a deeper purpose, which is to link with the external world, exposing the input and output data completely to the real world, to achieve the real purpose of HIL - hardware In the loop. The process of interacting with the external world can be very simple, just need to design a special dbc file for this purpose, load it into TSMaster, and map the contents of the system variables to the bus.