Clear Filters
Clear Filters

How to force the test harness to a defined sample time ?

11 views (last 30 days)
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

Answers (2)

Eeshan Mitra
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)
Subsequently call harness creation:
>> sltest.harness.create(<harnessOwnerModelName>,'Name',<harnessName>,'PostCreateCallback','updateHarnessSampleTime')
The PostCreateCallback option can also be specified using the harness create dialog.
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.

Swetha Murali
Swetha Murali on 14 Jun 2022
You could use change the configuration setting after creating the harness.
sltest.harness.load(model,'sample_harness') % Can also be replaced with
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)
% Pass this function name during call to harness create




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!