Access local symbol in a Simulink-based state in Stateflow

4 views (last 30 days)
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?

Accepted Answer

Kanishk
Kanishk on 19 Sep 2024
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 Comment
Francis Therien
Francis Therien on 19 Sep 2024
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Complex Logic in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!