Simulink Automated Code Generation for Motor Control: Summary of Software-in-the-Loop (SIL) Steps

Table of contents

foreword

model configuration

SIL model generation

Model simulation comparison

Summarize


foreword

Motor model simulation can be called model-in-the-loop test (MIL). As for SIL, it is software-in-the-loop simulation test. To put it bluntly, it is to verify whether there is any problem with the generated code. By generating code and then packaging the generated code into a model form, verify whether the generated code is reliable, you can test the code coverage, and verify whether the data is distorted after the code is generated. Sometimes the model simulation is fine, but the generated code behaves differently when it runs on the system. I have stepped on the pit before, so it is necessary to do SIL before going on the machine. Next, we will introduce the specific steps on how to achieve SIL.

model configuration

Configure model parameters, expand Code Generation to find Verification, and then find Advanced parameters, which are the three small dots at the bottom, and select SIL.

2aced8679d034b6bac03d0a390e3d053.png

 Since SIL is selected, you cannot check Generate code only. Here, Toolchain is automatically selected by default. If you want to debug the C code, install a Visual_studio. Here we don’t need to install it. It’s basically useless for the C code. If necessary for debugging, it is also possible to use MinGW64 for actual testing.9af4e50067224829b8ef86810e9a4fe4.png

 Get here and get ready

SIL model generation

Click on the main model to generate a SIL model for the sub-model, right-click on C/C++ Code, and select Build This subsystem.

5d0843207e5f4335b7ee42d362510c75.png

 The following window pops up, click Build56556ff5190d465da2cba73304690847.png

 After a while, the following window will pop up, this is the SIL model that is packaged after generating the code44500584f9a94ed7ae2d251dde533cb1.png

 It can be saved for easy traceability9346855e9d234e308b8c35e730101675.png

 Copy it to the main model interface, as follows:0eb74c44ddd34ea4b20bb151c4432368.png

 SIL model generation, ready for simulation comparison

Model simulation comparison

Comment out the SIL model, and first perform simulation verification on the original model, as shown in the figure below:

7bdfd438ec9544b3948b550ec2d096e2.png

 Then cut out the original model, replace it with a SIL model, and perform simulation verification on it

ae101492c384454b833c8fdf06e17713.png

 After the simulation is over, click on the Data Inspector, as shown below:

12d48307877e4fa2ad81dc55bbf2c4c3.png

 Comparing the results of the two simulations, it is almost the same without exception, which means that the generated code has no problem

 29a1402412d648849dafecd5b3aecbff.png

 Set tolerance for comparison

b7202a3fdc1640acbb49c441d28aeab1.png

Summarize

It briefly introduces the steps of SIL software-in-the-loop testing. It is very simple. The deeper things can be excavated according to the needs of the process. Let’s summarize here first. 

Guess you like

Origin blog.csdn.net/weixin_42665184/article/details/130750328
Recommended