Over the years, I've delivered dozens of talks on Stateflow, a state machine design and simulation environment. If this is a new concept to you, I recommend you check out my video series on the subject to get familiarized. State machines are a powerful means of expressing complex logic in a compact, efficient manner.
A common question that I receive from Stateflow audiences concerns conversion from other representations. "Can you take my MATLAB code, C code, or Simulink model and automatically turn it into a Stateflow chart?" For such questions, I'll point out how the other direction is possible. You can call Stateflow as on object in MATLAB or use Simulink Coder to convert it to C. But import has remained elusive, which is why I got excited when I came upon this File Exchange contribution. With this utility, you can convert certain Simulink patterns into Stateflow charts.
Here we have the initial model:
Right-click on the canvas:
Wait a moment, and this is the result:
Adding the action to the Simulink context menu is a nice touch that makes the task easier than running a MATLAB function. Truth be told, the resultant chart is not as pristine as the one I'm showing. The states and transitions are dropped on top of each other by the utility, but it's not too much work to clean it up. There's an automatic arranging feature of Stateflow that accelerates this process. But once you're done, you have a chart that is noticeably simpler than the Simulink diagram we started with.
I consider this tool a proof-of-concept because it has a number of limitations. So far as I can tell, it only can produce charts with two states; my attempts to generate a third were unsuccessful. Similar attempts to alter the examples yielded unexpected results. Insertion of a Math Function in one model yielded four transitions. The authors make it clear in their paper that the tool doesn't work with industrial-scale models. Nevertheless, I'm impressed with what has been built to-date. It's a solid foundation that I hope to see built atop.
Let us know what you think here or leave a comment for McSCert.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.