Co-simulation based on MATLAB\simulink and carsim

Xiao Luoge will bring you an article about the co-simulation of carsim and simulink today. The idea of ​​this co-simulation is to use carsim to provide the vehicle model, and simulink to build the controller model to achieve the control of the throttle valve and brake fluid cylinder of the vehicle model. The pressure, steering wheel angle, etc. to control the car. At the end of the article, the carsim installation package will be presented, so that those who need it can download it at any time.

1. Open simulink and save the new model in the path we specified

2. Close simulink, then open carsim

 

3. Select Models at the models under Run Control: Simulink

4. Create a new dataset

name the title

5. Select the simulink file we saved

 

6. Set the input volume and output volume. The input volume is carsim output, which is used as the input of simulink, and the output volume is carsim input, which is used as the output of simulink.

enter

 

output 

 

7. Edit the input volume and output volume.

Choose our model here

 After setting, we can search for the data that needs to be entered by unit

 

 

Here we select the required amount and double-click. If there is a variable we selected in the Variables Activated for Import column, it means that the addition is successful.

At the same time, select the selected variable and click Move in the middle to adjust the position of the data. The sequential position in this list represents the sequential position of the data in simulink. Click Clear List to delete all variables in the selected list

 After the setting is complete, you can use the refresh button to refresh

The method of setting output variables is the same as that of setting input variables, so I won't go into details.

 8. Before running the simulation, we need to remove the control model in carsim,

First open Procedure, then remove the driver control part.

 

The simulation time can be adjusted to Run forever

 

 

9. When we have set all the data, we can directly click Send to simulink. At this time, if your computer has installed MATLAB, it will automatically open simulink. Some computers are prone to flashbacks when using Run Now, so I don’t recommend you to use it here.

10. In simulink, we can see that there is an option of CarSim S-Function in the module library, and we drag the S-Function module into it.

Then double-click this module, enter simfile.sim in the Simfile name, and click OK.

 

 When setting the input quantity, we set three quantities, which are steering wheel handover, throttle opening and brake pressure. Here, the steering wheel parameter corresponds to in1 of simulink, the throttle corresponds to in2, and the brake corresponds to in3. I will use To Workspace The module outputs all the output to the work area of ​​matlab. As for the quantities of 1, 2, and 3, we can define them as variables or constants, or input them directly from the workspace or use the Constant module.

After the model is established, the simulation time and simulation speed can be set here. After everything is ready, you can click to run the co-simulation. 

 12. After running, the data can be observed through the workspace of matlab or the oscilloscope module of simulink, and at the same time, the visualized simulation video and image curve can be viewed in the post-processing part of carsim.

 Link: https://pan.baidu.com/s/1eEky9PMjdzyrnXOyqu3Vkg 
Extraction code: otv0 

 

Guess you like

Origin blog.csdn.net/m0_73134033/article/details/129669206