MATLAB: Link a GUI with Simulink

simulink gui

Hi everyone.
I have a problem which has been bugging me for some time now.
I am simulating vehicles movement, and want to display their movements on a GUI. Basically, I have two vehicles, one 'enemy and one 'friend' (which is supposed to intercept the enemy one), and a radar measuring the enemy position, and both vehicle is simulated trough a simulink model, to which i feed waypoints that vary over time.
Until now, i started simulatink the enemy vehicle, saved its trajectory data, then simulated the data measurement, and then simulated the 'friend' based on those measurements. Once ever thing was simulated and the data stored, i launched my GUI, which would load all this data and plot every thing.
I now need to make it all "real time". What i want to do is to launch both Simulink models at the beginning, and at each step of my loop, run one step of each model, do some computation to see if i need to update waypoints or not, and display the new position on my GUI.
Now comes the big problems:
  • Since i'm new to GUIs, i am not sure how to to all of this. For now, the OpeningFcn of my GUI loads the two Simulink models, and when i press a 'Start' button, runs a loop in which i continue/pause the programs. Is this the good approach, or should the Simulink and the GUI be decoupled ?
  • Then comes the big problem. I manage to communicate from the gui to Simulink, by setting waypoints, which basically are constant blocks. However, i can't resolve the problem of communicating from Simulink to my GUI, to get informations about my vehicles and compute the waypoints. I would like to use something like :
get_param('enemy_vehicle_model/Waypoint Tracking/isWaypointReached', 'Value')
Where isWaypointReached is either a MATLAB Function Block, or a ToWorkspace Block, but both don't have a Value parameter. I thought that using To Workspace blocks would be a good solution, but from my beginner point of view, it seems that the GUI works on a different workspace, and I don't see how to extract the data, even with evalin('base', …)
I have also read some documentations about the even listener, but it still is very obscure to me and i can't manage to use it for my case.
I hope someone will understand all this, and can help me 🙂
Thanks, Lilian

Best Answer

Most blocks in Simulink have a realtimeobject property from where you can get the run time value. If your block doesn't support runtimeobject, you can insert a gain block and fetch the runtime object from there. Refer here.
If you dont want to do even listening, you can pause the models at each sampletime, get the value using runtimeobject and poulate the GUI and continue simulation for one cycle and so on.