Efficiently update MATLAB App Designer GUI real time from Simulink

43 Ansichten (letzte 30 Tage)
I have a Simulink model and a GUI made in app designer from which I control said model. So far I have been able to let the GUI and the Simulink model communicate both ways. The GUI sets parameter constant blocks in the model using set_param whereas the model updates the GUI through a callback using add_exec_event_listener. The GUI object resides in the model workspace.
In the startup callback of the model StartFcn I have the following code
set(0,'ShowHiddenHandles','on');
blk = [model '/q-log']; % Block to bind listener to
event = 'PostOutputs'; % Event to bind to (fired at every sample)
app = getVariable(get_param(bdroot,'ModelWorkspace'),'app'); % The GUI
% The GUI is passed into the event handler and updated at every timestep
listener = @(obj,event) updategui(obj,event,app);
h = add_exec_event_listener(blk, event, listener);
The problem with this setup is that it is extremely slow. I'm not quite sure how to get it faster and if this is the way to go. I've looked at a lot of examples but none detail my needs.
So my question is if there is a faster or more efficient way to update the GUI fields and plots? It doesn't have to be hard real time but writing variables to workspace and importing it into the GUI afterwards not is not acceptable.
  2 Kommentare
ying xiong
ying xiong am 28 Mai 2017
Hi, I have the same question with you, do you have any idea with this question now?
Chinna
Chinna am 6 Nov. 2023
Hi, I am also facing the issue. Can someone help me if there is a faster or more efficient way to update the GUI fields and plots?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Pablo Romero
Pablo Romero am 6 Okt. 2018
Bearbeitet: Stefanie Schwarz am 21 Dez. 2021
Hi Nick,
I suggest using the Simulink Real-Time API to update and tune parameters of the real-time application on run-time. Please check the documentation in the following link for a further explanation of the setparam command that will allow you to tune parameters more efficiently. https://www.mathworks.com/help/releases/R2020a/xpc/api/setparam.html
Using the standard Simulink commands get_param and set_param for tuning parameters is not recommended for a real-time application, because you have to update the model afterwards, what depending on the size and complexity of your model might take some time.
Hope this helps.
Cheers

Weitere Antworten (3)

ES
ES am 29 Mai 2017
one way is instead of event listners, you can let the model update the gui.
For example, pause the model every cycle, read the values using get_param, runtimeobject and update the gui from the pause function.
  2 Kommentare
Nick
Nick am 29 Mai 2017
In fact, it turns out that it is not possible at high sample rates. Doesn't matter where the update is carried out, be it through events or callbacks in Simulink. The appdesigner is just not designer to be updated at more than 20Hz.
Other than that, it works fine with any construct.
Camile van der Heijden
Camile van der Heijden am 31 Aug. 2017
Bearbeitet: Camile van der Heijden am 31 Aug. 2017
Hi Nick,
I have a very similar problem, where I was using a timer object within an appdesigner app to refresh a number of plots at 'high' refresh rates. Even at a 20 Hz frequency I'm running into severe stuttering/lag problems. I'm still using rather simple functions and a ODE model has yet to be incorporated. Did you finally manage to get your application working? If yes, how did you do it? (I'm currently debating rewriting everything in a different language, maybe Java or C++, even though I have very little experience in both.)
Regards

Melden Sie sich an, um zu kommentieren.


Muharrem Akkaya
Muharrem Akkaya am 13 Dez. 2018
Bearbeitet: Muharrem Akkaya am 13 Dez. 2018
Hey,
I am trying to do the exact same thing.
Can you share your code or explain how did you achieve?
Thanks
  1 Kommentar
Pablo Romero
Pablo Romero am 17 Dez. 2018
Hi Muharrem,
The combination of timer class and drawnow gives usually a fast refresh rate on GUIs with AppDesigner.
To avoid additional processing when updating or retrieving parameters for real-time simulation, I usually suggest using the getparam and setparam functions from the Simulink Real-Time API instead of other functions because they are more performant. Please note that they are different from the more common get_param and set_param commands.
To get and display signal values, you can use either getsignal to get single signal values or signal logging with SDI for a complete data logging.
Cheers
Pablo

Melden Sie sich an, um zu kommentieren.


Stefanie Schwarz
Stefanie Schwarz am 21 Dez. 2021
Bearbeitet: Stefanie Schwarz am 21 Dez. 2021

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by