You are currently viewing TSMasterHIL实时仿真系列2-ECU代码生成与小程序集成

TSMasterHIL Real-Time Simulation Series 2 - ECU Code Generation and mini program Integration

This chapter introduces the second chapter of TSMaster's series on building a vehicle controller HIL real-time simulation from scratch. The example is our hands-on design of the real-time simulation also known as HIL session. To make the example easy to understand, we have selected the ABS controller that comes with CARSIM as the object of the simulation.

I. Simulink model

1, we open CARSIM, and then select the Simulink model, folio road Multi-port SLX, this example uses a small car without ABS system, it is the front-wheel drive configuration.

2, we look at procedure, that is, the driver control part, the initial speed is 65 km per hour, the automatic pressure is 15 MPa, in 0.3 seconds or 150 bar as we often say, gear control is within a reasonable range of automatic switching, and the steering part is given to the driver model for closed-loop control.

3, the pavement part for the pavement, starting from 3 meters, one side of the coefficient is 0.2, the other side is 0.5, back to the home page, click Send to Simulink, wait for Simulink to start finished, Simulink model is the focus of today.


Second, ABS control algorithm

1, we can generate embedded code for this control algorithm, download it to the ECU with ABS function and run it. We can see that this algorithm model contains a CARSIM S function as the interface to the vehicle model, and a simplified version of the wheel cylinder pressure control strategy based on the drift rate and the rear axle low selection strategy, as well as the braking force distribution in the brakability model, etc.

2, we run down this model, you can see, this wheel speed and vehicle speed graphics window plotted in the folio surface of the ABS automatic cycle, and this wheel cylinder pressure window, is the wheel cylinder pressure control curve of the four wheels, which is a simple version of the control algorithm. The braking force distribution, which is the ratio of front axle pressure to upper rear axle pressure, is 1 to 0.4. It is easy to tell that the two wheels whose pressure rises to 15 MPa at the end of braking are the front wheel pressures, while the ones whose pressure rises to 6 MPa are the rear wheel pressures.

III. Low-cost alternatives to RT

The Simulink simulation is not real time, but it is only executing the algorithm according to each step, collecting the data from each step and plotting it in the graph window.

 

If we want to send ABS activation flags or wheel cylinder pressure values in real time like the whole vehicle bus during ABS braking, these cannot be done. In the CarSim RT version of the environment, the model can be compiled into a dll and downloaded to run in a real-time system, thus enabling the interaction of the model algorithm with the real world, and this solution is now a widely adopted simulation model. The HIL simulation relied on by major OEMs and component manufacturers is also based on this solution. However, there are two problems with this solution: firstly, it is costly and requires not only the license of the vehicle dynamics software itself, but also the license of RT; secondly, the deployment process is time-consuming and requires redeployment after the parameters are modified in CarSim, which is not highly automatic.

 

In this case, we use TSMaster to simulate the ABS algorithm, and let the ABS algorithm run in the real-time environment of TSMaster, during which it can interact with the external world through the CAN interface or the IO interface connected to a personal computer, etc., and then use the self-developed real-time engine to take over the simulation process of CarSim to realize the vehicle model on the computer In this way we get a low-cost alternative to RT - the software HIL.


IV. ECU embedded code & mini program

In the following, we build a real-time simulation environment for the ABS algorithm based on TSMaster from scratch step by step. The first step is to automatically generate the embedded code for the ABS algorithm through Simulink and run it as an applet in the real-time environment of TSMaster.

 

1. We first save the model as a separate file, and then we need to modify the path so that the code generation is placed in this new path.

2. We then need to make some changes to the model to allow it to generate embedded code. First, we need to remove the oscilloscope and a series of useless controls, then remove the s function of CarSim, and convert the interface of the s function to in and out.

3, in order to correctly generate embedded code, but also need to do some changes in the code generation, open the configuration, first of all, stop time, set to inf, then salvar, again using a fixed step length, step we use the industry common 5 milliseconds.

4, next to 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 used in the middle of the transfer function, is a continuous state, and then press Ctrl + B to generate code, and soon the code is generated.

5, then in this code, we need to copy and paste ABS.c.h and some other header files into the middle of the TSMaster applet folder to participate in the compilation process.