Book a Demo

Author Topic: How to manage timed transitions in simulated state machines  (Read 6786 times)

YannM

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
How to manage timed transitions in simulated state machines
« on: November 21, 2019, 12:04:10 am »
Hi,

It has been a while I'm working with Enterprise Architect 13.5 and simulating state machines. Until now I manage transitions with simple triggers which are available in the simulation events window.

I am looking for a way to make a time based transition between two states but I do not figure how to do it.

In the "Transition Properties" pop up I see the configuration of Triggers: Name, Type, Specification.
How is the right use of those to have the simulation wait, for exemple, 30s before making a transition from State1 to State2 ?

Thanks

bknoth2

  • EA User
  • **
  • Posts: 129
  • Karma: +2/-0
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #1 on: November 21, 2019, 05:57:58 am »
One approach would be to start a timer when it enters the state and then have a transition that triggers when that timer exceeds 30 seconds.

YannM

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #2 on: November 22, 2019, 12:19:12 am »
Thanks for the advice but how do you actually do it ?

I did not find a way to start/stop/control a timer that can be managed by EA in the simulation of an executale stm ?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #3 on: November 22, 2019, 01:26:17 am »
As mentioned on SO: see if you can get feedback from the Sparxians here. If nobody chips in, send a mail to their support.

q.

bknoth2

  • EA User
  • **
  • Posts: 129
  • Karma: +2/-0
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #4 on: November 22, 2019, 03:34:58 am »
"Thanks for the advice but how do you actually do it ?"

The simulation supports Javascript. Presuming Javascript provides timers of some sort, you'd implement a timer-based trigger or guard. (See https://www.sparxsystems.com/enterprise_architect_user_guide/15.0/model_simulation/set_up_simulation.html)

I've implemented an extensive state machine using EA and C++ but have not done much with Javascript. Based on my experience, I expect you'll have to experiment - there won't be a simple, out-of-the-box way to do it.

First, I'd create a simple two-state state machine and create a transition from one to the other based on, perhaps, a counter (or other simple condition). Once that works, then try incorporating a timer.

YannM

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #5 on: December 05, 2019, 04:20:35 am »
Hi all,

The answer was in the Music Player Example.
Using a variable keeping the counter and an internal transition to decrease the counter makes the job.
Thus time based transition works.

However a new problem showed up: it looks like while the state executes internal transition it is not possible to manage any other event in this state.
In my example, the event evt_timeout is broadcasted and queued but never dispatched while the counter is decremented.
Thus I am obliged to wait until my counter reaches 0 for the exit transition from State 1 to be fired.
Quote
[25957608]      Command: broadcast evt_timeout
[25957614]      [Part1:Process_stm] Event Queued: evt_timeout

A screenshot can be found here
https://ibb.co/Ch3dyPc

Any idea how to make evt_timeout being dispatched ?
« Last Edit: December 05, 2019, 04:56:07 am by YannM »

YannM

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #6 on: December 11, 2019, 02:54:51 am »
Hi,

My last question might not be clear thus I set up this example to clarify my question:

https://ibb.co/cNBnF1S

While "count" is decreased in "State1", the state machine does not take into account events evt1. The event is broadcasted and queued only.
Quote
[540055289]      [Part1:Test] Transition Effect: State1__TO__State1_4
[540055291]      [Part1:Test] Entry Behavior: StateMachine_State3_State1
[540055292]      [Part1:Test] Do Behavior: StateMachine_State3_State1
[540055295]      Command: broadcast evt1
[540055296]      [Part1:Test] Event Queued: evt1
[540055957]      [Part1:Test] Completion: Test_StateMachine_State3_State1
[540055961]      [Part1:Test] Exit Behavior: StateMachine_State3_State1

... only when count reaches 0 and the state machine reaches "State2" this event is used. The event is at last dispatched !!
Quote
[540056626]      [Part1:Test] Transition Effect: State1__TO__State2_5
[540056628]      [Part1:Test] Entry Behavior: StateMachine_State3_State2
[540056629]      [Part1:Test] Do Behavior: StateMachine_State3_State2
[540057270]      [Part1:Test] Completion: Test_StateMachine_State3_State2
[540057275]      [Part1:Test] Event Dispatched: evt1
[540057277]      [Part1:Test] Exit Behavior: StateMachine_State3_State4
[540057278]      [Part1:Test] Transition Effect: State4__TO__State5_8
[540057280]      [Part1:Test] Entry Behavior: StateMachine_State3_State5
[540057281]      [Part1:Test] Do Behavior: StateMachine_State3_State5
[540057282]      [Part1:Test] Exit Behavior: StateMachine_State3_State2
[540057284]      [Part1:Test] Transition Effect: State2__TO__Final_7_3
[540057924]      [Part1:Test] Completion: Test_StateMachine_State3_State5
[540057951]      Waiting for Trigger

Is that a problem of Enterprise Architect 13.5 or is it a problem of design of the state machine ?
« Last Edit: December 11, 2019, 03:10:37 am by YannM »

bknoth2

  • EA User
  • **
  • Posts: 129
  • Karma: +2/-0
    • View Profile
Re: How to manage timed transitions in simulated state machines
« Reply #7 on: December 11, 2019, 03:49:42 am »
Check that your states are mutually exclusive. If they aren't then the state machine will be unpredictable. For example, in the diagram you show, both evt2 and count>0 can be true, so the state machine will unpredictably follow one transition or the other. A better way to define those two transitions could be (evt2 AND count>0) and (count>0 AND NOT evt2) respectively. Likewise, the third transition should be something like (NOT evt2 and count<=0). (My details may be wrong, but I think the concept is right).

- Bruce