Borrar filtros
Borrar filtros

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

9 visualizaciones (últimos 30 días)
ambre allard
ambre allard el 13 de Jun. de 2022
Respondida: Swetha Murali el 14 de Jun. de 2022
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

Respuestas (2)

Eeshan Mitra
Eeshan Mitra el 14 de Jun. de 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.
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 el 14 de Jun. de 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')

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by