Assertion block does not stop simulation if I run the model with “sim” function
Hi, I’m having issues with the Assertion block in Simulink when it comes to pause the current simulation.
Please refer to the following toy-example, which is enough to show the problem. Here, the assertion should be triggered after one second of simulation.
Here is what I’m trying to do:
Run the simulation programmatically, using a Matlab script
When a certain condition is met (here: after one seconds of simulation), pause the simulation in order to trigger the model callback "PauseFcn"
After performing some operations within the callback, resume the simulation
Following the documentation, I configured the Assertion block in order to monitor the desired condition and pause the model. Specifically, I set the Assertion block callback to:
set_param(bdroot,’SimulationCommand’,’pause’)
—————————————
If I run the model using Simulink GUI, everything works fine: the model pauses after one second and the "PauseFcn" callabck is executed.
However, if I run the model programmatically using
MyOut = sim("MyModelName");
Then the following happens:
The Assertion block triggers a warning after one second, as it should; the warning is dispayed in the Command Window
Despite this, the simulation does not pause: it proceeds beyond one second.
As an additional consequence, the model callback "PauseFcn" is not triggered (as confirmed by tracing the callbacks)
Do you have any suggestions?
I’m using Matlab R2024aHi, I’m having issues with the Assertion block in Simulink when it comes to pause the current simulation.
Please refer to the following toy-example, which is enough to show the problem. Here, the assertion should be triggered after one second of simulation.
Here is what I’m trying to do:
Run the simulation programmatically, using a Matlab script
When a certain condition is met (here: after one seconds of simulation), pause the simulation in order to trigger the model callback "PauseFcn"
After performing some operations within the callback, resume the simulation
Following the documentation, I configured the Assertion block in order to monitor the desired condition and pause the model. Specifically, I set the Assertion block callback to:
set_param(bdroot,’SimulationCommand’,’pause’)
—————————————
If I run the model using Simulink GUI, everything works fine: the model pauses after one second and the "PauseFcn" callabck is executed.
However, if I run the model programmatically using
MyOut = sim("MyModelName");
Then the following happens:
The Assertion block triggers a warning after one second, as it should; the warning is dispayed in the Command Window
Despite this, the simulation does not pause: it proceeds beyond one second.
As an additional consequence, the model callback "PauseFcn" is not triggered (as confirmed by tracing the callbacks)
Do you have any suggestions?
I’m using Matlab R2024a Hi, I’m having issues with the Assertion block in Simulink when it comes to pause the current simulation.
Please refer to the following toy-example, which is enough to show the problem. Here, the assertion should be triggered after one second of simulation.
Here is what I’m trying to do:
Run the simulation programmatically, using a Matlab script
When a certain condition is met (here: after one seconds of simulation), pause the simulation in order to trigger the model callback "PauseFcn"
After performing some operations within the callback, resume the simulation
Following the documentation, I configured the Assertion block in order to monitor the desired condition and pause the model. Specifically, I set the Assertion block callback to:
set_param(bdroot,’SimulationCommand’,’pause’)
—————————————
If I run the model using Simulink GUI, everything works fine: the model pauses after one second and the "PauseFcn" callabck is executed.
However, if I run the model programmatically using
MyOut = sim("MyModelName");
Then the following happens:
The Assertion block triggers a warning after one second, as it should; the warning is dispayed in the Command Window
Despite this, the simulation does not pause: it proceeds beyond one second.
As an additional consequence, the model callback "PauseFcn" is not triggered (as confirmed by tracing the callbacks)
Do you have any suggestions?
I’m using Matlab R2024a simulink, simulation, callback MATLAB Answers — New Questions