How to force the test harness to a defined sample time ?
14 views (last 30 days)
Show older comments
Hello,
The model I want to test using a test harness has the following solver settings:
- Solver type: Fixed-step
- Solver: discrete
- Fixed step size: auto
In the global code this model is called by a function at every 20ms. How can I create a test harness with the following settings ?
- Solver type: Fixed-step
- Solver: discrete
- Fixed step size: 0.02
Thanks
0 Comments
Answers (2)
Eeshan Mitra
on 14 Jun 2022
If you would like to specify sample time during harness creation, you can define a PostCreateCallback function to set the sample time using set_param:
function updateHarnessSampleTime(harnessInfo)
set_param(harnessInfo.HarnessModel,'FixedStep','0.02')
end
Subsequently call harness creation:
>> sltest.harness.create(<harnessOwnerModelName>,'Name',<harnessName>,'PostCreateCallback','updateHarnessSampleTime')
The PostCreateCallback option can also be specified using the harness create dialog.
More on this option here: https://www.mathworks.com/help/sltest/ug/customize-test-harnesses.html
Of course, harness sample time can also be updated post creation from it's Configuration Parameters or using the 'FixedStep' argument and set_param programmatically.
If you are trying to set up scheduling for the top model in the harness, one other option would be to add a scheduler during harness creation using the SchedulerBlock argument in the harness create API. A scheduler block can typically be inserted when creating harnesses for models with Export function semantics or global simulink functions. If you choose this option, you can also customize the frequency of 'send' calls in the generated scheduler.
0 Comments
Swetha Murali
on 14 Jun 2022
You could use change the configuration setting after creating the harness.
sltest.harness.create(model,'Name','sample_harness')
sltest.harness.load(model,'sample_harness') % Can also be replaced with sltest.harness.open
set_param('sample_harness','FixedStep','0.02')
The other alternative is to use the "Post-create callback" if you would like sltest.harness.create to automatically create a harness with this setting.
% Define the below function on path
function harnessCustomization(harnessInfo)
set_param(harnessInfo.HarnessModel,'FixedStep','0.02')
end
% Pass this function name during call to harness create
sltest.harness.create(model,'sample_harness','PostCreateCallback','harnessCustomization')
0 Comments
See Also
Categories
Find more on Inputs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!