Skip to content

Examples

All the examples are in StateCharts.Examples. Each one is covered by a scenario of the verification suite.

TrafficLight — traffic light

Diagram of TrafficLight

The initial pseudo-state leads to red (4 s), then green (3 s), yellow (1 s), and back to red. The transitions are time events after(delay).

  • color.y (Actions.SetInteger block connected to the do outputs): 1 = red, 2 = yellow, 3 = green;
  • cycles: number of entries into red, counted on the red.entry pulse. It is 1 from t = 0;
  • green.entry, red.exit, goGreen.effect: 0.1 s pulses at 4 s.

Timing diagram of TrafficLight: color.y (rouge = red, jaune = yellow, vert = green), active states, red.entry and goGreen.effect pulses

Thermostat — on/off control of a room

Thermostat model: the controller block (stm frame) drives the heater of the room

A room (heat capacity, losses to the outside at 5 °C) heated by a 500 W heater. The controller is a state machine used as a block, ThermostatChart (extends StateCharts.Chart): input T, output heating.

  • off → on: completion transition with the guard [T < TLow] (19 °C);
  • on → off: change event when(T > THigh) (21 °C);
  • heating is the do output of on.

Diagram of ThermostatChart

The room starts at 15 °C: the machine enters off and leaves it at once for on, at the same instant. The temperature then oscillates between 19 and 21 °C. To plot: room.T (in °C) and controller.heating; open controller (right-click → Open Class) to see the diagram.

Room temperature between 19 and 21 °C and heating command (labels in French: température = temperature, temps = time)

Toggle — push button

Diagram of Toggle

A push button (button, pressed for 0.2 s every second from 0.5 s) switches a lamp on, then off, at each press. Both transitions have a signal trigger: they fire on the rising edge of their signal input, so holding the button down does not switch the lamp back at once.

  • on.do: the lamp;
  • on.entry, on.exit: pulses when the lamp is switched on and off;
  • switchOn.effect, switchOff.effect: pulses at each firing;
  • presses: number of firings.

Timing diagram of Toggle: button, state on, entry and exit pulses, effects

Sorting — sorting parts

Diagram of Sorting

A part arrives every second (signal event on arrival). The choice pseudo-state choice sends it to heavy or light according to its weight, then the machine goes back to idle after 0.5 s (after(0.5 s)). After four parts, the next arrival leads to the final state done.

The three transitions leaving the choice show the priorities: finish [count >= 4] (1), toHeavy [weight > 5] (2), toLight without guard (3: the "else" branch).

Timing diagram of Sorting (seuil = threshold)

AutomaticDoor — automatic door

Diagram of AutomaticDoor: three transitions leave closing

A state with three outgoing transitions. The door opens on a call (closed → opening), moves to open when it is fully open (when(door.y >= 1)), then to closing after 5 s. The position of the door is the integral of the speed given by the do outputs of opening and closing (motor and door blocks).

From closing, three transitions leave on three different sides:

  1. reopenObstacle (priority 1, bottom side): guard [obstacle.y], an obstacle reopens the door;
  2. reopenCall (priority 2, left side): signal event, a call during the closing reopens the door;
  3. closedReached (priority 3, top side): event when(door.y <= 0), the door is closed.

Scenario: calls at 1 s, 14 s and 30 s, obstacle at 23 s. The first closing (9 s) goes to the end; the second one (22 s) is interrupted by the obstacle, the third one (29 s) by the call; the last one (36 s) ends at 39 s. To plot: door.y and the do outputs of the states.

Position of the door (fermée = closed, ouverte = open), calls (appel), obstacle and active states