当前位置:网站首页>建模规范:命名规范
建模规范:命名规范
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以及企业规范,正确地命名变量或信号名。
边栏推荐
- Follow the mouse's angle and keyboard events
- 有没有完全自主的国产化数据库技术
- Microservice registration and discovery
- 【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
- What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
- Sword finger offer 30 Stack containing min function
- CobaltStrike-4.4-K8修改版安装使用教程
- Redis skip table
- Force buckle 146 LRU cache
- PMP每日一练 | 考试不迷路-7.5
猜你喜欢

故障分析 | MySQL 耗尽主机内存一例分析
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9](/img/ed/0edff23fbd3880bc6c9dabd31755ac.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7](/img/44/1861f9016e959ed7c568721dd892db.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7

Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19](/img/7c/f728e88ca36524f92c56213370399b.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19

Network Security Learning - Web vulnerabilities (Part 1)
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13](/img/29/49da279efed22706545929157788f0.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13

【若依(ruoyi)】启用迷你导航栏

如何精准识别主数据?

Apt installation ZABBIX
随机推荐
Looking at the trend of sequence modeling of recommended systems in 2022 from the top paper
Accident index statistics
DDoS attacks - are we really at war?
Introduction to robotframework (II) app startup of appui automation
Misc (eternal night), the preliminary competition of the innovation practice competition of the National College Students' information security competition
有没有完全自主的国产化数据库技术
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
Building the prototype of library functions -- refer to the manual of wildfire
Sword finger offer 30 Stack containing min function
Shell脚本更新存储过程到数据库
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
1. Dynamic parameters of function: *args, **kwargs
如何精准识别主数据?
I changed the driver to 5.1.35, but it is still the same error. I can succeed even now, but I will report this every time I do an SQL operation
Redis delete policy
原型图设计
Classic interview question [gem pirate]
米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)