主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

创建接口

您可以在 System Composer™ 中创建组件之间的接口,以结构化传输数据。使用带有数据元素或值类型的复合数据接口来管理端口上定义的数据。将数据接口或值类型分配给数据元素,以便数据元素继承属性和重用数据。在使用接口编辑器添加接口之前,请先使用以下模型作为起点。

关于接口术语,请参阅定义组件之间的端口接口

要管理数据字典中模型之间共享的接口,请参阅使用数据字典管理接口。有关物理接口的信息,请参阅指定端口上的物理接口

打开模型

打开移动机器人平台架构模型。

打开接口编辑器

要打开接口编辑器,请导航至 建模 > 接口编辑器接口编辑器将出现在画布底部。

Example mobile robot architecture model with the Interface Editor indicated in red.

注意

System Composer 接口编辑器是一个基于网页的小工具,首次启动时可能显示为空白。如果发生这种情况,请保存模型,然后使用命令行选项 -cefdisablegpu 重新启动 MATLAB®

创建复合数据接口

要添加新的数据接口定义,请点击 add data interface 图标。将数据接口命名为 sensordata

Interface Editor showing one defined interface named 'sensor data'.

要将数据元素添加到数据接口,请点击 add data element 图标。数据接口和数据元素名称必须是有效的 MATLAB 变量名称。

Interface elements named 'coordinates' and 'motor speed' shown below an interface named 'sensor data'.

您可以使用 delete 按钮删除接口编辑器中的数据接口和数据元素。

您可以在属性检查器中查看和编辑元素的属性。右键点击数据元素,然后选择检查属性。对于数据接口,使用属性检查器应用构造型。

Properties for the interface element named 'motor speed' in the Property Inspector showing. Properties include Type as double, Dimensions as 1, Units as blank, Complexity as real, Minimum, which is empty, Maximum, which is empty, and Description, which is blank.

为了进行比较,您可以从相关的“接口编辑器”列中编辑数据元素属性。

Units being edited for the property under the motor speed interface element.

创建值类型作为接口

要在接口编辑器中添加值类型,请选择 add data interface 图标旁边的向下箭头,然后选择值类型。将值类型命名为 motorSpeedType。值类型名称必须是有效的 MATLAB 变量名称。

Add value type option in Interface Editor.

右键点击 motorSpeed 数据元素,然后选择 Set 'Type' > motorSpeedType。数据元素 motorSpeed 被赋值类型 motorSpeedType

Type motor speed by the value type motor speed type in the Interface Editor.

motorSpeedType 值类型的任何数据更改都会传播到 motorSpeed 数据元素。您可以多次重用值类型。值类型的数据更改将传播到使用该值类型的每个数据元素。

嵌套接口以重用数据

嵌套接口包含另一个数据接口。通过将数据接口指定为数据元素的类型来创建嵌套数据接口。有关相应公交车的信息,请参阅Define Multilevel Bus Hierarchy Using Type Editor

例如,假设 coordinates 是一个由 xyz 坐标组成的数据接口。GPSdata 数据接口包括 locationtimestamp。如果 location 数据元素与 coordinates 接口格式相同,则可以将其类型设置为 coordinates。右键点击 location,然后选择 Set 'Type' > 坐标。可用的接口选项包括模型中的所有值类型和所有数据接口,但数据元素的父元素除外。

Interface Editor with three interfaces named 'sensor data', 'coordinates' and 'GPS data'. Below each are interface elements with properties defined. The 'location' interface element under the interface named 'GPS data' has been right-clicked. The user is selecting the option 'Set type' to choose the interface named 'coordinates'.

嵌套数据接口显示继承的数据元素。

The coordinates interface is nested into the location interface element under GPS data. All coordinates interface elements show below location.

注意

要更改接口编辑器中显示的列数,请点击 show hide columns 图标。选择或取消选择要显示或隐藏的列。

The Interface Editor view with the drop down next to the show hide columns icon is selected. The columns Type, Dimensions, and Units are selected.

另请参阅

函数

模块

主题