Using simulink runtime data in callback functions

2 vues (au cours des 30 derniers jours)
Kizito Amungwa Achembong
Kizito Amungwa Achembong le 19 Juil 2021
Hello, I am stressedup with App Designer. I have stateflow model in Simulink to be controlled from an app built in app designer. I am able to creat a Listener and a run time object in an updateGui helper function.
properties (Access = public)
status3; % Description
end
methods (Access = public)
function updateGUI(app, varargin)
% Create an object that gets the run-time value of the specified block
rto_2 = get_param('ChargingProcess/Display3','RuntimeObject');
rto1 = get_param('ChargingProcess/CarBatteryOut1','RuntimeObject');
% Update the GUI accordingly.
app.status3 = rto_2.InputPort(1).Data.char;
% app.EditField.Value = rto_2.InputPort(1).Data.char;
% Assign input from Car Battery Level(CarBatteryOut1) to Car Battery level 1 editfield
app.CarBatteryLevel1EditField.Value = rto1.InputPort(1).Data;
end
end
there are other objects which are not very necessary now
This works well and displays the information on the app as I want. Now, i need some of this information (status3) in a push button callback to control a a switch. First issue is that I cannot access the varriable status3 directly in a callback function. I treid to declear it as a property and call it in the button callback funtion. It is called but does not update as the simulation progresses.
The main idea is for the switch controlled by the button callback function to stay on '1' when the button is pressed to the point when status3 matches a particular string 'WaitAtStation' and a certain edith field vallue == 100. In this case, I used a while loop. I treid to output the edith field value (gotten from simulink too ) with the same callback funtion but it also does not update as the value in the edith field changes
striingValue = num2str(app.status3)
function Charge1ButtonPushed(app, event)
set_param('ChargingProcess/ChargeMyCar1','sw','1');
while (app.CarBatteryLevel1EditField.Value == 100 && strcmp(stringValue, ~'WaitAtStation'))
set_param('ChargingProcess/ChargeMyCar1','sw','0');
end
end
This either doesnt work or freezes my system when the button is pushed. What i actually need help is;
1) How to get status3 and the app.CarBatteryLevel1EditField.Value in my callback function that will update as the actuall vallues change in simulink
2) A better way represent the logic because the while loop appears not to be doing the job

Réponses (0)

Catégories

En savoir plus sur Complex Logic dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by