当前位置:网站首页>建模规范:命名规范
建模规范:命名规范
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以及企业规范,正确地命名变量或信号名。
边栏推荐
- Advanced technology management - what is the physical, mental and mental strength of managers
- Microservice registration and discovery
- [postgraduate entrance examination English] prepare for 2023, learn list5 words
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
- Yyds dry inventory comparison of several database storage engines
- 微服务注册与发现
- Briefly describe the implementation principle of redis cluster
- Maturity of master data management (MDM)
- Template_ Quick sort_ Double pointer
- DDoS attacks - are we really at war?
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14](/img/c5/dde92f887e8e73d7db869fcddc107f.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14

Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework

一个复制也能玩出花来

米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析

Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands

Solution: attributeerror: 'STR' object has no attribute 'decode‘

Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator

全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)

#PAT#day10

A doctor's 22 years in Huawei
随机推荐
2.12 simulation
RobotFramework入门(二)appUI自动化之app启动
全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
Rust language -- iterators and closures
How to check the lock information in gbase 8C database?
有没有完全自主的国产化数据库技术
Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures
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
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation
Communication between microservices
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
Redis skip table
JS events (add, delete) and delegates
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
2020.02.11
原型图设计
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
CobaltStrike-4.4-K8修改版安装使用教程
Universal crud interface
Thinking on Architecture Design (under continuous updating)