How can I run a real-time simulation multiple times consecutively from within MATLAB using Real-Time Windows Target?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 5 Aug. 2010
Bearbeitet: MathWorks Support Team
am 7 Okt. 2019
I have a Simulink model that I would like to run using Real-Time Windows Target. I want to run this model many times consecutively from a MATLAB file. The problem is that, after I start the simulation once, I need the MATLAB file to wait until the simulation is finished before it moves on. It does not do this automatically, since the simulation is started in external mode with the command:
set_param(gcs,'SimulationCommand','start')
If I use the PAUSE function, both the MATLAB file and the Simulink simulation pause. The functionality I require is for the MATLAB file to pause while the simulation continues to run.
Akzeptierte Antwort
MathWorks Support Team
am 7 Okt. 2019
Bearbeitet: MathWorks Support Team
am 7 Okt. 2019
The ability to pause execution of a MATLAB file without pausing an external Simulink simulation is not available in MATLAB.
To work around this issue, you can use either the KEYBOARD function or MATLAB timer objects.
Inserting the KEYBOARD command stops execution of the file and gives control to the keyboard, allowing the user to determine manually when to continue execution. This requires manual user input.
You can automate the required functionality using MATLAB timer functions. The WAIT function in MATLAB pauses execution of a MATLAB file while allowing a Simulink simulation to continue. Here is an example of how this could be done:
for j = 1:50
T = timer('TimerFcn',@init_sim); %initialize timer object
start(T) %start timer object running
end
function init_sim(obj,event) %timer object callback function
set_param(gcs,'SimulationMode','external') %simulate Simulink model
set_param(gcs,'SimulationCommand','connect')
set_param(gcs,'SimulationCommand','start')
wait(obj) %wait for timer object to stop running (occurs when simulation is finished)
end
In this example, you must stop the timer object using one of the "StopFcn" callback functions in the model. To do this, use the following command:
evalin('caller', 'stop(obj)')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects 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!