modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
98 stars 42 forks source link

Initial state in state machines #2826

Open HansOlsson opened 3 years ago

HansOlsson commented 3 years ago

Currently it does not seem possible to select to start the state machine in different states in a good way; as the initalState will be active at least one step - and in some cases it will take multiple steps to get to the correct state.

In particular this seems useful for:

The best possibility I can see with current semantics would be if-parameter-then initialState; but it would still not cover the first use case and in contrast to the normal initialState there's no natural graphical representation.

One backwards compatible possibility would be as follows:

initialState gets a second argument (which must be either a parameter expression or on the same clock as the state-machine) with a default of true. This second argument can be displayed in the graphical user interface. The second argument is only evaluated when the state-machine starts (at the first tick of the clock or if the state-machine is reset). If true the corresponding state is initially active, and if false nothing happens. There must be exactly one initialState with second argument true for each state-machine when it starts.

HansOlsson commented 2 years ago

Note: This is present in several other state-machine formalisms by having multiple outgoing edges from the same initial node, or initial pseudo-state. (There are also other possibilities.)

HansOlsson commented 2 years ago

The proposal here is:

initialState gets a second argument (which must be either a parameter expression or on the same clock as the state-machine) with a default of true. This second argument can be displayed in the graphical user interface. The second argument is only evaluated when the state-machine starts (at the first tick of the clock or if the state-machine is reset). If true the corresponding state is initially active, and if false nothing happens. There must be exactly one initialState with second argument true for each state-machine when it starts.

This allows a state-machine to start in different states, which allows e.g., a hysteresis-state-machine to avoid an initial transient. It is backwards compatible. Question: Can we add we propose to add this without an MCP, provided there is a test-implementation?

HansOlsson commented 1 year ago

I still think we need this, but seems we have to postpone it for the next release.