1

I am new with Modelica but I would like to build an easy state machine with 2 variables : The initial step is "off" (the variable Light_cabin==0) then if button_Evac == 1 (second variable) then go to step "on" and Light_Cabin == 1 if Button_Evac==0 return to initial step. This is my state machine : state_machine

But when I launched the simulation Light_Cabin = 0 even if button_Evac = 1 and the active step is the initial step.

This is my code :

model StateMachine

block Off
  outer output Integer Light_Cabin;
equation 
Light_Cabin = 0;
end Off;

block On
  outer output Integer Light_Cabin;
equation 
  Light_Cabin = 1;
end On;

  parameter Integer Button_Evac(start=0);
  inner Integer Light_Cabin(start=0);

  Off off;
  On on;

equation 
  transition(
    off,
    on,
    Button_Evac == 1,
    immediate=true,
    reset=false,
    synchronize=false,
    priority=1); 
  transition(
    on,
    off,
    Button_Evac == 0,
    immediate=true,
    reset=false,
    synchronize=false,
    priority=1);

  initialState(off);
end StateMachine;

If you have any idea where my error is please let me know. Thank you for your help, Eloise

Markus A.
  • 4,470
  • 4
  • 21
Eloise
  • 37
  • 4

1 Answers1

2

This is due to the design of state machines in Modelica, as can be seen in https://specification.modelica.org/v3.4/Ch17.html#semantics-summary

  • Even though the transition is immediate the state is active one clock tick. If that wasn't the case there would be a risk of infinite loops if all transitions are immediate - which would require additional semantic checks.
  • It technically not starting in "off", but a separate "initial state" and in the first clock tick the state machine transitions to "off" and thus cannot transition further in that clock tick.
Hans Olsson
  • 8,971
  • 12
  • 33
  • 2
    The default clock is 1s, so simulating for longer than 1s will show the change of `Light_Cabin` in case `Button_Evac==1`. This is done after 1s as a result of what is explained in the answer. – Markus A. Jun 25 '20 at 10:05
  • Thank you for your answers, I changed the period of the clock but it hasn't changed the value of Light_Cabin. If I create another state "Initial state" what's the transition to go to "Initial state" to "Off" ? Is the transition "at the first clock tick" ? If so I don't really know how to write it because I am very new to the Modelica language. – Eloise Jun 25 '20 at 14:33