How do I set the Sample Time of a Test Sequence block programmatically?

조회 수: 10 (최근 30일)
I have a test harness set up to test an Export Function Model (EFM) where the Test Sequence block uses the "send" command to drive the model. I have noticed that there are actually TWO sample times available to set in the Test Sequence block:
  1. One can be found by right-clicking the Test Sequence block and choosing "Block Parameters (Subsystem)"
  2. One can be found by opening the "Property Inspector" and left-clicking on the Test Sequence block.
I have found in my own testing that these two Sample Times are NOT the same; changing one does not change the other. Further, depending on the model configuration, setting the first sample time causes errors when I Update Model. Only changing the second Sample Time seems to have the behavior I want; that is, creating a block that calls the EFM at the rate set in the Test Sequence's sample time.
What is further confusing is that using the set_param and get_param functions, as well as the normal litany of MATLAB functions that can be called on subsystems, returns the first Sample Time instance, and there doesn't seem to be a property for the second Sample Time, the one that is actually useful. How do I set that programmatically?

채택된 답변

Dana Schwanke
Dana Schwanke 2024년 1월 7일
TL;DR: Test Sequences are actually an undocumented type under the hood that you have to access in a very convoluted way to actually change the right Sample Time property programmatically.
Doing some web searching and testing, I was trying to find documentation about the properties that are listed in the Property Inspector when you click on a Test Sequence. What I realized when looking at "Create data to monitor the active step" is that the Property Inspector properties are displaying Stateflow Chart properties. This was the first clue I needed to find out how to access the second Sample Time property.
When trying to access Stateflow objects from MATLAB, you have to use the "find" command with "sfroot" as the "location" argument:
chartObjects = find(sfroot,'-isa','[Stateflow Type]');
The valid types that can be placed in [Stateflow Type] are actually found in the "location" part of the "find" documentation:
So, with the MATLAB current folder set to the location of my externally-saved Test Harness, I called "find" using every type. And guess what? The Test Sequence object does not appear for any of them...but the individual steps INSIDE the Test Sequence DO appear for the Stateflow.State type. And one of the properties of the Stateflow.State object is .Chart, which tells you what the parent chart containing the state is. And lo and behold, it is our Test Sequence.
>> chart = find(sfroot, '-isa', 'Stateflow.State')
chart =
Stateflow.State: 386-by-1
>> chart(1)
ans =
Path: 'MyTestHarness/TestSequence'
Id: 24
Machine: [1×1 Stateflow.Machine]
SSIdNumber: 55
Name: 'MyTestSequenceState'
Description: ''
LabelString: 'MyTestSequenceState'
FontSize: 12
ArrowSize: 8
TestPoint: 0
Chart: [1×1 Stateflow.ReactiveTestingTableChart]
BadIntersection: 0
Subviewer: [1×1 Stateflow.ReactiveTestingTableChart]
Document: ''
Tag: []
RequirementInfo: ''
ExecutionOrder: 0
ContentPreviewEnabled: 0
Position: [871 456 150 90]
Decomposition: 'EXCLUSIVE_OR'
Type: 'OR'
IsSubchart: 1
IsGrouped: 0
Debug: [1×1 Stateflow.StateDebug]
InlineOption: 'Auto'
LoggingInfo: [1×1 Stateflow.SigLoggingInfo]
HasOutputData: 0
OutputData: []
OutputMonitoringMode: 'ChildActivity'
IsExplicitlyCommented: 0
IsImplicitlyCommented: 0
CommentText: ''
AppData: [1×1 struct]
Huh...the Chart property for our State is showing a Stateflow type that wasn't listed before. "ReactiveTestingTableChart". In fact, go ahead and search Mathworks' website for this, and you won't find a single Mathworks piece of documentation on this object. If you want to see the only Mathworks documentation for this object, go back to the MATLAB command window and type
charts = find(sfroot, '-isa', 'Stateflow.ReactiveTestingTableChart')
When this object is opened as a collection in MATLAB, the type is at the top of the "Variables" page with a blue hyperlink.
Clicking that hyperlink brings up the Help window with the following comprehensive documentation:
So, there you have it. As much as Simulink would have you believe this is a Subsystem you're dealing with, you are actually dealing with a special, undocumented type of Stateflow chart. Now that we have wasted several hours tracking down what should be listed for easy reading on Mathworks' website, modifying the Sample Time is trivial:
chart = find(sfroot, '-isa', 'Stateflow.ReactiveTestingTableChart');
for i = 1:length(chart)
if(strcmp(chart(i).Name,"[Test Sequence Block Name]"))
chart(i).SampleTime = '0.001'; % Or whatever value you want; has to be a char vector
end
end
Now if you, too, have an EFM that needs to be tested when called at different rates, perhaps because it controls an external device that has different configurations based on communication rate, you can modify your Test Sequence call rate from within the Test Manager's Callbacks sections, too!
  댓글 수: 1
Dana Schwanke
Dana Schwanke 2024년 1월 7일
For anyone wondering, the reason my model has two instances of the ReactiveTestingTableChart object is because the Test Assessment block is the exact same object type as the Test Sequence block.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by