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_caruses 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.

You can simplify the debouncer logic by using thedurationoperator. 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_logicand, in theState Charttab, 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_state.gear_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_Logicand, in theState Charttab, clickLook Under Mask.

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

In this Stateflow chart, for the car to move from first gear to second gear, the conditionupmust betrue. The conditionupis 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. The conditiondownis defined as true if the length of time that the speed is less than or equal to the threshold is greater than the length of time that is specified byTWAIT. 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

Related Topics