Simulink sim命令在输入时间序列中不使用时间数据

时间:2018-06-23 21:40:48

标签: unit-testing time simulink

我正在尝试学习如何在Simulink中制作测试工具。为此,我制作了一个简单的叉积块,并在其上附加了两个向量输入(u,v)。 test_harnness_cross_product

cross_product里面是这个架构: cross_product_contents

要运行测试,我有一个单独的脚本,该脚本调用sim()命令:

%% SETUP
clear, clc, close all


%overwrite these params just to be safe that they are correct...
options.LoadExternalInput = 'on';
options.ExternalInput = 'u_in, v_in';
options.StopTime = 'end_time';

% generate vector data
u_in_data = [1 0 0; 0 1 0];
v_in_data = [0 1 0; 0 0 1];

% u_in_data = 10*rand(num_el,3)-5; % 10x3 of -5 to 5
% v_in_data = 10*rand(num_el,3)-5; % 10x3 of -5 to 5

% sim options
sim_dt = 1;
model_name = 'harness_cross_product';
u_size = size(u_in_data);
num_el = u_size(1);
end_time = num_el-sim_dt;
y_out_e = zeros(num_el,3);
test_limit = 1e-9;

% Generate time data
u_in_time = 0:sim_dt:end_time;
v_in_time = u_in_time;

% define input timeseries
u_in = timeseries(u_in_data, u_in_time);
v_in = timeseries(v_in_data, v_in_time);

%% sim
simOut = sim(model_name,options);

%% comparison and scoring
y_out  = simOut.yout{1}.Values.Data;
y_out = y_out(1:num_el,:);

% fetch expected results
for indx=1:num_el
    y_out_e(indx,:) = cross(u_in_data(indx,:),v_in_data(indx,:));
end

% scoring
res_norm = norm(y_out-y_out_e);
if res_norm < test_limit
    test_score = 'passed';
else
    test_score = 'failed!';
end

disp(['Test ' test_score]);

当我运行脚本时,它不会返回[0 0 1; -1 0 0]。而是返回一个51行3列的数据数组。我几乎肯定这与sim()有关,但我不理解我希望它使用离散时间u_in.Time = [0; 1],因为它会生成自己的时间simOut.tout = [0:0.02:1]的向量;我需要在我没有的选项结构中包含一些名称/值对吗?

1 个答案:

答案 0 :(得分:0)

我发现了问题。如果遇到此问题,请确保检查以下内容:

ModelConfigurationParameters> SolverOptions>键入[从下拉菜单中选择“固定步骤”]

ModelConfigurationParameters> SolverOptions>解算器[从下拉菜单中选择“离散(无连续状态)”]

这些选项中的

一旦被选中。我的测试通过了。

编辑:可能还需要设置

ModelConfigurationParameters> Additional options> Fixed-step size [set equal to 1]