Stateflow Statemachine not giving out the right output, Please Help

2 views (last 30 days)
I have a 16 state state machine that I build using Stateflow toolboxes statetable block. I have been testing this state machine for a couple weeks now and found out that although the resultant action of receiving an input from simulink x=23, while in State 11, is to change the State to State 7 and put out an output of y=33, the state machine puts out y=38. I have triple checked my code where it clearly says [x==23] {y=33} state 7. There are 3 other states that exhibit the same behavior and the rest of the machine works well. I have tried to test it, by coming to State 11 from many other states and conditions and every single time when it exits that state to state 7 because of an input of x=23, it sets y=38. The state machine itself is too big to be fit in one picture, so here are some zoomed in pictures on how the condition is set. The first picture shows the condition entry, second picture shows expected and received values. If you look at line 16 of that excel file, 23 was supposed to give 33 but it gave a 38. There are no conditions listed in state 11 that is supposed to give a 38. I also followed the state machine by running it step by step and saw with my own eyes to jump to State 11, get the 23 input and put out the 38 output where there is no such condition. Picture 1
  2 Comments
Ryan G
Ryan G on 27 Jun 2013
Where (if it exists) do you define y=38? Can you take a screenshot?
Is the Stateflow and Simulink stepper active? Can you visually see the transitions? Using the debugger/visualization, can you take a screenshot of the 3 steps (before/during/after) this problem?
Have you tried simplifying this? Removing states, see if it still does it and finding the minimum model that shows the issue.
Andy
Andy on 27 Jun 2013
Y=38 is triggered at
@State5 : [x==24||x==25] {y=38}-->State=7
@State6 : [x==24||x==25] {y=38}-->State=7
@State7 : [x==24] {y=38}-->State=Self
@State9 : [x==24||x==25] {y=38}-->State=12
@State12: [x==24] {y=38}-->State=Self
@State15: [x==24||x==25] {y=38}-->State=12
First picture you can see that the state machine is in state7 and is waiting for input, the input that is scheduled to go in is 23, which can be seen on the left data column. Also the x==23 then y=33 condition is circled in red. http://img132.imagevenue.com/img.php?image=356630115_1_122_493lo.jpg
On the second picture, we can see that the machine correctly went to State 7 as expected but gave an output of 38. All circled in red.

Sign in to comment.

Accepted Answer

Andy
Andy on 27 Jun 2013
After pondering for hours and trying different methods I figured out the problem and solved the issue. First thing I did was try to get the output without changing states, so I deleted the x==23 y=33 state=7 statement and just put an exclusive or statement to give me y=33 x==23. The output was correct. Then I forced the machine to move to a different state and check the output with x==23 y=33 State=8. The output was still wrong but it was different. Instead of 38, y was 35. There I realized that something was happening because of the state that we were going to. Then I realized that all my instate exclusive or functions had entry,du on them. I actually started them as entry and then added du for other reason. I realized that if the exclusive or function of the next state equals to the input of the previous state and entry was a part of the statement, the output changed to the entry statement of the next state instead of the during statement of the previous state like I wanted. Deleting "entry" command from all my exclusive or statements solved the problem.

More Answers (0)

Categories

Find more on Complex Logic in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!