Filter löschen
Filter löschen

I cannot evaluate "pauseFcn" callback by using "sim" command

2 Ansichten (letzte 30 Tage)
Burak Bayca
Burak Bayca am 18 Apr. 2024
Verschoben: Fangjun Jiang am 7 Jun. 2024
Hello, I'm having issues with Simulink callbacks. I'm using MATLAB 2019a.
I have a Simulink model. I am adding a listener to an output of that model by using startFcn callback. I am expecting the model to pause when the output takes a specific value. I am implementing this algorithm inside the listener's callback function.
When I try this from Simulink by using "Run" button, the results are as expected, i.e., model pauses and the calculations are done within the "pauseFcn". But when I use "sim('myModel')" command in MATLAB, Simulink does not evaluate the pauseFcn even if the condition is triggered.
In addition, I traced the callbacks from command window. I see that, when I use 'Run' button, pauseFcn callback is triggered properly and commands in it are evaluated. However, when I use sim command, I see that pauseFcn callback is not triggered.
What should I do to make the model work corretly with sim command? Is this a bug?

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 20 Apr. 2024
A few things.
  1. Try SimOut=sim(). It used to be, that if there is no return variable specified, then the simulation won't log the output after the simulation is completed. Many questions have been asked before when user could not find the expected output in the base workspace after the simulation is completed. The latest document on sim() doesn't seem to show this tip or limitation anymore but try it anyway.
  2. It sounds like your listener is MATLAB code executed by the StartFcn callback. Depending on the methods used, I am not sure if it is able to monitor the output while the simulation is running using sim(). I know the simulation output data logging when using sim() is done when the simulation is completed, not while the simulation is running.
  3. You could consider adding this monitoring and action into the model using the Assertation block. https://www.mathworks.com/help/releases/R2019a/simulink/slref/assertion.html
  4. Or start from here to see if you can find a better way. https://www.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html

Kategorien

Mehr zu Event Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by