当前位置:网站首页>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的测试与以上相仿,具体说明链接如下:官方链接
边栏推荐
- 记录一下初次使用Xray的有趣过程
- MySQL事务
- Customize redis connection pool
- 每天睡觉前30分钟阅读_day4_Files
- Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime
- Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
- How to install PHP in CentOS
- Who is better for Beijing software development? How to find someone to develop system software
- What are the waiting methods of selenium
- 个人经历&&博客现状
猜你喜欢

c语言编程题

分享一篇博客(水一篇博客)

Fragmenttabhost implements the interface of housing loan calculator

Error reporting on the first day of work (incomplete awvs unloading)

Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)

三相逆变器离网控制——PR控制

PI control of grid connected inverter (grid connected mode)

Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别

How to use PHP spoole to implement millisecond scheduled tasks

BugkuCTF-web24(解题思路及步骤)
随机推荐
Record personal understanding and experience of game console configuration
Alibaba / popular JSON parsing open source project fastjson2
QT QLabel样式设置
TD联合Modelsim进行功能仿真
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
Methods of classfile
Required request body is missing: (cross domain problem)
2837xd code generation - Supplement (2)
个人经历&&博客现状
Microservice practice | Eureka registration center and cluster construction
2837xd 代码生成——StateFlow(3)
每天睡觉前30分钟阅读_day3_Files
C语言之分草莓
上班第一天的报错(Nessus安装winpcap报错)
Idea view bytecode configuration
BugkuCTF-web21(详细解题思路及步骤)
Customize redis connection pool
Save video opencv:: videowriter
C语言之最小数
Int to string, int to qstring