Challenge

Week - 4

Aim:

Stateflow for the washing machine and gear shifting.

Objective :

  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 the next 20s & dryer runs for 50s

After all the processes have completed turn on the nished LED

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

Introduction:

Control logic is the part of a controller that denes how a reactive system responds to events or conditional changes. Applications for control logic include:

Supervising how to switch between different modes of operation

Scheduling a sequence of tasks or steps for a system

Defining fault detection, isolation, and recovery logic.

Common tasks for modeling control logic include:

Modeling hierarchical state machines for large-scale systems

Adding flow charts to dene complex control logic

Defining orthogonal states to represent systems with parallelism

Stateflow provides a graphical language that includes state transition diagrams, ow charts, state transition tables, and truth tables. You can use Stateow to describe how MATLAB algorithms and Simulink models react to input signals, events, and time-based conditions.

Stateow enables you to design and develop supervisory control, task scheduling, fault management, communication protocols, user interfaces, and hybrid systems.

With Stateow, 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.

Procedure :

Washing machine :

Explanation :

  1. To start with we have created a chart using ‘CHART BLOCK’ to dene the logic of the washing machine.
  1. Inside this chart, state blocks are called to dene the states. The rst state is the ‘Power’ state, this is where the program checks whether the power is ON/OFF. If the power is ON the process will go to the next state or else it will not go further. Here we have dened a variable ‘Power’ as it will help us to indicate whether this particular state is going On or not.
  2. Next, we have the ‘Water’ state where water will be lled, and similar to that of the power state we have dened variable ‘W’ which will help us to see whether is being lled or not. The process between ‘Power State’ and ‘Water State’ is dened as if power is equal to one which means if power is on then only its water state will start, and power equal to zero refers as power is OFF then it will remain in power state only.
  3. Now the next state is ‘Soak State’, this is where the clothes are soaked once the water is lled. Here we have dened inside this state that when it enters the state the value of variable ‘S’ will 1 which means that this state is going on.
  4. Now next is the ‘Washing State’, this is where the clothes are washed, here as per the conditions mentioned above after 200s of soaking the washing state takes place. This condition is mentioned from between ‘Soak State’ and ‘Wash State’. Inside the washing state, we have mentioned So=0 and W=1 which means that after the soaking is done the lamp for the soaking will switch off and the washing process will start.
  5. Then, ‘Rinse State’ takes place where all the water is drained out, here when the state is in this state it will indicate ‘R=1’ once this state is over it will indicate ‘R=0’ and it will move next state. The process between ‘Wash State’ and ‘Rinse State’ is dened as per the condition mentioned above.
  6. The next stage is the ‘Dry State’ where the clothes are dried inside the machine. Similar conditions are dened in this state as in previous states, and the process is dened as it is mentioned above.
  7. The last state is the ‘Finish state’, this where the process ends and the power needs to be switched off manually. Here also similar conditions are mentioned.
  8. Now once the machine logic is created we have dened the variables entered as output variables and power and water as inputs as these have to be provided to the machine in real-time.
  9. To give power and water as input we have used a ‘Slider Switch Block’ and ‘Constant Block’ is used. Each slider switch is connected to each constant block. When the slider switch is ON the value in the constant block will be ‘1’ and this constant block is connected to the chart block where the washing machine program is dened.
  10. If the slider switch is OFF the value in the constant block is ‘0’ which indicated there will no water or power supply. By this way, we have dened the inputs. And for the outputs, we have connected each one with each ‘Display Block’. This display block will show value 1 if the process is currently progressing and 0 if it not happening. 12. These display blocks are then connected to ‘Lamp Block’ which will turn green when a particular state is going and it will be red if that particular state is not going on. 13. To set conditions for the lamp block, double click on it set the conditions as shown. 14. Lastly, the number of outputs can be numbered from the simulation>Symbol pane.

OUTPUTS

Gear shifting :

Explanation :

  1. For the gear shifting, we have used ‘CHART BLOCK’ to dene the gear shift logic for the conditions given above.
  2. First, we have dened 5 states namely ‘Gear 1’, ‘Gear 2’, ‘Gear 3’, ‘Gear 4’, ‘Gear 5’.
  3. Now to shift from one state to another we have dened the conditions of the speeds as mentioned above.
  4. We have also dened values inside the states which represent that when that particular state is going on it will display the value that is dened in it. This will help to see that which is gear is the vehicle when at a particular speed.
  5. We have dened speed as input for the chart as the gears change only on basis of speed and variable ‘G1 till 5’ is the dened output of the chart as it tells us, which gear is the vehicle in. That means if the input is matched for each gear it is 1 and if not it 0.

6. Now to give speed as input we have used a ‘Signal Builder Block’, where we have dened the different speeds.

7.Now according to these speeds, the gears in the chart block will change. To indicate this change in gears we have used ‘Lamp Block’. We have set the
values of lamp blocks such that when a gear is executed that particular gear lamp will turn Green.

8.Now when we run the model, we get the above results, thus represents the shifts in gears at different speed

OUTPUTS

Conclusion :


Learned about the control logic and how to create the models for some systems like here washing machine and gear shifting using the charts and stateflow blocks.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.