Link Simulink Signal to App Designer (Lamp)
26 次查看(过去 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'?
0 个评论
回答(1 个)
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.
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!