Domanda

I'm studying state machines diagrams and was asked to come up with a diagram for a device that turns on and off when a button is pressed... but as with other modern devices nowadays, it can operate either when the battery has charge in it, or when connected to electricity, such as a cellphone device.

My question is... how is that check made in state machine diagrams (if done at all). Should there be states that verify if battery has charge in it or if a charger is connected, or are those just transitions in the diagram?

Don't need full solutions, just need some help in understanding this. Thanks everyone in advance!

È stato utile?

Soluzione

One way, focusing on the light and button. Viewing the power system as a separate concern.

| current State | event        | new State |
|---------------|--------------|-----------|
| Unpowered     | press button | Unpowered |
| Unpowered     | powered      | Off       |
| Off           | press button | On        |
| Off           | unpowered    | Unpowered |
| On            | press button | Off       |
| On            | unpowered    | Unpowered |

You could go further and model the battery state as well... But it itself has no relevance to the state of the light.

You can also fill in the other events combinations, I'm going with undefined => no change in state from event, as this is a controller, not a verifier fsm.

We can flip it so that processes (like on/off) are the events themselves, where as above they were the states.

| current State                       | event    | new State                               |
|-------------------------------------|----------|-----------------------------------------|
| Not Pressed,Plugged In,Battery Flat | On       | Pressed,Plugged In,Battery Flat         |
| Not Pressed,Plugged In,Battery Flat | Charging | Not Pressed,Plugged In,Battery not Flat |
| Pressed,Plugged In,Battery Flat     | Off      | Not Pressed,Unplugged,Battery Flat      |
| Pressed,Plugged In,Battery Flat     | Off      | Not Pressed,Plugged In,Battery Flat     |
...

Notice that this one isn't deterministic, the event "Off" implies two possible states, from the same starting state.

Altri suggerimenti

In a finite state machine with no push down stack, all state is encoded in... the states.

You have several different dimensions I can identify:

  1. Battery state: depleted/charging/charged
  2. Plgged-in state: unplugged/plugged
  3. Device state: on/off

You can imagine a 3D chart that has one cell for every possible comination of battery state, plugged-in state and device state. That gives 12 potential states, although perhaps not all of them make sense (deleted+unplugged won't make sense, for example).

You can then draw the arcs between all of these states. E.g. a button press takes you from charged/unplugged/off to charged/unplugged/on. Prolong usage might transition that to depleted/unplugged/off, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
scroll top