Skip to content

Commit

Permalink
Clean up tables for state machines
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Sep 20, 2020
1 parent b2b4245 commit 60dc74d
Showing 1 changed file with 84 additions and 69 deletions.
153 changes: 84 additions & 69 deletions chapters/statemachines.tex
Original file line number Diff line number Diff line change
Expand Up @@ -52,75 +52,90 @@ \section{Transitions}\label{transitions}
state machine. All parts of a state machine must have the same clock.
All transitions leaving one state must have different priorities. One
and only one instance in each state machine must be marked as initial by
appearing in an \lstinline!initialState! statement. The following special
kinds of connect-statements are used to define transitions between
states and to define the initial state:
\begin{longtable}[]{|p{4cm}|p{10cm}|}
\hline \endhead
\multicolumn{2}{|p{12cm}|}{\tablehead{Statements to define a state machine}}\\ \hline
\begin{tabular}{@{}p{4cm}@{}}
\lstinline!transition!(from, to,\\
condition,\\
immediate, reset,\\
synchronize, priority)
appearing in an \lstinline!initialState! statement.

The special kinds of connect-statements listed below are used to define define a state machine.
\begin{center}
\begin{tabular}{l|l l}
\hline
\tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\
\hline
\hline
\lstinline!transition($\mathit{from}$, $\mathit{to}$, $\mathit{condition}$, $\ldots$)! & State machine transition between states & \Cref{modelica:transition}\\
\lstinline!initialState($\mathit{state}$)! & State machine initial state & \Cref{modelica:initialState}\\
\hline
\end{tabular}
&
Arguments \lstinline!from! and \lstinline!to! are block instances and \lstinline!condition! is a
\lstinline!Boolean! argument. The optional arguments \lstinline!immediate!, \lstinline!reset!, and
\lstinline!synchronize! are of type \lstinline!Boolean!, have parametric variability and a
default of \lstinline!true!, \lstinline!true!, \lstinline!false! respectively. The optional
argument \lstinline!priority! is of type \lstinline!Integer!, has parametric variability and
a default of 1.

This operator defines a transition from instance \lstinline!from! to instance
\lstinline!to!. The \lstinline!from! and \lstinline!to! instances become states of a state
machine. The transition fires when \lstinline!condition = true! if
\lstinline!immediate = true! (this is called an \firstuse{immediate transition})
or \lstinline!previous(condition)! when \lstinline!immediate = false! (this is
called a \firstuse{delayed transition}). Argument \lstinline!priority! defines the
priority of firing when several transitions could fire. In this case the
transition with the smallest value of \lstinline!priority! fires. It is required
that $\textrm{priority}\ge 1$ and that for all transitions from the same state, the
priorities are different. If \lstinline!reset = true!, the states of the
target state are reinitialized, i.e.\ state machines are restarted in
initial state and state variables are reset to their start values. If
synchronize=true, any transition is disabled until all state machines of
the from-state have reached final states, i.e.\ states without outgoing
transitions. For the precise details about firing a transition, see
\cref{state-machine-semantics}.\\ \hline
\lstinline!initialState(state)! & Argument \lstinline!state! is the block instance
that is defined to be the initial state of a state machine. At the first
clock tick of the state machine, this state becomes active.\\ \hline
\end{longtable}

The transition-, and initialState-equations may only be used in
equations and may not be used inside if-equations with non-parametric
condition, or in when-equations.

It is possible to query the status of the state machine by using the
following operators:
\begin{longtable}[]{|p{4cm}|p{10cm}|}
\hline \endhead
\lstinline!activeState(state)!&
Argument \lstinline!state! is a block instance. The operator returns
\lstinline!true!, if this instance is a state of a state machine and this
state is active at the actual clock tick. If it is not active, the
operator returns \lstinline!false!.

It is an error if the instance is not a state of a state machine.\\ \hline
\lstinline!ticksInState()! & Returns the number of ticks of the clock of the state machine
for which the currently active state has maintained its active state without interruption,
i.e.\ without local or hierarchical transitions from this state.
In the case of a self-transition to the currently active state or to an active enclosing state,
the number is reset to one.
This function can only be used in state machines.\\ \hline
\lstinline!timeInState()! & Returns the time duration as \lstinline!Real! in {[}s{]}
for which the currently active state has maintained its active state without interruption,
i.e.\ without local or hierarchical transitions from this state.
In the case of a self-transition to the currently active state or to an active enclosing state,
the time is reset to zero.
This function can only be used in state machines.\\ \hline
\end{longtable}
\end{center}

The \lstinline!transition! and \lstinline!initialState! equations may only be used in equations and may not be used inside if-equations with non-parametric condition, or in when-equations.

The operators listed below are used to query the status of the state machine.
\begin{center}
\begin{tabular}{l|l l}
\hline
\tablehead{Expression} & \tablehead{Description} & \tablehead{Details}\\
\hline
\hline
\lstinline!activeState($\mathit{state}$)! & Predicate for active state & \Cref{modelica:activeState}\\
\lstinline!ticksInState()! & Ticks since activation & \Cref{modelica:ticksInState}\\
\lstinline!timeInState()! & Time since activation & \Cref{modelica:timeInState}\\
\hline
\end{tabular}
\end{center}

\begin{operatordefinition}[transition]
\begin{synopsis}\begin{lstlisting}
transition($\mathit{from}$, $\mathit{to}$, $\mathit{condition}$,
immediate=$\mathit{imm}$, reset=$\mathit{reset}$, synchronize=$\mathit{synch}$, priority=$\mathit{prio}$)
\end{lstlisting}\end{synopsis}
\begin{semantics}
Arguments $\mathit{from}$ and $\mathit{to}$ are block instances, and $\mathit{condition}$ is a \lstinline!Boolean! argument. The optional arguments \lstinline!immediate!, \lstinline!reset!, and \lstinline!synchronize! are of type \lstinline!Boolean!, have parametric variability and a default of \lstinline!true!, \lstinline!true!, \lstinline!false! respectively. The optional argument \lstinline!priority! is of type \lstinline!Integer!, has parametric variability and a default of 1.

This operator defines a transition from instance $\mathit{from}$ to instance $\mathit{to}$. The $\mathit{from}$ and $\mathit{to}$ instances become states of a state machine. The transition fires when $\mathit{condition} = \text{\lstinline!true!}$ if $\mathit{imm} = \text{\lstinline!true!}$ (this is called an \firstuse{immediate transition}) or \lstinline!previous($\mathit{condition}$)! when $\mathit{imm} = \text{\lstinline!false!}$ (this is called a \firstuse{delayed transition}). Argument \lstinline!priority! defines the priority of firing when several transitions could fire. In this case the transition with the smallest value of \lstinline!priority! fires. It is required that $\mathit{prio} \geq 1$ and that for all transitions from the same state, the priorities are different. If $\mathit{reset} = \text{\lstinline!true!}$, the states of the target state are reinitialized, i.e.\ state machines are restarted in initial state and state variables are reset to their start values. If $\mathit{synch} = \text{\lstinline!true!}$, any transition is disabled until all state machines of the from-state have reached final states, i.e.\ states without outgoing transitions. For the precise details about firing a transition, see \cref{state-machine-semantics}.
\end{semantics}
\end{operatordefinition}

\begin{operatordefinition}[initialState]
\begin{synopsis}\begin{lstlisting}
initialState($\mathit{state}$)
\end{lstlisting}\end{synopsis}
\begin{semantics}
Argument $\mathit{state}$ is the block instance that is defined to be the initial state of a state machine. At the first clock tick of the state machine, this state becomes active.
\end{semantics}
\end{operatordefinition}

\begin{operatordefinition}[activeState]
\begin{synopsis}\begin{lstlisting}
activeState($\mathit{state}$)
\end{lstlisting}\end{synopsis}
\begin{semantics}
Argument $\mathit{state}$ is a block instance. The operator returns \lstinline!true! if this instance is a state of a state machine and this state is active at the actual clock tick. If it is not active, the operator returns \lstinline!false!.

It is an error if the instance is not a state of a state machine.
\end{semantics}
\end{operatordefinition}

\begin{operatordefinition}[ticksInState]
\begin{synopsis}\begin{lstlisting}
ticksInState()
\end{lstlisting}\end{synopsis}
\begin{semantics}
Returns the number of ticks of the clock of the state machine for which the currently active state has maintained its active state without interruption, i.e.\ without local or hierarchical transitions from this state. In the case of a self-transition to the currently active state or to an active enclosing state, the number is reset to one.

This function can only be used in state machines.
\end{semantics}
\end{operatordefinition}

\begin{operatordefinition}[timeInState]
\begin{synopsis}\begin{lstlisting}
timeInState()
\end{lstlisting}\end{synopsis}
\begin{semantics}
Returns the time duration as \lstinline!Real! in {[}s{]} for which the currently active state has maintained its active state without interruption, i.e.\ without local or hierarchical transitions from this state. In the case of a self-transition to the currently active state or to an active enclosing state, the time is reset to zero.

This function can only be used in state machines.
\end{semantics}
\end{operatordefinition}

\begin{example}
If there is a transition with \lstinline!immediate=false! from
Expand All @@ -134,7 +149,7 @@ \section{Transitions}\label{transitions}
State A2;
equation
initialState(A0);
transition(A0, A1, sample(time,Clock(1,1000)) > 0.0095);
transition(A0, A1, sample(time, Clock(1, 1000)) > 0.0095);
transition(A1, A2, ticksInState() >= 5, immediate=false);
\end{lstlisting}
\end{example}
Expand Down

0 comments on commit 60dc74d

Please sign in to comment.