main content

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

  1. open model slrt_ex_osc_sltest in a writable folder.

  2. open the configuration parameters. on the real-time tab, click hardware settings.

  3. select model referencing > total number of instances allowed per top model > one.

  4. select data import/export > format > structure with time.

  5. select data import/export > time.

  6. select data import/export > output.

  7. de-select data import/export > states.

  8. de-select data import/export > final states.

  9. de-select data import/export > signal logging.

  10. de-select data import/export > data stores.

  11. 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.

  1. open model explorer.

  2. create a simulink® parameter frequency in model workspace for model slrt_ex_osc_sltest.

  3. mark the parameter as a model argument.

step 3. create test harness

  1. on the simulink apps tab, click simulink test.

  2. on the test tab, click add test harness. the software creates a test harness with the default name slrt_ex_osc_sltest_harness1.

  3. in the basic properties tab, for the input to component under test, select none.

  4. for the output from component under test, select outport.

  5. select the add separate assessment block check box.

  6. select the open harness after creation check box.

  7. 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:

  1. in simulink editor, on the test tab, click manage test harnesses.

  2. click slrt_ex_osc_sltest_harness1.

  3. 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

  1. open test harness slrt_ex_osc_sltest_harness1.

  2. open the configuration parameters. on the real-time tab, click hardware settings.

  3. select model referencing > total number of instances allowed per top model > one.

  4. select data import/export > format > structure with time.

  5. select data import/export > time.

  6. select data import/export > output.

  7. de-select data import/export > states.

  8. de-select data import/export > final states.

  9. de-select data import/export > signal logging.

  10. de-select data import/export > data stores.

  11. de-select data import/export > log dataset data to file.

step 5. configure test harness

  1. open the test assessment block.

  2. to simplify the test assessment configuration, in the input symbol list, replace input outport with inputs int1 and siggen.

  3. in slrt_ex_osc_sltest_harness1, connect a demux block to slrt_ex_osc_sltest/outport.

  4. in the demux block dialog box, set number of outputs to 2.

  5. to make the demux outputs visible to the test assessment block, connect unitary gain blocks to each of the demux block outputs.

  6. connect the top demux block output to test assessment/int1 and the bottom output to test assessment/siggen.

step 6. configure simulink parameters

  1. open the model explorer. on the modeling tab, pull down the design section and click model explorer.

  2. click node slrt_ex_osc_sltest_harness1 > model workspace.

  3. in the toolbar, click the add simulink parameter button.

  4. 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

  1. right click on slrt_ex_osc_sltest_harness1/slrt_ex_osc_sltest.

  2. select block parameter(model reference).

  3. select instance parameters on pop out window.

  4. 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

  1. click on the slrt_ex_osc_sltest subsystem.

  2. on the apps tab, click simulink test.

  3. on the test tab, click test manager.

  4. select new > test file.

  5. name the test file realtimetest.

  6. right-click the test file and select new > real-time test.

  7. in the new real-time test dialog box, enter simulation in the test type field.

  8. click create.

  9. rename the new test suite to realtimesuite.

  10. rename the new test case to frequencysweep.

step 10. initialize system under test

  1. in test manager, select node frequencysweep.

  2. select tab system under test.

  3. set model to slrt_ex_osc_sltest.

  4. in tab test harness, set harness to slrt_ex_osc_sltest_harness1.

  5. in tab simulation settings and release overrides, select the stop time check box.

  6. 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 evaluating criterion.

  • cwclose = 0.99 end of time window for evaluating criterion.

  • 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.

  1. in test manager, select tab iterations > scripted iterations.

  2. 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

  1. build and download slrt_ex_osc_sltest to the target computer.

  2. in test manager, click the run button.

  3. to view test results, in the left column, click results and artifacts. in this case, the test failed at iteration 23 hz.

  4. to view the failing results, open nodes 23 hz > verify statements and 23 hz > sim output (slrt_ex_osc_sltest).

step 14. display results

  1. in the simulation data inspector pane, select the layout button.

  2. select two horizontal displays.

  3. in the simulation data inspector top display, select the two out check boxes and the top test assessment check box. this assessment corresponds to the hicheck substep.

  4. in the bottom display, select the two out check boxes and the bottom test assessment check box. this assessment corresponds to the locheck substep.

  5. 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

网站地图