Simulink for Mechanical & Electrical Engineers Challenges = Week 4
- Aim
- To Make a Simulink model using State-Flow for given questions.
- Questions & Solution
- Q1. 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 the 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.
- Solution 1.
- Theory
- A washing machine (laundry machine, clothes washer, or washer) is a home appliance used to wash laundry. The term is mostly applied to machines that use water as opposed to dry cleaning (which uses alternative cleaning fluids and is performed by specialist businesses) or ultrasonic cleaners. The user adds laundry detergent, which is sold in liquid or powder form, to the wash water.
- The requirements to run the machine are the Power Supply and Water Supply. And it performs the cleaning process of clothes by soaking, washing, rinsing and drying, and many more process.

- Following is the simulation model for Washing Machine applying a given control logic.

- In the above model the simulation blocks used & their purpose are as follows :
- Constant – The Constant block generates a real or complex constant value signal.
- StateFlowChart – Stateflow provides a graphical language that includes state transition diagrams, flow charts, state transition tables, and truth tables. You can use Stateflow to describe how MATLAB® algorithms and Simulink models react to input signals, events, and time-based conditions.
- Outport – Provide an output port for a subsystem or model.
- Scope – Display signals generated during simulation.
- Relational Operator – Applies the selected relational operator to the inputs and outputs the result.
- Delay One Step – Delay input signal by a specified number of samples.
- Stop Simulation – Stop simulation when input is nonzero.
- Lamp – Display a color that reflects an input value.
- Rocker Switch – Set on/off value to tune parameters or variables.
- MultiStateImage – Display an image that reflects an input value.
- Working of Model
- According to the given control logic, we need two inputs and single output to complete the control logic.
- The input signals are required for Power & Water Supply and the output port is required to know the machine status.
- Using constant block we provide the input signals, since they are user interface the input signals are provided using the Rocker Switch block which is Power Supply Switch & Water Supply Switch.
- Then for the machine to work according to the control logic sequence we use the StateFlowChart block, where we build the control logic of the given sequence which acts upon the given inputs.
- Now depending upon the inputs, the control logic takes to transition from one state to another.
- The control logic is created in stateflowchart as shown below and works according to the given sequence.

- The control logic is built accordingly.
- First, we check the input of the power supply and display the signal according to the input.
- Then after 3 sec of getting the power supply, we move to the next state and check the water supply.
- After getting the power supply and water supply for 3 sec we make the transition from the state of soaking, where it also checks the power and water supply continuously.
- After the soaking process is completed of 200 sec it moves towards the washing process with 3 sec delay.
- Then all the following states are achieved according to the given sequence and for each state transition power & water supply are checked.
- From the control logic stateflowchart, we collect the machine status as output.
- And according to outputs we display its process on the dashboard.
- After finishing the complete process, we check it using the relational operator and then stops the simulation with 3 sec delay.
- In the scope, we record the inputs and the machine status with time.
- Results
- Following are the results of the simulation sequentially with time.
- Power Supply

- Water Supply

- Soaking


- Washing


- Rinsing


- Drying


- Finish


- Following is the video of the Washing Machine simulation.
- Q2. Make a Simulink chart for the “Gear shift” logic as per the 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.
- Solution 2.
- Theory
- A transmission is a machine in a power transmission system, which provides a controlled application of power. Often the term 5-speed transmission refers simply to the gearbox, that uses gears and gear trains to provide speed and torque conversions from a rotating power source to another device.


- Following is the simulation model Solving the given question.

- In the above model the simulation blocks used & their purpose are as follows :
- Constant – The Constant block generates a real or complex constant value signal.
- Slider Gain – The Slider Gain block performs a scalar gain that you can modify during simulation.
- StateFlowChart – Stateflow provides a graphical language that includes state transition diagrams, flow charts, state transition tables, and truth tables. You can use Stateflow to describe how MATLAB® algorithms and Simulink models react to input signals, events, and time-based conditions.
- Scope – Display signals generated during simulation.
- Circular Gauge – Display an input value on a customized gauge.
- Display – The Display block shows the signal value as text.
- Working of Subsystem Model
- The model is just a simple program of the control logic with the simple arithmetic equation.
- We have a 5-speed range & 5 gear system.
- According to the given system requirement, we have built the control logic where it checks the speed and changes the gear according to it.
- Following is the stateflowchart for provided gear system.

- Here we give the input speed while the simulation is running, the stateflowchart runs the control logic and changes the gear according to the given speed input.
- We collect the output value from the chart
- The two blocks circular gauge and display blocks represent the input speed the gear value according to it.
- After running the simulation we change the speed values using slider gain, and then check its respective gear.
- We also use the scope block to record the speed input and then the gear output for the entire simulation.
- Results
- Following is the video of simulation for the gear change according to the speed, and the graph of it.

