Link Simulink Signal to App Designer (Lamp)

24 vues (au cours des 30 derniers jours)
Michael Jarboe
Michael Jarboe le 1 Oct 2019
Commenté : Michael Jarboe le 10 Oct 2019
Hello MatLab users,
I want to create an App that can control Inputs to my Simulink model and display signal values/status during simulation. PLEASE SEE ATTACHMENTS
Using App Designer and the Common Components - for most components you can create Callbacks - creates function NAME(app,event). When componet value changes - perform action. In my attachments - when the user changes the 'Ignition_Status' knob - the 'Ignition_Status' simulink block value changes.
function Ignition_StatusValueChanged(app,event)
value = app.Ignition_Status.Value;
if strcmp(value, 'Off')
% If Ignition_Status knob is changed to OFF --> Simulink 'Ignition_Status' Signal = 0
set_param('GUI_Interactive_Model/Ignition_Status','Value', '0');
elseif strcmp(value, 'Acc')
% If Ignition_Status knob is changed to Acc --> Simulink 'Ignition_Status' Signal = 2
set_param('GUI_Interactive_Model/Ignition_Status','Value', '2');
elseif strcmp(value, 'Run')
% If Ignition_Status knob is changed to Run --> Simulink 'Ignition_Status' Signal = 4
set_param('GUI_Interactive_Model/Ignition_Status','Value', '4');
elseif strcmp(value, 'Crank')
% If Ignition_Status knob is changed to Crank --> Simulink 'Ignition_Status' Signal = 8
set_param('GUI_Interactive_Model/Ignition_Status','Value', '8');
end
end
function func_lamp_status(app,Model)
% CODE DOES NOT WORK -- BUT I WANT TO PERFORM THIS ACTION -- PLEASE ADVISE!!!
% CONSTANTLY MONITOR SIGNAL -- OR -- APP IS NOTIFIED THAT Simulink Signal 'Power_Value' has CHANGED
value = get_param(['GUI_Interactive_Model/Power_Value'],'Value');
if value == 1
app.Lamp.Enable = 'on'; % TURN App LAMP ON
elseif value == 0
app.Lamp.Enable = 'off'; % TURN App LAMP OFF
end
end
end
In the Simulink Model - Output of the stateflow is the signal Power. In Simulink - I added a 'Lamp'. In "Block Parameters: Lamp" you can set the Color of the Lamp based on the State of a signal. When I run the simulation the Simulink Lamp correctly changes color based on the Output of the stateflow.
**** HOW CAN I LINK THE STATE of the Simulink Signal --> to app.Lamp.Enable 'on' or 'off'?

Réponses (1)

Nathan Gyger
Nathan Gyger le 9 Oct 2019
Hello Michael,
In order to have a periodical update of the UI, it is possible to create a timer object that is connected to a callback-function. The update interval can be set and then the specified callback-function is executed at this rate. Inside this function the status of the LED can be read with the get_param() command.
The timer class is explained here: https://mathworks.com/help/matlab/ref/timer-class.html
In addition, MathWorks as a nice example app that shows the concept. This app can be opened directly in MATLAB with the following command:
>> openExample('matlab/AppdMemoryMonitorExample')
I hope that this is helpful.
  1 commentaire
Michael Jarboe
Michael Jarboe le 10 Oct 2019
I will give this a try, thank you for the input! hopefully I can get the output :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by