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

조회 수: 5 (최근 30일)
ambre allard
ambre allard 2022년 6월 13일
답변: Swetha Murali 2022년 6월 14일
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

답변 (2개)

Eeshan Mitra
Eeshan Mitra 2022년 6월 14일
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 2022년 6월 14일
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')

카테고리

Help CenterFile Exchange에서 Inputs에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by