Stateflow是一种图形化的建模和仿真环境,在这种环境下,可以实现有限状态理论的各种基本元素,构建有限状态机实现逻辑转换模型或者事件驱动系统模型。
1.打开Stateflow的3种方式
方式1
在MATLAB的命令窗口中输入“stateflow"或“sf”命令,会自动打开Library.sflib窗口和一个未命名的Simulink模型,其中自动配置了一个空白的Stateflow模块,其中 Chart为空白的 Stateflow模块,Truth table为真值表,如图所示。
>> stateflow
警告: The model name 'untitled' is shadowing another name in the MATLAB workspace or path. Type "which -all untitled"
at the command line to find the other uses of this name. You should change the name of the model to avoid problems.
> In sfnew (line 68)
In sflibrary (line 13)
In stateflow (line 16)
>>
方式2
在MATLAB的命令窗口中输人“sfnew”命令,会自动弹出一个未命名的Simulink模型,其中自动配置了一个空白的Stateflow 模块,如图所示。
>> sfnew
警告: The model name 'untitled' is shadowing another name in the MATLAB workspace or path. Type "which -all untitled"
at the command line to find the other uses of this name. You should change the name of the model to avoid problems.
> In sfnew (line 68)
>>
方式3
从Simulink的模型库窗口找到Stateflow库,并将Chart拖拽至模型编辑窗口。最常用的还是方式3。在创建了包含Stateflow模型的Simulink模型之后,建议将Stateflow的模块修改为一个合理的名字,而不是系统默认的Chart或Chart1等,这样能够提高模型的通用性,有利于其他的工程师使用该系统模型。
2.Stateflow编辑界面介绍
在使用Stateflow创建模型时,需要首先澄清几个基本的概念——状态机、Stateflow图块和Stateflow框图的含义:
(1)Stateflow状态机(State machine)——包含在模型中所有的Stateflow块的集合,即一个Simulink模型中包含所有Stateflow模型统称为一个Stateflow状态机。
(2)Stateflow图块(Chart)——包含状态图的模块,即Simulink模型中的Chart。
(3)Stateflow框图(Diagram)——状态图的图形化表述,即具体的Stateflow图块所包含的内容。在每个Stateflow块和Stateflow框图之间存在一一对应的关系。
双击任何模型中的Chart模块都可以打开Stateflow编辑界面,如图所示,用户可以在此窗口中编辑所需要的Stateflow模型。
从图形界面上看,Stateflow编辑器主要由菜单栏、工具栏、图形对象面板以及用来绘制Stateflow状态图的空白部分(编辑区)等四部分组成。其中图形对象面板包含了直接能够绘制的有限状态机图形对象,这些对象分别为:
State 状态
Junction 节点
Default Transition 默认转移
Box 图形盒
Simulink state
Simulink Function
Graphical function 图形函数
MATLAB function 内嵌MATLAB函数
Truth table 真值表
History Junction 历史节点
参考文献
[1] 刘杰.基于模型的设计及其嵌入式实现[M].北京:北京航空航天大学出版社,2010.
[2] 张威.Stateflow逻辑系统建模[M].西安:西安电子科技大写出版社,2007.
[3] Mathwork官网帮助Stateflow的操作说明:
https://ww2.mathworks.cn/help/stateflow/gs/stateflow-charts.html
本文内容来源于网络,仅供参考学习,如内容、图片有任何版权问题,请联系处理,24小时内删除。
作 者 | 郭志龙
编 辑 | 郭志龙
校 对 | 郭志龙