Menu

Superstate and substate sharing event

2019-02-10
2019-02-10
  • Javier Hidalgo

    Javier Hidalgo - 2019-02-10

    I am learning HSMs and I can see a problem that I don’t know how to address. The problem is shown in the image bellow.

    Inside S1, substates S11 and S12 are continuously changing in reaction to TIMERTICK event. At the same time the superstate S1 needs also to keep track of TIMERTICK event in order to change to S2 after an amount of time.

    As far as I understand TIMERTICK event will be always processed in one of the substates first so it can’t be used by superstate S1. What is the way to deal with this situation?

     
  • Quantum Leaps

    Quantum Leaps - 2019-02-10

    Your understanding of hierarchical event handling is correct. In your design the S1:TIMETICK transition will never be taken, because the nested transitions (S11:TIMETICK and S12:TIMETICK) will always "consume" the TIMETICK event, so that it will never "bubble up" to the S1 superstate.

    I attach a hierarchical state machine that does what you want. The change is that the two transitions (S11:TIMETICK and S12:TIMETICK) now have guard conditions, which are complementary to your guard on S1:TIMETICK. In that case, when a guard evaluates to false, the UML semantics requires the event to propagate up to the superstate (S1).

    The attached screen shot is from the free QM modeling tool. You can use this tool just to draw state diagrams, but you can also use it to generate code, which I would highly recommend over the error-prone process of manual coding state machines.

    --MMS

     
  • Javier Hidalgo

    Javier Hidalgo - 2019-02-10

    Thank you I can see it now. It is the same as in the "Exhaustive Example" figure 2.11. Then "counter " must be declared as an extended state variable.

     

Log in to post a comment.