PIL 的目标连接配置

在运行 PIL 仿真之前,必须配置目标连接。通过目标连接配置,PIL 仿真能够:

编译目标应用程序。

在目标上下载、启动和停止应用程序。

支持 Simulink 与目标之间的通信。

对于支持的硬件,可以使用目标支持包。有关详细信息,请参阅Embedded Coder 支持的硬件。

对顶层模型运行 SIL 或 PIL 仿真

通过运行顶层模型 SIL 或 PIL 仿真测试生成的模型代码。使用这种方法:

测试从顶层模型生成的代码,它使用独立代码接口。

配置模型以从 MATLAB 工作区加载测试向量或激励输入。

在顶层模型的 Normal、SIL 和 PIL 仿真模式之间轻松切换。

打开一个简单的计数器顶层模型。

model='rtwdemo_sil_topmodel';

close_system(model,0)

open_system(model)

要专注于数值等效性测试,请关闭以下报告:

模型覆盖率

代码覆盖率

执行时间探查

set_param(gcs, 'RecordCoverage','off');

coverageSettings = get_param(model, 'CodeCoverageSettings');

coverageSettings.CoverageTool='None';

set_param(model, 'CodeCoverageSettings',coverageSettings);

set_param(model, 'CodeExecutionProfiling','off');

配置输入激励数据。

[ticks_to_count, reset, counter_mode, count_enable] = ...

rtwdemo_sil_topmodel_data(T);

配置模型的日志记录选项。

set_param(model, 'LoadExternalInput','on');

set_param(model, 'ExternalInput','ticks_to_count, reset, counter_mode, count_enable');

set_param(model, 'SignalLogging', 'on');

set_param(model, 'SignalLoggingName', 'logsOut');

set_param(model, 'SaveOutput','on')

运行 Normal 模式仿真。

set_param(model,'SimulationMode','normal')

sim_output = sim(model,10);

yout_normal = [sim_output.yout.signals(1).values sim_output.yout.signals(2).values];

运行顶层模型 SIL 仿真。

set_param(model,'SimulationMode','Software-in-the-Loop (SIL)')

sim_output = sim(model,10);

yout_sil = [sim_output.yout.signals(1).values sim_output.yout.signals(2).values];

### Starting build procedure for: rtwdemo_sil_topmodel

### Generated code for 'rtwdemo_sil_topmodel' is up to date because no structural, parameter or code replacement library changes were found.

### Successful completion of build procedure for: rtwdemo_sil_topmodel

Build Summary

Top model targets built:

Model Action Rebuild Reason

==============================================================================

rtwdemo_sil_topmodel Code compiled Compilation artifacts were out of date.

1 of 1 models built (0 models already up to date)

Build duration: 0h 0m 5.8268s

### Preparing to start SIL simulation ...

### Preparing to start SIL simulation ...

### Starting SIL simulation for component: rtwdemo_sil_topmodel

### Stopping SIL simulation for component: rtwdemo_sil_topmodel

如果模型有新的改动,则会重新生成并编译代码。生成的代码在您的计算机上作为单独的进程运行。

绘制并比较 Normal 和 SIL 仿真的结果。观察结果是否匹配。

fig1 = figure;

subplot(3,1,1), plot(yout_normal), title('Counter Output for Normal Simulation')

subplot(3,1,2), plot(yout_sil), title('Counter Output for SIL Simulation')

subplot(3,1,3), plot(yout_normal-yout_sil), ...

title('Difference Between Normal and SIL');

清空仿真结果。

close_system(model,0);

if ishandle(fig1), close(fig1), end

clear fig1

simResults = {'yout_sil','yout_normal','model','T',...

'ticks_to_count','reset'};

save([model '_results'],simResults{:});

clear(simResults{:},'simResults')

对 Model 模块运行 SIL 或 PIL 仿真

通过使用在 SIL 模式下运行 Model 模块的测试框架模型来测试生成的模型代码。使用这种方法:

测试从顶层模型或引用模型生成的代码。从顶层模型生成的代码使用独立的代码接口。从引用模型生成的代码使用模型引用代码接口。有关详细信息,请参阅SIL 和 PIL 的代码接口。

您可以使用测试框架模型或系统模型来提供测试向量或激励输入。

您可以在 Model 模块的 Normal、SIL 和 PIL 仿真模式之间轻松切换。

打开示例模型,其中包含两个引用同一模型的 Model 模块。在仿真中,您在 SIL 模式下运行一个 Model 模块,在 Normal 模式下运行另一个 Model 模块。

model='rtwdemo_sil_modelblock';

open_system(model);

关闭以下报告:

代码覆盖率

执行时间探查

coverageSettings = get_param(model, 'CodeCoverageSettings');

coverageSettings.CoverageTool='None';

set_param(model, 'CodeCoverageSettings',coverageSettings);

open_system('rtwdemo_sil_modelblock')

set_param('rtwdemo_sil_modelblock', 'CodeExecutionProfiling','off');

open_system('rtwdemo_sil_counter')

set_param('rtwdemo_sil_counter', 'CodeExecutionProfiling','off');

currentFolder=pwd;

save_system('rtwdemo_sil_counter', fullfile(currentFolder,'rtwdemo_sil_counter.slx'))

为模型配置状态日志记录。

set_param('rtwdemo_sil_counter', 'SaveFormat','Dataset');

save_system('rtwdemo_sil_counter', fullfile(currentFolder,'rtwdemo_sil_counter.slx'))

set_param(model, 'SaveFormat','Dataset');

set_param(model, 'SaveState','on');

set_param(model, 'StateSaveName', 'xout');

测试顶层模型代码

对于 SIL 模式下的 Model 模块,指定使用独立代码接口生成顶层模型代码。

set_param([model '/CounterA'], 'CodeInterface', 'Top model');

运行测试框架模型的仿真。

out = sim(model,20);

Build Summary

0 of 0 models built (0 models already up to date)

Build duration: 0h 0m 0.67407s

### Starting build procedure for: rtwdemo_sil_counter

### Generated code for 'rtwdemo_sil_counter' is up to date because no structural, parameter or code replacement library changes were found.

### Successful completion of build procedure for: rtwdemo_sil_counter

Build Summary

Top model targets built:

Model Action Rebuild Reason

=============================================================================

rtwdemo_sil_counter Code compiled Compilation artifacts were out of date.

1 of 1 models built (0 models already up to date)

Build duration: 0h 0m 4.6326s

### Preparing to start SIL simulation ...

The top model "rtwdemo_sil_modelblock" is configured to load initial state and / or save states (see Data Import/Export configuration parameters). However, the SIL or PIL component "rtwdemo_sil_modelblock/CounterA" does not expose any states to Simulink and therefore cannot participate in state initialization or logging.

### Starting SIL simulation for component: rtwdemo_sil_counter

### Stopping SIL simulation for component: rtwdemo_sil_counter

SIL 模式下的 Model 模块在您的计算机上作为单独的进程运行。在工作文件夹中,如果不存在之前编译生成的代码,则会为引用模型生成独立代码。

比较 Normal 和 SIL 模式下 Model 模块的行为。结果是匹配的。

yout = out.logsOut;

yout_sil = yout.get('counterA').Values.Data;

yout_normal = yout.get('counterB').Values.Data;

fig1 = figure;

subplot(3,1,1), plot(yout_normal), title('Counter Output for Normal Simulation')

subplot(3,1,2), ...

plot(yout_sil), title('Counter Output for Model Block SIL (Top-Model) Simulation')

subplot(3,1,3), plot(yout_normal-yout_sil), ...

title('Difference Between Normal and SIL');

比较在 Normal 模式仿真和 SIL 模式仿真中记录的 Model 模块的状态。

xout = out.xout;

xout_sil = xout{1}.Values.Data;

xout_normal = xout{2}.Values.Data;

fig1 = figure;

subplot(3,1,1), plot(xout_sil), title('State Logging for Normal Simulation')

subplot(3,1,2), ...

plot(xout_normal), title('State Logging for Model Block SIL (Top-Model) Simulation')

subplot(3,1,3), plot(xout_normal-xout_sil), ...

title('Difference Between Normal and SIL');

测试模型引用代码

对于 SIL 模式下的 Model 模块,指定使用模型引用代码接口生成引用模型代码。

set_param([model '/CounterA'], 'CodeInterface', 'Model reference');

运行测试框架模型的仿真。

out2 = sim(model,20);

### Starting serial model reference code generation build

### Starting build procedure for: rtwdemo_sil_counter

### Model reference code generation target for rtwdemo_sil_counter is up to date.

Build Summary

0 of 1 models built (1 models already up to date)

Build duration: 0h 0m 3.5832s

### Preparing to start SIL simulation ...

The top model "rtwdemo_sil_modelblock" is configured to load initial state and / or save states (see Data Import/Export configuration parameters). However, the SIL or PIL component "rtwdemo_sil_modelblock/CounterA" does not expose any states to Simulink and therefore cannot participate in state initialization or logging.

### Starting SIL simulation for component: rtwdemo_sil_counter

### Stopping SIL simulation for component: rtwdemo_sil_counter

SIL 模式下的 Model 模块在您的计算机上作为单独的进程运行。在工作文件夹中,如果不存在之前编译生成的代码,则会为引用模型生成独立代码。

比较 Normal 和 SIL 模式下 Model 模块的行为。结果是匹配的。

yout2 = out2.logsOut;

yout2_sil = yout2.get('counterA').Values.Data;

yout2_normal = yout2.get('counterB').Values.Data;

fig1 = figure;

subplot(3,1,1), plot(yout2_normal), title('Counter Output for Normal Simulation')

subplot(3,1,2), ...

plot(yout2_sil), title('Counter Output for Model Block SIL (Model Reference) Simulation')

subplot(3,1,3), plot(yout2_normal-yout2_sil), ...

title('Difference Between Normal and SIL');

比较在 Normal 模式仿真和 SIL 模式仿真中记录的 Model 模块的状态。

xout2 = out.xout;

xout2_sil = xout2{1}.Values.Data;

xout2_normal = xout2{2}.Values.Data;

fig1 = figure;

subplot(3,1,1), plot(xout2_sil), title('State Logging for Normal Simulation')

subplot(3,1,2), ...

plot(xout2_normal), title('State Logging for Model Block SIL (Model Reference) Simulation')

subplot(3,1,3), plot(xout2_normal-xout2_sil), ...

title('Difference Between Normal and SIL');

清空仿真结果。

close_system(model,0);

if ishandle(fig1), close(fig1), end, clear fig1

simResults={'out','yout','yout_sil','yout_normal', ...

'out2','yout2','yout2_sil','yout2_normal', ...

'SilCounterBus','T','reset','ticks_to_count','Increment'};

save([model '_results'],simResults{:});

clear(simResults{:},'simResults')

SIL 或 PIL 模块仿真

通过在仿真中使用 SIL 或 PIL 模块测试生成的子系统代码。使用这种方法:

测试从子系统生成的代码,这些代码使用独立的代码接口。

提供测试框架或系统模型,以提供测试向量或激励输入。

使用生成的 SIL 或 PIL 模块替换原始子系统。

打开一个简单模型,它由闭环形式的控制算法和被控对象模型组成。控制算法调节被控对象的输出。

model='rtwdemo_sil_block';

close_system(model,0)

open_system(model)

运行 Normal 模式仿真

out = sim(model,10);

yout_normal = out.yout;

clear out

配置编译过程以创建 SIL 模块进行测试。

set_param(model,'CreateSILPILBlock','SIL');

要测试在生产硬件上的行为,请指定一个 PIL 模块。

要创建 SIL 模块,请为控制算法子系统生成代码。您在编译过程结束时会看到 SIL 模块。其输入和输出端口与控制算法子系统的对应项匹配。

close_system('untitled',0);

rtwbuild([model '/Controller'])

### Starting build procedure for: Controller

### Generated code for 'Controller' is up to date because no structural, parameter or code replacement library changes were found.

### Successful completion of build procedure for: Controller

### Creating SIL block ...

Build Summary

Top model targets built:

Model Action Rebuild Reason

====================================================================

Controller Code compiled Compilation artifacts were out of date.

1 of 1 models built (0 models already up to date)

Build duration: 0h 0m 6.8271s

您也可以右键点击子系统并选择 C/C++ Code > Build This Subsystem。在打开的对话框中,点击 Build。

要执行闭环形式的控制器和被控对象模型的 SIL 仿真,请使用新 SIL 模块替换原始控制算法。为避免丢失原始子系统,请勿以此状态保存模型。

controllerBlock = [model '/Controller'];

blockPosition = get_param(controllerBlock,'Position');

delete_block(controllerBlock);

add_block('untitled/Controller',[controllerBlock '(SIL)'],...

'Position', blockPosition);

close_system('untitled',0);

clear controllerBlock blockPosition

运行 SIL 仿真。

out = sim(model,10);

### Preparing to start SIL block simulation: rtwdemo_sil_block/Controller(SIL) ...

### Starting SIL simulation for component: rtwdemo_sil_block

### Stopping SIL simulation for component: rtwdemo_sil_block

控制算法使用单精度浮点算术运算。SIL 和 Normal 仿真之间差异的数量级可能接近单精度数据的计算机精度。

定义 SIL 仿真结果的误差容限,该误差容限基于单精度 Normal 仿真结果的计算机精度。

machine_precision = eps(single(yout_normal));

tolerance = 4 * machine_precision;

比较 Normal 和 SIL 仿真结果。在第三个绘图中,仿真之间的差异全部在定义的误差容限内。

yout_sil = out.yout;

tout = out.tout;

fig1 = figure;

subplot(3,1,1), plot(yout_normal), title('Controller Output for Normal Simulation')

subplot(3,1,2), plot(yout_sil), title('Controller Output for SIL Simulation')

subplot(3,1,3), plot(tout,abs(yout_normal-yout_sil),'g-', tout,tolerance,'r-'), ...

title('Normal and SIL Difference and Error Tolerance');

清空仿真结果。

close_system(model,0);

if ishandle(fig1), close(fig1), end

clear fig1

simResults={'out','yout_sil','yout_normal','tout','machine_precision'};

save([model '_results'],simResults{:});

clear(simResults{:},'simResults')

硬件实现设置

当您运行 SIL 仿真时,您必须配置硬件实现设置(本机字长等特性),以允许针对开发计算机进行编译。这些设置可能不同于针对生产硬件编译模型时使用的硬件实现设置。为避免在 SIL 和 PIL 仿真之间更改硬件实现设置,请启用可移植字长。有关详细信息,请参阅Configure Hardware Implementation Settings。

matlab2017b怎么进行sil测试,用 SIL 和 PIL 仿真测试生成的代码相关推荐

  1. 汽车电子测试小知识(2)——什么是SiL测试?

    正月初七,开工大吉!继上一篇汽车电子测试小知识(1)--什么是MiL测试之后,小编为大家带来春节科普小知识第二弹,SiL测试! 什么是SiL测试? 软件在环测试,也称SiL测试,是指在PC机上测试嵌入 ...

  2. MATLAB中simulink的SIL测试

    关于MATLAB的simulink的测试的重要性我就不多说了,想了解的话,可以关注一下老胡的微信公众号. 其实对于SIL测试,几乎每一个版本都不太一样.我的电脑里安装了两个MATLAB,一个是2012 ...

  3. 自动驾驶 | SIL测试简单介绍

    SIL(software in-the-loop)测试,软件在环测试,通过运行系统环境中的车辆模型和虚拟ECU中的I/O模型来模拟控制器所需的各种传感器信号,并能接收台架传感器的信号和虚拟ECU发出的 ...

  4. 软件在环SIL和硬件在环PIL实现过程记录

    标题Matlab/Simulink 自动代码生成 基于模型设计学习教程 NO.1 软件在环SIL和硬件在环PIL实现过程记录. 在完成模型算法的过程当中,为了验证算法的准确性,依此为模型验证.软件在环 ...

  5. paddlepaddle测试安装_PaddlePaddle升级解读 | 十余行代码完成迁移学习,PaddleHub实战篇...

    迁移学习 (Transfer Learning) 是属于深度学习的一个子研究领域,该研究领域的目标在于利用数据.任务.或模型之间的相似性,将在旧领域学习过的知识,迁移应用于新领域中.迁移学习吸引了很多 ...

  6. 测试Rockey 4 Smart加密锁的C语言代码

    测试Rockey 4 Smart加密锁的C语言代码 // win32Console_dog_test.cpp : Defines the entry point for the console app ...

  7. 汽车智能安装仿真测试软件,智能网联汽车仿真测试平台建设.pdf

    国家轿车质量监督检验中心 智能网联汽车仿真测试平台建设 目录 1 智能网联汽车仿真测试平台建设的需求 基于仿真工具的智能网联汽车研发测试 2 及认证测试 3 现阶段智能网联汽车仿真测试面临的关键问题 ...

  8. 小学数学测试软件报告,小学数学测试系统C课程设计报告及源程序代码论文

    小学数学测试系统C课程设计报告及源程序代码论文 (34页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 19.90 积分 课 程 设 计 报 告课程名称 ...

  9. matlab2017b怎么进行sil测试,基于Matlab的模型自动测试方法与流程

    本发明属于航空发动机控制律模型全自动测试领域. 背景技术: : 目前,Matlab工具软件在航空发动机控制领域使用非常广泛,发控项目都是采用Matlab工具进行模型开发设计.控制律模型都是人工开发,随 ...

最新文章

  1. 【Netty】NIO 缓冲区 ( Buffer ) 组件
  2. “===” 也有不靠谱的时候
  3. 第四周实践项目6 循环双链表应用
  4. 5187. 收集足够苹果的最小花园周长
  5. hive工作中分享总结
  6. Linux 系统调用 Ptrace 详解
  7. 小白入门angular-cli的第一次旅程(学习目标 学习目标 1. 路由基础知识)补充学习...
  8. 江苏开放计算机应用基础性考,江苏开放大学计算机应用基础形考第二次作业答案...
  9. Spring tool suite4 安装及配置
  10. java封装继承多态实验总结_java封装继承多态理解3000字论文
  11. 计算机表格制作ppt,计算机基础使用excel2003制作表格.ppt
  12. WPF 加载PDF文件
  13. FBreader多端同步心得补充
  14. 如何搭建一个asp网站(具体操作流程——详细步骤+图)(Windows server2003 和 Windows server2008)
  15. Python Fitter 判断数据样本的分布函数拟合
  16. 自有APP上如何运行小游戏?
  17. js的常见的三种密码加密方式-MD5、Base64、sha1加密详解总结
  18. HDU 5473(There was a kingdom-凸包+dp)
  19. 一名IT界“老”技术人关于学习与成长的分享,受益!
  20. Leetcode 590: N-ary树的后序遍历

热门文章

  1. 计算机基本操作小技巧
  2. 假设有一条绳子长3000m,每天剪去一半,请问需要几天时间,绳子的长度会短于五米?
  3. MySQL 视图(详解) navicat如何创建视图
  4. STM32基础(11)光敏传感
  5. 计算机科学与技术书单
  6. 湖南2020年计算机等级考试报名时间,2020年湖南12月计算机等级考试报名时间:11月7日—10日...
  7. js基础-event对象
  8. SPEC MPI 安装运行
  9. C语言(void *)用法实例
  10. 第三章 Python基础——文件操作函数