Week - 4
1. Implement control logic of a "washing machine" using Stateflow as per 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 next 20s & dryer runs for 50s
After all the processes have completed turn on the finished LED
Ans :
part1: Implementation of control logic chart for Washing Machine using Stateflow
process:
1.Start simulink and create a blank model.
2.Search for chart block in the stateflow category of library browser.
3.0pen the chart block and select the junction feature from the stateflow window,
4.Control logic for washing m/c is such that it should soak the water for the first 200sec followed by washing time of 100sec. Rinsing for the next 20sec followed by drying time of 50sec.
5.After finishing the control logic run the STATEFLOW and check the sequence of operation for 370sec.
Blocks Used
1.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.

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


Logic Explanation
A larmp 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 stutus of the running process can be seen by the glowing lamp corresponding to the process name.
Washing Machine Logic

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

Here,
PowerSwitch & W(water supply) is as input given while all other like Washing State, D(dryer), Wafarashing). Sheaking). Riing Washing Completed are all output given.
Complete Simulink Model, Showing that the washing process is completed

Simulink Model, Showing that the washing process is completed & Rinsing is going on.

Here Red light means operation is not completed and green LED shows operation is completed which is also check from display be output 1.
2. Make a Simulink chart for the "Gear shift" logic as per below conditions:
Speed Range(kmph) Gear
O 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.
Ans>
Part II: IMPLEMENTATION OF CONTROL LOGIC FOR GEAR SHIFT USING STATEFLOW
PROCESS:
1.Start simulink and create a blank model
2. Search for CHART block in the stateflow category of library browser.
3. Open the chart block and select the vanous features from the stateflow window.
4. Control logic for gear shift is such that it should change the gear when the speed increases of decreases automatically.
5. Alter finishing the control logic run the stateflow and check the gear shift operation for an infinite time
Blocks Used
1.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.
2. Display
The Display block shows the value of the input data. You can specify the frequency of the display. For numeric ingut data, you can also specify the format of the display
3. Constant
The Constant block generates a real or complex constant value signal. Use this block to provide a constant signal input.
4.Lamp
The Lamp block display a color indicating the value of the input signal. You can use the Lamp block with other Dashboard blocks to build an interactive
Dashboard and indicators for your model. You can specify pairs of input values and colors to provide the information you want during the simulation.


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

From slide block i,e Throttle pedal we can change value of vehicle speed while simulation is running.
Logic Explanation
The speed ranges from O to 100 and the slider is used to send the input. The 1st gear has speed values from O to 15 so the entry condition for the 1st gear is O<=speed and speed<=15 and the exit condition is when the speed greater than 15.
Similarly for 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.
Logic

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

Here,
'E'(Engine on/oft) and 'Speed 'as input given while all other like PowerSwitch, Gear_first, Gear second, Gear_third. Gear fourth, Gear fifth are all as output given.
Simulink Madel at different speeds
Gear_1 At Speed=13 kmph

At speed 13kmph which is above 10kmph gear 1 is implemented and Gear fifth LED is glow green and display output as 1.
Gear_2 At Speed=20 kmph

At speed 20kmph which is above 16kmph gear 2 is implemented and Gear fifth LED is glow green and display output as 1.
Gear_3 At Speed=36 kmph

At speed 36kmph which is above 26kmph gear 3 is implemented and Gear fifth LED is glow green and display output as 1.
Gear_4 At Speed=50 kmph
At speed 36kmph which is above 41kmph gear 4 is implemented and Gear fifth LED is glow green and display output as 1.
Gear_5 At Speed=72 kmph 
At speed 72kmph which is above 61kmph gear 5 is implemented and Gear fifth LED is glow green and display output as 1.
And thus all condition simulated through stateflow chart successfully