Eloise
Eloise

Reputation: 37

Build state machine with 2 variables

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

Upvotes: 1

Views: 295

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 12527

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.

Upvotes: 2

Related Questions