test real-凯发k8网页登录
this example shows how to perform a frequency-response test of the model slrt_ex_osc_sltest
.
using this information, in the design phase, you can modify the internal parameters of the model to meet your frequency requirements. in the production phase, you can bin manufactured parts based on frequency response.
open the model
to open the model, in the matlab® command window, type:
open_system(fullfile(matlabroot,'toolbox','slrealtime','examples','slrt_ex_osc_sltest'));
the figure shows representative output from a real-time application running on a target computer. at low frequencies, the output of the integrator1 block settles to the same value as the output of the signal generator block. at high frequencies, the output of the integrator1 block is still ringing at the end of each pulse.
the test determines the highest frequency at which the output values of the integrator and signal generator blocks are within a specified criterion of each other. the test uses the model itself as a signal source and uses a test harness to compare the outputs of the integrator and signal generator blocks.
step 1. set model configuration parameters
open model
slrt_ex_osc_sltest
in a writable folder.open the configuration parameters. on the real-time tab, click hardware settings.
select model referencing > total number of instances allowed per top model > one.
select data import/export > format > structure with time.
select data import/export > time.
select data import/export > output.
de-select data import/export > states.
de-select data import/export > final states.
de-select data import/export > signal logging.
de-select data import/export > data stores.
de-select data import/export > log dataset data to file.
step 2. create frequency parameter
create the parameter frequency
that is tuned at the end of this example.
open model explorer.
create a simulink® parameter
frequency
in model workspace for modelslrt_ex_osc_sltest
.mark the parameter as a model argument.
step 3. create test harness
on the simulink apps tab, click simulink test.
on the test tab, click add test harness. the software creates a test harness with the default name
slrt_ex_osc_sltest_harness1
.in the basic properties tab, for the input to component under test, select
none
.for the output from component under test, select
outport
.select the add separate assessment block check box.
select the open harness after creation check box.
take the defaults in the remaining tabs.
8. click ok.
the example model slrt_ex_osc_sltest
stores the test harness within the model. to access the test harness from the example model:
in simulink editor, on the test tab, click manage test harnesses.
click
slrt_ex_osc_sltest_harness1
.to return to the example model, select it in the perspectives view in the lower right corner of the test harness.
step 4. set test harness configuration parameters
open test harness
slrt_ex_osc_sltest_harness1
.open the configuration parameters. on the real-time tab, click hardware settings.
select model referencing > total number of instances allowed per top model > one.
select data import/export > format > structure with time.
select data import/export > time.
select data import/export > output.
de-select data import/export > states.
de-select data import/export > final states.
de-select data import/export > signal logging.
de-select data import/export > data stores.
de-select data import/export > log dataset data to file.
step 5. configure test harness
open the test assessment block.
to simplify the test assessment configuration, in the input symbol list, replace input
outport
with inputsint1
andsiggen
.in
slrt_ex_osc_sltest_harness1
, connect a demux block toslrt_ex_osc_sltest/outport
.in the demux block dialog box, set number of outputs to
2
.to make the demux outputs visible to the test assessment block, connect unitary gain blocks to each of the demux block outputs.
connect the top demux block output to
test assessment/int1
and the bottom output totest assessment/siggen
.
step 6. configure simulink parameters
open the model explorer. on the modeling tab, pull down the design section and click model explorer.
click node slrt_ex_osc_sltest_harness1 > model workspace.
in the toolbar, click the add simulink parameter button.
add the following data object:
name — criterion
value — 0
datatype — double
storage class — exportedglobal
5. in a similar manner, add simulink parameters w_open and w_close. because these parameters are in the slrt_ex_osc_sltest_harness1
model workspace as model parameters, you access them by name directly, without model hierarchy.
6. save the model.
step 7. setup frequency argument
right click on
slrt_ex_osc_sltest_harness1/slrt_ex_osc_sltest
.select
block parameter(model reference)
.select
instance parameters
on pop out window.mark
frequency
as an argument.
step 8. prepare test assessment steps
1. open the test assessment block
2. add these parameters to the parameter symbol list:
criterion
w_open
w_close
3. to add a step, in the step column, move the cursor to the top row, click add step after, and type:
checksetting
4. right-click step checksetting
and set the when decomposition check box.
5. to add a substep to checksetting
, click add sub-step, and type:
hi when (siggen > 0)
the when expression selects one half of the waveform.
6. right-click substep hi when
and set the when decomposition check box.
7. to substep hi when
, add substep:
hicheck when ((et >= w_open) && (et <= w_close)) verify((abs(int1) >= abs(siggen) * (1.0 - criterion)) && ... (abs(int1) <= abs(siggen) * (1.0 criterion)));
the when expression selects the time window for testing the acceptance criterion. the verify command tests the acceptance criterion.
8. in a similar manner, to step checksetting
, add substep:
lo when (siggen < 0)
9. to substep lo when
, add substep:
locheck when ((et >= w_open) && (et <= w_close)) verify((abs(int1) >= abs(siggen) * (1.0 - criterion)) && ... (abs(int1) <= abs(siggen) * (1.0 criterion)));
10. right-click substep lo when
and set the when decomposition check box.
11. to satisfy the requirements of when decomposition, remove the default run
step and insert defaultstep
substeps after steps checksetting
, hi when
, and lo when
. when decomposition requires at least two steps at each level of nesting, and one nondecomposed step at the end of each list of steps.
step 9. initialize test suite
click on the
slrt_ex_osc_sltest
subsystem.on the apps tab, click simulink test.
on the test tab, click test manager.
select new > test file.
name the test file
realtimetest
.right-click the test file and select new > real-time test.
in the new real-time test dialog box, enter
simulation
in the test type field.click create.
rename the new test suite to
realtimesuite
.rename the new test case to
frequencysweep
.
step 10. initialize system under test
in test manager, select node frequencysweep.
select tab system under test.
set model to
slrt_ex_osc_sltest
.in tab test harness, set harness to
slrt_ex_osc_sltest_harness1
.in tab simulation settings and release overrides, select the stop time check box.
take the defaults for the other fields.
step 11. initialize parameter overrides
1. in test manager, select tab parameter overrides.
2. click the add button. a dialog box opens containing a list of parameters. if parameters are not visible, click the refresh line at the top of the dialog box.
the refresh builds the model and uploads the model and block parameters from slrt_ex_osc_sltest_harness1
and slrt_ex_osc_sltest
.
3. open parameter set 1 and select the criterion, frequency, w_close, and w_open check boxes. leave the other check boxes cleared.
step 12. create scripted iterations
to configure and control iterated runs of the test harness, a number of constants and variables provide input.
test harness constants include:
cstartfreq = 15.0
start frequency of parameter sweep.cstopfreq = 25.0
end frequency of parameter sweep.cfreqincr = 1.0
frequency increment.cwopen = 0.90
start of time window for evaluatingcriterion
.cwclose = 0.99
end of time window for evaluatingcriterion
.ccriterion = 0.025
maximum normalized amplitude difference between signal generator and integrator1 within the time window.
test harness variables include:
vfreq
frequency at each iteration.vw_open
window opens once in each half-period.vw_close
window closes once in each half-period.
in test manager, select tab iterations > scripted iterations.
in the text box, enter the following code. to resize the scripted iterations text box, click and drag the lower-right corner of the box.
% initialize constants cstartfreq = 15.0; cstopfreq = 25.0; cfreqincr = 5.0; cwopen = 0.90; cwclose = 0.99; ccriterion = 0.025; % loop through test frequencies for vfreq = cstartfreq:cfreqincr:cstopfreq % create a new iteration testitr = sltest.testmanager.testiteration(); % calculate the time window half_period = 0.5 * (1.0/vfreq); vw_open = half_period * cwopen; vw_close = half_period * cwclose; % set the parameters for the iteration testitr.setvariable('name','frequency','source', ... 'slrt_ex_osc_sltest','value',vfreq); testitr.setvariable('name','w_open','source', ... '','value', vw_open); testitr.setvariable('name','w_close','source', ... '','value', vw_close); testitr.setvariable('name','criterion','source', ... '','value', ccriterion); % name and add the iteration to the testcase str = sprintf('%.0f hz', vfreq); additeration(sltest_testcase, testitr, str); end
step 13. run test
build and download
slrt_ex_osc_sltest
to the target computer.in test manager, click the run button.
to view test results, in the left column, click results and artifacts. in this case, the test failed at iteration 23 hz.
to view the failing results, open nodes 23 hz > verify statements and 23 hz > sim output (slrt_ex_osc_sltest).
step 14. display results
in the simulation data inspector pane, select the layout button.
select two horizontal displays.
in the simulation data inspector top display, select the two
out
check boxes and the top test assessment check box. this assessment corresponds to thehicheck
substep.in the bottom display, select the two
out
check boxes and the bottom test assessment check box. this assessment corresponds to thelocheck
substep.click the zoom in time button and select the range
4.00-4.1
.
in the top display, the vertical red line near 4.04
followed by a horizontal green line shows that the hicheck
test failed briefly before succeeding. in the bottom display, the vertical red spike near 4.02
followed by a horizontal green line shows that the locheck
test failed briefly before succeeding.
see also
(simulink test) | (simulink test)
related topics
- (simulink test)
- reuse desktop test cases for real-time testing (simulink test)