当前位置:网站首页>Matlab代码生成之SIL/PIL测试
Matlab代码生成之SIL/PIL测试
2022-07-02 06:35:00 【Quikk】
Matlab代码生成之SIL/PIL测试
一、SIL与PIL测试流程
1.SIL(Software in the Loop),使用SIL可以在PC端进行测试生成的代码。 PIL(Processor in the Loop),使用PIL可以在实际目标硬件或指令集模拟器 上运行源代码进行测试。
测试标准:将PIL(SIL)结果与正常模型测试结果进行对比,可以得到生代码的执行效果。
2.需要配置与PC端的直接连接参数
二、Top Model的SIL/PIL仿真
特点:
1.可以直接使用独立的代码接口进行测试
2.可以配置模型从Workspace中加载测试向量和激励输入
3.便捷地在Top model、Normal、SIL、PIL之间进行切换
官方链接:官方链接1
在matlab command window中输入以下命令:
model='rtwdemo_sil_topmodel';
close_system(model,0) //关闭不保存
open_system(model) //打开model
之后在Simulink中打开如下模型:

在matlab command window中输入以下命令:
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,'SimulationMode','normal')
[~, ~, yout_normal] = sim(model,10); /*运行normal 模型(结果存储在yout_normal)*/
set_param(model,'SimulationMode','Software-in-the-Loop (SIL)')
[~, ~, yout_sil] = sim(model,10); /*运行SIL模型(结果存储在yout_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'); /*绘制图像,观看两者差异*/
模型中有关的设置:

整个模型的执行就是,从外部输入控制参量然后进行执行,然后对比SIL与normal模型下的运行结果进行分析。
三、基于模型的SIL(PIL)测试
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([model '/CounterA'], 'CodeInterface', 'Top model'); /*设置模型的运行方式*/
out = sim(model,20); /*开始运行*/

yout = find(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(PIL)各自封装成一个测试模块同时执行(如图中的CounterA与CounterB),对比执行后的结果。
四、基于SIL(PIL)控制模块测试
model='rtwdemo_sil_block';
close_system(model,0)
open_system(model) /*打开模型*/
out = sim(model,10);
yout_normal = find(out,'yout');
clear out /*启动模型*/ 这里是normal模型的仿真
set_param(model,'CreateSILPILBlock','SIL');
close_system('untitled',0);
rtwbuild([model '/Controller'])
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
之后出现一个新的model构建框:

controllerBlock = [model '/Controller'];
blockPosition = get_param(controllerBlock,'Position');
delete_block(controllerBlock); //删除原来模型中的模块
add_block('untitled/Controller',[controllerBlock '(SIL)'],... //将生成的Model替代原来模型中的模块
'Position', blockPosition);
close_system('untitled',0);
clear controllerBlock blockPosition
out = sim(model,10); //启动仿真
machine_precision = eps(single(yout_normal));
tolerance = 4 * machine_precision; //设置仿真容许误差
yout_sil = find(out,'yout');
tout = find(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') //关闭图像
五、总结
PIL测试方面,可以验证测试生成代码。C2000的测试与以上相仿,具体说明链接如下:官方链接
边栏推荐
猜你喜欢

2837xd 代碼生成——補充(1)

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd

Chrome browser plug-in fatkun installation and introduction

Redis installation and deployment (windows/linux)

个人经历&&博客现状

FragmentTabHost实现房贷计算器界面

Chrome user script manager tempermonkey monkey

Typora installation package sharing

DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!

Tinyxml2 reading and modifying files
随机推荐
上班第一天的报错(Nessus安装winpcap报错)
C语言之分草莓
Vs+qt set application icon
Tools used for Yolo object recognition and data generation
保存视频 opencv::VideoWriter
In SQL injection, why must the ID of union joint query be equal to 0
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
Insight into cloud native | microservices and microservice architecture
MySQL error: unblock with mysqladmin flush hosts
Required request body is missing:(跨域问题)
Methods of classfile
Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
互联网API接口幂等设计
2837xd code generation - Supplement (1)
Thinkphp5 how to determine whether a table exists
Operation and application of stack and queue
In depth analysis of how the JVM executes Hello World
在SQL注入中,为什么union联合查询,id必须等于0
2837xd 代码生成——StateFlow(1)
ZK configuration center -- configuration and use of config Toolkit