Skip to content

Getting started

This page builds a state machine diagram in OMEdit step by step: a lamp that is on for 2 s, off for 1 s, and so on.

1. Simulate an example

Open StateCharts.Examples.Sorting and simulate it. The diagram is a SysML state machine: a black dot (initial pseudo-state), states with compartments (idle, heavy, light), a choice diamond, a bull's eye (final state), and arrows labelled trigger [guard] / effect.

In the Plotting tab, tick idle.do, heavy.do, light.do and done.completed. The Diagram window (menu View → Windows) shows the diagram at the instant chosen with the time slider: the active state is colored green there, and the arrow of a transition turns green during its effect.

Timing diagram of Sorting: weight of the part, arrivals, states idle, heavy, light and final state (labels in French)

2. Create your own model

  1. File → New → New Modelica Class, type model, name Lamp.
  2. From the library browser, drag into the diagram:
    • a StateCharts.Initial (the black dot);
    • two StateCharts.State, renamed off and on;
    • three StateCharts.Transition, renamed init, switchOn and switchOff.

3. Connect states and transitions

A transition is a small block placed on the arrow: its left end (source) connects to the state it leaves, its right end (target) to the state it enters; the arrowhead shows the direction.

A state has ports on its four sides (top, right, bottom, left): an arrow may leave or enter on any side, and several arrows may leave the same state. OMEdit enlarges the port array of the side used at each connection.

  • Connect the black dot to init.source, then init.target to the left side of off.
  • Connect the right side of off to switchOn.source, then switchOn.target to the left side of on.
  • To come back, flip switchOff (right-click → Flip Horizontal), connect the bottom of on to switchOff.source and switchOff.target to the bottom of off.

4. Set the transitions

Double-click a transition:

  • Trigger: After, with delay = 1 for switchOn and delay = 2 for switchOff. init keeps Completion (no trigger).
  • Guard: nothing to tick here.

The label follows: after(1 s) / switchOn.

5. Use the Boolean outputs

Each state has three outputs on its right side:

  • entry: 0.1 s pulse at each entry into the state;
  • do: true while the state is active;
  • exit: 0.1 s pulse at each exit.

Each transition has an effect output (bottom right): 0.1 s pulse each time it fires. The duration of the pulses is set by pulseDuration.

Connect for instance on.do to a Modelica.Blocks.Math.BooleanToReal: its output is 1 while the lamp is on. Simulate 10 s and plot on.do, on.entry and switchOn.effect.

6. A guard on the physical model

In the Guard group, tick useGuard and write the guard, for instance sensor.T < 292.15: the transition fires only if the temperature is below 19 °C. See the Thermostat example in Examples, then The blocks for all the settings.