MATLAB Answers

Stateflow, Determine Initial State

2 views (last 30 days)
I'm using the stateflow toolbox to track and control the states of an external physical unit. I'm reading a feedback signal from the unit telling me which state it's in, and sending the correct command signal (depending on current state) to bring it to the next desired state. During startup of the system, the unit could be in any state. Basically, the initial state is unknown (must read feedback signal to determine it) since I'm not controlling it. What’s the best way to configure this in the Stateflow chart? Current solution is to have a dedicated "dummy" initial state, which (depending on value of feedback signal) transitions directly to the correct actual starting state of the unit. This clutters the chart a bit, and there’s probably a more elegant way. I could probably use transition tables, but can these be combined for example, so I use a chart like now, but a table just to get the starting state right?

  0 Comments

Sign in to comment.

Accepted Answer

Nicolas Schoonbroodt
Nicolas Schoonbroodt on 28 Sep 2020
It's also possible to use a junction: connect the default transition to a junction (a circle) and from that junction, have transition to the different possible initial state with conditions on these transition. (be sure to have one valid path to a default state in all cases)
State machine with several possible initial state

  3 Comments

André Hvatum
André Hvatum on 28 Sep 2020
Thanks! My goal was to avoid too many lines cluttering the chart. Hopefully it will work using a default transition to every state, with the relevant condition specified for each. And then a final default transition (highest execution order) without condition, to ensure handling of all cases, in case none of the other transitions trigger. Does this make sense?
Nicolas Schoonbroodt
Nicolas Schoonbroodt on 28 Sep 2020
Yes it makes a lot of sense. I would say that both approachs have positive and negative, but they are functionally equivalent.
As you say, the use of one defaut transition with multiple transition from that junction add a lot "cluttering" due to the many transitions, but in term of readability it has one advantage: there is only one default transition, meaning that it's easier for a reader to see all possible states starting from that point.
The many default transition has the exact opposite: less transitions polluting the chart, but a potential reader has to "find" all possible starting transition.
I think the choice between the two is more a preference matters (either personal preference, or company modeling guidance)
André Hvatum
André Hvatum on 28 Sep 2020
Thanks again for clarifying :)

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 24 Sep 2020
Use the default transition to pick any state as your initial state.

  1 Comment

André Hvatum
André Hvatum on 24 Sep 2020
Thanks! You mean add a "default transition" arrow to each of the states? I didn't think this would work since I didn't see how to add condition to it. But I see now this is straightforward... Will give it a try, thanks again!

Sign in to comment.

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!