Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)

Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第1张图片

文章目录

  • Create a Dataset for an FMU
  • Create a Simulink Model that Uses an FMU
  • FMU Multiple Ports in Simulink

(前面这一段是简介,用处有限,可以跳过)
Functional Mock-up Interface (FMI) is standardized interface to be used in computer simulations to support both model exchange and co-simulation of dynamic models provided using different simulation tools. (See the web site https://www.fmi-standard.org for definitive information about
FMI.)
功能模拟接口(FMI) 是用于计算机仿真的标准化接口,支持与不同的仿真工具联合仿真。(有关FMI的确切信息,请参见网站https://www.fmi-standard.org。)

One means for combining simulation tools with FMI is through co-simulation, where each tool is represented in the form of a Functional Mock-up Unit (FMU). Starting with version 2016.0, BikeSim, CarSim, and TruckSim support FMI co-simulation by including the capability to automatically generate a slave VS FMU.
联合仿真是一种将仿真工具与FMI相结合的方法,其中每个工具都表现为一个功能模拟单元(FMU)。从2016.0版开始,BikeSim、CarSim和TruckSim都支持FMI联合仿真,包括自动生成从属的VS FMU。

This memo is a tutorial that describes how you can create a VS FMU from BikeSim, CarSim, or TruckSim, and run it within the Simulink environment. The example involves a simple antilock brake system (ABS) example that has long been provided in databases for VehicleSim products.
本备忘录是一个教程,介绍了如何从BikeSim、CarSim或TruckSim创建VS FMU,并在Simulink环境中运行它。这个例子涉及到一个简单的防抱死制动系统(ABS)的例子,这个例子在早期的版本就已经提供了。

Notes BikeSim, CarSim, and TruckSim are typically run in Simulink using VS S-Functions, without needing FMI. This memo describes co-simulation with Simulink because this third-party software tool is the most familiar to users of VehicleSim products. The example ABS controller is not intended for specialists in ABS or brake system modeling. Rather, the point is to show how to set up a VS FMU to work in another environment. This memo shows datasets and results from CarSim. Nearly identical datasets are provided in BikeSim and TruckSim.
注意,BikeSim、CarSim和TruckSim通常在Simulink中使用VS S-Functions运行,不需要FMI。本教程描述了与Simulink的联合仿真,因为第三方软件和VehicleSim产品非常相似。示例中使用的ABS控制器不适用于ABS或制动系统建模方面的专家。相反,教程的重点是展示如何设置VS FMU在另一个环境中工作(以FMU方式于matlab进行联合仿真)。本教程显示了来自CarSim的数据集和结果。在BikeSim和TruckSim中提供了几乎相同的数据集。

In order to follow this tutorial, you must have your VehicleSim product installed with version 2016.0 or newer and Simulink 2015a or newer (from The MathWorks), with the MATLAB Pilot Support package installed. The document assumes you have a basic understanding of how to use your VehicleSim product; if you have not done so, please go through the Quick Start Guide. You should also be familiar with Simulink, and should first read the Tech Memo available from the VehicleSim product Help menu: Running a VS Math Model in Simulink.
为了可以能跟着本教程一起动手做,您必须将您的VehicleSim产品安装到版本2016.0或更新版本以及Simulink 2015a或更新版本(来自MathWorks),并安装MATLAB支持包。本文件假设您对VehicleSim的产品有基本的了解;如果你还没有这样做,请阅读Quick Start Guide。您还应该熟悉Simulink,并且应该首先阅读VehicleSim产品帮助菜单中的技术备忘录:Running a VS Math Model in Simulink



Create a Dataset for an FMU

1.Navigate to the existing Run Control dataset for the Simulink ABS Example in the category Simulink and LabVIEW Models (Figure 1).
1.选择Datasets->Simulink and LabVIEW Models->Ext.ABS:Split Mu(图1)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第2张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第3张图片


2.Duplicate the dataset using the Duplicate button or pressing Ctrl+N. You will be prompted to name the new dataset (Figure 2). For example, change the category to “FMU with Simulink” and the dataset title to “Ext. ABS: Split Mu”.
2.点击Duplicate复制数据集。将提示为新数据集命名(图2)。例如,数据库标题更改为FMU with Simulink,将数据集标题更改为Ext. ABS: Split Mu。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第4张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第5张图片


3.From the drop-down Models control, select the option Models: Export FMU/FMI(Figure 3).
3.从下拉模型控件中,选择选项模型:导出FMU/FMI(图3)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第6张图片


4.Use the drop-down control for the link that appears, and select Link to New Dataset (Figure 4). When prompted, name the new dataset “FMU Simulink” (Figure 5) and click the Create button.
4.点击选择链接下拉控件,并选择Link to New Dataset(图4)。当出现提示时,将新数据集命名为FMU Simulink(图5)并单击Create按钮。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第7张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第8张图片


5.Click on the blue link for FMU Simulink to view the new dataset in the library Models:Export FMU/FMI (Figure 6).
5.单击FMU Simulink的蓝色链接,以查看库模型中的Models:Export FMU/FMI(图6)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第9张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第10张图片


6.对新数据集进行以下更改
在这里插入图片描述
Choose FMI Version 2.0.
选择 FMI Version 2.0.

在这里插入图片描述
Choose the Variable Naming Convention: Structured. This option will show channels as a one dimension array to the VS FMU in Simulink.

选择Structured或者Structured(Array)

在这里插入图片描述
Specify a relative pathname for the FMU Module that you will soon create: Extensions\FMU_FMI\ABS_FMU_Simulink.fmu

为即将创建的FMU指定一个路径 Extensions\FMU_FMI\ABS_FMU_Simulink.fmu
在这里插入图片描述在这里插入图片描述
Use the Import Channels link to select ABS Import in the category Braking Imports.

使用 Import Channels 链接到 ABS Import (在Braking Imports中)(但是我没找到,所以我选的下面这两个)

Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第11张图片


7.Go back to the Run Control screen and click the button Generate FMU for this Run. Anew FMU with the specified pathname will be created (Figure 7).

7.回到Run Control界面,单击Generate FMU for this Run按钮生成FMU。将创建一个具有指定路径名的新FMU(图7)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第12张图片
You have now created an FMU that can be run in co-simulation. Next, you will create a Simulink model to make use of this FMU.
您现在已经创建了一个可以在联合仿真中运行的FMU。接下来,您将创建一个Simulink模型来使用这个FMU。



Create a Simulink Model that Uses an FMU

1.In the Windows File Explorer, copy the existing Simulink file (e.g., abs_CS9.mdl) from the folder Extensions\simulink to the folder Extensions\FMU_FMI and rename it to the specified name: abs_fmu.mdl.
1.在Windows文件资源管理器中,将现有的Simulink文件(例如,abs_CS9.mdl)从文件夹*\Simulink* 复制粘贴到文件夹 \FMU_FMI ,并将其重命名:abs_fmu.mdl
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第13张图片


2.Open this Simulink model (Figure 8). (Recall that MATLAB 2015a or newer is required with the “Pilot Support Package v0.2.0” installed.)
2.打开这个Simulink模型(图8)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第14张图片


3.Delete the block named Unresolved Link that represented the VS S-Function in the original Simulink model.
3.删除原始Simulink模型中的Unresolved Link。(图八)


4.Go to the Simulink Library Browser window (Figure 9). Drag the FMU Co-Simulation block to the Simulink model.
4.打开Simulink Library Browser窗口(图9),将FMU Co-Simulation模块拖放到Simulink模型中(我的simulink库里是下图这样的,仅供参考)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第15张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第16张图片


5.Double-click the block named Unspecified FMU Co-Simulation ( in Figure 9) to bring up a window to set parameters (Figure 10). Set the FMU name to match the name of the FMU you created in step 5, and then click the OK button. The Simulink model should now match the appearance shown in Figure 11.
5.拖动FMU Co-Simulation(我的电脑显示的不太一样,显示的是FUM Import,(图9),双击设置参数(图10)。将FMU名称设置为与您在步骤5中创建的FMU名称匹配,然后单击OK按钮。Simulink模型现在应该与图11所示的外观相匹配。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第17张图片Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第18张图片


6.Double-click the FMU block again to see more options (Figure 12). Set the time step to 0.001, and then click the OK button to return to the Simulink model.
6.再次双击FMU块以查看更多选项(图12)。将时间步长设置为0.001,然后单击OK按钮返回Simulink模型。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第19张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第20张图片


7.Save the Simulnk model.
7.保存Simulnk模型。


8.Run the model; click the button or type Ctrl+T. Simulink will show plots as the model runs (Figure 13).
8.运行模型;单击按钮或键入Ctrl+T。Simulink将在模型运行时显示图(图13)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第21张图片


9.Return to the Run Control screen and click the button “Video + Plot” to view results with VS Visualizer (Figure 14).
9.返回到Run Control界面,然后单击按钮Video + Plot,使用VS Visualizer查看结果(图14)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第22张图片



FMU Multiple Ports in Simulink

You can configure VS FMU I/O ports as a single port or with multi-ports. To see this, return to the Models: Export FMU/FMI dataset (Figure 6). The drop-down control Variable Naming Convention (Figure 6,圆圈2) has two options: Structured and Flat.
可以将VS的I/O端口配置为单个端口或多个端口。要看到这一点,返回到Models: Export FMU/FMI数据集(图6)。下拉控件变量命名约定(图6)有两个选项: StructuredFlat.


1.The Structured option provides Ports (Import and Export with Simulink) to match datasets linked to the Models: Export FMU/FMI dataset. In the example shown, there is a single Import Port and a single Export Port, with channels for each port set using the linked I/O Import and Export datasets (ABS Import and ABS Export, Figure 15).
1.Structured选项提供端口(使用Simulink导入和导出)来匹配链接到到Models: Export FMU/FMI的数据集。在示例中,有一个导入端口和一个导出端口,每个端口集都有使用链接的I/O导入和导出数据集的通道(ABS ImportABS Export,图15)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第23张图片
The Structured option also supports linking to an I/O Channels: Ports dataset that can in turn link to a single Import and a single Export dataset (see the bottom part of Figure 15), or multiple Import and/or Export datasets (Figure 16).
Structured选项还支持链接到I/O Channels: 可以链接到单个导入和单个导出数据集(参见图15的底部部分),或者多个导入和/或导出数据集(图16)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第24张图片

Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第25张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第26张图片


2.The Flat option always provides multiple ports, each with a single value for Import or Export data (Figure 17).
2.Flat选项总是提供多个端口,每个端口都有一个用于导入或导出数据的值(图17)。
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第27张图片
Carsim2019_官方Help学习笔记_Running a VS FMU in Simulink (Carsim与Matlab联合仿真方法之一)_第28张图片
最后几张图自己多试试就知道什么意思了。
如有错误,欢迎批评指正,共同进步!

你可能感兴趣的:(Carsim2019,MATLAB)