当前位置: 首页 > news >正文

simulink系列之模型接口表生成及自动连线脚本

总目录

simulink系列之汽车应用层信号处理

    第一章 simulink信号处理——debounce

    第二章 simulink接口表生成及自动连线脚本

目录

前言

一、simulink接口表生成脚本

1.使用方法:

二、模型整理连线脚本

1.使用方法:

总结

前言

本系列主要围绕作者采用simulink进行日常软件开发过程中的实战和思考。话不多说,直接开干。

对于汽车应用层开发人员来说,几乎可以说日常开发接触到最多的东西就是各种报文信号了。因此,本文主要分享一下应用层软件报文信号处理之debounce,作为本系列的第一篇文章。


一、simulink接口表生成脚本

该脚本主要用来生成simulink应用层输入输出信号的基本信息。

1.使用方法:

使用对象:一般是针对最外层的子系统,当然也可以是内部的子系统

使用方法:打开simulink模型,点击一个子系统,然后运行脚本即可。

注意:如果需要在最终的接口表中生成特定的字段,需要稍微修改一下脚本内容。

脚本如下:

% 脚本1:生成iflist
% filepath: extract_ports_info.m
% 获取当前选中的子系统
subsys = gcs;% 只查找当前子系统下的一级 Inport/Outport(不递归)
inports  = find_system(subsys, 'SearchDepth', 1, 'BlockType', 'Inport');
outports = find_system(subsys, 'SearchDepth', 1, 'BlockType', 'Outport');% 初始化结果
names = {};
types = {};
directions = {};% 处理 Inport
for i = 1:length(inports)blk = inports{i};names{end+1,1} = get_param(blk, 'Name');types{end+1,1} = get_param(blk, 'OutDataTypeStr');directions{end+1,1} = 'Input';
end% 处理 Outport
for i = 1:length(outports)blk = outports{i};names{end+1,1} = get_param(blk, 'Name');types{end+1,1} = get_param(blk, 'OutDataTypeStr');directions{end+1,1} = 'Output';
end% 生成表格
T = table(names, types, directions, ...'VariableNames', {'Name', 'DataType', 'Direction'});disp(T);
writetable(T, 'ports_info.xlsx');

二、模型整理连线脚本

该脚本主要用来整理子系统联系不美观,弯曲的问题。

1.使用方法:

使用对象:一般是针对各个子系统

使用方法:打开simulink模型,点击一个子系统,然后运行脚本即可。

注意:如果选中的子系统连线已经交错等情况时,输出的结果可能不是最佳状态,需要手动协助调整。

脚本如下:

% 脚本2:自动连线
clear;
clc;
port_handles = get_param(gcbh,'PortHandles');
inport_handles = port_handles.Inportfor i = 1:length(inport_handles)line_handles = get_param(inport_handles(i),'Line');
src_handles = get_param(line_handles,'SrcBlockHandle');port_pos = get_param(inport_handles(i),'Position');src_pos = get_param(src_handles,'Position');
src_len = src_pos(3) - src_pos(1);
src_width = src_pos(4) - src_pos(2);new_pos(1) = port_pos(1) - 100;
new_pos(3) = new_pos(1) + src_len;
new_pos(2) = port_pos(2) - fix(src_width/2);
new_pos(4) = port_pos(2) + fix(src_width/2);set_param(src_handles,'Position',new_pos);endoutport_handles = port_handles.Outportfor i = 1:length(outport_handles)line_handles = get_param(outport_handles(i),'Line');
src_handles = get_param(line_handles,'DstBlockHandle');port_pos = get_param(outport_handles(i),'Position');src_pos = get_param(src_handles,'Position');
src_len = src_pos(3) - src_pos(1);
src_width = src_pos(4) - src_pos(2);new_pos(1) = port_pos(1) + 100;
new_pos(3) = new_pos(1) + src_len;
new_pos(2) = port_pos(2) - fix(src_width/2);
new_pos(4) = port_pos(2) + fix(src_width/2);set_param(src_handles,'Position',new_pos);end

总结

以上就是本篇要分享的内容,觉得有用可以关注我后续文章。

http://www.xdnf.cn/news/1153459.html

相关文章:

  • Nestjs框架: 理解 RxJS响应式编程的核心概念与实践
  • 商业秘密视域下计算机软件的多重保护困境
  • 支付宝支付
  • day11 ADC
  • 论文略读: RASA: RANK-SHARING LOW-RANK ADAPTATION
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘sqlalchemy’问题
  • Linux内核设计与实现 - 第6章 内核数据结构
  • NX二次开发常用函数坐标转化UF_MTX4_csys_to_csys和UF_MTX4_vec3_multipl
  • 轻松学习C++:基本语法解析
  • 多线程 示例
  • leetcode_121 买卖股票的最佳时期
  • AWS Partner: Accreditation (Technical)
  • 轻松上手:从零开始启动第一个 Solana 测试节点
  • 综合实验--eNSP实验
  • TypeScript 泛型详解:从基础到实战应用
  • Linux中添加重定向(Redirection)功能到minishell
  • python网络爬虫之selenium库(二)
  • 【Web APIs】JavaScript 自定义属性操作 ② ( H5 自定义属性 )
  • 图片放大镜案例
  • Patch-wise Structural:一种引入局部统计特性的时序预测损失函数
  • CS231n-2017 Lecture3线性分类器、最优化笔记
  • QT窗口(7)-QColorDiag
  • [spring6: AspectJAdvisorFactory AspectJProxyFactory]-源码解析
  • Linux C 信号操作
  • “外卖大战”正在改变国内“大零售”
  • 图解系统-小林coding笔记
  • 骑行邂逅LV巨轮,VELO维乐Angel Rise坐垫与时尚超适配
  • YOLOv11改进 | RFAConv重塑空间注意力助力性能提升
  • 开关电源和线性电源Multisim电路仿真实验汇总——硬件工程师笔记
  • 使用UV管理FastAPI项目