How to read the value of a 'Local' Data field in stateflow using Simulink test?

9 visualizaciones (últimos 30 días)
For whitebox testing (using Simulink Test) of a stateflow diagram I need to read some data field values which has its Scope type set to 'Local'. How can this be done?

Respuesta aceptada

Renato SL
Renato SL el 4 de Sept. de 2019
I found something else. There is an old blog post about it (here) that describes the idea.
In the Model Explorer window (where you define data and its Scope type), when you click on a data, on your right hand side you can set certain parameters of the data.
Click on the Logging tab, and tick the Log signal data box.
logging.png
This is a screenshot from my example.
After that, once you run the simulation, click on the Simulation Data Inspector button (beside the Simulation stop time box, top side of the Simulink window) and you can see the logged data there.
logging2.png
In the screenshot above, it's the one in the red circle.
I think it would turn yellowish once you run the simulation and you have a logged data.
I think this is how you can test the model without physically altering the blocks, which is what you are looking for.
  2 comentarios
bert de Jong
bert de Jong el 4 de Sept. de 2019
OK nice, almost there.
The only thing still needed is actually reading the logged value(s) at runtime. I tried some stuff, and I can actually read the logged values using:
logsout.getElement('NAME_OF_SIGNAL').Values.Data
However the logsout variable only gets loaded after the simulation is finished.
Renato SL
Renato SL el 4 de Sept. de 2019
From the documentation of the data inspector (here), I believe it isn't meant to be used during runtime. For Matlab in general, I also think that observing data during runtime for the sake of seeing it change through time is not facilitated. (I found an interesting discussion here).
Other than observing the logsout through the command window, I think it's better to see it directly with the Simulation Data Inspector.
While opening the inspector, you could progress the simulation some steps at a time (by clicking the Step Forward button beside the Run button).
If this is what you meant by 'reading the logged value(s) at runtime', then this should be it.

Iniciar sesión para comentar.

Más respuestas (1)

Renato SL
Renato SL el 4 de Sept. de 2019
I think you should create a new data with Scope type set to 'Output'. This new data will just take the value of the concerned Local data so that it can be inspected from outside of the Chart.
%example
en:
x = 0; %the local data
du:
x = x + 1; %something is done to the local data
y = x; %the output data takes the value of the local data
I explored this possibility some time ago and I made this simple example (.slx file attached). I hope this helps.
  1 comentario
bert de Jong
bert de Jong el 4 de Sept. de 2019
Hi Renato,
Thanks for your answer.
I understand changing the data scope to 'output' will make it easily readable from outside the stateflow block, however this would mean I have to modify my model just for testing. As a consequence, my model which uses the model under test, will be cluttered with a lot of unused terminated outputs.
Also, routing the local signals out, makes the test more black box than white box. I expect/hope simulink test supports white box testing.

Iniciar sesión para comentar.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by