Control Oscillations by Using theduration
Operator
The following example focuses on the gear logic of a car as it shifts from first gear to fourth gear.
When modeling the gear changes of this system, it is important to control the oscillation that occur. The modelsf_car.
uses parallel state debouncer logic that controls which gear state is active. For more information about how debouncers work in Stateflow®, seeReduce Transient Signals by Using Debouncing Logic。
您可以通过使用替代替代逻辑逻辑duration
operator. You can see this simplification in the modelsf_car._using_duration
。Theduration
operator evaluates a condition expression and outputs the length of time that the expression has beentrue
。When that length of time crosses a known time threshold, the state transitions to a higher or lower gear.
By removing the parallel state logic and using theduration
operator, you can control oscillations with simpler Stateflow logic. Theduration
operator is supported only in Stateflow charts in a Simulink®model.
Control Oscillation with Parallel State Logic
Open the modelsf_car.
。
openExample("stateflow/AutomaticTransmissionWithActiveStateDataExample")
Select the chartshift_logic
而且,在国家图表tab, clickLook Under Mask。
The Stateflow chartshift_logic
控制齿轮car is in, given the speed of the car and how much throttle is being applied. Withinshift_logic
there are two parallel states:gear_state
andselection_state
。gear_state
contains four exclusive states for each gear.selection_state
determines whether the car is downshifting, upshifting, or remaining in its current gear.
In this Stateflow chart, for the car to move from first gear to second gear, the eventUP
must be sent fromselection_state
togear_state
。The event is sent when the speed crosses the threshold and remains higher than the threshold for the length of time determined byTWAIT
。When the eventUP
is sent,gear_state
transitions fromfirst
tosecond
。
Control Oscillation with theduration
Operator
Open the modelsf_car._using_duration
。
openExample("stateflow/AutomaticTransmissionUsingDurationOperatorExample")
Select the chartGear_Logic
而且,在国家图表tab, clickLook Under Mask。
WithinGear_Logic
there are four exclusive states for each gear. The local variablesup
anddown
guard the transitions between each state.
在此状态溢图中,为汽车从第一齿轮移动到第二档,条件up
must betrue
。条件up
is defined as true if the length of time that the speed is greater than or equal to the threshold is greater than the length of time that is specified byTWAIT
。条件down
如果速度小于或等于阈值的时间长度大于所指定的时间长度,则定义为trueTWAIT
。The operatorduration
keeps track of the length of time that the speed has been above or below the threshold. When theup
condition is met, the active state transitions fromfirst
tosecond
。
By replacing the parallel state debouncer logic with theduration
operator, you can create a simpler Stateflow chart to model the gear shifting.