检测数据和表达式值的变化
州流程®图表可以检测时间步长之间数据值和表达式的更改。你可以:
使用更改检测运算符以确定变量更改为值或从值。
使用边缘检测操作员确定表达式何时以上升高或低于阈值。
要生成隐式本地事件,当图表设置变量的值时,请使用改变
操作员。有关更多信息,请参阅使用隐式事件控制图表行为。
Change Detection Operators
检测Stateflow变化数据,使用歌剧tors listed in this table.
操作员 | 句法 | Description | 例子 |
---|---|---|---|
hasChanged |
tf = hasChanged(data_name) |
返回1(真的 ) if the value ofdata_name. 在当前时间步骤的开始与值不同data_name. at the beginning of the previous time step. Otherwise, the operator returns 0 (错误的 )。 |
如果矩阵的任何元素,转换出状态 [占(m)] |
如果在第1行中的元素和矩阵的第3列中的元素,则过渡 在使用matlab的图表中®as the action language, use: [hasChanged(M(1,3))] 在使用C作为动作语言的图表中,使用: [占(m [0] [2])]] |
|||
咯咯喊道 |
tf = hascangedfrom(data_name,值) |
返回1(真的 ) if the value ofdata_name. 等于指定的value at the beginning of the previous time step and is a different value at the beginning of the current time step. Otherwise, the operator returns 0 (错误的 )。 |
如果结构的先前值,则过渡状态 [遍布频率(struct,structvalue)] |
哈曼呼吸 |
tf = hascangedto(data_name,值) |
返回1(真的 ) if the value ofdata_name. 不等于指定的value 在上一步一步的开始,等于value 在当前时间步骤的开始。否则,操作员返回0(错误的 )。 |
Transition out of state if the structure field [哈桑(Struct.field,5)] |
笔记
如果在同一时间步骤中发生多个输入事件,则这些运算符可以检测输入事件之间的数据值的变化。
具有变更检测的图表示例
此模型显示了操作员如何hasChanged
那咯咯喊道
, 和哈曼呼吸
detect specific changes in an input signal. In this example, a斜坡(金宝appSimulink)block sends a discrete, increasing time signal to a chart.
The model uses a fixed-step solver with a step size of 1. The signal increments by 1 every time step. The chart analyzes the input signal你
对于这些变化:
从前一步一步的任何变化
改变价值3
价值3的变化
要检查信号,图表在转换措施中调用三个更改检测运算符。该图表将返回值输出为Y1.
那Y2.
, 和Y3.
。
在模拟期间,范围(金宝appSimulink)块显示图表的输入和输出信号。
的价值
你
每次逐步增加1。的价值
Y1.
在时间从0变为1t = 1
。的价值Y1.
仍然是1因为你
继续在每个后续时间步骤更改。的价值
Y2.
在时间从0变为1T = 4.
当值你
从3到4的变化Y2.
一次返回0。的价值
Y3.
在时间从0变为1T = 3.
当值你
从2到3的变化Y3.
一次返回0。
Limitations of Change Detection
StateFlow图表的类型确定了用于更改检测的数据的范围:金宝app
MATLAB中的独立状态流图:
Local
onlySimulink中的金宝app图表®that use MATLAB as the action language:
Input
onlySimulink中的金宝app图表that use C as the action language:
Input
那输出
那Local
, 要么数据存储内存
争论data_name.
可:
标量变量。
矩阵或矩阵的元素。
如果
data_name.
是一个矩阵,操作员返回真的
当它检测到任何元素的变化时data_name.
。使用评估到恒定整数的数字或表达式来矩阵的索引元素。看金宝app支持向量和矩阵的支持操作。
结构中的结构或场。
如果
data_name.
是一种结构,变更检测运算符返回真的
当它检测到任何字段的变化时data_name.
。使用点表示法在结构中的索引字段。看索引并将值分配给stateflow结构。
结构字段或矩阵元素的任何有效组合。
争论data_name.
不能成为非活动表达式或自定义代码变量。
笔记
Standalone charts in MATLAB do not support change detection on an element of a matrix or a field in a structure.
为了咯咯喊道
和哈曼呼吸
operators, the argumentvalue
可以是解决与可比值相当的值的任何表达式data_name.
。
如果
data_name.
is a scalar, thenvalue
必须解析为标量值。如果
data_name.
is a matrix, thenvalue
must resolve to a matrix value with the same dimensions asdata_name.
。或者,在使用C作为动作语言的图表中,
value
可以解析标量值。图表使用标量扩展来比较data_name.
到矩阵,其元素全部等于由指定的值value
。看Assign Values to All Elements of a Matrix。如果
data_name.
是一个结构,然后value
must resolve to a structure value whose field specification matchesdata_name.
确切地。
如果从使用更改检测运算符和行主数组布局启用的图表生成代码,则代码生成会产生错误。在生成代码之前,请启用列主要数组布局。看Select Array Layout for Matrices in Generated Code。
Edge Detection Operators
要确定何时表达式何时上升或低于阈值,请使用本表中列出的运算符。
操作员 | 句法 | Description | 例子 |
---|---|---|---|
横渡 |
TF =交叉(表达) |
返回1(
否则,操作员返回0( This operator imitates the behavior of a扳机(金宝appSimulink)块触发类型调成 |
如果输入数据的值,则过渡状态 [交叉(信号-2.5)] 当表达式的值时,检测到边缘 |
落下 |
tf =下降(表达) |
返回1(
否则,操作员返回0( This operator imitates the behavior of a扳机(金宝appSimulink)块触发类型调成 |
如果输入数据的值,则过渡状态 [falling(signal-2.5)] The falling edge is detected when the value of the expression |
升起 |
tf = rising(expression) |
返回1(
否则,操作员返回0( This operator imitates the behavior of a扳机(金宝appSimulink)块触发类型调成 |
如果输入数据的值,则过渡状态 [上升(信号-2.5)] 当表达式的值时,检测到上升沿 |
笔记
如扳机块,这些运算符在何时检测单个边缘表达
参数将数字从正为零变为负或从负到零到零,以连续三个时间步长。当表达式的值变为零时,发生边缘。
具有边缘检测的图表示例
此模型显示了操作员如何横渡
那落下
, 和升起
检测输入信号中的边缘。在这个例子中,一个脉冲发生器(金宝appSimulink)块向图表发送方波。
该模型使用具有步长为1的固定步骤求解器。输入信号的值你
每两段步骤0到5之间的交替。图表分析了输入信号你
对于这些边缘:
落下或上升的边缘过于2.5的阈值
超过2.5的阈值的边缘
边缘落在2.5的阈值下
要检查信号,图表在转换动作中调用三个边缘检测运算符。该图表将返回值输出为Y1.
那Y2.
, 和Y3.
。
在模拟期间,范围(金宝appSimulink)块显示图表的输入和输出信号。
的价值
你
每隔一个时间步骤在0和5之间交替。的价值
Y1.
在时间从0变为1t = 1
那3.
那5.
, 和7.
,当表达的值U-2.5
改变s sign. The value ofY1.
一次返回0。的价值
Y2.
在时间从0变为1t = 1
和5.
,当表达的值U-2.5
从负面变为正面。的价值Y2.
一次返回0。的价值
Y3.
在时间从0变为1T = 3.
和7.
,当表达的值U-2.5
从积极变为消极的变化。的价值Y3.
一次返回0。
边缘检测的限制
边缘检测仅在Simulink模型中的金宝app状态流图中支持。金宝app
争论表达
:
M.你st be a scalar-valued expression
Can combine chart input data, constants, nontunable parameters, continuous-time local data, and state data from Simulink based states
可以包括标量变量的加法,减法和乘法,矩阵的元素,结构中的结构中的字段,或结构字段和矩阵元素的任何有效组合
使用评估到恒定整数的数字或表达式来矩阵的索引元素。
仅在转换条件下仅支持用于连续时间数据和来自Simulink的状态的状态数据的边缘检测。金宝app金宝app
在原子区间,将在边缘检测表达式中映射使用的所有输入数据以在主图表中输入数据或不可运送的参数。将这些输入数据映射到输出数据,本地数据或可调参数可能导致未定义的行为。
州流程charts that use edge detection operators do not support operating points.
实施变更和边缘检测
A chart detects changes in chart data and expressions by evaluating the values at time step boundaries. The chart compares the value at the beginning of the previous execution step with the value at the beginning of the current execution step.
For example, when you invoke thehasChanged
operator with an argument ofX
,stateflow图表双缓冲值X
在局部变量。
Local Buffer | Description |
---|---|
X_prev |
Value of data |
X_Start. |
Value of data |
要检测更改,图表双缓冲数据值后一个事件触发了图表但是beforethe chart begins execution. If the values ofX上一个
和X开始
匹配,更改检测运算符返回错误的
to indicate that no change occurred; otherwise, it returns真的
表示改变。此图将这些任务放在图表生命周期的上下文中。
边缘检测运算符以类似的方式行事,除了它们比较最后一次步骤开始时表达式的值(X上一个
)其当前值(X
)。实现的差异允许连续时间图表在次要时间步骤期间检测本地数据中的边缘。
本地数据中的瞬态值更改
The change detection operators attempt to filter out transient changes in local chart variables by evaluating their values only at time boundaries. The chart evaluates the specified local variable only once at the end of the execution step. The return value of the change detection operators remains constant even if the value of the local variable fluctuates within a given time step. For example, suppose that in the current time step, the local variabletemp
改变s from its value at the previous time step but then reverts to the original value. The operator剩下的(温度)
回报错误的
在下次步骤中,表示未发生任何更改。
相反,边缘检测操作员可以在次要时间步骤期间在连续时间数据中检测边缘。例如,假设P.
是一种连续时间局部变量,具有负导数。然后是运营商落下(p)
回报真的
在次要时间步骤P.
将符号从正面变为负面。
检测输入事件或超级步骤迭代之间的值更改
当多个输入事件发生在同一时间步骤中,或者启用超级步语义时,图表更新X上一个
和X开始
buffers every time it executes. The chart detects changes in value between input events and super step iterations even if the changes occur more than once in a given time step. For more information, see使用事件执行图表和超级步骤语义。
也可以看看
改变|横渡|落下|hasChanged|咯咯喊道|哈曼呼吸|升起