Week - 4
Week-4 challenge
- Implement control logic of a “washing machine” using Stateflow as per the given sequence:
- If the power supply is available, the system gets activated
- If the Water supply is not available, stop the process & indicate through LED
- Soaking time should be 200s followed by Washing time of 100s.
- Then rinsing happens for the next 20s & dryer runs for 50s
After all the processes have been completed turn on the finished LED
Answer:
part1: Implementation of control logic chart for Washing Machine using Stateflow
process:
- Start Simulink and create a blank model.
- Search for chart block in the Stateflow category of the library browser.
- Open the chart block and select the junction feature from the Stateflow window.
- Control logic for washing m/c is such that it should soak the water for the first 200sec followed by a washing time of 100sec. Rinsing the water for the next 20sec followed by a drying time of 50sec.
- After finishing the control logic run the STATEFLOW and check the sequence of operations for 370sec.
Blocks Used:
- Chart
A finite state machine is a representation of an event-driven (reactive) system. In an event-driven system, the system responds to an event by making a transition from one state (mode) to another. This transition occurs if the condition defining the change is true.

- Display
The Display block shows the value of the input data. I can specify the frequency of the display. For numeric input data, I can also specify the format of the display.
- Constant
The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input.
- Lamp
The Lamp block displays a color indicating the value of the input signal. I can use the Lamp block with other Dashboard blocks to build an interactive dashboard of controls and indicators for my model. I can specify pairs of input values and colors to provide the information I want during the simulation.


- Rocker Switch:
The Rocker Switch block toggles the value of the connected block parameter between two values during simulation. For example, I can connect the Rocker Switch block to a Switch block in my model and change its state during simulation.


Logic Explanation:
A Rocker switch from the dashboard library is used with a constant to supply the power and as water supply. A lamp is used to indicate the power status & water status. The power status is checked at the entry for every state and the water supply is checked for the soaking and the rinsing process. The timing for each state is as per the given inputs. The glowing lamp corresponding can see the status of the running process to the process name.
Washing Machine Logic

In the above control logic, the first state is created with 2 conditions for power supply.
One is with power supply available(PowerSwitch==1)and the second with water supply available
(W==1).If the power supply at entry is 1 and the water supply is on, then the machine will get activated and start the next process of operation.
The next 4 Operation states have been created in flow order Soaking, Washing, Rinsing and Drying with their time of operation as 200sec for a soak,100sec for wash,20sec for rinse & 50sec for dry.
Entry and exit conditions of the state are kept as 0 & i.e at the entry of operation states it is 0 and as operation completes it is 1 for every state.
After all, the process has been done washing machine is completed LED will glow and we can shut the machine off.
SYMBOLS PANE:

Here, PowerSwitch & W(water supply) is the input given while all others like Washing_State, D(dryer), Wa(washing), S(soaking), R(rinsing), and Washing_Completed are all outputs given.
Complete Simulink Model, Showing that the washing process is completed.

Here all LED glow as red means all process has been completed and all display output as 1.
Simulink Model, Shows that the washing process is completed & Rinsing is going on.

Here the green light means the operation is not completed and the red LED shows operation is completed which is also checked from the display box as output 1.
2. Make a Simulink chart for the “Gear shift” logic as per below conditions:
Speed Range(kmph) Gear
0 to 15 1
16 to 25 2
26 to 40 3
41 to 60 4
Above 61 5
Give speed input while the simulation is running & display the gear number.
Answer:
Part II: IMPLEMENTATION OF CONTROL LOGIC FOR GEAR SHIFT USING STATEFLOW
PROCESS:
- Start Simulink and create a blank model.
- Search for the CHART block in the Stateflow category of the library browser.
- Open the chart block and select the various features from the Stateflow window.
- Control logic for gear shift is such that it should change the gear when the speed increases or decreases automatically.
- After finishing the control logic run the Stateflow and check the gear shift operation for an infinite time.
Blocks Used:
- Chart
A finite state machine is a representation of an event-driven (reactive) system. In an event-driven system, the system responds to an event by making a transition from one state (mode) to another. This transition occurs if the condition defining the change is true.
- Display
The Display block shows the value of the input data. I can specify the frequency of the display. For numeric input data, I can also specify the format of the display.
- Constant
The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input.
- Lamp
The Lamp block displays a color indicating the value of the input signal. I can use the Lamp block with other Dashboard blocks to build an interactive dashboard of controls and indicators for my model. I can specify pairs of input values and colors to provide the information I want during the simulation.


5. Rocker Switch:
The Rocker Switch block toggles the value of the connected block parameter between two values during simulation. For example, I can connect the Rocker Switch block to a Switch block in my model and change its state during simulation.

6. Slider
The Slider block tunes the value of the connected block parameter during the simulation. For example, I can connect the Slider block to a Gain block in my model and adjust its value during the simulation. I can modify the range of the Slider block's scale to fit my data. Use the Slider block with other Dashboard blocks to create an interactive dashboard to control my model.

From the slide block i.e Throttle pedal we can change the value of vehicle speed while the simulation is running.
Logic Explanation:
The speed ranges from 0 to 100 and the slider is used to send the input. The 1st gear has speed values from 0 to 15 so the entry condition for the 1st gear is 0<=speed and speed<=15 and the exit condition is when the speed is greater than 15. Similarly, for the 2nd gear, the entry condition is 16<=speed and speed<=25 the exit condition is when speed<16 and speed>25. In the same way for each gear, the entry and the exit condition are specified and the out is mapped to the lamp and the display block.
Gear shift Stateflow Logic:

- In the above control logic, the first Engine is started from input switch E=0/1 through the Rocker switch which is the power switch to make the engine ON. Then next Gear_Shift is implemented through the following states.
- Five Gear State is created with state condition of gear (G) 1,2,3,4and 5 respectively and their transition is connected with speed range condition as shown.
- The transitions condition for the gear shift is decided as
Speed>15 shift to G=2
Speed>25 shift to G=3
Speed >40 shift to G=4
Speed>60 shift to G=5 when the speed is increasing from 0-60kmph similarly in the reverse direction
Speed<60 shift to G=4
Speed<40 shift to G=3
Speed<25 shift to G=2
Speed<15 shift to G=1 when the speed is decreasing from 60-0 Kmph
While simulating Gear_Shift, Engine [E==1] condition is given with various speed change values.
SYMBOLS PANE:

Here,
Speed is the input given while all others like Gear_first, Gear_second, Gear_third, Gear_fourth, and Gear_fifth are all as output given.
Simulink Model at different speeds
At Speed=72 kmph

At speed 72kmph, above 61kmph gear, 5 is implemented, and Gear_fifth LED glows red and displays the output as 1.
At Speed=20kmph

At a speed of 20kmph, above 16kmph gear, 2 is implemented, and Gear_second LED glows red and displays the output as 1.
At Speed=48 kmph

At speed 48kmph, above 40kmph gear, 4 is implemented, and Gear_fourth LED glows red and displays the output as 1.
RESULT:
Simulation of gear shift corresponding to the given speed range has been simulated successfully.