Link Simulink Signal to App Designer (Lamp)

9 次查看(过去 30 天)
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'?

回答(1 个)

Nathan Gyger
Nathan Gyger 2019-10-9
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 个评论
Michael Jarboe
Michael Jarboe 2019-10-10
I will give this a try, thank you for the input! hopefully I can get the output :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multicore Processor Targets 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by