在架构模型中使用包含架构数据的 FMU 组件
此示例展示了如何将 FMU 文件链接到 System Composer™ 中的组件,以指定和查看其架构数据。
将 FMU 与组件链接到 System Composer
创建一个新的 System Composer 模型,添加一个新的组件 f14comp
,然后从该组件链接到 FMU 文件 f14.fmu
。
model = systemcomposer.createModel("archModel"); systemcomposer.openModel("archModel"); arch = get(model,"Architecture"); comp = addComponent(arch,"f14comp"); fmuHandle = linkToFMU(comp,"f14.fmu");
检查 FMU 组件上的端口和接口
当 FMU 组件具有带接口的端口时,您可以检查这些接口与连接端口的兼容性。对于 f14comp
组件上的每个端口,都不能设置共享数据接口。FMU 组件支持从底层 FMU 文件定义的端口上的本地只读专属接口。没有专属接口的 FMU 端口从其他连接端口继承。
portA = getPort(comp,"u"); portB = getPort(comp,"alpha_rad"); portC = getPort(comp,"Nz_pilot_g");
您可以使用 接口编辑器 中的端口接口视图或以下代码行查看分配给 FMU 组件的专属接口。
portA.ArchitecturePort.Interface
ans = 0×0 DataInterface array with properties: Name Description Owner Elements Model UUID ExternalUID
将构造型应用于 FMU 组件
使用组件构造型生成配置文件。
profile = systemcomposer.profile.Profile.createProfile("LatencyProfile"); stereotype = addStereotype(profile,"electricalComponent",AppliesTo="Component");
将配置文件应用到模型和 FMU 文件,然后将 electricalComponent
构造型应用到 FMU 组件。
applyProfile(model,"LatencyProfile"); applyProfile(comp.Architecture,"LatencyProfile"); applyStereotype(comp,"LatencyProfile.electricalComponent");
选择 f14comp
组件,并在属性检查器中观察 electricalComponent
构造型。
注意:从 Simulink 模型导出 FMU 需要 Simulink Compiler™ 和 FMU Builder for Simulink 支持包。
load_system('f14') set_param('f14',SolverType='Fixed-step') exportToFMU('f14',SaveSourceCodeToFMU='on',ExportedParameters={''},FMIVersion='3.0',FMUType='CS', ... CreateModelAfterGeneratingFMU='off')