Hello, I am a teacher who is working toward learning programming so I can pass that knowledge to my students. Please forgive me if my question is elementary, but I just started working with Simulink during last year's BEST competition. Before that, I'd never been exposed to coding with Simulink.

I have recently been trying to learn to write autonomous programs with state flow. The first state flow chart I wrote will work through several states, then stop for no reason that is apparent to me. I will attach images of the chart along with the image of the simulation. state flow.PNG 

state flow2.PNG 

The simulation shows that all of the states work up to the last travel state. The way the chart is written, I am trying to move in a square shape beginning at the top left corner, then travel diagonally to the lower right corner. I guess my question is: Why will all of the states work except the last "diagonal_travel" state? I've looked at syntax and can come up with nothing.

I'd appreciate any help with this.
Espy Smith
Early County High School
Quote 0 0

That's a great question. In fact, there was an example that I shared of a similar model in a Simulink webinar (recording is here) last year. Wondering if you followed that to get to this example.

In any case, based on the image of the Stateflow chart that you have above, I put together something similar that seems to work for me. Not sure exactly why in your case the state for diagonal travel is not executed. I cannot see any possible reason for it to fail execution, it most possibly is being executed but its output may not be visible in the XY plot window?

Could you try the model attached (Zip file) and let me know if this works for you? I have optimized the repetitive forward and turn motions to achieve the square with just 2 states. Then, the right side set of states achieve the diagonal turn and travel. Note 2 things here-
1) I use a diagonal turn value of 1.7/2 and that gives me half the turn angle of 90 degrees 
2) I use 2*sqrt(2) to get the travel to be equal to the diagonal length of the square...basic math

This should get me to the lower right corner of the square. See the simulation results in the GIF below:

You may have to adjust these values a little bit to make it work in your case but it should work after that. 
Let me know if this particular model works for you or not.

If you send me your particular model (.slx file) at, I can look at it in detail and get back to you.


Simulink model screenshots:

Quote 0 0
Sandeep, your program did work correctly for me. I really appreciate the help.

Currently, I am not at the point of writing programs that involve working with counts and am just trying to feel my way through simple programs that I can teach my students. I'd rather have them learn the basics before moving on to more complex functions.

With state flow, we are working to learn the different commands (i.e. entry;during;etc) before moving on to more advanced logic. In learning these more advanced functions, though, I plan to dissect your program to learn how the commands you used affect the function of the robot.

Thanks again,
Espy Smith
Quote 0 0
I understand the need to start with the basics for your team. Yes, feel free to use the model as you see fit. If you need help with designing more examples in the future, please post here. 

Good luck!
Quote 0 0

Add a Website Forum to your website.