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

2
  • 1
    Can you post the code? Difficult to help with only the screenshot... Commented Jun 25, 2020 at 8:59
  • Yes I just edited my post thank you :) Commented Jun 25, 2020 at 9:19

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.