Main Content

Control Oscillations by Using thedurationOperator

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

您可以通过使用替代替代逻辑逻辑durationoperator. You can see this simplification in the modelsf_car._using_duration。Thedurationoperator 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 thedurationoperator, you can control oscillations with simpler Stateflow logic. Thedurationoperator 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_logicthere are two parallel states:gear_stateandselection_stategear_statecontains four exclusive states for each gear.selection_statedetermines 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 eventUPmust be sent fromselection_statetogear_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 eventUPis sent,gear_statetransitions fromfirsttosecond

Control Oscillation with thedurationOperator

Open the modelsf_car._using_duration

openExample("stateflow/AutomaticTransmissionUsingDurationOperatorExample")

Select the chartGear_Logic而且,在国家图表tab, clickLook Under Mask

WithinGear_Logicthere are four exclusive states for each gear. The local variablesupanddownguard the transitions between each state.

在此状态溢图中,为汽车从第一齿轮移动到第二档,条件upmust betrue。条件upis 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 operatordurationkeeps track of the length of time that the speed has been above or below the threshold. When theupcondition is met, the active state transitions fromfirsttosecond

By replacing the parallel state debouncer logic with thedurationoperator, you can create a simpler Stateflow chart to model the gear shifting.

See Also

相关话题