汽车轮胎平均磨损分析
此示例展示了如何使用分析函数计算汽车系统架构模型中的轮胎平均磨损。您可以为与 System Composer™ 中的组件链接的 mWheel.slx
模型引用每次使用指定 Wear
作为实例特定参数。
打开车辆模型
打开汽车系统架构 mAuto.slx
。
systemcomposer.openModel("mAuto");
这个简单汽车的架构模型包含两个顶层组件,代表两个车轴。每个车轴都有一个嵌套架构和两个车轮。
编写分析函数
您可以使用分析函数对实例模型进行分析。有关不同分析函数的更多信息,请参阅分析函数构造。
此分析函数计算汽车所有轮胎的平均磨损程度。
function calculateAverages(instance,varargin) % Analysis function calculating the average wear of tires in a vehicle % Pass the number of tires as an input to the analysis function if numel(varargin) > 0 numTires = eval(varargin{1}); end % Get the architecture instance as a place to accumulate the total wear using a % stereotype property if instance.isArchitecture archInst = instance; else % Get the architecture instance from the path of the node currently being % iterated instName = strsplit(instance.QualifiedName,'/'); archInst = systemcomposer.analysis.lookup(string(instName{1})); end if instance.isComponent && any(instance.getParameterNames.matches("Wear")) % Get the stored stereotype property value on the architecture instance accumulatedValue = archInst.getValue('AxleProfile.Metrics.total_wear'); % Get the evaluated parameter value from the instance currentValue = instance.getEvaluatedParameterValue("Wear"); % Update the accumulated value newValue = accumulatedValue + currentValue; % Update the stereotype property value on the architecture instance archInst.setValue('AxleProfile.Metrics.total_wear',num2str(newValue)); if newValue > 0 fprintf(sprintf("Average wear of tires: %f\n", ... newValue/numTires)); end end end
使用分析函数实例化架构模型
要计算架构模型中的轮胎平均磨损,请实例化模型以创建快照或实例模型,然后从中执行计算。要启动 实例化架构模型 工具,请从 System Composer 工具栏中选择建模 > 视图 > 分析模型。选择 AxleProfile
配置文件。这样,您就可以在属性值中显示分析结果。使用文件夹导航到函数 calculateAverages.m
,并将其插入到分析函数框中。在函数参量框中输入 4
,表示模型有四个轮子。然后,点击实例化。
分析实例模型计算平均磨损
在实例化架构模型后,分析查看器 工具将启动。点击分析使用提供的分析函数 calculateAverages
分析实例模型。
架构实例级别中 mAuto
的 total_wear
单元格以黄色突出显示,因为 total_wear
是实例模型上每个轮组件实例的所有实例属性的计算值。total_wear
值 0.0595
代表汽车所有轮胎的总磨损程度。在 MATLAB® 命令行窗口中,最后的打印输出还会显示车辆轮胎的平均磨损情况。
Average wear of tires: 0.014875
平均磨损度是衡量轮胎整体耐用性的度量单位,也是轮胎更换时间的参考指标。轮胎的平均磨损程度约为 0.0149
。
另请参阅
工具
对象
函数
instantiate
|deleteInstance
|update
|refresh
|save
|getEvaluatedParameterValue
|getParameterNames