Week - 4
- 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
To implement the control logic of a washing machine using Stateflow based on the given sequence, we can define the states and transitions to model the behavior of the washing machine. Below is a conceptual representation of how you might set this up:
1. **Define States and Conditions:**
- `Inactive`: Initial state when power supply is not available.
- `Waiting for Water`: Transition state waiting for water supply.
`Soaking`: Soaking the clothes for 200 seconds.
- `Washing`: Washing the clothes for 100 seconds.
`Rinsing`: Rinsing the clothes for 20 seconds.
- `Drying`: Drying the clothes for 50 seconds.
`Finished`: All processes are complete.
2. **Define Inputs and Outputs:**
- `PowerAvailable`: Input signal indicating power supply availability.
- `WaterAvailable`: Input signal indicating water supply availability.
- `LEDWater`: Output signal to indicate water supply status (e.g., turn on/off an LED).
`LEDFinished`: Output signal to indicate when the washing process is finished.
3. **Stateflow Implementation:**
```matlab
chart washingMachine
properties
time_soaking = 200; % Soaking time in seconds
time_washing = 100; % Washing time in seconds
time_rinsing = 20; % Rinsing time in seconds
time_drying = 50; % Drying time in seconds
end
% Define states
states
state(Inactive)
state(WaitingForWater)
state(Soaking)
state(Washing)
state(Rinsing)
state(Drying)
state(Finished)
end
% Define events (inputs)
events
event PowerAvailable
event WaterAvailable
end
% Define outputs
outputs
output LEDWater
output LEDFinished
end
Define state actions and transitions
methods
State entry actions
function entryActions()
if isStateActive(WaitingForWater)
LEDWater = 1; % Turn on water supply indicator
end
if isStateActive(Finished)
LEDFinished = 1; % Turn on finished indicator
end
end
% State during actions (for timing)
function duringActions()
if isStateActive(Soaking)
delay(time_soaking);
elseif isStateActive(Washing)
delay(time_washing);
elseif isStateActive(Rinsing)
delay(time_rinsing);
elseif isStateActive(Drying)
delay(time_drying);
end
end
% State transitions
function transitions
% Transition from Inactive to Waiting for Water on PowerAvailable
Inactive.PowerAvailable -> WaitingForWater;
% Transition from Waiting for Water to Soaking on WaterAvailable
WaitingForWater.WaterAvailable -> Soaking;
% Sequential transitions for washing process
Soaking.after(time_soaking) -> Washing;
Washing.after(time_washing) -> Rinsing;
Rinsing.after(time_rinsing) -> Drying;
Drying.after(time_drying) -> Finished;
end
end
In this state flow chart,
The washing machine starts in the `inactive` state.
When `PowerAvailable` is triggered, it transitions to `Waiting for Water`.
If `WaterAvailable` is received while in `WaitingForWater`, it proceeds to `Soaking` and starts the washing process.
Each state's `duringActions()` method uses `delay()` to simulate the required time for each process.
Once all processes (`Soaking`, `Washing`, `Rinsing`, `Drying`) are completed, it transitions to `Finished` and activates the `LEDFinished`.