Week - 4
Stateflow:
Stateflow provides a graphical language that includes state transition diagrams, flow charts, state transition tables, and truth tables. It is used to describe how MATLAB algorithms and Simulink models react to input signals, events, and time-based conditions. Stateflow enables you to design and develop supervisory control, task scheduling, fault management, communication protocols, user interfaces, and hybrid systems. With Stateflow, you model combinatorial and sequential decision logic that can be simulated as a block within a Simulink model or executed as an object in MATLAB. Graphical animation enables you to analyze and debug your logic while it is executing. Edit-time and run-time checks ensure design consistency and completeness before implementation.
Control Logic:
Control logic is a key part of a software program that controls the operations of the program. The control logic responds to commands from the user, and it also acts on its own to perform automated tasks that have been structured into the program. Control logic can be modeled using a state diagram, which is a form of hierarchical state machine.
AIM:-Implement control logic of a “washing machine” using Stateflow as per given sequence:
1.If the power supply is available, the system gets activated.
2- If the water supply is not available, stop the process and indicate through LED.
3- Soaking time should be 200s followed by Washing time of 100s.
4- Then rinsing happens for next 20s and dryer runs for 50s.
5- After all the processes have completed turn on the finished LED.

Stateflow:-

PROCEDURE:-
1. Creating a chart block for defining the stateflow for the given condition:
2. The junction is provided to terminate the signal value and retutn the null value to the system
3. if power supply is OFF i.e 0 the proocess is terminated at the junction and 1 is carry forworded.and same for the water supply.
4. if power and water supply is available soaking block will be activated
5. After 200 sec of Soaking, Wash block gets activated and washing action takes place.
7. After 100 sec of Washing, Rinse block gets activated and rinsing action takes place.
8. After 20 sec of Rinsing, Dry block gets activated and drying action takes place.
9. After 50 sec of dry, Finish block gets activated. Finish is to terminate the signal flow in the process and exits the chart.
10. Define x and y as inputs whereas soak, wash, rinse, dry, finish as outputs.
11. Connect the chart block with constant blocks for power and water inputs. Input switches connected to them are slider switch and a toggle switch respectively (to distinguish between the two). Attach lamps to observe the ON/OFF condition.
12. A common scope block is connected to observe the entire washing process and obtain the output plot. Blue color in the lamp indicates that the process is complete.
2. GEAR SHIFT MECHANISM:-
Create a chart block for defining the stateflow as per the given conditions.
2. Inside it, the circular junction is to terminate the signal flow and return a null value.
3. If ignition is OFF i.e. 0, the process is terminated at the junction else 1 is carry forwarded.
4. If speed is less than or equal to 0, the flow is terminated and gear 0 is activated. at the junction else 1 is carry forwarded.
5. If speed is greater than 0 and less than or equal to 15, the flow is terminated and gear 1 is activated.
6. If speed is greater than 15 and less than or equal to 25, the flow is terminated and gear 2 is activated.
7. If speed is greater than 25 and less than or equal to 40, the flow is terminated and gear 3 is activated.
8. If speed is greater than 40 and less than or equal to 60, the flow is terminated and gear 4 is activated.
9. If speed is greater than 60, the flow is terminated and gear 5 is activated.
11. Define ignition and speed as inputs whereas speedometer, scope and gear number display as outputs.
12. Connect the chart block with constant blocks for ignition and speed inputs. Input switches connected to them are slider switch and a slider bar to adjust variable speeds respectively (to distinguish between the two). Attach lamps to observe the ON/OFF condition.
13. A common scope block is connected to observe the speed numerically and obtain the output plot.
A Simulink model for operating the gear shift mechanism according to given conditions is shown below.


OUTPUT:-
