Access local symbol in a Simulink-based state in Stateflow

조회 수: 2 (최근 30일)
Francis Therien
Francis Therien 2024년 9월 17일
댓글: Francis Therien 2024년 9월 19일
I have a simulink-based state in a stateflow chart. Simulink-based states can access input and output symbols (chart symbols) using in and out ports. Is it possible to read or modify the value of a local symbol from a simulink-based state?
Alternatively, how can I trigger a transition from a simulink-based state? The pole-vaulter example uses integrator states, but what about using other signals within the simulink state that are not block states?

채택된 답변

Kanishk
Kanishk 2024년 9월 19일
Hi Francis,
Local symbols in Stateflow cannot be modified in the Simulink based states. Instead, to read/modify values from Stateflow in Simulink based states “Data Store Memory” can be used.
To implement Data Store memory,
  • Place a "Data Store Memory" block in your Simulink model outside of the Stateflow chart. This block will serve as a shared memory resource.
  • Change the "Data type" to "double" and "Signal Type" to "real" of "Data Store Memory" block.
  • In the Stateflow chart, add a data object and configure it as "Data Store Memory" using the Symbols pane. This allows the chart to access the shared memory.
  • Within Simulink-based states, utilize "Data Store Read" and "Data Store Write" blocks to access and modify the shared memory. These blocks enable interaction with the data store memory object.
To trigger transitions based on signals from Simulink-based states, use "Data Store Write" to update the signals in the Data Store Memory object. These updated values can then be used to trigger transitions within the Stateflow chart.
To learn more about “Data Store Memory” and how to access the memory in Stateflow, please go through these official MATLAB documentations:
I am also attaching the example model I created for better understanding.
Hope this helps!
Thanks
  댓글 수: 1
Francis Therien
Francis Therien 2024년 9월 19일
Thank you @Kanishk. This workaround is a bit annoying, but it works. It would be a great addition by Mathworks in future versions of Simulink and Stateflow to provide a mechanism for direct access to local data in charts from Simulink based states.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by