Main Content

Control Chart Behavior by Using Implicit Events

Implicit eventsare built-in events that occur during chart execution when:

  • The chart wakes up.

  • The chart enters a state and the state becomes active.

  • The chart exits a state and the state becomes inactive.

  • The chart assigns a value to an internal data object.

这些事件是隐式的,是因为你不define or trigger them explicitly. Implicit events are children of the chart in which they occur and are visible only in the parent chart.

Implicit Events Based on Chart Execution

The keywordtickspecifies the implicit event generated when a chart wakes up in a discrete-time simulation.

For example, in this chart,FanandHeaterare parallel (AND) states. Each state has a pair of substates,OnandOff. Initially, the substatesFan.OffandHeater.Offare active. Each time the chart wakes up, it generates atickevent. The thirdticktriggers the transition fromHeater.OfftoHeater.On. Similarly, the fourthticktriggers the transition fromFan.OfftoFan.On. On the eighthtick, the chart transitions back toFan.OffandHeater.Off.

Stateflow chart that uses the implicit event tick.

For information about the temporal logic operatorafter, seeControl Chart Execution by Using Temporal Logic.

Note

Thetickevent refers to the chart containing the action being evaluated. The event cannot refer to a different chart.

Implicit Events Based on Data and States

In Stateflow®charts in Simulink®models, these operators generate implicit events when a chart sets the value of a variable or when a chart enters or exits a state.

Operator Syntax Description Example
change

change(data_name)

chg(data_name)

Generates an implicit local event when the chart sets the value of the variabledata_name. The variabledata_namecannot be machine-parented data. This implicit event works only with data that is at the chart level or lower in the hierarchy. For machine-parented data, use change detection operators to determine when the data value changes. For more information, seeDetect Changes in Data and Expression Values.

Define an implicit local event when a state or transition action writes a value to the variableEngine.rpm.

change(Engine.rpm)

enter

enter(state_name)

en(state_name)

Generates an implicit local event when the specified statestate_namebecomes active.

Define an implicit local event when the chart execution enters the stateFan.On.

enter(Fan.On)

exit

exit(state_name)

ex(state_name)

Generates an implicit local event when the specified statestate_namebecomes inactive.

Define an implicit local event when the chart execution exits the stateFan.Off.

exit(Fan.Off)

If more than one state or data object has the same name, use dot notation to qualify the name of the state. For more information, seeIdentify Data by Using Dot Notation.

For example, in this chart,FanandHeaterare parallel (AND) states. Each state has a pair of substates,OnandOff. Initially, the substatesFan.OffandHeater.Offare active. When the chart wakes up, it generates atickevent that triggers the transition fromFan.OfftoFan.On. When theFan.Offbecomes inactive, the chart generates another implicit event that triggers the transition fromHeater.OfftoHeater.On. When the chart execution ends, the substatesFan.OnandHeater.Onare active.

Stateflow chart that uses the implicit event exit.

Note

如果相同的隐式活动组织ers multiple transitions in parallel states, the order in which the transitions execute does not necessarily match the execution order of the parallel states. To avoid unexpected behavior and ensure that the transitions execute in the order specified for the parallel states, do not use implicit events. Instead, use transition conditions that call operators such asinorhasChanged. For more information, seeCheck State Activity by Using the in OperatorandDetect Changes in Data and Expression Values.

See Also

|||||

Related Topics