当前位置:网站首页>建模规范:命名规范
建模规范:命名规范
2022-07-06 02:46:00 【chhttty】
本文研究MAAB建模规范中的命名规范,同时结合工作实际谈谈博主的理解。
文章目录
1 命名规范
命名规范是第一个在MAAB中定义的规范,其中规定了文件夹,模型,变量,接口等应该如何命名。
2 命名规范内容
2.1 基本规则
1)在命名规范中,可以对模块、信号等命名使用的字符只能是以下几种:
- 英文字母大小写:a-z, A-Z
- 阿拉伯数字:0-9
- 下划线:_
2)除此之外,都不可以用于命名。例如以下几点一定不允许:
- 不能在路径或模块名等出现中文字符串,有可能解析出错;
- 不能出现空格、回车符、括号等特殊字符,例如JMAAB(Model).slx;
- 名称开头必须是字母,不能是数字或者下划线,例如001_JMAABModel.slx;
- 不能连续写两个下划线,例如 JMAAB__Model.slx;
3)字符串长度不能过长,应该小于63;
2.2 Model Advisor检查项
在Matlab 2018a的Model Advisor中,以下几条检查项可以对文件、接口等进行命名规范检查:
Check ID | Description |
---|---|
ar_0001 | Check file names |
ar_0002 | Check folder names |
jc_0201 | Check subsystem names |
jc_0211 | Check port block names |
jc_0221 | Check character usage in signal labels |
jc_0231 | Check character usage in block names |
这些检查条目位于Model Advisor检查器中:
2.3 Model Advisor检查示例
1)新建一个模型,其中建模如下:
上图模型中,有两点命名上的错误:
- 1号输入端口以下划线开头;
- 输出信号线以数字开头;
这两点问题都可以用Model Advisor检查出来。
2)运行上文的Model Advisor检查项,得出结果如下:
左侧的检查项中有两条变成了Warning的感叹号,4条通过。
3)点击其中一条Warning,就可以看到具体是模型的什么位置出现了问题,并且可以通过超链接直接定位过去;
3 企业命名规范
上面讲的都是MAAB文档中的基本规范条目,十分易于理解。在企业实际工作中,会以此为基础,制定出自己的命名规范。如此可以便于工程师的理解和交流。下面博主会举例说明自己呆过的公司是怎么做的。
3.1 企业命名规范详解
1)善于使用名称的缩写,将模型名缩写成固定长度的几个字符,例如下图;
图中,车速控制模块VehicleSpeedControlModule取了四个首字母,将模型名命名为VSCM。
2)对于输入输出接口,需要体现出除了变量本身含义以外的信息;例如数据类型是uint8还是uint16,作用域是在哪个模块中;
例如车速是CAN信号接收到的,由CSDM模块滤波后输出的全局变量(用G表示Global),物理单位是kmph(公里每小时),就可以命名为 G_CSDM_kmph_VehSpd,而不是直接命名为VehicleSpeed。这样命名就可以一眼看出来。
变量类型 | 物理单位 | 模块 | 描述 | 名称 |
---|---|---|---|---|
全局变量 | kmph | CSDM | VehSpd | G_CSDM_kmph_VehSpd |
标定量 | enum | / | GearPosition | P_enum_GearPos |
宏定义 | enum | / | ReverseGear | M_enum_ReverseGear |
输入接口 | rpm | / | EngineSpeed | Get_rpm_EngineSpeed |
输出接口 | Nm | / | EngineTorque | Set_Nm_EngineTorque |
在非Autosar架构的应用层模型中,通常把模型和模型之间的接口做成全局变量,底层到应用层的接口为Get_XXX()函数,应用层到底层的接口为Set_XXX()函数,标定量或常量做在Const模块中。基于以上这些原则,可以制定企业的命名规范。更进一步,还可以自己开发ModelAdvisor检查工具,检查模型中的命名规范是不是符合企业规范。
3.2 通过脚本检查命名规范
MAAB规范可以通过Model Advisor检查,自定义的命名规范也可以自己开发脚本,发布到Model Advisor检查项目中。博主通过一个脚本演示如何检查模型中的Constant模块是否符合标定量命名,发布到Advisor的过程可以参考博主别的博客。
1)首先,用find_system函数在模型中搜索出所有Const模块;
% 查找模型中的Constant模块
Const_Cell = find_system(gcs,'BlockType','Constant');
2)接着,循环所有的数组,通过调用子函数检查Constant模块中的值是否合法;
% 循环检测Constant模块中的值
for i = 1:length(Const_Cell)
Const_Path = Const_Cell{i};
Const_Value = get_param(Const_Path,'Value');
if(CheckName(Const_Value))
continue;
else
InvalidNameList{end+1} = Const_Path;
end
end
3)调用的子函数判断首字母是否为P,以及是否含有两个下划线;
function IsValidName = CheckName(Value)
if(Value(1) ~= 'P') %是否以P开头
IsValidName = false;
elseif(length(strfind(Value,'_')) ~= 2) %是否包含两个下划线
IsValidName = false;
else
IsValidName = true;
end
end
最终,整个脚本如下:
function InvalidNameList = CheckCaliName()
InvalidNameList = {};
% 查找模型中的Constant模块
Const_Cell = find_system(gcs,'BlockType','Constant');
% 循环检测Constant模块中的值
for i = 1:length(Const_Cell)
Const_Path = Const_Cell{i};
Const_Value = get_param(Const_Path,'Value');
if(CheckName(Const_Value))
continue;
else
InvalidNameList{end+1} = Const_Path;
end
end
end
function IsValidName = CheckName(Value)
if(Value(1) ~= 'P') %是否以P开头
IsValidName = false;
elseif(length(strfind(Value,'_')) ~= 2) %是否包含两个下划线
IsValidName = false;
else
IsValidName = true;
end
end
4 总结
本文研究MAAB建模规范中的命名规范,在工作中应该遵守MAAB以及企业规范,正确地命名变量或信号名。
边栏推荐
- Force buckle 146 LRU cache
- Trends in DDoS Attacks
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
- Pat 1084 broken keyboard (20 points) string find
- 如何精准识别主数据?
- Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
- tcpdump: no suitable device found
- What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
- 【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
- High number_ Vector algebra_ Unit vector_ Angle between vector and coordinate axis
猜你喜欢
Communication between microservices
RobotFramework入门(三)WebUI自动化之百度搜索
4. File modification
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
Misc (eternal night), the preliminary competition of the innovation practice competition of the National College Students' information security competition
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
High number_ Vector algebra_ Unit vector_ Angle between vector and coordinate axis
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
【若依(ruoyi)】启用迷你导航栏
随机推荐
技术分享 | undo 太大了怎么办
Single instance mode of encapsulating PDO with PHP in spare time
[kubernetes series] learn the exposed application of kubernetes service security
QT release exe software and modify exe application icon
Apt installation ZABBIX
Pat grade a 1033 to fill or not to fill
Function knowledge points
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Master data management theory and Practice
Briefly describe the implementation principle of redis cluster
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
RobotFramework入门(三)WebUI自动化之百度搜索
Rust language -- iterators and closures
[postgraduate entrance examination English] prepare for 2023, learn list5 words
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
一个复制也能玩出花来
Elimination games
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
2.12 simulation
Maturity of master data management (MDM)