Challenge

Week - 4

WEEK-4

Part-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 200 seconds followed by Washing time of 100 seconds
  • Then Rinsing happens for next 20 seconds & Dryer runs for 50 seconds

After all the processes have completed turn on the finished LED.

Solution-1

A Stateflow is a graphical environment that helps in modelling flow charts, state transition diagrams, state transition tables and truth tables. It enables you to develop and design supervisory control, task scheduling, fault management, communication protocols, user interfaces and hybrid systems. It is a graphical representation of a finite state machine.

We are required to implement a control logic for a washing machine as per some given data and the steps involved in doing so are:

  1. Soaking
  2. Washing
  3. Risnsing
  4. Drying

The necessary blocks required to build this model include rocker switch, stateflow chart, displays and lamps, the displays are used to show the output in 1 or 0 depending on whether the event is on or off and the lamps are connected to all the outputs to show which event is on going at ever step of the process.

The rocker switches are used to activate the power and water supply inputs as we they are linked to the two constant blocks and will generate a constant value of 1 when on and 0 when off.

The state flow chart which is graphical representation of an event driven model and the states in this transition from on to the other only if the condition provided is true.

The logic written in this state flow chart represents the given task which is if the power gets switched on the power gets activated and if the water is not on the process does not start. This is then followed by Soaking time of 200 seconds followed by Washing time of 100 seconds plus Rinsing happens for next 20 seconds & Dryer runs for 50 seconds. After the dryer event the washing machine is given the signal to Finish. The two constant values of are given as input to the stateflow chart as the power and water supply also the output include Power, Water, soaking, washing, rinsing, dryer and finish.

These output ports are then connected to separate displays and show the output in terms of 1 as on or 0 as off. The displays in turn are linked to individual Lamps which switch to green when on and red when off depending on the condition of the connected display block.

In figure2 we can see the complete model of the washing machine where both the rocker switches are on, but the simulation has not been run as yet that’s why we are seeing all red lights in the Lamps.

By connecting all the output ports to a scope, we get the following graphs:

We can see that the power starts at 10 seconds and the water starts at 20 seconds followed by the first soaking process starting at 30 seconds. Hence the run time for the various processes will be as follows:

Soaking: 30-230 seconds

Washing: 230-330 seconds

Rinsing: 330-350 seconds

Drying: 350-400 seconds

The process of the washing machine finishes after a total time of 400 seconds.

Results:

For Case1-

The power switch in turned on and the simulation is run for 500 seconds but only the power on lamp turns green which means it is receiving the power signal and none of the other lamps are initiated. The water supply is off, and the process has not begun.

Figure 4 shows the model of washing machine when both Power and Water switch are off and the simulation in run. Not a single Lamp is turned on and hence the process does not start.

Case-2

In figure 5, when we set the stop time of the simulation as 200 seconds, we can see that the soaking process has started while the power and water lamps are also on and the displays of the power, water and soaking are showing 1.

And when we set the simulation time as 250 seconds, we can see in the figure below the soaking process has ended and the washing process has started. The soaking lamp turns red and the washing lamps turn green.

Case-3

In this figure below we see the rinsing process in action. We are getting an output of 1 for power water and rinsing display only.

The figure 8 displays the dryer in process and the lamp indicating the same.

Case-4

After the washing goes through washing, soaking, rinsing and drying a lamp has been used in Simulink that turns green which signals you that the process has been completed.

In the below figure we can see only the power and finish are getting a signal in their display also only these two lamps are on indicating the completion of the washing process.

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

Solution-2

In order to model a Simulink model for the gear shifts we require a logic to be written as per the given conditions. We have used a Chart block in Simulink to implement the control logic with the help of Stateflow. A logic has to be made in such a way that each gear should have some speed at which it will transition from one state to another and back i.e., from gear 1 to 5 and back. From the figure below we can see the setup of the mode to execute these gear shifts according to varying speeds. All the speeds displayed will be in kilometres per hour as per the given conditions.

The other blocks used to model this situation are:

Slider block

A slider block has been used as an input of speed. With the help of this slider block we will be able to adjust the speed input as we like. It does not use ports to be linked but uses a connect mode to join to dashboard blocks in the model. It has been connected to the constant block in this model so the value we receive on the constant block will change according to the needle on the slider is changed to.

Constant block

This block is used as an input of speed in the model and is connected to the Slider, digital display and circular gauge blocks. The constant block values will change according to the input given in the slider block.

Chart block

It is an event driven system; it transitions from one state to another as long as the condition describing the shift is true. We have used this to write a control logic to execute gear shifts according to the given speeds. The transitions in this case will be from gear 1 to 5 or 5 to 1. From the Symbols Pane in the Prepare option we have defined Speed as the input and Gear1,2,3,4 and 5 as outputs. The logic used in this chart using transitions between states are according to the given information as follows:

GEAR NO.

Shift UP

Shift DOWN

1

If the speed is equal to or greater than 16kmph.

If the speed falls below 16kmph.

2

If the speed is equal to or greater than 26kmph.

If the speed falls below 26kmph.

3

If the speed is equal to or greater than 41kmph.

If the speed falls below 40kmph.

4

If the speed is equal to or greater than 61kmph.

If the speed falls below 60kmph.

Display block

The outputs from the Chart block are connected to 5 different displays which will show us a value of 1 whenever a gear is active according to the speed input. No two gears can be active at the same time hence only one block will show us value of 1 at a time.

Lamp

The lamp block has been used to display a colour according to the input linked to it using connect mode. The input of each of the lamps are the displays which have been connected to the outputs from the chart block. We have used five different lamps with corresponding names to show which gear is active at that particular moment. The lamp has been set to display a red light when inactive and green when active.

Another green display is placed above the slider to give out a digital number to what speed is currently chosen in the slider.

Results:

The model in figure 10 is run for infinite time so that the speed input can be varied, and the output is displayed accordingly. The gear which is active will glow green and the gears that are inactive will remain red.

Gear 1:

We can confirm that the first gear lasts from 0-15.99 kmph, the gear will only change once the speed in increased to 16 or above that.

Gear 2:

From figure 14 and 15 we can conclude that the second gear is active through speeds from 16 to 25.99 kmph, the gear will only change when the speed is increased to 26 or above. We can also see the lamp for Gear 2 light up to green since it is active.

Gear 3:

We can see the lamp of Gear 3 turn green as soon as we reach the speed of 26 or above and this gear stays active till the speed of 40.99 kmph.

Gear 4:

The fourth gear last from the speeds of 41 through till 60.99 kmph. The circular gauge displays the output in analogue according to the value at the constant block.

Gear 5:

In figure 20 & 21, the speed of 61 is given as the transition state for the fifth gear so any speed above that will also hold the same gear since this is the last gear. The slider block has been limited to a maximum value of 80 hence the gear active till the speed of 80kmph will be 5.

Conclusion

The working of a washing machine was built in a Simulink model using Stateflow in the Chart block and also with the help of other blocks. The transition states were given, and the logic had to be created according to that. We can see the different lamps get activated as the process of the washing machine progresses.

A Simulink model was successfully created where a control logic using Chart was implemented for gear shift according to the given conditions. The Gears will shift up or down according to the given transition states. The lamps remain red when inactive and turn to green when active.

A video has been posted on YouTube. It has been uploaded to show the working of the gear shifts. The video can be viewed at- https://youtu.be/0QAQ0aQN3TY

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.